@@ -3353,14 +3353,13 @@ struct ScriptCompileTimerScope {
33533353 }
33543354};
33553355
3356- Handle<Script> NewScript (
3357- Isolate* isolate, ParseInfo* parse_info, Handle<String> source,
3358- ScriptDetails script_details, NativesFlag natives,
3359- MaybeHandle<FixedArray> maybe_wrapped_arguments = kNullMaybeHandle ) {
3356+ Handle<Script> NewScript (Isolate* isolate, ParseInfo* parse_info,
3357+ Handle<String> source, ScriptDetails script_details,
3358+ NativesFlag natives) {
33603359 // Create a script object describing the script to be compiled.
3361- Handle<Script> script =
3362- parse_info-> CreateScript ( isolate, source, maybe_wrapped_arguments ,
3363- script_details.origin_options , natives);
3360+ Handle<Script> script = parse_info-> CreateScript (
3361+ isolate, source, script_details. wrapped_arguments ,
3362+ script_details.origin_options , natives);
33643363 DisallowGarbageCollection no_gc;
33653364 SetScriptFieldsFromDetails (isolate, *script, script_details, &no_gc);
33663365 LOG (isolate, ScriptDetails (*script));
@@ -3742,26 +3741,37 @@ Compiler::GetSharedFunctionInfoForScriptWithCompileHints(
37423741
37433742// static
37443743MaybeHandle<JSFunction> Compiler::GetWrappedFunction (
3745- Handle<String> source, Handle<FixedArray> arguments,
3746- Handle<Context> context, const ScriptDetails& script_details,
3747- AlignedCachedData* cached_data,
3744+ Handle<String> source, Handle<Context> context,
3745+ const ScriptDetails& script_details, AlignedCachedData* cached_data,
37483746 v8::ScriptCompiler::CompileOptions compile_options,
37493747 v8::ScriptCompiler::NoCacheReason no_cache_reason) {
37503748 Isolate* isolate = context->GetIsolate ();
37513749 ScriptCompileTimerScope compile_timer (isolate, no_cache_reason);
37523750
37533751 if (compile_options == ScriptCompiler::kConsumeCodeCache ) {
37543752 DCHECK (cached_data);
3753+ DCHECK_EQ (script_details.repl_mode , REPLMode::kNo );
37553754 } else {
37563755 DCHECK_NULL (cached_data);
37573756 }
37583757
37593758 LanguageMode language_mode = construct_language_mode (v8_flags.use_strict );
3760-
3759+ DCHECK (!script_details. wrapped_arguments . is_null ());
37613760 MaybeHandle<SharedFunctionInfo> maybe_result;
3761+ Handle<SharedFunctionInfo> result;
3762+ Handle<Script> script;
3763+ IsCompiledScope is_compiled_scope;
37623764 bool can_consume_code_cache =
37633765 compile_options == ScriptCompiler::kConsumeCodeCache ;
3764- if (can_consume_code_cache) {
3766+ CompilationCache* compilation_cache = isolate->compilation_cache ();
3767+ // First check per-isolate compilation cache.
3768+ CompilationCacheScript::LookupResult lookup_result =
3769+ compilation_cache->LookupScript (source, script_details, language_mode);
3770+ maybe_result = lookup_result.toplevel_sfi ();
3771+ if (maybe_result.ToHandle (&result)) {
3772+ is_compiled_scope = result->is_compiled_scope (isolate);
3773+ compile_timer.set_hit_isolate_cache ();
3774+ } else if (can_consume_code_cache) {
37653775 compile_timer.set_consuming_code_cache ();
37663776 // Then check cached code provided by embedder.
37673777 NestedTimedHistogramScope timer (isolate->counters ()->compile_deserialize ());
@@ -3770,16 +3780,22 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
37703780 " V8.CompileDeserialize" );
37713781 maybe_result = CodeSerializer::Deserialize (isolate, cached_data, source,
37723782 script_details.origin_options );
3773- if (maybe_result.is_null ()) {
3783+ bool consuming_code_cache_succeeded = false ;
3784+ if (maybe_result.ToHandle (&result)) {
3785+ is_compiled_scope = result->is_compiled_scope (isolate);
3786+ if (is_compiled_scope.is_compiled ()) {
3787+ consuming_code_cache_succeeded = true ;
3788+ // Promote to per-isolate compilation cache.
3789+ compilation_cache->PutScript (source, language_mode, result);
3790+ }
3791+ }
3792+ if (!consuming_code_cache_succeeded) {
37743793 // Deserializer failed. Fall through to compile.
37753794 compile_timer.set_consuming_code_cache_failed ();
37763795 }
37773796 }
37783797
3779- Handle<SharedFunctionInfo> wrapped;
3780- Handle<Script> script;
3781- IsCompiledScope is_compiled_scope;
3782- if (!maybe_result.ToHandle (&wrapped)) {
3798+ if (maybe_result.is_null ()) {
37833799 UnoptimizedCompileFlags flags = UnoptimizedCompileFlags::ForToplevelCompile (
37843800 isolate, true , language_mode, script_details.repl_mode ,
37853801 ScriptType::kClassic , v8_flags.lazy );
@@ -3799,9 +3815,8 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
37993815 if (!IsNativeContext (*context)) {
38003816 maybe_outer_scope_info = handle (context->scope_info (), isolate);
38013817 }
3802-
38033818 script = NewScript (isolate, &parse_info, source, script_details,
3804- NOT_NATIVES_CODE, arguments );
3819+ NOT_NATIVES_CODE);
38053820
38063821 Handle<SharedFunctionInfo> top_level;
38073822 maybe_result = v8::internal::CompileToplevel (&parse_info, script,
@@ -3814,18 +3829,23 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
38143829 for (Tagged<SharedFunctionInfo> info = infos.Next (); !info.is_null ();
38153830 info = infos.Next ()) {
38163831 if (info->is_wrapped ()) {
3817- wrapped = Handle<SharedFunctionInfo>(info, isolate);
3832+ result = Handle<SharedFunctionInfo>(info, isolate);
38183833 break ;
38193834 }
38203835 }
3821- DCHECK (!wrapped.is_null ());
3822- } else {
3823- is_compiled_scope = wrapped->is_compiled_scope (isolate);
3824- script = Handle<Script>(Script::cast (wrapped->script ()), isolate);
3836+ DCHECK (!result.is_null ());
3837+
3838+ is_compiled_scope = result->is_compiled_scope (isolate);
3839+ script = Handle<Script>(Script::cast (result->script ()), isolate);
3840+ // Add the result to the isolate cache if there's no context extension.
3841+ if (maybe_outer_scope_info.is_null ()) {
3842+ compilation_cache->PutScript (source, language_mode, result);
3843+ }
38253844 }
3845+
38263846 DCHECK (is_compiled_scope.is_compiled ());
38273847
3828- return Factory::JSFunctionBuilder{isolate, wrapped , context}
3848+ return Factory::JSFunctionBuilder{isolate, result , context}
38293849 .set_allocation_type (AllocationType::kYoung )
38303850 .Build ();
38313851}
0 commit comments