Cleanup and speedup MarkCompactCollector test case.

R=bmeurer@chromium.org
TEST=cctest/test-mark-compact/MarkCompactCollector

Review URL: https://codereview.chromium.org/23112026

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16288 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
mstarzinger@chromium.org 2013-08-23 11:04:25 +00:00
parent 140ebd974e
commit af908ee5bc

View File

@ -147,86 +147,88 @@ TEST(NoPromotion) {
TEST(MarkCompactCollector) { TEST(MarkCompactCollector) {
FLAG_incremental_marking = false;
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
v8::HandleScope sc(CcTest::isolate()); v8::HandleScope sc(CcTest::isolate());
// call mark-compact when heap is empty // call mark-compact when heap is empty
HEAP->CollectGarbage(OLD_POINTER_SPACE); heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1");
// keep allocating garbage in new space until it fails // keep allocating garbage in new space until it fails
const int ARRAY_SIZE = 100; const int ARRAY_SIZE = 100;
Object* array; Object* array;
MaybeObject* maybe_array; MaybeObject* maybe_array;
do { do {
maybe_array = HEAP->AllocateFixedArray(ARRAY_SIZE); maybe_array = heap->AllocateFixedArray(ARRAY_SIZE);
} while (maybe_array->ToObject(&array)); } while (maybe_array->ToObject(&array));
HEAP->CollectGarbage(NEW_SPACE); heap->CollectGarbage(NEW_SPACE, "trigger 2");
array = HEAP->AllocateFixedArray(ARRAY_SIZE)->ToObjectChecked(); array = heap->AllocateFixedArray(ARRAY_SIZE)->ToObjectChecked();
// keep allocating maps until it fails // keep allocating maps until it fails
Object* mapp; Object* mapp;
MaybeObject* maybe_mapp; MaybeObject* maybe_mapp;
do { do {
maybe_mapp = HEAP->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); maybe_mapp = heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
} while (maybe_mapp->ToObject(&mapp)); } while (maybe_mapp->ToObject(&mapp));
HEAP->CollectGarbage(MAP_SPACE); heap->CollectGarbage(MAP_SPACE, "trigger 3");
mapp = HEAP->AllocateMap(JS_OBJECT_TYPE, mapp = heap->AllocateMap(JS_OBJECT_TYPE,
JSObject::kHeaderSize)->ToObjectChecked(); JSObject::kHeaderSize)->ToObjectChecked();
// allocate a garbage // allocate a garbage
String* func_name = String::cast( String* func_name = String::cast(
HEAP->InternalizeUtf8String("theFunction")->ToObjectChecked()); heap->InternalizeUtf8String("theFunction")->ToObjectChecked());
SharedFunctionInfo* function_share = SharedFunctionInfo::cast( SharedFunctionInfo* function_share = SharedFunctionInfo::cast(
HEAP->AllocateSharedFunctionInfo(func_name)->ToObjectChecked()); heap->AllocateSharedFunctionInfo(func_name)->ToObjectChecked());
JSFunction* function = JSFunction::cast( JSFunction* function = JSFunction::cast(
HEAP->AllocateFunction(*Isolate::Current()->function_map(), heap->AllocateFunction(*isolate->function_map(),
function_share, function_share,
HEAP->undefined_value())->ToObjectChecked()); heap->undefined_value())->ToObjectChecked());
Map* initial_map = Map* initial_map =
Map::cast(HEAP->AllocateMap(JS_OBJECT_TYPE, Map::cast(heap->AllocateMap(JS_OBJECT_TYPE,
JSObject::kHeaderSize)->ToObjectChecked()); JSObject::kHeaderSize)->ToObjectChecked());
function->set_initial_map(initial_map); function->set_initial_map(initial_map);
Isolate::Current()->context()->global_object()->SetProperty( isolate->context()->global_object()->SetProperty(
func_name, function, NONE, kNonStrictMode)->ToObjectChecked(); func_name, function, NONE, kNonStrictMode)->ToObjectChecked();
JSObject* obj = JSObject::cast( JSObject* obj = JSObject::cast(
HEAP->AllocateJSObject(function)->ToObjectChecked()); heap->AllocateJSObject(function)->ToObjectChecked());
HEAP->CollectGarbage(OLD_POINTER_SPACE); heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 4");
func_name = String::cast( func_name = String::cast(
HEAP->InternalizeUtf8String("theFunction")->ToObjectChecked()); heap->InternalizeUtf8String("theFunction")->ToObjectChecked());
CHECK(Isolate::Current()->context()->global_object()-> CHECK(isolate->context()->global_object()->HasLocalProperty(func_name));
HasLocalProperty(func_name)); Object* func_value = isolate->context()->global_object()->
Object* func_value = Isolate::Current()->context()->global_object()->
GetProperty(func_name)->ToObjectChecked(); GetProperty(func_name)->ToObjectChecked();
CHECK(func_value->IsJSFunction()); CHECK(func_value->IsJSFunction());
function = JSFunction::cast(func_value); function = JSFunction::cast(func_value);
obj = JSObject::cast(HEAP->AllocateJSObject(function)->ToObjectChecked()); obj = JSObject::cast(heap->AllocateJSObject(function)->ToObjectChecked());
String* obj_name = String* obj_name =
String::cast(HEAP->InternalizeUtf8String("theObject")->ToObjectChecked()); String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked());
Isolate::Current()->context()->global_object()->SetProperty( isolate->context()->global_object()->SetProperty(
obj_name, obj, NONE, kNonStrictMode)->ToObjectChecked(); obj_name, obj, NONE, kNonStrictMode)->ToObjectChecked();
String* prop_name = String* prop_name =
String::cast(HEAP->InternalizeUtf8String("theSlot")->ToObjectChecked()); String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked());
obj->SetProperty(prop_name, obj->SetProperty(prop_name,
Smi::FromInt(23), Smi::FromInt(23),
NONE, NONE,
kNonStrictMode)->ToObjectChecked(); kNonStrictMode)->ToObjectChecked();
HEAP->CollectGarbage(OLD_POINTER_SPACE); heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 5");
obj_name = obj_name =
String::cast(HEAP->InternalizeUtf8String("theObject")->ToObjectChecked()); String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked());
CHECK(Isolate::Current()->context()->global_object()-> CHECK(isolate->context()->global_object()->HasLocalProperty(obj_name));
HasLocalProperty(obj_name)); CHECK(isolate->context()->global_object()->
CHECK(Isolate::Current()->context()->global_object()->
GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); GetProperty(obj_name)->ToObjectChecked()->IsJSObject());
obj = JSObject::cast(Isolate::Current()->context()->global_object()-> obj = JSObject::cast(isolate->context()->global_object()->
GetProperty(obj_name)->ToObjectChecked()); GetProperty(obj_name)->ToObjectChecked());
prop_name = prop_name =
String::cast(HEAP->InternalizeUtf8String("theSlot")->ToObjectChecked()); String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked());
CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23)); CHECK(obj->GetProperty(prop_name) == Smi::FromInt(23));
} }