Index: test/cctest/test-mark-compact.cc |
=================================================================== |
--- test/cctest/test-mark-compact.cc (revision 7267) |
+++ test/cctest/test-mark-compact.cc (working copy) |
@@ -31,7 +31,6 @@ |
#include "global-handles.h" |
#include "snapshot.h" |
-#include "top.h" |
#include "cctest.h" |
using namespace v8::internal; |
@@ -79,7 +78,7 @@ |
// from new space. |
FLAG_gc_global = true; |
FLAG_always_compact = true; |
- Heap::ConfigureHeap(2*256*KB, 4*MB, 4*MB); |
+ HEAP->ConfigureHeap(2*256*KB, 4*MB, 4*MB); |
InitializeVM(); |
@@ -87,25 +86,25 @@ |
// Allocate a fixed array in the new space. |
int array_size = |
- (Heap::MaxObjectSizeInPagedSpace() - FixedArray::kHeaderSize) / |
+ (HEAP->MaxObjectSizeInPagedSpace() - 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, 4*MB, 4*MB); |
+ HEAP->ConfigureHeap(2*256*KB, 4*MB, 4*MB); |
// Test the situation that some objects in new space are promoted to |
// the old space |
@@ -114,23 +113,23 @@ |
v8::HandleScope sc; |
// Do a mark compact GC to shrink the heap. |
- Heap::CollectGarbage(OLD_POINTER_SPACE); |
+ HEAP->CollectGarbage(OLD_POINTER_SPACE); |
// Allocate a big Fixed array in the new space. |
- int size = (Heap::MaxObjectSizeInPagedSpace() - FixedArray::kHeaderSize) / |
+ int size = (HEAP->MaxObjectSizeInPagedSpace() - FixedArray::kHeaderSize) / |
kPointerSize; |
- Object* obj = Heap::AllocateFixedArray(size)->ToObjectChecked(); |
+ Object* obj = HEAP->AllocateFixedArray(size)->ToObjectChecked(); |
Handle<FixedArray> array(FixedArray::cast(obj)); |
// Array still stays in the new space. |
- CHECK(Heap::InSpace(*array, NEW_SPACE)); |
+ CHECK(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 = HEAP->AllocateFixedArray(100, TENURED); |
if (!maybe_obj->ToObject(&obj)) break; |
} |
@@ -139,10 +138,10 @@ |
} |
// Call mark compact GC, and it should pass. |
- Heap::CollectGarbage(OLD_POINTER_SPACE); |
+ HEAP->CollectGarbage(OLD_POINTER_SPACE); |
// array should not be promoted because the old space is full. |
- CHECK(Heap::InSpace(*array, NEW_SPACE)); |
+ CHECK(HEAP->InSpace(*array, NEW_SPACE)); |
} |
@@ -151,90 +150,86 @@ |
v8::HandleScope sc; |
// call mark-compact when heap is empty |
- Heap::CollectGarbage(OLD_POINTER_SPACE); |
+ HEAP->CollectGarbage(OLD_POINTER_SPACE); |
// keep allocating garbage in new space until it fails |
const int ARRAY_SIZE = 100; |
Object* array; |
MaybeObject* maybe_array; |
do { |
- maybe_array = Heap::AllocateFixedArray(ARRAY_SIZE); |
+ maybe_array = HEAP->AllocateFixedArray(ARRAY_SIZE); |
} while (maybe_array->ToObject(&array)); |
- Heap::CollectGarbage(NEW_SPACE); |
+ HEAP->CollectGarbage(NEW_SPACE); |
- array = Heap::AllocateFixedArray(ARRAY_SIZE)->ToObjectChecked(); |
+ array = HEAP->AllocateFixedArray(ARRAY_SIZE)->ToObjectChecked(); |
// keep allocating maps until it fails |
Object* mapp; |
MaybeObject* maybe_mapp; |
do { |
- maybe_mapp = Heap::AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
+ maybe_mapp = HEAP->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
} while (maybe_mapp->ToObject(&mapp)); |
- Heap::CollectGarbage(MAP_SPACE); |
- mapp = Heap::AllocateMap(JS_OBJECT_TYPE, |
+ HEAP->CollectGarbage(MAP_SPACE); |
+ mapp = HEAP->AllocateMap(JS_OBJECT_TYPE, |
JSObject::kHeaderSize)->ToObjectChecked(); |
// allocate a garbage |
String* func_name = |
- String::cast(Heap::LookupAsciiSymbol("theFunction")->ToObjectChecked()); |
+ String::cast(HEAP->LookupAsciiSymbol("theFunction")->ToObjectChecked()); |
SharedFunctionInfo* function_share = SharedFunctionInfo::cast( |
- Heap::AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); |
+ HEAP->AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); |
JSFunction* function = JSFunction::cast( |
- Heap::AllocateFunction(*Top::function_map(), |
+ HEAP->AllocateFunction(*Isolate::Current()->function_map(), |
function_share, |
- Heap::undefined_value())->ToObjectChecked()); |
+ HEAP->undefined_value())->ToObjectChecked()); |
Map* initial_map = |
- Map::cast(Heap::AllocateMap(JS_OBJECT_TYPE, |
+ Map::cast(HEAP->AllocateMap(JS_OBJECT_TYPE, |
JSObject::kHeaderSize)->ToObjectChecked()); |
function->set_initial_map(initial_map); |
- Top::context()->global()->SetProperty(func_name, |
- function, |
- NONE, |
- kNonStrictMode)->ToObjectChecked(); |
+ Isolate::Current()->context()->global()->SetProperty( |
+ func_name, function, NONE, kNonStrictMode)->ToObjectChecked(); |
- JSObject* obj = |
- JSObject::cast(Heap::AllocateJSObject(function)->ToObjectChecked()); |
- Heap::CollectGarbage(OLD_POINTER_SPACE); |
+ JSObject* obj = JSObject::cast( |
+ HEAP->AllocateJSObject(function)->ToObjectChecked()); |
+ HEAP->CollectGarbage(OLD_POINTER_SPACE); |
func_name = |
- String::cast(Heap::LookupAsciiSymbol("theFunction")->ToObjectChecked()); |
- CHECK(Top::context()->global()->HasLocalProperty(func_name)); |
- Object* func_value = |
- Top::context()->global()->GetProperty(func_name)->ToObjectChecked(); |
+ String::cast(HEAP->LookupAsciiSymbol("theFunction")->ToObjectChecked()); |
+ CHECK(Isolate::Current()->context()->global()->HasLocalProperty(func_name)); |
+ Object* func_value = Isolate::Current()->context()->global()-> |
+ GetProperty(func_name)->ToObjectChecked(); |
CHECK(func_value->IsJSFunction()); |
function = JSFunction::cast(func_value); |
- obj = JSObject::cast(Heap::AllocateJSObject(function)->ToObjectChecked()); |
+ obj = JSObject::cast(HEAP->AllocateJSObject(function)->ToObjectChecked()); |
String* obj_name = |
- String::cast(Heap::LookupAsciiSymbol("theObject")->ToObjectChecked()); |
- Top::context()->global()->SetProperty(obj_name, |
- obj, |
- NONE, |
- kNonStrictMode)->ToObjectChecked(); |
+ String::cast(HEAP->LookupAsciiSymbol("theObject")->ToObjectChecked()); |
+ Isolate::Current()->context()->global()->SetProperty( |
+ obj_name, obj, NONE, kNonStrictMode)->ToObjectChecked(); |
String* prop_name = |
- String::cast(Heap::LookupAsciiSymbol("theSlot")->ToObjectChecked()); |
+ String::cast(HEAP->LookupAsciiSymbol("theSlot")->ToObjectChecked()); |
obj->SetProperty(prop_name, |
Smi::FromInt(23), |
NONE, |
kNonStrictMode)->ToObjectChecked(); |
- Heap::CollectGarbage(OLD_POINTER_SPACE); |
+ HEAP->CollectGarbage(OLD_POINTER_SPACE); |
obj_name = |
- String::cast(Heap::LookupAsciiSymbol("theObject")->ToObjectChecked()); |
- CHECK(Top::context()->global()->HasLocalProperty(obj_name)); |
- CHECK(Top::context()->global()-> |
- GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); |
- obj = JSObject::cast( |
- Top::context()->global()->GetProperty(obj_name)->ToObjectChecked()); |
+ String::cast(HEAP->LookupAsciiSymbol("theObject")->ToObjectChecked()); |
+ CHECK(Isolate::Current()->context()->global()->HasLocalProperty(obj_name)); |
+ CHECK(Isolate::Current()->context()->global()-> |
+ GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); |
+ obj = JSObject::cast(Isolate::Current()->context()->global()-> |
+ GetProperty(obj_name)->ToObjectChecked()); |
prop_name = |
- String::cast(Heap::LookupAsciiSymbol("theSlot")->ToObjectChecked()); |
- CHECK(obj->GetProperty(prop_name)->ToObjectChecked() == Smi::FromInt(23)); |
+ String::cast(HEAP->LookupAsciiSymbol("theSlot")->ToObjectChecked()); |
+ CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); |
} |
static Handle<Map> CreateMap() { |
- return Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
+ return FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
} |
@@ -246,20 +241,20 @@ |
v8::HandleScope sc; |
// keep allocating maps while pointers are still encodable and thus |
// mark compact is permitted. |
- Handle<JSObject> root = Factory::NewJSObjectFromMap(CreateMap()); |
+ Handle<JSObject> root = FACTORY->NewJSObjectFromMap(CreateMap()); |
do { |
Handle<Map> map = CreateMap(); |
map->set_prototype(*root); |
- root = Factory::NewJSObjectFromMap(map); |
- } while (Heap::map_space()->MapPointersEncodable()); |
+ root = FACTORY->NewJSObjectFromMap(map); |
+ } while (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(true); |
+ HEAP->CollectAllGarbage(true); |
// And now map pointers should be encodable again. |
- CHECK(Heap::map_space()->MapPointersEncodable()); |
+ CHECK(HEAP->map_space()->MapPointersEncodable()); |
} |
@@ -281,16 +276,16 @@ |
TEST(GCCallback) { |
InitializeVM(); |
- Heap::SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc); |
- Heap::SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc); |
+ HEAP->SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc); |
+ HEAP->SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc); |
// Scavenge does not call GC callback functions. |
- Heap::PerformScavenge(); |
+ HEAP->PerformScavenge(); |
CHECK_EQ(0, gc_starts); |
CHECK_EQ(gc_ends, gc_starts); |
- Heap::CollectGarbage(OLD_POINTER_SPACE); |
+ HEAP->CollectGarbage(OLD_POINTER_SPACE); |
CHECK_EQ(1, gc_starts); |
CHECK_EQ(gc_ends, gc_starts); |
} |
@@ -304,44 +299,45 @@ |
} |
TEST(ObjectGroups) { |
+ GlobalHandles* global_handles = Isolate::Current()->global_handles(); |
InitializeVM(); |
NumberOfWeakCalls = 0; |
v8::HandleScope handle_scope; |
Handle<Object> g1s1 = |
- GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); |
+ global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
Handle<Object> g1s2 = |
- GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); |
+ global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
Handle<Object> g1c1 = |
- GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); |
- GlobalHandles::MakeWeak(g1s1.location(), |
- reinterpret_cast<void*>(1234), |
- &WeakPointerCallback); |
- GlobalHandles::MakeWeak(g1s2.location(), |
- reinterpret_cast<void*>(1234), |
- &WeakPointerCallback); |
- GlobalHandles::MakeWeak(g1c1.location(), |
- reinterpret_cast<void*>(1234), |
- &WeakPointerCallback); |
+ global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
+ global_handles->MakeWeak(g1s1.location(), |
+ reinterpret_cast<void*>(1234), |
+ &WeakPointerCallback); |
+ global_handles->MakeWeak(g1s2.location(), |
+ reinterpret_cast<void*>(1234), |
+ &WeakPointerCallback); |
+ global_handles->MakeWeak(g1c1.location(), |
+ reinterpret_cast<void*>(1234), |
+ &WeakPointerCallback); |
Handle<Object> g2s1 = |
- GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); |
+ global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
Handle<Object> g2s2 = |
- GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); |
+ global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
Handle<Object> g2c1 = |
- GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); |
- GlobalHandles::MakeWeak(g2s1.location(), |
- reinterpret_cast<void*>(1234), |
- &WeakPointerCallback); |
- GlobalHandles::MakeWeak(g2s2.location(), |
- reinterpret_cast<void*>(1234), |
- &WeakPointerCallback); |
- GlobalHandles::MakeWeak(g2c1.location(), |
- reinterpret_cast<void*>(1234), |
- &WeakPointerCallback); |
+ global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
+ global_handles->MakeWeak(g2s1.location(), |
+ reinterpret_cast<void*>(1234), |
+ &WeakPointerCallback); |
+ global_handles->MakeWeak(g2s2.location(), |
+ reinterpret_cast<void*>(1234), |
+ &WeakPointerCallback); |
+ global_handles->MakeWeak(g2c1.location(), |
+ reinterpret_cast<void*>(1234), |
+ &WeakPointerCallback); |
- Handle<Object> root = GlobalHandles::Create(*g1s1); // make a root. |
+ Handle<Object> root = global_handles->Create(*g1s1); // make a root. |
// Connect group 1 and 2, make a cycle. |
Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
@@ -352,27 +348,27 @@ |
Object** g1_children[] = { g1c1.location() }; |
Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
Object** g2_children[] = { g2c1.location() }; |
- GlobalHandles::AddObjectGroup(g1_objects, 2, NULL); |
- GlobalHandles::AddImplicitReferences(HeapObject::cast(*g1s1), |
- g1_children, 1); |
- GlobalHandles::AddObjectGroup(g2_objects, 2, NULL); |
- GlobalHandles::AddImplicitReferences(HeapObject::cast(*g2s2), |
- g2_children, 1); |
+ global_handles->AddObjectGroup(g1_objects, 2, NULL); |
+ global_handles->AddImplicitReferences(HeapObject::cast(*g1s1), |
+ g1_children, 1); |
+ global_handles->AddObjectGroup(g2_objects, 2, NULL); |
+ global_handles->AddImplicitReferences(HeapObject::cast(*g2s2), |
+ 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); |
// Weaken the root. |
- GlobalHandles::MakeWeak(root.location(), |
- reinterpret_cast<void*>(1234), |
- &WeakPointerCallback); |
+ global_handles->MakeWeak(root.location(), |
+ reinterpret_cast<void*>(1234), |
+ &WeakPointerCallback); |
// But make children strong roots---all the objects (except for children) |
// should be collectable now. |
- GlobalHandles::ClearWeakness(g1c1.location()); |
- GlobalHandles::ClearWeakness(g2c1.location()); |
+ global_handles->ClearWeakness(g1c1.location()); |
+ global_handles->ClearWeakness(g2c1.location()); |
// Groups are deleted, rebuild groups. |
{ |
@@ -380,27 +376,27 @@ |
Object** g1_children[] = { g1c1.location() }; |
Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
Object** g2_children[] = { g2c1.location() }; |
- GlobalHandles::AddObjectGroup(g1_objects, 2, NULL); |
- GlobalHandles::AddImplicitReferences(HeapObject::cast(*g1s1), |
+ global_handles->AddObjectGroup(g1_objects, 2, NULL); |
+ global_handles->AddImplicitReferences(HeapObject::cast(*g1s1), |
g1_children, 1); |
- GlobalHandles::AddObjectGroup(g2_objects, 2, NULL); |
- GlobalHandles::AddImplicitReferences(HeapObject::cast(*g2s2), |
+ global_handles->AddObjectGroup(g2_objects, 2, NULL); |
+ global_handles->AddImplicitReferences(HeapObject::cast(*g2s2), |
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); |
// And now make children weak again and collect them. |
- GlobalHandles::MakeWeak(g1c1.location(), |
- reinterpret_cast<void*>(1234), |
- &WeakPointerCallback); |
- GlobalHandles::MakeWeak(g2c1.location(), |
- reinterpret_cast<void*>(1234), |
- &WeakPointerCallback); |
+ global_handles->MakeWeak(g1c1.location(), |
+ reinterpret_cast<void*>(1234), |
+ &WeakPointerCallback); |
+ global_handles->MakeWeak(g2c1.location(), |
+ reinterpret_cast<void*>(1234), |
+ &WeakPointerCallback); |
- Heap::CollectGarbage(OLD_POINTER_SPACE); |
+ HEAP->CollectGarbage(OLD_POINTER_SPACE); |
CHECK_EQ(7, NumberOfWeakCalls); |
} |