Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: test/cctest/test-heap.cc

Issue 6685088: Merge isolates to bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-func-name-inference.cc ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-heap.cc
===================================================================
--- test/cctest/test-heap.cc (revision 7267)
+++ test/cctest/test-heap.cc (working copy)
@@ -24,9 +24,9 @@
static void CheckMap(Map* map, int type, int instance_size) {
CHECK(map->IsHeapObject());
#ifdef DEBUG
- CHECK(Heap::Contains(map));
+ CHECK(HEAP->Contains(map));
#endif
- CHECK_EQ(Heap::meta_map(), map->map());
+ CHECK_EQ(HEAP->meta_map(), map->map());
CHECK_EQ(type, map->instance_type());
CHECK_EQ(instance_size, map->instance_size());
}
@@ -34,10 +34,10 @@
TEST(HeapMaps) {
InitializeVM();
- CheckMap(Heap::meta_map(), MAP_TYPE, Map::kSize);
- CheckMap(Heap::heap_number_map(), HEAP_NUMBER_TYPE, HeapNumber::kSize);
- CheckMap(Heap::fixed_array_map(), FIXED_ARRAY_TYPE, kVariableSizeSentinel);
- CheckMap(Heap::string_map(), STRING_TYPE, kVariableSizeSentinel);
+ CheckMap(HEAP->meta_map(), MAP_TYPE, Map::kSize);
+ CheckMap(HEAP->heap_number_map(), HEAP_NUMBER_TYPE, HeapNumber::kSize);
+ CheckMap(HEAP->fixed_array_map(), FIXED_ARRAY_TYPE, kVariableSizeSentinel);
+ CheckMap(HEAP->string_map(), STRING_TYPE, kVariableSizeSentinel);
}
@@ -58,7 +58,7 @@
static void CheckNumber(double value, const char* string) {
- Object* obj = Heap::NumberFromDouble(value)->ToObjectChecked();
+ Object* obj = HEAP->NumberFromDouble(value)->ToObjectChecked();
CHECK(obj->IsNumber());
bool exc;
Object* print_string = *Execution::ToString(Handle<Object>(obj), &exc);
@@ -76,27 +76,27 @@
CodeDesc desc;
assm.GetCode(&desc);
- Object* code = Heap::CreateCode(
+ Object* code = HEAP->CreateCode(
desc,
Code::ComputeFlags(Code::STUB),
- Handle<Object>(Heap::undefined_value()))->ToObjectChecked();
+ Handle<Object>(HEAP->undefined_value()))->ToObjectChecked();
CHECK(code->IsCode());
HeapObject* obj = HeapObject::cast(code);
Address obj_addr = obj->address();
for (int i = 0; i < obj->Size(); i += kPointerSize) {
- Object* found = Heap::FindCodeObject(obj_addr + i);
+ Object* found = HEAP->FindCodeObject(obj_addr + i);
CHECK_EQ(code, found);
}
- Object* copy = Heap::CreateCode(
+ Object* copy = HEAP->CreateCode(
desc,
Code::ComputeFlags(Code::STUB),
- Handle<Object>(Heap::undefined_value()))->ToObjectChecked();
+ Handle<Object>(HEAP->undefined_value()))->ToObjectChecked();
CHECK(copy->IsCode());
HeapObject* obj_copy = HeapObject::cast(copy);
- Object* not_right = Heap::FindCodeObject(obj_copy->address() +
+ Object* not_right = HEAP->FindCodeObject(obj_copy->address() +
obj_copy->Size() / 2);
CHECK(not_right != code);
}
@@ -106,41 +106,41 @@
InitializeVM();
v8::HandleScope sc;
- Object* value = Heap::NumberFromDouble(1.000123)->ToObjectChecked();
+ Object* value = HEAP->NumberFromDouble(1.000123)->ToObjectChecked();
CHECK(value->IsHeapNumber());
CHECK(value->IsNumber());
CHECK_EQ(1.000123, value->Number());
- value = Heap::NumberFromDouble(1.0)->ToObjectChecked();
+ value = HEAP->NumberFromDouble(1.0)->ToObjectChecked();
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(1.0, value->Number());
- value = Heap::NumberFromInt32(1024)->ToObjectChecked();
+ value = HEAP->NumberFromInt32(1024)->ToObjectChecked();
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(1024.0, value->Number());
- value = Heap::NumberFromInt32(Smi::kMinValue)->ToObjectChecked();
+ value = HEAP->NumberFromInt32(Smi::kMinValue)->ToObjectChecked();
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(Smi::kMinValue, Smi::cast(value)->value());
- value = Heap::NumberFromInt32(Smi::kMaxValue)->ToObjectChecked();
+ value = HEAP->NumberFromInt32(Smi::kMaxValue)->ToObjectChecked();
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(Smi::kMaxValue, Smi::cast(value)->value());
#ifndef V8_TARGET_ARCH_X64
// TODO(lrn): We need a NumberFromIntptr function in order to test this.
- value = Heap::NumberFromInt32(Smi::kMinValue - 1)->ToObjectChecked();
+ value = HEAP->NumberFromInt32(Smi::kMinValue - 1)->ToObjectChecked();
CHECK(value->IsHeapNumber());
CHECK(value->IsNumber());
CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number());
#endif
MaybeObject* maybe_value =
- Heap::NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1);
+ HEAP->NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1);
value = maybe_value->ToObjectChecked();
CHECK(value->IsHeapNumber());
CHECK(value->IsNumber());
@@ -148,21 +148,22 @@
value->Number());
// nan oddball checks
- CHECK(Heap::nan_value()->IsNumber());
- CHECK(isnan(Heap::nan_value()->Number()));
+ CHECK(HEAP->nan_value()->IsNumber());
+ CHECK(isnan(HEAP->nan_value()->Number()));
- Handle<String> s = Factory::NewStringFromAscii(CStrVector("fisk hest "));
+ Handle<String> s = FACTORY->NewStringFromAscii(CStrVector("fisk hest "));
CHECK(s->IsString());
CHECK_EQ(10, s->length());
- String* object_symbol = String::cast(Heap::Object_symbol());
- CHECK(Top::context()->global()->HasLocalProperty(object_symbol));
+ String* object_symbol = String::cast(HEAP->Object_symbol());
+ CHECK(
+ Isolate::Current()->context()->global()->HasLocalProperty(object_symbol));
// Check ToString for oddballs
- CheckOddball(Heap::true_value(), "true");
- CheckOddball(Heap::false_value(), "false");
- CheckOddball(Heap::null_value(), "null");
- CheckOddball(Heap::undefined_value(), "undefined");
+ CheckOddball(HEAP->true_value(), "true");
+ CheckOddball(HEAP->false_value(), "false");
+ CheckOddball(HEAP->null_value(), "null");
+ CheckOddball(HEAP->undefined_value(), "undefined");
// Check ToString for Smis
CheckSmi(0, "0");
@@ -197,25 +198,25 @@
v8::HandleScope sc;
// Check GC.
- Heap::CollectGarbage(NEW_SPACE);
+ HEAP->CollectGarbage(NEW_SPACE);
- Handle<String> name = Factory::LookupAsciiSymbol("theFunction");
- Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot");
- Handle<String> prop_namex = Factory::LookupAsciiSymbol("theSlotx");
- Handle<String> obj_name = Factory::LookupAsciiSymbol("theObject");
+ Handle<String> name = FACTORY->LookupAsciiSymbol("theFunction");
+ Handle<String> prop_name = FACTORY->LookupAsciiSymbol("theSlot");
+ Handle<String> prop_namex = FACTORY->LookupAsciiSymbol("theSlotx");
+ Handle<String> obj_name = FACTORY->LookupAsciiSymbol("theObject");
{
v8::HandleScope inner_scope;
// Allocate a function and keep it in global object's property.
Handle<JSFunction> function =
- Factory::NewFunction(name, Factory::undefined_value());
+ FACTORY->NewFunction(name, FACTORY->undefined_value());
Handle<Map> initial_map =
- Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
+ FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
function->set_initial_map(*initial_map);
- Top::context()->global()->SetProperty(
+ Isolate::Current()->context()->global()->SetProperty(
*name, *function, NONE, kNonStrictMode)->ToObjectChecked();
// Allocate an object. Unrooted after leaving the scope.
- Handle<JSObject> obj = Factory::NewJSObject(function);
+ Handle<JSObject> obj = FACTORY->NewJSObject(function);
obj->SetProperty(
*prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
obj->SetProperty(
@@ -225,34 +226,34 @@
CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex));
}
- Heap::CollectGarbage(NEW_SPACE);
+ HEAP->CollectGarbage(NEW_SPACE);
// Function should be alive.
- CHECK(Top::context()->global()->HasLocalProperty(*name));
+ CHECK(Isolate::Current()->context()->global()->HasLocalProperty(*name));
// Check function is retained.
- Object* func_value =
- Top::context()->global()->GetProperty(*name)->ToObjectChecked();
+ Object* func_value = Isolate::Current()->context()->global()->
+ GetProperty(*name)->ToObjectChecked();
CHECK(func_value->IsJSFunction());
Handle<JSFunction> function(JSFunction::cast(func_value));
{
HandleScope inner_scope;
// Allocate another object, make it reachable from global.
- Handle<JSObject> obj = Factory::NewJSObject(function);
- Top::context()->global()->SetProperty(
+ Handle<JSObject> obj = FACTORY->NewJSObject(function);
+ Isolate::Current()->context()->global()->SetProperty(
*obj_name, *obj, NONE, kNonStrictMode)->ToObjectChecked();
obj->SetProperty(
*prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
}
// After gc, it should survive.
- Heap::CollectGarbage(NEW_SPACE);
+ HEAP->CollectGarbage(NEW_SPACE);
- CHECK(Top::context()->global()->HasLocalProperty(*obj_name));
- CHECK(Top::context()->global()->GetProperty(*obj_name)->ToObjectChecked()->
- IsJSObject());
- Object* obj =
- Top::context()->global()->GetProperty(*obj_name)->ToObjectChecked();
+ CHECK(Isolate::Current()->context()->global()->HasLocalProperty(*obj_name));
+ CHECK(Isolate::Current()->context()->global()->
+ GetProperty(*obj_name)->ToObjectChecked()->IsJSObject());
+ Object* obj = Isolate::Current()->context()->global()->
+ GetProperty(*obj_name)->ToObjectChecked();
JSObject* js_obj = JSObject::cast(obj);
CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name));
}
@@ -260,7 +261,7 @@
static void VerifyStringAllocation(const char* string) {
v8::HandleScope scope;
- Handle<String> s = Factory::NewStringFromUtf8(CStrVector(string));
+ Handle<String> s = FACTORY->NewStringFromUtf8(CStrVector(string));
CHECK_EQ(StrLength(string), s->length());
for (int index = 0; index < s->length(); index++) {
CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index));
@@ -284,12 +285,13 @@
v8::HandleScope scope;
const char* name = "Kasper the spunky";
- Handle<String> string = Factory::NewStringFromAscii(CStrVector(name));
+ Handle<String> string = FACTORY->NewStringFromAscii(CStrVector(name));
CHECK_EQ(StrLength(name), string->length());
}
TEST(GlobalHandles) {
+ GlobalHandles* global_handles = Isolate::Current()->global_handles();
InitializeVM();
Handle<Object> h1;
@@ -300,17 +302,17 @@
{
HandleScope scope;
- Handle<Object> i = Factory::NewStringFromAscii(CStrVector("fisk"));
- Handle<Object> u = Factory::NewNumber(1.12344);
+ Handle<Object> i = FACTORY->NewStringFromAscii(CStrVector("fisk"));
+ Handle<Object> u = FACTORY->NewNumber(1.12344);
- h1 = GlobalHandles::Create(*i);
- h2 = GlobalHandles::Create(*u);
- h3 = GlobalHandles::Create(*i);
- h4 = GlobalHandles::Create(*u);
+ h1 = global_handles->Create(*i);
+ h2 = global_handles->Create(*u);
+ h3 = global_handles->Create(*i);
+ h4 = global_handles->Create(*u);
}
// after gc, it should survive
- Heap::CollectGarbage(NEW_SPACE);
+ HEAP->CollectGarbage(NEW_SPACE);
CHECK((*h1)->IsString());
CHECK((*h2)->IsHeapNumber());
@@ -318,12 +320,12 @@
CHECK((*h4)->IsHeapNumber());
CHECK_EQ(*h3, *h1);
- GlobalHandles::Destroy(h1.location());
- GlobalHandles::Destroy(h3.location());
+ global_handles->Destroy(h1.location());
+ global_handles->Destroy(h3.location());
CHECK_EQ(*h4, *h2);
- GlobalHandles::Destroy(h2.location());
- GlobalHandles::Destroy(h4.location());
+ global_handles->Destroy(h2.location());
+ global_handles->Destroy(h4.location());
}
@@ -337,6 +339,7 @@
TEST(WeakGlobalHandlesScavenge) {
+ GlobalHandles* global_handles = Isolate::Current()->global_handles();
InitializeVM();
WeakPointerCleared = false;
@@ -347,33 +350,34 @@
{
HandleScope scope;
- Handle<Object> i = Factory::NewStringFromAscii(CStrVector("fisk"));
- Handle<Object> u = Factory::NewNumber(1.12344);
+ Handle<Object> i = FACTORY->NewStringFromAscii(CStrVector("fisk"));
+ Handle<Object> u = FACTORY->NewNumber(1.12344);
- h1 = GlobalHandles::Create(*i);
- h2 = GlobalHandles::Create(*u);
+ h1 = global_handles->Create(*i);
+ h2 = global_handles->Create(*u);
}
- GlobalHandles::MakeWeak(h2.location(),
- reinterpret_cast<void*>(1234),
- &TestWeakGlobalHandleCallback);
+ global_handles->MakeWeak(h2.location(),
+ reinterpret_cast<void*>(1234),
+ &TestWeakGlobalHandleCallback);
// Scavenge treats weak pointers as normal roots.
- Heap::PerformScavenge();
+ HEAP->PerformScavenge();
CHECK((*h1)->IsString());
CHECK((*h2)->IsHeapNumber());
CHECK(!WeakPointerCleared);
- CHECK(!GlobalHandles::IsNearDeath(h2.location()));
- CHECK(!GlobalHandles::IsNearDeath(h1.location()));
+ CHECK(!global_handles->IsNearDeath(h2.location()));
+ CHECK(!global_handles->IsNearDeath(h1.location()));
- GlobalHandles::Destroy(h1.location());
- GlobalHandles::Destroy(h2.location());
+ global_handles->Destroy(h1.location());
+ global_handles->Destroy(h2.location());
}
TEST(WeakGlobalHandlesMark) {
+ GlobalHandles* global_handles = Isolate::Current()->global_handles();
InitializeVM();
WeakPointerCleared = false;
@@ -384,34 +388,35 @@
{
HandleScope scope;
- Handle<Object> i = Factory::NewStringFromAscii(CStrVector("fisk"));
- Handle<Object> u = Factory::NewNumber(1.12344);
+ Handle<Object> i = FACTORY->NewStringFromAscii(CStrVector("fisk"));
+ Handle<Object> u = FACTORY->NewNumber(1.12344);
- h1 = GlobalHandles::Create(*i);
- h2 = GlobalHandles::Create(*u);
+ h1 = global_handles->Create(*i);
+ h2 = global_handles->Create(*u);
}
- Heap::CollectGarbage(OLD_POINTER_SPACE);
- Heap::CollectGarbage(NEW_SPACE);
+ HEAP->CollectGarbage(OLD_POINTER_SPACE);
+ HEAP->CollectGarbage(NEW_SPACE);
// Make sure the object is promoted.
- GlobalHandles::MakeWeak(h2.location(),
- reinterpret_cast<void*>(1234),
- &TestWeakGlobalHandleCallback);
+ global_handles->MakeWeak(h2.location(),
+ reinterpret_cast<void*>(1234),
+ &TestWeakGlobalHandleCallback);
CHECK(!GlobalHandles::IsNearDeath(h1.location()));
CHECK(!GlobalHandles::IsNearDeath(h2.location()));
- Heap::CollectGarbage(OLD_POINTER_SPACE);
+ HEAP->CollectGarbage(OLD_POINTER_SPACE);
CHECK((*h1)->IsString());
CHECK(WeakPointerCleared);
CHECK(!GlobalHandles::IsNearDeath(h1.location()));
- GlobalHandles::Destroy(h1.location());
+ global_handles->Destroy(h1.location());
}
TEST(DeleteWeakGlobalHandle) {
+ GlobalHandles* global_handles = Isolate::Current()->global_handles();
InitializeVM();
WeakPointerCleared = false;
@@ -421,21 +426,21 @@
{
HandleScope scope;
- Handle<Object> i = Factory::NewStringFromAscii(CStrVector("fisk"));
- h = GlobalHandles::Create(*i);
+ Handle<Object> i = FACTORY->NewStringFromAscii(CStrVector("fisk"));
+ h = global_handles->Create(*i);
}
- GlobalHandles::MakeWeak(h.location(),
- reinterpret_cast<void*>(1234),
- &TestWeakGlobalHandleCallback);
+ global_handles->MakeWeak(h.location(),
+ reinterpret_cast<void*>(1234),
+ &TestWeakGlobalHandleCallback);
// Scanvenge does not recognize weak reference.
- Heap::PerformScavenge();
+ HEAP->PerformScavenge();
CHECK(!WeakPointerCleared);
// Mark-compact treats weak reference properly.
- Heap::CollectGarbage(OLD_POINTER_SPACE);
+ HEAP->CollectGarbage(OLD_POINTER_SPACE);
CHECK(WeakPointerCleared);
}
@@ -507,12 +512,12 @@
static void CheckSymbols(const char** strings) {
for (const char* string = *strings; *strings != 0; string = *strings++) {
Object* a;
- MaybeObject* maybe_a = Heap::LookupAsciiSymbol(string);
+ MaybeObject* maybe_a = HEAP->LookupAsciiSymbol(string);
// LookupAsciiSymbol may return a failure if a GC is needed.
if (!maybe_a->ToObject(&a)) continue;
CHECK(a->IsSymbol());
Object* b;
- MaybeObject *maybe_b = Heap::LookupAsciiSymbol(string);
+ MaybeObject* maybe_b = HEAP->LookupAsciiSymbol(string);
if (!maybe_b->ToObject(&b)) continue;
CHECK_EQ(b, a);
CHECK(String::cast(b)->IsEqualTo(CStrVector(string)));
@@ -532,15 +537,15 @@
InitializeVM();
v8::HandleScope sc;
- Handle<String> name = Factory::LookupAsciiSymbol("theFunction");
+ Handle<String> name = FACTORY->LookupAsciiSymbol("theFunction");
Handle<JSFunction> function =
- Factory::NewFunction(name, Factory::undefined_value());
+ FACTORY->NewFunction(name, FACTORY->undefined_value());
Handle<Map> initial_map =
- Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
+ FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
function->set_initial_map(*initial_map);
- Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot");
- Handle<JSObject> obj = Factory::NewJSObject(function);
+ Handle<String> prop_name = FACTORY->LookupAsciiSymbol("theSlot");
+ Handle<JSObject> obj = FACTORY->NewJSObject(function);
obj->SetProperty(
*prop_name, Smi::FromInt(23), NONE, kNonStrictMode)->ToObjectChecked();
CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
@@ -555,14 +560,14 @@
InitializeVM();
v8::HandleScope sc;
- String* object_symbol = String::cast(Heap::Object_symbol());
- Object* raw_object =
- Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked();
+ String* object_symbol = String::cast(HEAP->Object_symbol());
+ Object* raw_object = Isolate::Current()->context()->global()->
+ GetProperty(object_symbol)->ToObjectChecked();
JSFunction* object_function = JSFunction::cast(raw_object);
Handle<JSFunction> constructor(object_function);
- Handle<JSObject> obj = Factory::NewJSObject(constructor);
- Handle<String> first = Factory::LookupAsciiSymbol("first");
- Handle<String> second = Factory::LookupAsciiSymbol("second");
+ Handle<JSObject> obj = FACTORY->NewJSObject(constructor);
+ Handle<String> first = FACTORY->LookupAsciiSymbol("first");
+ Handle<String> second = FACTORY->LookupAsciiSymbol("second");
// check for empty
CHECK(!obj->HasLocalProperty(*first));
@@ -608,18 +613,18 @@
// check string and symbol match
static const char* string1 = "fisk";
- Handle<String> s1 = Factory::NewStringFromAscii(CStrVector(string1));
+ Handle<String> s1 = FACTORY->NewStringFromAscii(CStrVector(string1));
obj->SetProperty(
*s1, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
- Handle<String> s1_symbol = Factory::LookupAsciiSymbol(string1);
+ Handle<String> s1_symbol = FACTORY->LookupAsciiSymbol(string1);
CHECK(obj->HasLocalProperty(*s1_symbol));
// check symbol and string match
static const char* string2 = "fugl";
- Handle<String> s2_symbol = Factory::LookupAsciiSymbol(string2);
+ Handle<String> s2_symbol = FACTORY->LookupAsciiSymbol(string2);
obj->SetProperty(
*s2_symbol, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
- Handle<String> s2 = Factory::NewStringFromAscii(CStrVector(string2));
+ Handle<String> s2 = FACTORY->NewStringFromAscii(CStrVector(string2));
CHECK(obj->HasLocalProperty(*s2));
}
@@ -628,15 +633,15 @@
InitializeVM();
v8::HandleScope sc;
- Handle<String> name = Factory::LookupAsciiSymbol("theFunction");
+ Handle<String> name = FACTORY->LookupAsciiSymbol("theFunction");
Handle<JSFunction> function =
- Factory::NewFunction(name, Factory::undefined_value());
+ FACTORY->NewFunction(name, FACTORY->undefined_value());
Handle<Map> initial_map =
- Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
+ FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
function->set_initial_map(*initial_map);
- Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot");
- Handle<JSObject> obj = Factory::NewJSObject(function);
+ Handle<String> prop_name = FACTORY->LookupAsciiSymbol("theSlot");
+ Handle<JSObject> obj = FACTORY->NewJSObject(function);
// Set a propery
obj->SetProperty(
@@ -652,14 +657,14 @@
InitializeVM();
v8::HandleScope sc;
- Handle<String> name = Factory::LookupAsciiSymbol("Array");
- Object* raw_object =
- Top::context()->global()->GetProperty(*name)->ToObjectChecked();
+ Handle<String> name = FACTORY->LookupAsciiSymbol("Array");
+ Object* raw_object = Isolate::Current()->context()->global()->
+ GetProperty(*name)->ToObjectChecked();
Handle<JSFunction> function = Handle<JSFunction>(
JSFunction::cast(raw_object));
// Allocate the object.
- Handle<JSObject> object = Factory::NewJSObject(function);
+ Handle<JSObject> object = FACTORY->NewJSObject(function);
Handle<JSArray> array = Handle<JSArray>::cast(object);
// We just initialized the VM, no heap allocation failure yet.
Object* ok = array->Initialize(0)->ToObjectChecked();
@@ -676,7 +681,7 @@
// Set array length with larger than smi value.
Handle<Object> length =
- Factory::NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
+ FACTORY->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
ok = array->SetElementsLength(*length)->ToObjectChecked();
uint32_t int_length = 0;
@@ -698,14 +703,14 @@
InitializeVM();
v8::HandleScope sc;
- String* object_symbol = String::cast(Heap::Object_symbol());
- Object* raw_object =
- Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked();
+ String* object_symbol = String::cast(HEAP->Object_symbol());
+ Object* raw_object = Isolate::Current()->context()->global()->
+ GetProperty(object_symbol)->ToObjectChecked();
JSFunction* object_function = JSFunction::cast(raw_object);
Handle<JSFunction> constructor(object_function);
- Handle<JSObject> obj = Factory::NewJSObject(constructor);
- Handle<String> first = Factory::LookupAsciiSymbol("first");
- Handle<String> second = Factory::LookupAsciiSymbol("second");
+ Handle<JSObject> obj = FACTORY->NewJSObject(constructor);
+ Handle<String> first = FACTORY->LookupAsciiSymbol("first");
+ Handle<String> second = FACTORY->LookupAsciiSymbol("second");
obj->SetProperty(
*first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
@@ -761,17 +766,17 @@
non_ascii[3 * i + 2] = chars[2];
}
Handle<String> non_ascii_sym =
- Factory::LookupSymbol(Vector<const char>(non_ascii, 3 * length));
+ FACTORY->LookupSymbol(Vector<const char>(non_ascii, 3 * length));
CHECK_EQ(length, non_ascii_sym->length());
Handle<String> ascii_sym =
- Factory::LookupSymbol(Vector<const char>(ascii, length));
+ FACTORY->LookupSymbol(Vector<const char>(ascii, length));
CHECK_EQ(length, ascii_sym->length());
Handle<String> non_ascii_str =
- Factory::NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length));
+ FACTORY->NewStringFromUtf8(Vector<const char>(non_ascii, 3 * length));
non_ascii_str->Hash();
CHECK_EQ(length, non_ascii_str->length());
Handle<String> ascii_str =
- Factory::NewStringFromUtf8(Vector<const char>(ascii, length));
+ FACTORY->NewStringFromUtf8(Vector<const char>(ascii, length));
ascii_str->Hash();
CHECK_EQ(length, ascii_str->length());
DeleteArray(non_ascii);
@@ -805,22 +810,22 @@
int next_objs_index = 0;
// Allocate a JS array to OLD_POINTER_SPACE and NEW_SPACE
- objs[next_objs_index++] = Factory::NewJSArray(10);
- objs[next_objs_index++] = Factory::NewJSArray(10, TENURED);
+ objs[next_objs_index++] = FACTORY->NewJSArray(10);
+ objs[next_objs_index++] = FACTORY->NewJSArray(10, TENURED);
// Allocate a small string to OLD_DATA_SPACE and NEW_SPACE
objs[next_objs_index++] =
- Factory::NewStringFromAscii(CStrVector("abcdefghij"));
+ FACTORY->NewStringFromAscii(CStrVector("abcdefghij"));
objs[next_objs_index++] =
- Factory::NewStringFromAscii(CStrVector("abcdefghij"), TENURED);
+ FACTORY->NewStringFromAscii(CStrVector("abcdefghij"), TENURED);
// Allocate a large string (for large object space).
- int large_size = Heap::MaxObjectSizeInPagedSpace() + 1;
+ int large_size = HEAP->MaxObjectSizeInPagedSpace() + 1;
char* str = new char[large_size];
for (int i = 0; i < large_size - 1; ++i) str[i] = 'a';
str[large_size - 1] = '\0';
objs[next_objs_index++] =
- Factory::NewStringFromAscii(CStrVector(str), TENURED);
+ FACTORY->NewStringFromAscii(CStrVector(str), TENURED);
delete[] str;
// Add a Map object to look for.
@@ -834,9 +839,9 @@
TEST(LargeObjectSpaceContains) {
InitializeVM();
- Heap::CollectGarbage(NEW_SPACE);
+ HEAP->CollectGarbage(NEW_SPACE);
- Address current_top = Heap::new_space()->top();
+ Address current_top = HEAP->new_space()->top();
Page* page = Page::FromAddress(current_top);
Address current_page = page->address();
Address next_page = current_page + Page::kPageSize;
@@ -859,7 +864,7 @@
kPointerSize;
CHECK_EQ(bytes_to_allocate, FixedArray::SizeFor(n_elements));
FixedArray* array = FixedArray::cast(
- Heap::AllocateFixedArray(n_elements)->ToObjectChecked());
+ HEAP->AllocateFixedArray(n_elements)->ToObjectChecked());
int index = n_elements - 1;
CHECK_EQ(flags_ptr,
@@ -869,8 +874,8 @@
// CHECK(Page::FromAddress(next_page)->IsLargeObjectPage());
HeapObject* addr = HeapObject::FromAddress(next_page + 2 * kPointerSize);
- CHECK(Heap::new_space()->Contains(addr));
- CHECK(!Heap::lo_space()->Contains(addr));
+ CHECK(HEAP->new_space()->Contains(addr));
+ CHECK(!HEAP->lo_space()->Contains(addr));
}
@@ -901,7 +906,7 @@
// Increase the chance of 'bump-the-pointer' allocation in old space.
bool force_compaction = true;
- Heap::CollectAllGarbage(force_compaction);
+ HEAP->CollectAllGarbage(force_compaction);
v8::HandleScope scope;
@@ -910,11 +915,12 @@
// that region dirty marks are updated correctly.
// Step 1: prepare a map for the object. We add 1 inobject property to it.
- Handle<JSFunction> object_ctor(Top::global_context()->object_function());
+ Handle<JSFunction> object_ctor(
+ Isolate::Current()->global_context()->object_function());
CHECK(object_ctor->has_initial_map());
Handle<Map> object_map(object_ctor->initial_map());
// Create a map with single inobject property.
- Handle<Map> my_map = Factory::CopyMap(object_map, 1);
+ Handle<Map> my_map = FACTORY->CopyMap(object_map, 1);
int n_properties = my_map->inobject_properties();
CHECK_GT(n_properties, 0);
@@ -924,15 +930,15 @@
// just enough room to allocate JSObject and thus fill the newspace.
int allocation_amount = Min(FixedArray::kMaxSize,
- Heap::MaxObjectSizeInNewSpace());
+ HEAP->MaxObjectSizeInNewSpace());
int allocation_len = LenFromSize(allocation_amount);
- NewSpace* new_space = Heap::new_space();
+ NewSpace* new_space = HEAP->new_space();
Address* top_addr = new_space->allocation_top_address();
Address* limit_addr = new_space->allocation_limit_address();
while ((*limit_addr - *top_addr) > allocation_amount) {
- CHECK(!Heap::always_allocate());
- Object* array =
- Heap::AllocateFixedArray(allocation_len)->ToObjectChecked();
+ CHECK(!HEAP->always_allocate());
+ Object* array = HEAP->AllocateFixedArray(allocation_len)->ToObjectChecked();
+ CHECK(!array->IsFailure());
CHECK(new_space->Contains(array));
}
@@ -941,12 +947,12 @@
int fixed_array_len = LenFromSize(to_fill);
CHECK(fixed_array_len < FixedArray::kMaxLength);
- CHECK(!Heap::always_allocate());
- Object* array =
- Heap::AllocateFixedArray(fixed_array_len)->ToObjectChecked();
+ CHECK(!HEAP->always_allocate());
+ Object* array = HEAP->AllocateFixedArray(fixed_array_len)->ToObjectChecked();
+ CHECK(!array->IsFailure());
CHECK(new_space->Contains(array));
- Object* object = Heap::AllocateJSObjectFromMap(*my_map)->ToObjectChecked();
+ Object* object = HEAP->AllocateJSObjectFromMap(*my_map)->ToObjectChecked();
CHECK(new_space->Contains(object));
JSObject* jsobject = JSObject::cast(object);
CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length());
@@ -958,15 +964,15 @@
// Step 4: clone jsobject, but force always allocate first to create a clone
// in old pointer space.
- Address old_pointer_space_top = Heap::old_pointer_space()->top();
+ Address old_pointer_space_top = HEAP->old_pointer_space()->top();
AlwaysAllocateScope aa_scope;
- Object* clone_obj = Heap::CopyJSObject(jsobject)->ToObjectChecked();
+ Object* clone_obj = HEAP->CopyJSObject(jsobject)->ToObjectChecked();
JSObject* clone = JSObject::cast(clone_obj);
if (clone->address() != old_pointer_space_top) {
// Alas, got allocated from free list, we cannot do checks.
return;
}
- CHECK(Heap::old_pointer_space()->Contains(clone->address()));
+ CHECK(HEAP->old_pointer_space()->Contains(clone->address()));
// Step 5: verify validity of region dirty marks.
Address clone_addr = clone->address();
@@ -988,7 +994,7 @@
" var z = x + y;"
"};"
"foo()";
- Handle<String> foo_name = Factory::LookupAsciiSymbol("foo");
+ Handle<String> foo_name = FACTORY->LookupAsciiSymbol("foo");
// This compile will add the code to the compilation cache.
{ v8::HandleScope scope;
@@ -996,23 +1002,23 @@
}
// Check function is compiled.
- Object* func_value =
- Top::context()->global()->GetProperty(*foo_name)->ToObjectChecked();
+ Object* func_value = Isolate::Current()->context()->global()->
+ GetProperty(*foo_name)->ToObjectChecked();
CHECK(func_value->IsJSFunction());
Handle<JSFunction> function(JSFunction::cast(func_value));
CHECK(function->shared()->is_compiled());
- Heap::CollectAllGarbage(true);
- Heap::CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
CHECK(function->shared()->is_compiled());
- Heap::CollectAllGarbage(true);
- Heap::CollectAllGarbage(true);
- Heap::CollectAllGarbage(true);
- Heap::CollectAllGarbage(true);
- Heap::CollectAllGarbage(true);
- Heap::CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
// foo should no longer be in the compilation cache
CHECK(!function->shared()->is_compiled() || function->IsOptimized());
@@ -1027,7 +1033,7 @@
// Count the number of global contexts in the weak list of global contexts.
static int CountGlobalContexts() {
int count = 0;
- Object* object = Heap::global_contexts_list();
+ Object* object = HEAP->global_contexts_list();
while (!object->IsUndefined()) {
count++;
object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK);
@@ -1051,6 +1057,8 @@
TEST(TestInternalWeakLists) {
+ v8::V8::Initialize();
+
static const int kNumTestContexts = 10;
v8::HandleScope scope;
@@ -1094,35 +1102,35 @@
// Scavenge treats these references as strong.
for (int j = 0; j < 10; j++) {
- Heap::PerformScavenge();
+ HEAP->PerformScavenge();
CHECK_EQ(opt ? 5 : 0, CountOptimizedUserFunctions(ctx[i]));
}
// Mark compact handles the weak references.
- Heap::CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
// Get rid of f3 and f5 in the same way.
CompileRun("f3=null");
for (int j = 0; j < 10; j++) {
- Heap::PerformScavenge();
+ HEAP->PerformScavenge();
CHECK_EQ(opt ? 4 : 0, CountOptimizedUserFunctions(ctx[i]));
}
- Heap::CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i]));
CompileRun("f5=null");
for (int j = 0; j < 10; j++) {
- Heap::PerformScavenge();
+ HEAP->PerformScavenge();
CHECK_EQ(opt ? 3 : 0, CountOptimizedUserFunctions(ctx[i]));
}
- Heap::CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
CHECK_EQ(opt ? 2 : 0, CountOptimizedUserFunctions(ctx[i]));
ctx[i]->Exit();
}
// Force compilation cache cleanup.
- Heap::CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
// Dispose the global contexts one by one.
for (int i = 0; i < kNumTestContexts; i++) {
@@ -1131,12 +1139,12 @@
// Scavenge treats these references as strong.
for (int j = 0; j < 10; j++) {
- Heap::PerformScavenge();
+ HEAP->PerformScavenge();
CHECK_EQ(kNumTestContexts - i, CountGlobalContexts());
}
// Mark compact handles the weak references.
- Heap::CollectAllGarbage(true);
+ HEAP->CollectAllGarbage(true);
CHECK_EQ(kNumTestContexts - i - 1, CountGlobalContexts());
}
@@ -1148,10 +1156,10 @@
// causing a GC after the specified number of elements.
static int CountGlobalContextsWithGC(int n) {
int count = 0;
- Handle<Object> object(Heap::global_contexts_list());
+ Handle<Object> object(HEAP->global_contexts_list());
while (!object->IsUndefined()) {
count++;
- if (count == n) Heap::CollectAllGarbage(true);
+ if (count == n) HEAP->CollectAllGarbage(true);
object =
Handle<Object>(Context::cast(*object)->get(Context::NEXT_CONTEXT_LINK));
}
@@ -1170,7 +1178,7 @@
while (object->IsJSFunction() &&
!Handle<JSFunction>::cast(object)->IsBuiltin()) {
count++;
- if (count == n) Heap::CollectAllGarbage(true);
+ if (count == n) HEAP->CollectAllGarbage(true);
object = Handle<Object>(
Object::cast(JSFunction::cast(*object)->next_function_link()));
}
@@ -1179,6 +1187,8 @@
TEST(TestInternalWeakListsTraverseWithGC) {
+ v8::V8::Initialize();
+
static const int kNumTestContexts = 10;
v8::HandleScope scope;
@@ -1228,7 +1238,7 @@
TEST(TestSizeOfObjectsVsHeapIteratorPrecision) {
InitializeVM();
- intptr_t size_of_objects_1 = Heap::SizeOfObjects();
+ intptr_t size_of_objects_1 = HEAP->SizeOfObjects();
HeapIterator iterator(HeapIterator::kFilterFreeListNodes);
intptr_t size_of_objects_2 = 0;
for (HeapObject* obj = iterator.next();
@@ -1283,10 +1293,10 @@
InitializeVM();
v8::HandleScope scope;
CompileRun("a = {}; b = {};");
- v8::Handle<Object> a(Top::context()->global()->GetProperty(
- *Factory::LookupAsciiSymbol("a"))->ToObjectChecked());
- v8::Handle<Object> b(Top::context()->global()->GetProperty(
- *Factory::LookupAsciiSymbol("b"))->ToObjectChecked());
+ v8::Handle<Object> a(ISOLATE->context()->global()->GetProperty(
+ *FACTORY->LookupAsciiSymbol("a"))->ToObjectChecked());
+ v8::Handle<Object> b(ISOLATE->context()->global()->GetProperty(
+ *FACTORY->LookupAsciiSymbol("b"))->ToObjectChecked());
CHECK_NE(*a, *b);
{
HeapIteratorTestHelper helper(*a, *b);
@@ -1294,8 +1304,8 @@
CHECK(helper.a_found());
CHECK(helper.b_found());
}
- CHECK(Top::context()->global()->DeleteProperty(
- *Factory::LookupAsciiSymbol("a"), JSObject::FORCE_DELETION));
+ CHECK(ISOLATE->context()->global()->DeleteProperty(
+ *FACTORY->LookupAsciiSymbol("a"), JSObject::FORCE_DELETION));
// We ensure that GC will not happen, so our raw pointer stays valid.
AssertNoAllocation no_alloc;
Object* a_saved = *a;
« no previous file with comments | « test/cctest/test-func-name-inference.cc ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698