Upgrade to 3.29
Update V8 to 3.29.88.17 and update makefiles to support building on
all the relevant platforms.
Bug: 17370214
Change-Id: Ia3407c157fd8d72a93e23d8318ccaf6ecf77fa4e
diff --git a/test/cctest/test-dictionary.cc b/test/cctest/test-dictionary.cc
index 793e228..14e5d69 100644
--- a/test/cctest/test-dictionary.cc
+++ b/test/cctest/test-dictionary.cc
@@ -25,118 +25,230 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include "v8.h"
+#include "src/v8.h"
+#include "test/cctest/cctest.h"
-#include "api.h"
-#include "debug.h"
-#include "execution.h"
-#include "factory.h"
-#include "macro-assembler.h"
-#include "objects.h"
-#include "global-handles.h"
-#include "cctest.h"
+#include "src/api.h"
+#include "src/debug.h"
+#include "src/execution.h"
+#include "src/factory.h"
+#include "src/global-handles.h"
+#include "src/macro-assembler.h"
+#include "src/objects.h"
using namespace v8::internal;
+namespace {
-TEST(ObjectHashTable) {
- v8::HandleScope scope;
- LocalContext context;
- Handle<ObjectHashTable> table = FACTORY->NewObjectHashTable(23);
- Handle<JSObject> a = FACTORY->NewJSArray(7);
- Handle<JSObject> b = FACTORY->NewJSArray(11);
- table = PutIntoObjectHashTable(table, a, b);
+
+template<typename HashMap>
+static void TestHashMap(Handle<HashMap> table) {
+ Isolate* isolate = CcTest::i_isolate();
+ Factory* factory = isolate->factory();
+
+ Handle<JSObject> a = factory->NewJSArray(7);
+ Handle<JSObject> b = factory->NewJSArray(11);
+ table = HashMap::Put(table, a, b);
CHECK_EQ(table->NumberOfElements(), 1);
- CHECK_EQ(table->Lookup(*a), *b);
- CHECK_EQ(table->Lookup(*b), HEAP->undefined_value());
+ CHECK_EQ(table->Lookup(a), *b);
+ // When the key does not exist in the map, Lookup returns the hole.
+ CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value());
// Keys still have to be valid after objects were moved.
- HEAP->CollectGarbage(NEW_SPACE);
+ CcTest::heap()->CollectGarbage(NEW_SPACE);
CHECK_EQ(table->NumberOfElements(), 1);
- CHECK_EQ(table->Lookup(*a), *b);
- CHECK_EQ(table->Lookup(*b), HEAP->undefined_value());
+ CHECK_EQ(table->Lookup(a), *b);
+ CHECK_EQ(table->Lookup(b), CcTest::heap()->the_hole_value());
// Keys that are overwritten should not change number of elements.
- table = PutIntoObjectHashTable(table, a, FACTORY->NewJSArray(13));
+ table = HashMap::Put(table, a, factory->NewJSArray(13));
CHECK_EQ(table->NumberOfElements(), 1);
- CHECK_NE(table->Lookup(*a), *b);
+ CHECK_NE(table->Lookup(a), *b);
- // Keys mapped to undefined should be removed permanently.
- table = PutIntoObjectHashTable(table, a, FACTORY->undefined_value());
+ // Keys that have been removed are mapped to the hole.
+ bool was_present = false;
+ table = HashMap::Remove(table, a, &was_present);
+ CHECK(was_present);
CHECK_EQ(table->NumberOfElements(), 0);
- CHECK_EQ(table->NumberOfDeletedElements(), 1);
- CHECK_EQ(table->Lookup(*a), HEAP->undefined_value());
+ CHECK_EQ(table->Lookup(a), CcTest::heap()->the_hole_value());
// Keys should map back to their respective values and also should get
// an identity hash code generated.
for (int i = 0; i < 100; i++) {
- Handle<JSObject> key = FACTORY->NewJSArray(7);
- Handle<JSObject> value = FACTORY->NewJSArray(11);
- table = PutIntoObjectHashTable(table, key, value);
+ Handle<JSReceiver> key = factory->NewJSArray(7);
+ Handle<JSObject> value = factory->NewJSArray(11);
+ table = HashMap::Put(table, key, value);
CHECK_EQ(table->NumberOfElements(), i + 1);
- CHECK_NE(table->FindEntry(*key), ObjectHashTable::kNotFound);
- CHECK_EQ(table->Lookup(*key), *value);
- CHECK(key->GetIdentityHash(OMIT_CREATION)->ToObjectChecked()->IsSmi());
+ CHECK_NE(table->FindEntry(key), HashMap::kNotFound);
+ CHECK_EQ(table->Lookup(key), *value);
+ CHECK(key->GetIdentityHash()->IsSmi());
}
// Keys never added to the map which already have an identity hash
// code should not be found.
for (int i = 0; i < 100; i++) {
- Handle<JSObject> key = FACTORY->NewJSArray(7);
- CHECK(key->GetIdentityHash(ALLOW_CREATION)->ToObjectChecked()->IsSmi());
- CHECK_EQ(table->FindEntry(*key), ObjectHashTable::kNotFound);
- CHECK_EQ(table->Lookup(*key), HEAP->undefined_value());
- CHECK(key->GetIdentityHash(OMIT_CREATION)->ToObjectChecked()->IsSmi());
+ Handle<JSReceiver> key = factory->NewJSArray(7);
+ CHECK(JSReceiver::GetOrCreateIdentityHash(key)->IsSmi());
+ CHECK_EQ(table->FindEntry(key), HashMap::kNotFound);
+ CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value());
+ CHECK(key->GetIdentityHash()->IsSmi());
}
// Keys that don't have an identity hash should not be found and also
// should not get an identity hash code generated.
for (int i = 0; i < 100; i++) {
- Handle<JSObject> key = FACTORY->NewJSArray(7);
- CHECK_EQ(table->Lookup(*key), HEAP->undefined_value());
- CHECK_EQ(key->GetIdentityHash(OMIT_CREATION), HEAP->undefined_value());
+ Handle<JSReceiver> key = factory->NewJSArray(7);
+ CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value());
+ Object* identity_hash = key->GetIdentityHash();
+ CHECK_EQ(identity_hash, CcTest::heap()->undefined_value());
+ }
+}
+
+
+TEST(HashMap) {
+ LocalContext context;
+ v8::HandleScope scope(context->GetIsolate());
+ Isolate* isolate = CcTest::i_isolate();
+ TestHashMap(ObjectHashTable::New(isolate, 23));
+ TestHashMap(isolate->factory()->NewOrderedHashMap());
+}
+
+
+class ObjectHashTableTest: public ObjectHashTable {
+ public:
+ void insert(int entry, int key, int value) {
+ set(EntryToIndex(entry), Smi::FromInt(key));
+ set(EntryToIndex(entry) + 1, Smi::FromInt(value));
+ }
+
+ int lookup(int key) {
+ Handle<Object> key_obj(Smi::FromInt(key), GetIsolate());
+ return Smi::cast(Lookup(key_obj))->value();
+ }
+
+ int capacity() {
+ return Capacity();
+ }
+};
+
+
+TEST(HashTableRehash) {
+ LocalContext context;
+ Isolate* isolate = CcTest::i_isolate();
+ v8::HandleScope scope(context->GetIsolate());
+ // Test almost filled table.
+ {
+ Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 100);
+ ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table);
+ int capacity = t->capacity();
+ for (int i = 0; i < capacity - 1; i++) {
+ t->insert(i, i * i, i);
+ }
+ t->Rehash(handle(Smi::FromInt(0), isolate));
+ for (int i = 0; i < capacity - 1; i++) {
+ CHECK_EQ(i, t->lookup(i * i));
+ }
+ }
+ // Test half-filled table.
+ {
+ Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 100);
+ ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table);
+ int capacity = t->capacity();
+ for (int i = 0; i < capacity / 2; i++) {
+ t->insert(i, i * i, i);
+ }
+ t->Rehash(handle(Smi::FromInt(0), isolate));
+ for (int i = 0; i < capacity / 2; i++) {
+ CHECK_EQ(i, t->lookup(i * i));
+ }
}
}
#ifdef DEBUG
-TEST(ObjectHashSetCausesGC) {
- v8::HandleScope scope;
- LocalContext context;
- Handle<ObjectHashSet> table = FACTORY->NewObjectHashSet(1);
- Handle<JSObject> key = FACTORY->NewJSArray(0);
+template<class HashSet>
+static void TestHashSetCausesGC(Handle<HashSet> table) {
+ Isolate* isolate = CcTest::i_isolate();
+ Factory* factory = isolate->factory();
+
+ Handle<JSObject> key = factory->NewJSArray(0);
+ v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key);
+
+ // Force allocation of hash table backing store for hidden properties.
+ key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1"));
+ key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2"));
+ key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3"));
// Simulate a full heap so that generating an identity hash code
// in subsequent calls will request GC.
- FLAG_gc_interval = 0;
+ SimulateFullSpace(CcTest::heap()->new_space());
+ SimulateFullSpace(CcTest::heap()->old_pointer_space());
// Calling Contains() should not cause GC ever.
- CHECK(!table->Contains(*key));
+ int gc_count = isolate->heap()->gc_count();
+ CHECK(!table->Contains(key));
+ CHECK(gc_count == isolate->heap()->gc_count());
- // Calling Remove() should not cause GC ever.
- CHECK(!table->Remove(*key)->IsFailure());
+ // Calling Remove() will not cause GC in this case.
+ bool was_present = false;
+ table = HashSet::Remove(table, key, &was_present);
+ CHECK(!was_present);
+ CHECK(gc_count == isolate->heap()->gc_count());
- // Calling Add() should request GC by returning a failure.
- CHECK(table->Add(*key)->IsRetryAfterGC());
+ // Calling Add() should cause GC.
+ table = HashSet::Add(table, key);
+ CHECK(gc_count < isolate->heap()->gc_count());
+}
+
+
+TEST(ObjectHashSetCausesGC) {
+ i::FLAG_stress_compaction = false;
+ LocalContext context;
+ v8::HandleScope scope(context->GetIsolate());
+ Isolate* isolate = CcTest::i_isolate();
+ TestHashSetCausesGC(isolate->factory()->NewOrderedHashSet());
}
#endif
#ifdef DEBUG
-TEST(ObjectHashTableCausesGC) {
- v8::HandleScope scope;
- LocalContext context;
- Handle<ObjectHashTable> table = FACTORY->NewObjectHashTable(1);
- Handle<JSObject> key = FACTORY->NewJSArray(0);
+template<class HashMap>
+static void TestHashMapCausesGC(Handle<HashMap> table) {
+ Isolate* isolate = CcTest::i_isolate();
+ Factory* factory = isolate->factory();
+
+ Handle<JSObject> key = factory->NewJSArray(0);
+ v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key);
+
+ // Force allocation of hash table backing store for hidden properties.
+ key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1"));
+ key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2"));
+ key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3"));
// Simulate a full heap so that generating an identity hash code
// in subsequent calls will request GC.
- FLAG_gc_interval = 0;
+ SimulateFullSpace(CcTest::heap()->new_space());
+ SimulateFullSpace(CcTest::heap()->old_pointer_space());
// Calling Lookup() should not cause GC ever.
- CHECK(table->Lookup(*key)->IsUndefined());
+ CHECK(table->Lookup(key)->IsTheHole());
// Calling Put() should request GC by returning a failure.
- CHECK(table->Put(*key, *key)->IsRetryAfterGC());
+ int gc_count = isolate->heap()->gc_count();
+ HashMap::Put(table, key, key);
+ CHECK(gc_count < isolate->heap()->gc_count());
+}
+
+
+TEST(ObjectHashTableCausesGC) {
+ i::FLAG_stress_compaction = false;
+ LocalContext context;
+ v8::HandleScope scope(context->GetIsolate());
+ Isolate* isolate = CcTest::i_isolate();
+ TestHashMapCausesGC(ObjectHashTable::New(isolate, 1));
+ TestHashMapCausesGC(isolate->factory()->NewOrderedHashMap());
}
#endif
+
+
+}