| Index: test/cctest/test-heap.cc
|
| diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
|
| index eef43dc6147ea9afb7308b3b9877c7f7d2daf7bd..8f7fa60d375be4ec072d7231c031617af266fb69 100644
|
| --- a/test/cctest/test-heap.cc
|
| +++ b/test/cctest/test-heap.cc
|
| @@ -3074,6 +3074,66 @@ TEST(ReleaseOverReservedPages) {
|
| }
|
|
|
|
|
| +// Tests the FlushEagerly class from heap.h
|
| +TEST(ReleaseUnoptimizedCode) {
|
| + i::FLAG_trace_gc = true;
|
| + // The optimizer can allocate stuff, messing up the test.
|
| + i::FLAG_crankshaft = false;
|
| + if (i::FLAG_always_opt) return;
|
| +
|
| + CcTest::InitializeVM();
|
| + Isolate* isolate = CcTest::i_isolate();
|
| + Heap* heap = isolate->heap();
|
| + v8::HandleScope scope(CcTest::isolate());
|
| +
|
| + PagedSpace* code_space = heap->code_space();
|
| + CompileRun(
|
| + "var a = [];"
|
| + "var sum = 0;"
|
| + "for (var j = 0; j < 1e4; j++) {"
|
| + " var fn = new Function("
|
| + " 'var k; var o = {}; for (k in o) { } return ' + j + ';');"
|
| + " sum += fn();"
|
| + " a.push(fn);"
|
| + "}");
|
| + heap->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation");
|
| + CHECK_GE(code_space->CountTotalPages(), 5);
|
| + // We trigger an emergency GC, but only one round, because that should be
|
| + // enough to flush out the code.
|
| + heap->CollectAllAvailableGarbage("triggered really hard", 2);
|
| + CHECK_LE(code_space->CountTotalPages(), 2);
|
| +}
|
| +
|
| +
|
| +// Tests the FlushEagerly class from heap.h on regexp code.
|
| +TEST(ReleaseRegexpCode) {
|
| + i::FLAG_trace_gc = true;
|
| + // The optimizer can allocate stuff, messing up the test.
|
| + i::FLAG_crankshaft = false;
|
| + if (i::FLAG_always_opt) return;
|
| +
|
| + CcTest::InitializeVM();
|
| + Isolate* isolate = CcTest::i_isolate();
|
| + Heap* heap = isolate->heap();
|
| + v8::HandleScope scope(CcTest::isolate());
|
| +
|
| + PagedSpace* code_space = heap->code_space();
|
| + CompileRun(
|
| + "var a = [];"
|
| + "for (var j = 0; j < 2e4; j++) {"
|
| + " var re = RegExp(j + '?');"
|
| + " a.push(re);"
|
| + " re.test('foo');"
|
| + "}");
|
| + heap->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation");
|
| + CHECK_GT(code_space->CountTotalPages(), 5);
|
| + // We trigger an emergency GC, but only one round, because that should be
|
| + // enough to flush out the code.
|
| + heap->CollectAllAvailableGarbage("triggered really hard", 1);
|
| + CHECK_LE(code_space->CountTotalPages(), 2);
|
| +}
|
| +
|
| +
|
| TEST(Regress2237) {
|
| i::FLAG_stress_compaction = false;
|
| CcTest::InitializeVM();
|
| @@ -3366,7 +3426,8 @@ void ReleaseStackTraceDataTest(v8::Isolate* isolate, const char* source,
|
| CHECK(!resource->IsDisposed());
|
|
|
| CompileRun(accessor);
|
| - i_isolate->heap()->CollectAllAvailableGarbage();
|
| + i_isolate->heap()->CollectAllAvailableGarbage(
|
| + "force release of external source in one round", 1);
|
|
|
| // External source has been released.
|
| CHECK(resource->IsDisposed());
|
| @@ -4126,7 +4187,7 @@ TEST(NextCodeLinkIsWeak) {
|
| code = scope.CloseAndEscape(Handle<Code>(immortal->code()));
|
| CompileRun("mortal = null; immortal = null;");
|
| }
|
| - heap->CollectAllAvailableGarbage();
|
| + heap->CollectAllAvailableGarbage("kill mortal code", 1);
|
| // Now mortal code should be dead.
|
| code_chain_length_after = GetCodeChainLength(*code);
|
| CHECK_EQ(code_chain_length_before - 1, code_chain_length_after);
|
| @@ -4169,7 +4230,7 @@ TEST(NextCodeLinkIsWeak2) {
|
| context->set(Context::OPTIMIZED_CODE_LIST, *immortal);
|
| new_head = scope.CloseAndEscape(immortal);
|
| }
|
| - heap->CollectAllAvailableGarbage();
|
| + heap->CollectAllAvailableGarbage("kill mortal code", 1);
|
| // Now mortal code should be dead.
|
| CHECK_EQ(*old_head, new_head->next_code_link());
|
| }
|
| @@ -4311,7 +4372,7 @@ TEST(WeakCell) {
|
| heap->CollectGarbage(NEW_SPACE);
|
| CHECK(weak_cell1->value()->IsFixedArray());
|
| CHECK_EQ(*survivor, weak_cell2->value());
|
| - heap->CollectAllAvailableGarbage();
|
| + heap->CollectAllAvailableGarbage("kill weak cell", 1);
|
| CHECK(weak_cell1->cleared());
|
| CHECK_EQ(*survivor, weak_cell2->value());
|
| }
|
|
|