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

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

Issue 181833004: Fix memory leak caused by treating Code::next_code_link as strong in marker. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix test Created 6 years, 10 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
« src/objects-visiting-inl.h ('K') | « src/objects-visiting-inl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
« src/objects-visiting-inl.h ('K') | « src/objects-visiting-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698