| Index: test/cctest/test-heap.cc
|
| diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
|
| index 158e146967ce067485272c37ca6df11976066004..459520367c93f9b983fda73e17b9c4de52a17067 100644
|
| --- a/test/cctest/test-heap.cc
|
| +++ b/test/cctest/test-heap.cc
|
| @@ -2689,6 +2689,64 @@ static int CountMapTransitions(Map* map) {
|
| }
|
|
|
|
|
| +// Snippet should have a function "f" that returns an object. The object
|
| +// should have a memento behind it in optimized code if there hasn't
|
| +// been enough data to decide on pretenuring.
|
| +static void VerifyResultHasMemento(const char* snippet) {
|
| + i::ScopedVector<char> source(1024);
|
| + i::OS::SNPrintF(
|
| + source,
|
| + "%s"
|
| + "f(); gc();"
|
| + "f(); f();"
|
| + "%%OptimizeFunctionOnNextCall(f);"
|
| + "f();",
|
| + snippet);
|
| +
|
| + v8::Local<v8::Value> res = CompileRun(source.start());
|
| + Handle<JSObject> o =
|
| + v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
|
| + CHECK(CcTest::heap()->InNewSpace(*o));
|
| + AllocationMemento* memento = CcTest::heap()->FindAllocationMemento(*o);
|
| + CHECK(memento != NULL);
|
| +}
|
| +
|
| +
|
| +TEST(MementosEmittedFromOptimizedCode) {
|
| + i::FLAG_allow_natives_syntax = true;
|
| + i::FLAG_expose_gc = true;
|
| + CcTest::InitializeVM();
|
| + if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
|
| + if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
|
| + v8::HandleScope scope(CcTest::isolate());
|
| +
|
| + VerifyResultHasMemento("function f() { return [1, 2, 3]; };");
|
| + VerifyResultHasMemento("function f() { return { foo: 'bar' }; };");
|
| +
|
| + // String binary ops. Not currently working.
|
| + // TODO(mvstanton): Talk to benedikt about this. Currently we refuse to
|
| + // emit mementos in string add if we aren't creating a stub. We should
|
| + // understand the performance consequences. It seems that we'd need to
|
| + // 1) allow inlining of stringadd in optimized functions, 2) be able
|
| + // to pass an allocation site argument to HStringAdd, 3) both.
|
| + // VerifyResultHasMemento("function f() { return 'hi' + 'gee'; };");
|
| +
|
| + // The tests below require us to be able to pretenure call new.
|
| + if (i::FLAG_pretenuring_call_new) {
|
| + // This allocation could be inlined.
|
| + VerifyResultHasMemento(
|
| + "function Blargh() { this.foo = 3; return this; };"
|
| + "function f() { return new Blargh(); };");
|
| + // Object isn't inlineable, a stub is called.
|
| + VerifyResultHasMemento("function f() { return new Object(); };");
|
| + // Array has a different path, this one will inline the constructor.
|
| + VerifyResultHasMemento("function f() { return new Array(); };");
|
| + // This one will call a stub, passing the request to create a memento.
|
| + VerifyResultHasMemento("function f() { return new Array(100); };");
|
| + }
|
| +}
|
| +
|
| +
|
| // Test that map transitions are cleared and maps are collected with
|
| // incremental marking as well.
|
| TEST(Regress1465) {
|
|
|