| Index: test/cctest/test-mementos.cc
|
| diff --git a/test/cctest/test-mementos.cc b/test/cctest/test-mementos.cc
|
| index 9662effa50fdff501aa52add25fc7f3472554f1d..1dc38f9af5cef8d59af377f2a255f9577b95880f 100644
|
| --- a/test/cctest/test-mementos.cc
|
| +++ b/test/cctest/test-mementos.cc
|
| @@ -77,3 +77,47 @@ TEST(BadMementoAfterTopForceScavenge) {
|
| // Force GC to test the poisoned memento handling
|
| CcTest::i_isolate()->heap()->CollectGarbage(i::NEW_SPACE);
|
| }
|
| +
|
| +
|
| +TEST(PretenuringCallNew) {
|
| + CcTest::InitializeVM();
|
| + if (!i::FLAG_allocation_site_pretenuring) return;
|
| + if (!i::FLAG_pretenuring_call_new) return;
|
| +
|
| + v8::HandleScope scope(CcTest::isolate());
|
| + Isolate* isolate = CcTest::i_isolate();
|
| + Heap* heap = isolate->heap();
|
| +
|
| + // We need to create several instances to get past the slack-tracking
|
| + // phase, where mementos aren't emitted.
|
| + int call_count = 10;
|
| + CHECK_GE(call_count, SharedFunctionInfo::kGenerousAllocationCount);
|
| + i::ScopedVector<char> test_buf(1024);
|
| + const char* program =
|
| + "function f() {"
|
| + " this.a = 3;"
|
| + " this.b = {};"
|
| + " return this;"
|
| + "};"
|
| + "var a;"
|
| + "for(var i = 0; i < %d; i++) {"
|
| + " a = new f();"
|
| + "}"
|
| + "a;";
|
| + i::OS::SNPrintF(test_buf, program, call_count);
|
| + v8::Local<v8::Value> res = CompileRun(test_buf.start());
|
| + Handle<JSObject> o =
|
| + v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
| +
|
| + // The object of class f should have a memento secreted behind it.
|
| + Address memento_address = o->address() + o->map()->instance_size();
|
| + AllocationMemento* memento =
|
| + reinterpret_cast<AllocationMemento*>(memento_address + kHeapObjectTag);
|
| + CHECK_EQ(memento->map(), heap->allocation_memento_map());
|
| +
|
| + // Furthermore, how many mementos did we create? The count should match
|
| + // call_count - SharedFunctionInfo::kGenerousAllocationCount.
|
| + AllocationSite* site = memento->GetAllocationSite();
|
| + CHECK_EQ(call_count - SharedFunctionInfo::kGenerousAllocationCount,
|
| + site->pretenure_create_count()->value());
|
| +}
|
|
|