@@ -3373,14 +3373,13 @@ struct ScriptCompileTimerScope {
33733373 }
33743374};
33753375
3376- Handle<Script> NewScript (
3377- Isolate* isolate, ParseInfo* parse_info, Handle<String> source,
3378- ScriptDetails script_details, NativesFlag natives,
3379- MaybeHandle<FixedArray> maybe_wrapped_arguments = kNullMaybeHandle ) {
3376+ Handle<Script> NewScript (Isolate* isolate, ParseInfo* parse_info,
3377+ Handle<String> source, ScriptDetails script_details,
3378+ NativesFlag natives) {
33803379 // Create a script object describing the script to be compiled.
3381- Handle<Script> script =
3382- parse_info-> CreateScript ( isolate, source, maybe_wrapped_arguments ,
3383- script_details.origin_options , natives);
3380+ Handle<Script> script = parse_info-> CreateScript (
3381+ isolate, source, script_details. wrapped_arguments ,
3382+ script_details.origin_options , natives);
33843383 DisallowGarbageCollection no_gc;
33853384 SetScriptFieldsFromDetails (isolate, *script, script_details, &no_gc);
33863385 LOG (isolate, ScriptDetails (*script));
@@ -3790,9 +3789,8 @@ Compiler::GetSharedFunctionInfoForScriptWithCompileHints(
37903789
37913790// static
37923791MaybeHandle<JSFunction> Compiler::GetWrappedFunction (
3793- Handle<String> source, Handle<FixedArray> arguments,
3794- Handle<Context> context, const ScriptDetails& script_details,
3795- AlignedCachedData* cached_data,
3792+ Handle<String> source, Handle<Context> context,
3793+ const ScriptDetails& script_details, AlignedCachedData* cached_data,
37963794 v8::ScriptCompiler::CompileOptions compile_options,
37973795 v8::ScriptCompiler::NoCacheReason no_cache_reason) {
37983796 Isolate* isolate = context->GetIsolate ();
@@ -3802,16 +3800,28 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
38023800
38033801 if (compile_options == ScriptCompiler::kConsumeCodeCache ) {
38043802 DCHECK (cached_data);
3803+ DCHECK_EQ (script_details.repl_mode , REPLMode::kNo );
38053804 } else {
38063805 DCHECK_NULL (cached_data);
38073806 }
38083807
38093808 LanguageMode language_mode = construct_language_mode (v8_flags.use_strict );
3810-
3809+ DCHECK (!script_details. wrapped_arguments . is_null ());
38113810 MaybeHandle<SharedFunctionInfo> maybe_result;
3811+ Handle<SharedFunctionInfo> result;
3812+ Handle<Script> script;
3813+ IsCompiledScope is_compiled_scope;
38123814 bool can_consume_code_cache =
38133815 compile_options == ScriptCompiler::kConsumeCodeCache ;
3814- if (can_consume_code_cache) {
3816+ CompilationCache* compilation_cache = isolate->compilation_cache ();
3817+ // First check per-isolate compilation cache.
3818+ CompilationCacheScript::LookupResult lookup_result =
3819+ compilation_cache->LookupScript (source, script_details, language_mode);
3820+ maybe_result = lookup_result.toplevel_sfi ();
3821+ if (maybe_result.ToHandle (&result)) {
3822+ is_compiled_scope = result->is_compiled_scope (isolate);
3823+ compile_timer.set_hit_isolate_cache ();
3824+ } else if (can_consume_code_cache) {
38153825 compile_timer.set_consuming_code_cache ();
38163826 // Then check cached code provided by embedder.
38173827 NestedTimedHistogramScope timer (isolate->counters ()->compile_deserialize ());
@@ -3820,16 +3830,22 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
38203830 " V8.CompileDeserialize" );
38213831 maybe_result = CodeSerializer::Deserialize (isolate, cached_data, source,
38223832 script_details.origin_options );
3823- if (maybe_result.is_null ()) {
3833+ bool consuming_code_cache_succeeded = false ;
3834+ if (maybe_result.ToHandle (&result)) {
3835+ is_compiled_scope = result->is_compiled_scope (isolate);
3836+ if (is_compiled_scope.is_compiled ()) {
3837+ consuming_code_cache_succeeded = true ;
3838+ // Promote to per-isolate compilation cache.
3839+ compilation_cache->PutScript (source, language_mode, result);
3840+ }
3841+ }
3842+ if (!consuming_code_cache_succeeded) {
38243843 // Deserializer failed. Fall through to compile.
38253844 compile_timer.set_consuming_code_cache_failed ();
38263845 }
38273846 }
38283847
3829- Handle<SharedFunctionInfo> wrapped;
3830- Handle<Script> script;
3831- IsCompiledScope is_compiled_scope;
3832- if (!maybe_result.ToHandle (&wrapped)) {
3848+ if (maybe_result.is_null ()) {
38333849 UnoptimizedCompileFlags flags = UnoptimizedCompileFlags::ForToplevelCompile (
38343850 isolate, true , language_mode, script_details.repl_mode ,
38353851 ScriptType::kClassic , v8_flags.lazy );
@@ -3849,9 +3865,8 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
38493865 if (!IsNativeContext (*context)) {
38503866 maybe_outer_scope_info = handle (context->scope_info (), isolate);
38513867 }
3852-
38533868 script = NewScript (isolate, &parse_info, source, script_details,
3854- NOT_NATIVES_CODE, arguments );
3869+ NOT_NATIVES_CODE);
38553870
38563871 Handle<SharedFunctionInfo> top_level;
38573872 maybe_result = v8::internal::CompileToplevel (&parse_info, script,
@@ -3864,18 +3879,23 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
38643879 for (Tagged<SharedFunctionInfo> info = infos.Next (); !info.is_null ();
38653880 info = infos.Next ()) {
38663881 if (info->is_wrapped ()) {
3867- wrapped = Handle<SharedFunctionInfo>(info, isolate);
3882+ result = Handle<SharedFunctionInfo>(info, isolate);
38683883 break ;
38693884 }
38703885 }
3871- DCHECK (!wrapped.is_null ());
3872- } else {
3873- is_compiled_scope = wrapped->is_compiled_scope (isolate);
3874- script = Handle<Script>(Script::cast (wrapped->script ()), isolate);
3886+ DCHECK (!result.is_null ());
3887+
3888+ is_compiled_scope = result->is_compiled_scope (isolate);
3889+ script = Handle<Script>(Script::cast (result->script ()), isolate);
3890+ // Add the result to the isolate cache if there's no context extension.
3891+ if (maybe_outer_scope_info.is_null ()) {
3892+ compilation_cache->PutScript (source, language_mode, result);
3893+ }
38753894 }
3895+
38763896 DCHECK (is_compiled_scope.is_compiled ());
38773897
3878- return Factory::JSFunctionBuilder{isolate, wrapped , context}
3898+ return Factory::JSFunctionBuilder{isolate, result , context}
38793899 .set_allocation_type (AllocationType::kYoung )
38803900 .Build ();
38813901}
0 commit comments