Index: test/cctest/test-heap.cc |
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc |
index f8757e1c0cf97899902a0df831205d00bdd15af0..d1e4bcdb979538ed9b9c1c263beadb129f7447d0 100644 |
--- a/test/cctest/test-heap.cc |
+++ b/test/cctest/test-heap.cc |
@@ -3688,3 +3688,58 @@ TEST(ObjectsInOptimizedCodeAreWeak) { |
ASSERT(code->marked_for_deoptimization()); |
} |
+ |
+ |
+static Handle<JSFunction> OptimizeDummyFunction(const char* name) { |
+ char source[256]; |
+ snprintf(source, sizeof(source), |
+ "function %s() { return 0; }" |
+ "%s(); %s();" |
+ "%%OptimizeFunctionOnNextCall(%s);" |
+ "%s();", name, name, name, name, name); |
+ CompileRun(source); |
+ Handle<JSFunction> fun = |
+ v8::Utils::OpenHandle( |
+ *v8::Handle<v8::Function>::Cast( |
+ CcTest::global()->Get(v8_str(name)))); |
+ return fun; |
+} |
+ |
+ |
+static int GetCodeChainLength(Code* code) { |
+ int result = 0; |
+ while (code->next_code_link()->IsCode()) { |
+ result++; |
+ code = Code::cast(code->next_code_link()); |
+ } |
+ return result; |
+} |
+ |
+ |
+TEST(NextCodeLinkIsWeak) { |
titzer
2014/03/05 08:58:02
Why not make a test case that creates optimized co
ulan
2014/03/06 11:13:32
It assumes two things:
- next_code_link is used fo
|
+ if (!i::FLAG_crankshaft) return; |
+ i::FLAG_allow_natives_syntax = true; |
+ CcTest::InitializeVM(); |
+ Isolate* isolate = CcTest::i_isolate(); |
+ v8::internal::Heap* heap = CcTest::heap(); |
+ |
+ if (!isolate->use_crankshaft()) return; |
+ HandleScope outer_scope(heap->isolate()); |
+ Handle<Code> code; |
+ heap->CollectAllAvailableGarbage(); |
+ int code_chain_length_before, code_chain_length_after; |
+ { |
+ HandleScope scope(heap->isolate()); |
+ Handle<JSFunction> mortal = OptimizeDummyFunction("mortal"); |
+ Handle<JSFunction> immortal = OptimizeDummyFunction("immortal"); |
+ CHECK_EQ(immortal->code()->next_code_link(), mortal->code()); |
+ code_chain_length_before = GetCodeChainLength(immortal->code()); |
+ // Keep the immortal code and let the mortal code die. |
+ code = scope.CloseAndEscape(Handle<Code>(immortal->code())); |
+ CompileRun("mortal = null; immortal = null;"); |
+ } |
+ heap->CollectAllAvailableGarbage(); |
+ // Now mortal code should be dead. |
+ code_chain_length_after = GetCodeChainLength(*code); |
+ CHECK_EQ(code_chain_length_before - 1, code_chain_length_after); |
+} |