From b1fe586e6bd553c3a9d69e53d2ffc7fbeeb4fabb Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Mon, 18 Jun 2012 13:26:43 +0000 Subject: [PATCH] Fix optimized code caching in FastNewClosureStub. This fixes a corner-case on ARM and MIPS where optimized code was not shared immediately across closures when a function was used in several global contexts at once. R=ulan@chromium.org TEST=cctest/test-compiler/OptimizedCodeSharing Review URL: https://chromiumcodereview.appspot.com/10544205 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11850 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/code-stubs-arm.cc | 1 - src/mips/code-stubs-mips.cc | 1 - test/cctest/test-compiler.cc | 29 +++++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index 7c0db4cbbf..169a032fb0 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -158,7 +158,6 @@ void FastNewClosureStub::Generate(MacroAssembler* masm) { __ ldr(r5, FieldMemOperand(r1, FixedArray::kHeaderSize)); __ cmp(r2, r5); __ b(eq, &install_optimized); - __ b(&install_unoptimized); // Iterate through the rest of map backwards. r4 holds an index as a Smi. Label loop; diff --git a/src/mips/code-stubs-mips.cc b/src/mips/code-stubs-mips.cc index 2155b18647..7ae84fa9ff 100644 --- a/src/mips/code-stubs-mips.cc +++ b/src/mips/code-stubs-mips.cc @@ -159,7 +159,6 @@ void FastNewClosureStub::Generate(MacroAssembler* masm) { __ lw(t0, FieldMemOperand(a1, FixedArray::kHeaderSize + kPointerSize)); __ lw(t1, FieldMemOperand(a1, FixedArray::kHeaderSize)); __ Branch(&install_optimized, eq, a2, Operand(t1)); - __ Branch(&install_unoptimized); // Iterate through the rest of map backwards. t0 holds an index as a Smi. Label loop; diff --git a/test/cctest/test-compiler.cc b/test/cctest/test-compiler.cc index 9ca0b0a170..e366a06828 100644 --- a/test/cctest/test-compiler.cc +++ b/test/cctest/test-compiler.cc @@ -352,6 +352,35 @@ TEST(GetScriptLineNumber) { } +// Test that optimized code for different closures is actually shared +// immediately by the FastNewClosureStub when run in the same context. +TEST(OptimizedCodeSharing) { + FLAG_allow_natives_syntax = true; + InitializeVM(); + v8::HandleScope scope; + for (int i = 0; i < 10; i++) { + LocalContext env; + env->Global()->Set(v8::String::New("x"), v8::Integer::New(i)); + CompileRun("function MakeClosure() {" + " return function() { return x; };" + "}" + "var closure0 = MakeClosure();" + "%DebugPrint(closure0());" + "%OptimizeFunctionOnNextCall(closure0);" + "%DebugPrint(closure0());" + "var closure1 = MakeClosure();" + "var closure2 = MakeClosure();"); + Handle fun1 = v8::Utils::OpenHandle( + *v8::Local::Cast(env->Global()->Get(v8_str("closure1")))); + Handle fun2 = v8::Utils::OpenHandle( + *v8::Local::Cast(env->Global()->Get(v8_str("closure2")))); + CHECK(fun1->IsOptimized() || !FLAG_crankshaft); + CHECK(fun2->IsOptimized() || !FLAG_crankshaft); + CHECK_EQ(fun1->code(), fun2->code()); + } +} + + #ifdef ENABLE_DISASSEMBLER static Handle GetJSFunction(v8::Handle obj, const char* property_name) {