| Index: test/cctest/test-mark-compact.cc
|
| diff --git a/test/cctest/test-mark-compact.cc b/test/cctest/test-mark-compact.cc
|
| index 33d9230e01763b35f8841f395b3f8db2dd72913e..624969f45f09820ee4a22183e77f1431a1619e06 100644
|
| --- a/test/cctest/test-mark-compact.cc
|
| +++ b/test/cctest/test-mark-compact.cc
|
| @@ -77,13 +77,14 @@ TEST(Promotion) {
|
| // skip the entire test.
|
| if (FLAG_never_compact) return;
|
|
|
| + CcTest::InitializeVM();
|
| +
|
| // Ensure that we get a compacting collection so that objects are promoted
|
| // from new space.
|
| FLAG_gc_global = true;
|
| FLAG_always_compact = true;
|
| - HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB);
|
| -
|
| - CcTest::InitializeVM();
|
| + Heap* heap = CcTest::heap();
|
| + heap->ConfigureHeap(2*256*KB, 8*MB, 8*MB);
|
|
|
| v8::HandleScope sc(CcTest::isolate());
|
|
|
| @@ -91,49 +92,49 @@ TEST(Promotion) {
|
| int array_size =
|
| (Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) /
|
| (kPointerSize * 4);
|
| - Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked();
|
| + Object* obj = heap->AllocateFixedArray(array_size)->ToObjectChecked();
|
|
|
| Handle<FixedArray> array(FixedArray::cast(obj));
|
|
|
| // Array should be in the new space.
|
| - CHECK(HEAP->InSpace(*array, NEW_SPACE));
|
| + CHECK(heap->InSpace(*array, NEW_SPACE));
|
|
|
| // Call the m-c collector, so array becomes an old object.
|
| - HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
| + heap->CollectGarbage(OLD_POINTER_SPACE);
|
|
|
| // Array now sits in the old space
|
| - CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE));
|
| + CHECK(heap->InSpace(*array, OLD_POINTER_SPACE));
|
| }
|
|
|
|
|
| TEST(NoPromotion) {
|
| - HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB);
|
| -
|
| // Test the situation that some objects in new space are promoted to
|
| // the old space
|
| CcTest::InitializeVM();
|
|
|
| + CcTest::heap()->ConfigureHeap(2*256*KB, 8*MB, 8*MB);
|
| +
|
| v8::HandleScope sc(CcTest::isolate());
|
|
|
| // Do a mark compact GC to shrink the heap.
|
| - HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
| + CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE);
|
|
|
| // Allocate a big Fixed array in the new space.
|
| int length = (Page::kMaxNonCodeHeapObjectSize -
|
| FixedArray::kHeaderSize) / (2 * kPointerSize);
|
| - Object* obj = i::Isolate::Current()->heap()->AllocateFixedArray(length)->
|
| + Object* obj = CcTest::heap()->AllocateFixedArray(length)->
|
| ToObjectChecked();
|
|
|
| Handle<FixedArray> array(FixedArray::cast(obj));
|
|
|
| // Array still stays in the new space.
|
| - CHECK(HEAP->InSpace(*array, NEW_SPACE));
|
| + CHECK(CcTest::heap()->InSpace(*array, NEW_SPACE));
|
|
|
| // Allocate objects in the old space until out of memory.
|
| FixedArray* host = *array;
|
| while (true) {
|
| Object* obj;
|
| - { MaybeObject* maybe_obj = HEAP->AllocateFixedArray(100, TENURED);
|
| + { MaybeObject* maybe_obj = CcTest::heap()->AllocateFixedArray(100, TENURED);
|
| if (!maybe_obj->ToObject(&obj)) break;
|
| }
|
|
|
| @@ -142,17 +143,18 @@ TEST(NoPromotion) {
|
| }
|
|
|
| // Call mark compact GC, and it should pass.
|
| - HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
| + CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE);
|
| }
|
|
|
|
|
| TEST(MarkCompactCollector) {
|
| FLAG_incremental_marking = false;
|
| CcTest::InitializeVM();
|
| - Isolate* isolate = Isolate::Current();
|
| + Isolate* isolate = CcTest::i_isolate();
|
| Heap* heap = isolate->heap();
|
|
|
| v8::HandleScope sc(CcTest::isolate());
|
| + Handle<GlobalObject> global(isolate->context()->global_object());
|
|
|
| // call mark-compact when heap is empty
|
| heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1");
|
| @@ -191,8 +193,8 @@ TEST(MarkCompactCollector) {
|
| Map::cast(heap->AllocateMap(JS_OBJECT_TYPE,
|
| JSObject::kHeaderSize)->ToObjectChecked());
|
| function->set_initial_map(initial_map);
|
| - isolate->context()->global_object()->SetProperty(
|
| - func_name, function, NONE, kNonStrictMode)->ToObjectChecked();
|
| + JSReceiver::SetProperty(
|
| + global, handle(func_name), handle(function), NONE, kNonStrictMode);
|
|
|
| JSObject* obj = JSObject::cast(
|
| heap->AllocateJSObject(function)->ToObjectChecked());
|
| @@ -200,7 +202,7 @@ TEST(MarkCompactCollector) {
|
|
|
| func_name = String::cast(
|
| heap->InternalizeUtf8String("theFunction")->ToObjectChecked());
|
| - CHECK(isolate->context()->global_object()->HasLocalProperty(func_name));
|
| + CHECK(JSReceiver::HasLocalProperty(global, handle(func_name)));
|
| Object* func_value = isolate->context()->global_object()->
|
| GetProperty(func_name)->ToObjectChecked();
|
| CHECK(func_value->IsJSFunction());
|
| @@ -209,20 +211,19 @@ TEST(MarkCompactCollector) {
|
| obj = JSObject::cast(heap->AllocateJSObject(function)->ToObjectChecked());
|
| String* obj_name =
|
| String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked());
|
| - isolate->context()->global_object()->SetProperty(
|
| - obj_name, obj, NONE, kNonStrictMode)->ToObjectChecked();
|
| + JSReceiver::SetProperty(
|
| + global, handle(obj_name), handle(obj), NONE, kNonStrictMode);
|
| String* prop_name =
|
| String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked());
|
| - obj->SetProperty(prop_name,
|
| - Smi::FromInt(23),
|
| - NONE,
|
| - kNonStrictMode)->ToObjectChecked();
|
| + Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
|
| + JSReceiver::SetProperty(
|
| + handle(obj), handle(prop_name), twenty_three, NONE, kNonStrictMode);
|
|
|
| heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 5");
|
|
|
| obj_name =
|
| String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked());
|
| - CHECK(isolate->context()->global_object()->HasLocalProperty(obj_name));
|
| + CHECK(JSReceiver::HasLocalProperty(global, handle(obj_name)));
|
| CHECK(isolate->context()->global_object()->
|
| GetProperty(obj_name)->ToObjectChecked()->IsJSObject());
|
| obj = JSObject::cast(isolate->context()->global_object()->
|
| @@ -243,7 +244,7 @@ static Handle<Map> CreateMap(Isolate* isolate) {
|
| TEST(MapCompact) {
|
| FLAG_max_map_space_pages = 16;
|
| CcTest::InitializeVM();
|
| - Isolate* isolate = Isolate::Current();
|
| + Isolate* isolate = CcTest::i_isolate();
|
| Factory* factory = isolate->factory();
|
|
|
| {
|
| @@ -255,51 +256,18 @@ TEST(MapCompact) {
|
| Handle<Map> map = CreateMap();
|
| map->set_prototype(*root);
|
| root = factory->NewJSObjectFromMap(map);
|
| - } while (HEAP->map_space()->MapPointersEncodable());
|
| + } while (CcTest::heap()->map_space()->MapPointersEncodable());
|
| }
|
| // Now, as we don't have any handles to just allocated maps, we should
|
| // be able to trigger map compaction.
|
| // To give an additional chance to fail, try to force compaction which
|
| // should be impossible right now.
|
| - HEAP->CollectAllGarbage(Heap::kForceCompactionMask);
|
| + CcTest::heap()->CollectAllGarbage(Heap::kForceCompactionMask);
|
| // And now map pointers should be encodable again.
|
| - CHECK(HEAP->map_space()->MapPointersEncodable());
|
| + CHECK(CcTest::heap()->map_space()->MapPointersEncodable());
|
| }
|
| #endif
|
|
|
| -static int gc_starts = 0;
|
| -static int gc_ends = 0;
|
| -
|
| -static void GCPrologueCallbackFunc() {
|
| - CHECK(gc_starts == gc_ends);
|
| - gc_starts++;
|
| -}
|
| -
|
| -
|
| -static void GCEpilogueCallbackFunc() {
|
| - CHECK(gc_starts == gc_ends + 1);
|
| - gc_ends++;
|
| -}
|
| -
|
| -
|
| -TEST(GCCallback) {
|
| - i::FLAG_stress_compaction = false;
|
| - CcTest::InitializeVM();
|
| -
|
| - HEAP->SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc);
|
| - HEAP->SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc);
|
| -
|
| - // Scavenge does not call GC callback functions.
|
| - HEAP->PerformScavenge();
|
| -
|
| - CHECK_EQ(0, gc_starts);
|
| - CHECK_EQ(gc_ends, gc_starts);
|
| -
|
| - HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
| - CHECK_EQ(1, gc_starts);
|
| - CHECK_EQ(gc_ends, gc_starts);
|
| -}
|
| -
|
|
|
| static int NumberOfWeakCalls = 0;
|
| static void WeakPointerCallback(v8::Isolate* isolate,
|
| @@ -314,17 +282,17 @@ static void WeakPointerCallback(v8::Isolate* isolate,
|
| TEST(ObjectGroups) {
|
| FLAG_incremental_marking = false;
|
| CcTest::InitializeVM();
|
| - GlobalHandles* global_handles = Isolate::Current()->global_handles();
|
| -
|
| + GlobalHandles* global_handles = CcTest::i_isolate()->global_handles();
|
| + Heap* heap = CcTest::heap();
|
| NumberOfWeakCalls = 0;
|
| v8::HandleScope handle_scope(CcTest::isolate());
|
|
|
| Handle<Object> g1s1 =
|
| - global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
| + global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
| Handle<Object> g1s2 =
|
| - global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
| + global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
| Handle<Object> g1c1 =
|
| - global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
| + global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
| global_handles->MakeWeak(g1s1.location(),
|
| reinterpret_cast<void*>(1234),
|
| &WeakPointerCallback);
|
| @@ -336,11 +304,11 @@ TEST(ObjectGroups) {
|
| &WeakPointerCallback);
|
|
|
| Handle<Object> g2s1 =
|
| - global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
| + global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
| Handle<Object> g2s2 =
|
| - global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
| + global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
| Handle<Object> g2c1 =
|
| - global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
| + global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
| global_handles->MakeWeak(g2s1.location(),
|
| reinterpret_cast<void*>(1234),
|
| &WeakPointerCallback);
|
| @@ -370,7 +338,7 @@ TEST(ObjectGroups) {
|
| Handle<HeapObject>::cast(g2s1).location(), g2_children, 1);
|
| }
|
| // Do a full GC
|
| - HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
| + heap->CollectGarbage(OLD_POINTER_SPACE);
|
|
|
| // All object should be alive.
|
| CHECK_EQ(0, NumberOfWeakCalls);
|
| @@ -398,7 +366,7 @@ TEST(ObjectGroups) {
|
| Handle<HeapObject>::cast(g2s1).location(), g2_children, 1);
|
| }
|
|
|
| - HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
| + heap->CollectGarbage(OLD_POINTER_SPACE);
|
|
|
| // All objects should be gone. 5 global handles in total.
|
| CHECK_EQ(5, NumberOfWeakCalls);
|
| @@ -411,7 +379,7 @@ TEST(ObjectGroups) {
|
| reinterpret_cast<void*>(1234),
|
| &WeakPointerCallback);
|
|
|
| - HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
| + heap->CollectGarbage(OLD_POINTER_SPACE);
|
| CHECK_EQ(7, NumberOfWeakCalls);
|
| }
|
|
|
| @@ -442,12 +410,12 @@ class TestRetainedObjectInfo : public v8::RetainedObjectInfo {
|
|
|
| TEST(EmptyObjectGroups) {
|
| CcTest::InitializeVM();
|
| - GlobalHandles* global_handles = Isolate::Current()->global_handles();
|
| + GlobalHandles* global_handles = CcTest::i_isolate()->global_handles();
|
|
|
| v8::HandleScope handle_scope(CcTest::isolate());
|
|
|
| - Handle<Object> object =
|
| - global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
| + Handle<Object> object = global_handles->Create(
|
| + CcTest::heap()->AllocateFixedArray(1)->ToObjectChecked());
|
|
|
| TestRetainedObjectInfo info;
|
| global_handles->AddObjectGroup(NULL, 0, &info);
|
|
|