Index: test/cctest/test-weakmaps.cc |
diff --git a/test/cctest/test-weakmaps.cc b/test/cctest/test-weakmaps.cc |
index cd333d3846ec3d6c90e5470734c76875774664a8..714c8ccec28bf5fe1cfa554b46c09152ccece9fb 100644 |
--- a/test/cctest/test-weakmaps.cc |
+++ b/test/cctest/test-weakmaps.cc |
@@ -39,12 +39,14 @@ static Isolate* GetIsolateFrom(LocalContext* context) { |
} |
-static Handle<JSWeakMap> AllocateJSWeakMap() { |
- Handle<Map> map = FACTORY->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); |
- Handle<JSObject> weakmap_obj = FACTORY->NewJSObjectFromMap(map); |
+static Handle<JSWeakMap> AllocateJSWeakMap(Isolate* isolate) { |
+ Factory* factory = isolate->factory(); |
+ Heap* heap = isolate->heap(); |
+ Handle<Map> map = factory->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); |
+ Handle<JSObject> weakmap_obj = factory->NewJSObjectFromMap(map); |
Handle<JSWeakMap> weakmap(JSWeakMap::cast(*weakmap_obj)); |
// Do not use handles for the hash table, it would make entries strong. |
- Object* table_obj = ObjectHashTable::Allocate(1)->ToObjectChecked(); |
+ Object* table_obj = ObjectHashTable::Allocate(heap, 1)->ToObjectChecked(); |
ObjectHashTable* table = ObjectHashTable::cast(table_obj); |
weakmap->set_table(table); |
weakmap->set_next(Smi::FromInt(0)); |
@@ -74,16 +76,19 @@ static void WeakPointerCallback(v8::Isolate* isolate, |
TEST(Weakness) { |
FLAG_incremental_marking = false; |
LocalContext context; |
+ Isolate* isolate = GetIsolateFrom(&context); |
+ Factory* factory = isolate->factory(); |
+ Heap* heap = isolate->heap(); |
v8::HandleScope scope; |
- Handle<JSWeakMap> weakmap = AllocateJSWeakMap(); |
- GlobalHandles* global_handles = GetIsolateFrom(&context)->global_handles(); |
+ Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); |
+ GlobalHandles* global_handles = isolate->global_handles(); |
// Keep global reference to the key. |
Handle<Object> key; |
{ |
v8::HandleScope scope; |
- Handle<Map> map = FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
- Handle<JSObject> object = FACTORY->NewJSObjectFromMap(map); |
+ Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
+ Handle<JSObject> object = factory->NewJSObjectFromMap(map); |
key = global_handles->Create(*object); |
} |
CHECK(!global_handles->IsWeak(key.location())); |
@@ -93,12 +98,12 @@ TEST(Weakness) { |
v8::HandleScope scope; |
PutIntoWeakMap(weakmap, |
Handle<JSObject>(JSObject::cast(*key)), |
- Handle<Smi>(Smi::FromInt(23), GetIsolateFrom(&context))); |
+ Handle<Smi>(Smi::FromInt(23), isolate)); |
} |
CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
// Force a full GC. |
- HEAP->CollectAllGarbage(false); |
+ heap->CollectAllGarbage(false); |
CHECK_EQ(0, NumberOfWeakCalls); |
CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
CHECK_EQ( |
@@ -117,12 +122,12 @@ TEST(Weakness) { |
// Force a full GC. |
// Perform two consecutive GCs because the first one will only clear |
// weak references whereas the second one will also clear weak maps. |
- HEAP->CollectAllGarbage(false); |
+ heap->CollectAllGarbage(false); |
CHECK_EQ(1, NumberOfWeakCalls); |
CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
CHECK_EQ( |
0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); |
- HEAP->CollectAllGarbage(false); |
+ heap->CollectAllGarbage(false); |
CHECK_EQ(1, NumberOfWeakCalls); |
CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
CHECK_EQ( |
@@ -132,8 +137,11 @@ TEST(Weakness) { |
TEST(Shrinking) { |
LocalContext context; |
+ Isolate* isolate = GetIsolateFrom(&context); |
+ Factory* factory = isolate->factory(); |
+ Heap* heap = isolate->heap(); |
v8::HandleScope scope; |
- Handle<JSWeakMap> weakmap = AllocateJSWeakMap(); |
+ Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); |
// Check initial capacity. |
CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); |
@@ -141,11 +149,10 @@ TEST(Shrinking) { |
// Fill up weak map to trigger capacity change. |
{ |
v8::HandleScope scope; |
- Handle<Map> map = FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
+ Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
for (int i = 0; i < 32; i++) { |
- Handle<JSObject> object = FACTORY->NewJSObjectFromMap(map); |
- PutIntoWeakMap(weakmap, object, |
- Handle<Smi>(Smi::FromInt(i), GetIsolateFrom(&context))); |
+ Handle<JSObject> object = factory->NewJSObjectFromMap(map); |
+ PutIntoWeakMap(weakmap, object, Handle<Smi>(Smi::FromInt(i), isolate)); |
} |
} |
@@ -156,7 +163,7 @@ TEST(Shrinking) { |
CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
CHECK_EQ( |
0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); |
- HEAP->CollectAllGarbage(false); |
+ heap->CollectAllGarbage(false); |
CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
CHECK_EQ( |
32, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); |
@@ -171,22 +178,25 @@ TEST(Shrinking) { |
TEST(Regress2060a) { |
FLAG_always_compact = true; |
LocalContext context; |
+ Isolate* isolate = GetIsolateFrom(&context); |
+ Factory* factory = isolate->factory(); |
+ Heap* heap = isolate->heap(); |
v8::HandleScope scope; |
Handle<JSFunction> function = |
- FACTORY->NewFunction(FACTORY->function_string(), FACTORY->null_value()); |
- Handle<JSObject> key = FACTORY->NewJSObject(function); |
- Handle<JSWeakMap> weakmap = AllocateJSWeakMap(); |
+ factory->NewFunction(factory->function_string(), factory->null_value()); |
+ Handle<JSObject> key = factory->NewJSObject(function); |
+ Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); |
// Start second old-space page so that values land on evacuation candidate. |
- Page* first_page = HEAP->old_pointer_space()->anchor()->next_page(); |
- FACTORY->NewFixedArray(900 * KB / kPointerSize, TENURED); |
+ Page* first_page = heap->old_pointer_space()->anchor()->next_page(); |
+ factory->NewFixedArray(900 * KB / kPointerSize, TENURED); |
// Fill up weak map with values on an evacuation candidate. |
{ |
v8::HandleScope scope; |
for (int i = 0; i < 32; i++) { |
- Handle<JSObject> object = FACTORY->NewJSObject(function, TENURED); |
- CHECK(!HEAP->InNewSpace(object->address())); |
+ Handle<JSObject> object = factory->NewJSObject(function, TENURED); |
+ CHECK(!heap->InNewSpace(object->address())); |
CHECK(!first_page->Contains(object->address())); |
PutIntoWeakMap(weakmap, key, object); |
} |
@@ -194,7 +204,7 @@ TEST(Regress2060a) { |
// Force compacting garbage collection. |
CHECK(FLAG_always_compact); |
- HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
+ heap->CollectAllGarbage(Heap::kNoGCFlags); |
} |
@@ -207,32 +217,35 @@ TEST(Regress2060b) { |
#endif |
LocalContext context; |
+ Isolate* isolate = GetIsolateFrom(&context); |
+ Factory* factory = isolate->factory(); |
+ Heap* heap = isolate->heap(); |
v8::HandleScope scope; |
Handle<JSFunction> function = |
- FACTORY->NewFunction(FACTORY->function_string(), FACTORY->null_value()); |
+ factory->NewFunction(factory->function_string(), factory->null_value()); |
// Start second old-space page so that keys land on evacuation candidate. |
- Page* first_page = HEAP->old_pointer_space()->anchor()->next_page(); |
- FACTORY->NewFixedArray(900 * KB / kPointerSize, TENURED); |
+ Page* first_page = heap->old_pointer_space()->anchor()->next_page(); |
+ factory->NewFixedArray(900 * KB / kPointerSize, TENURED); |
// Fill up weak map with keys on an evacuation candidate. |
Handle<JSObject> keys[32]; |
for (int i = 0; i < 32; i++) { |
- keys[i] = FACTORY->NewJSObject(function, TENURED); |
- CHECK(!HEAP->InNewSpace(keys[i]->address())); |
+ keys[i] = factory->NewJSObject(function, TENURED); |
+ CHECK(!heap->InNewSpace(keys[i]->address())); |
CHECK(!first_page->Contains(keys[i]->address())); |
} |
- Handle<JSWeakMap> weakmap = AllocateJSWeakMap(); |
+ Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); |
for (int i = 0; i < 32; i++) { |
PutIntoWeakMap(weakmap, |
keys[i], |
- Handle<Smi>(Smi::FromInt(i), GetIsolateFrom(&context))); |
+ Handle<Smi>(Smi::FromInt(i), isolate)); |
} |
// Force compacting garbage collection. The subsequent collections are used |
// to verify that key references were actually updated. |
CHECK(FLAG_always_compact); |
- HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
- HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
- HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
+ heap->CollectAllGarbage(Heap::kNoGCFlags); |
+ heap->CollectAllGarbage(Heap::kNoGCFlags); |
+ heap->CollectAllGarbage(Heap::kNoGCFlags); |
} |