@@ -3255,14 +3255,13 @@ struct ScriptCompileTimerScope {
32553255 }
32563256};
32573257
3258- Handle<Script> NewScript (
3259- Isolate* isolate, ParseInfo* parse_info, Handle<String> source,
3260- ScriptDetails script_details, NativesFlag natives,
3261- MaybeHandle<FixedArray> maybe_wrapped_arguments = kNullMaybeHandle ) {
3258+ Handle<Script> NewScript (Isolate* isolate, ParseInfo* parse_info,
3259+ Handle<String> source, ScriptDetails script_details,
3260+ NativesFlag natives) {
32623261 // Create a script object describing the script to be compiled.
3263- Handle<Script> script =
3264- parse_info-> CreateScript ( isolate, source, maybe_wrapped_arguments ,
3265- script_details.origin_options , natives);
3262+ Handle<Script> script = parse_info-> CreateScript (
3263+ isolate, source, script_details. wrapped_arguments ,
3264+ script_details.origin_options , natives);
32663265 DisallowGarbageCollection no_gc;
32673266 SetScriptFieldsFromDetails (isolate, *script, script_details, &no_gc);
32683267 LOG (isolate, ScriptDetails (*script));
@@ -3639,26 +3638,37 @@ Compiler::GetSharedFunctionInfoForScriptWithCompileHints(
36393638
36403639// static
36413640MaybeHandle<JSFunction> Compiler::GetWrappedFunction (
3642- Handle<String> source, Handle<FixedArray> arguments,
3643- Handle<Context> context, const ScriptDetails& script_details,
3644- AlignedCachedData* cached_data,
3641+ Handle<String> source, Handle<Context> context,
3642+ const ScriptDetails& script_details, AlignedCachedData* cached_data,
36453643 v8::ScriptCompiler::CompileOptions compile_options,
36463644 v8::ScriptCompiler::NoCacheReason no_cache_reason) {
36473645 Isolate* isolate = context->GetIsolate ();
36483646 ScriptCompileTimerScope compile_timer (isolate, no_cache_reason);
36493647
36503648 if (compile_options == ScriptCompiler::kConsumeCodeCache ) {
36513649 DCHECK (cached_data);
3650+ DCHECK_EQ (script_details.repl_mode , REPLMode::kNo );
36523651 } else {
36533652 DCHECK_NULL (cached_data);
36543653 }
36553654
36563655 LanguageMode language_mode = construct_language_mode (v8_flags.use_strict );
3657-
3656+ DCHECK (!script_details. wrapped_arguments . is_null ());
36583657 MaybeHandle<SharedFunctionInfo> maybe_result;
3658+ Handle<SharedFunctionInfo> result;
3659+ Handle<Script> script;
3660+ IsCompiledScope is_compiled_scope;
36593661 bool can_consume_code_cache =
36603662 compile_options == ScriptCompiler::kConsumeCodeCache ;
3661- if (can_consume_code_cache) {
3663+ CompilationCache* compilation_cache = isolate->compilation_cache ();
3664+ // First check per-isolate compilation cache.
3665+ CompilationCacheScript::LookupResult lookup_result =
3666+ compilation_cache->LookupScript (source, script_details, language_mode);
3667+ maybe_result = lookup_result.toplevel_sfi ();
3668+ if (maybe_result.ToHandle (&result)) {
3669+ is_compiled_scope = result->is_compiled_scope (isolate);
3670+ compile_timer.set_hit_isolate_cache ();
3671+ } else if (can_consume_code_cache) {
36623672 compile_timer.set_consuming_code_cache ();
36633673 // Then check cached code provided by embedder.
36643674 NestedTimedHistogramScope timer (isolate->counters ()->compile_deserialize ());
@@ -3667,16 +3677,22 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
36673677 " V8.CompileDeserialize" );
36683678 maybe_result = CodeSerializer::Deserialize (isolate, cached_data, source,
36693679 script_details.origin_options );
3670- if (maybe_result.is_null ()) {
3680+ bool consuming_code_cache_succeeded = false ;
3681+ if (maybe_result.ToHandle (&result)) {
3682+ is_compiled_scope = result->is_compiled_scope (isolate);
3683+ if (is_compiled_scope.is_compiled ()) {
3684+ consuming_code_cache_succeeded = true ;
3685+ // Promote to per-isolate compilation cache.
3686+ compilation_cache->PutScript (source, language_mode, result);
3687+ }
3688+ }
3689+ if (!consuming_code_cache_succeeded) {
36713690 // Deserializer failed. Fall through to compile.
36723691 compile_timer.set_consuming_code_cache_failed ();
36733692 }
36743693 }
36753694
3676- Handle<SharedFunctionInfo> wrapped;
3677- Handle<Script> script;
3678- IsCompiledScope is_compiled_scope;
3679- if (!maybe_result.ToHandle (&wrapped)) {
3695+ if (maybe_result.is_null ()) {
36803696 UnoptimizedCompileFlags flags = UnoptimizedCompileFlags::ForToplevelCompile (
36813697 isolate, true , language_mode, script_details.repl_mode ,
36823698 ScriptType::kClassic , v8_flags.lazy );
@@ -3696,9 +3712,8 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
36963712 if (!context->IsNativeContext ()) {
36973713 maybe_outer_scope_info = handle (context->scope_info (), isolate);
36983714 }
3699-
37003715 script = NewScript (isolate, &parse_info, source, script_details,
3701- NOT_NATIVES_CODE, arguments );
3716+ NOT_NATIVES_CODE);
37023717
37033718 Handle<SharedFunctionInfo> top_level;
37043719 maybe_result = v8::internal::CompileToplevel (&parse_info, script,
@@ -3711,18 +3726,23 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
37113726 for (SharedFunctionInfo info = infos.Next (); !info.is_null ();
37123727 info = infos.Next ()) {
37133728 if (info.is_wrapped ()) {
3714- wrapped = Handle<SharedFunctionInfo>(info, isolate);
3729+ result = Handle<SharedFunctionInfo>(info, isolate);
37153730 break ;
37163731 }
37173732 }
3718- DCHECK (!wrapped.is_null ());
3719- } else {
3720- is_compiled_scope = wrapped->is_compiled_scope (isolate);
3721- script = Handle<Script>(Script::cast (wrapped->script ()), isolate);
3733+ DCHECK (!result.is_null ());
3734+
3735+ is_compiled_scope = result->is_compiled_scope (isolate);
3736+ script = Handle<Script>(Script::cast (result->script ()), isolate);
3737+ // Add the result to the isolate cache if there's no context extension.
3738+ if (maybe_outer_scope_info.is_null ()) {
3739+ compilation_cache->PutScript (source, language_mode, result);
3740+ }
37223741 }
3742+
37233743 DCHECK (is_compiled_scope.is_compiled ());
37243744
3725- return Factory::JSFunctionBuilder{isolate, wrapped , context}
3745+ return Factory::JSFunctionBuilder{isolate, result , context}
37263746 .set_allocation_type (AllocationType::kYoung )
37273747 .Build ();
37283748}
0 commit comments