Commit 567e45a1 authored by yangguo's avatar yangguo Committed by Commit bot

Promote code from code cache to compilation cache.

The per-isolate compilation cache is a lot faster still than
the serialized code cache. Promote code to compilation cache
after deserialization.

R=vogelheim@chromium.org
BUG=chromium:399580
LOG=N

Review URL: https://codereview.chromium.org/1008363002

Cr-Commit-Position: refs/heads/master@{#27220}
parent cf1c4911
...@@ -1246,6 +1246,7 @@ Handle<SharedFunctionInfo> Compiler::CompileScript( ...@@ -1246,6 +1246,7 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
MaybeHandle<SharedFunctionInfo> maybe_result; MaybeHandle<SharedFunctionInfo> maybe_result;
Handle<SharedFunctionInfo> result; Handle<SharedFunctionInfo> result;
if (extension == NULL) { if (extension == NULL) {
// First check per-isolate compilation cache.
maybe_result = compilation_cache->LookupScript( maybe_result = compilation_cache->LookupScript(
source, script_name, line_offset, column_offset, source, script_name, line_offset, column_offset,
is_embedder_debug_script, is_shared_cross_origin, context, is_embedder_debug_script, is_shared_cross_origin, context,
...@@ -1253,10 +1254,14 @@ Handle<SharedFunctionInfo> Compiler::CompileScript( ...@@ -1253,10 +1254,14 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
if (maybe_result.is_null() && FLAG_serialize_toplevel && if (maybe_result.is_null() && FLAG_serialize_toplevel &&
compile_options == ScriptCompiler::kConsumeCodeCache && compile_options == ScriptCompiler::kConsumeCodeCache &&
!isolate->debug()->is_loaded()) { !isolate->debug()->is_loaded()) {
// Then check cached code provided by embedder.
HistogramTimerScope timer(isolate->counters()->compile_deserialize()); HistogramTimerScope timer(isolate->counters()->compile_deserialize());
Handle<SharedFunctionInfo> result; Handle<SharedFunctionInfo> result;
if (CodeSerializer::Deserialize(isolate, *cached_data, source) if (CodeSerializer::Deserialize(isolate, *cached_data, source)
.ToHandle(&result)) { .ToHandle(&result)) {
// Promote to per-isolate compilation cache.
DCHECK(!result->dont_cache());
compilation_cache->PutScript(source, context, language_mode, result);
return result; return result;
} }
// Deserializer failed. Fall through to compile. // Deserializer failed. Fall through to compile.
......
...@@ -819,6 +819,37 @@ TEST(SerializeToplevelOnePlusOne) { ...@@ -819,6 +819,37 @@ TEST(SerializeToplevelOnePlusOne) {
} }
TEST(CodeCachePromotedToCompilationCache) {
FLAG_serialize_toplevel = true;
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate());
const char* source = "1 + 1";
Handle<String> src = isolate->factory()
->NewStringFromUtf8(CStrVector(source))
.ToHandleChecked();
ScriptData* cache = NULL;
CompileScript(isolate, src, src, &cache,
v8::ScriptCompiler::kProduceCodeCache);
DisallowCompilation no_compile_expected(isolate);
Handle<SharedFunctionInfo> copy = CompileScript(
isolate, src, src, &cache, v8::ScriptCompiler::kConsumeCodeCache);
CHECK(isolate->compilation_cache()
->LookupScript(src, src, 0, 0, false, false,
isolate->native_context(), SLOPPY)
.ToHandleChecked()
.is_identical_to(copy));
delete cache;
}
TEST(SerializeToplevelInternalizedString) { TEST(SerializeToplevelInternalizedString) {
FLAG_serialize_toplevel = true; FLAG_serialize_toplevel = true;
LocalContext context; LocalContext context;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment