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

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

Issue 1208013002: [turbofan] Implement sharing of context-independent code. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_opt-code-map-3
Patch Set: Disable test for GC stress. Created 5 years, 6 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
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-compiler.cc
diff --git a/test/cctest/test-compiler.cc b/test/cctest/test-compiler.cc
index 493189cb543ec812905c779748e55470e8518851..3b25480a4aa784687daacb44cdc7ea90bbd74d0e 100644
--- a/test/cctest/test-compiler.cc
+++ b/test/cctest/test-compiler.cc
@@ -370,7 +370,7 @@ TEST(FeedbackVectorUnaffectedByScopeChanges) {
// Test that optimized code for different closures is actually shared
// immediately by the FastNewClosureStub when run in the same context.
-TEST(OptimizedCodeSharing) {
+TEST(OptimizedCodeSharing1) {
FLAG_stress_compaction = false;
FLAG_allow_natives_syntax = true;
FLAG_cache_optimized_code = true;
@@ -380,15 +380,16 @@ TEST(OptimizedCodeSharing) {
LocalContext env;
env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"),
v8::Integer::New(CcTest::isolate(), i));
- CompileRun("function MakeClosure() {"
- " return function() { return x; };"
- "}"
- "var closure0 = MakeClosure();"
- "%DebugPrint(closure0());"
- "%OptimizeFunctionOnNextCall(closure0);"
- "%DebugPrint(closure0());"
- "var closure1 = MakeClosure();"
- "var closure2 = MakeClosure();");
+ CompileRun(
+ "function MakeClosure() {"
+ " return function() { return x; };"
+ "}"
+ "var closure0 = MakeClosure();"
+ "%DebugPrint(closure0());"
+ "%OptimizeFunctionOnNextCall(closure0);"
+ "%DebugPrint(closure0());"
+ "var closure1 = MakeClosure();"
+ "var closure2 = MakeClosure();");
Handle<JSFunction> fun1 = v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure1"))));
Handle<JSFunction> fun2 = v8::Utils::OpenHandle(
@@ -400,6 +401,61 @@ TEST(OptimizedCodeSharing) {
}
+// Test that optimized code for different closures is actually shared
+// immediately by the FastNewClosureStub when run different contexts.
+TEST(OptimizedCodeSharing2) {
+ if (FLAG_stress_compaction) return;
+ FLAG_allow_natives_syntax = true;
+ FLAG_cache_optimized_code = true;
+ FLAG_turbo_cache_shared_code = true;
+ const char* flag = "--turbo-filter=*";
+ FlagList::SetFlagsFromString(flag, StrLength(flag));
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
+ v8::Local<v8::Script> script = v8_compile(
+ "function MakeClosure() {"
+ " return function() { return x; };"
+ "}");
+ Handle<Code> reference_code;
+ {
+ LocalContext env;
+ env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"),
+ v8::Integer::New(CcTest::isolate(), 23));
+ script->GetUnboundScript()->BindToCurrentContext()->Run();
+ CompileRun(
+ "var closure0 = MakeClosure();"
+ "%DebugPrint(closure0());"
+ "%OptimizeFunctionOnNextCall(closure0);"
+ "%DebugPrint(closure0());");
+ Handle<JSFunction> fun0 = v8::Utils::OpenHandle(
+ *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure0"))));
+ CHECK(fun0->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
+ reference_code = handle(fun0->code());
+ }
+ for (int i = 0; i < 10; i++) {
+ LocalContext env;
+ env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"),
+ v8::Integer::New(CcTest::isolate(), i));
+ script->GetUnboundScript()->BindToCurrentContext()->Run();
+ CompileRun(
+ "var closure0 = MakeClosure();"
+ "%DebugPrint(closure0());"
+ "%OptimizeFunctionOnNextCall(closure0);"
+ "%DebugPrint(closure0());"
+ "var closure1 = MakeClosure();"
+ "var closure2 = MakeClosure();");
+ Handle<JSFunction> fun1 = v8::Utils::OpenHandle(
+ *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure1"))));
+ Handle<JSFunction> fun2 = v8::Utils::OpenHandle(
+ *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure2"))));
+ CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
+ CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
+ CHECK_EQ(*reference_code, fun1->code());
+ CHECK_EQ(*reference_code, fun2->code());
+ }
+}
+
+
TEST(CompileFunctionInContext) {
CcTest::InitializeVM();
v8::HandleScope scope(CcTest::isolate());
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698