Commit 983462da authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[cleanup] Pass Isolate to Compiler::Compile*

Pass an explicit Isolate* argument to Compiler::Compile*, rather
than grabbing the Isolate from the function

Change-Id: I37a38103c67305077225ea3951d36007cf07beea
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2696655Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72762}
parent e9ee4982
...@@ -1745,18 +1745,17 @@ bool Compiler::CollectSourcePositions(Isolate* isolate, ...@@ -1745,18 +1745,17 @@ bool Compiler::CollectSourcePositions(Isolate* isolate,
} }
// static // static
bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info, bool Compiler::Compile(Isolate* isolate, Handle<SharedFunctionInfo> shared_info,
ClearExceptionFlag flag, ClearExceptionFlag flag,
IsCompiledScope* is_compiled_scope) { IsCompiledScope* is_compiled_scope) {
// We should never reach here if the function is already compiled. // We should never reach here if the function is already compiled.
DCHECK(!shared_info->is_compiled()); DCHECK(!shared_info->is_compiled());
DCHECK(!is_compiled_scope->is_compiled()); DCHECK(!is_compiled_scope->is_compiled());
Isolate* isolate = shared_info->GetIsolate();
DCHECK(AllowCompilation::IsAllowed(isolate)); DCHECK(AllowCompilation::IsAllowed(isolate));
DCHECK_EQ(ThreadId::Current(), isolate->thread_id()); DCHECK_EQ(ThreadId::Current(), isolate->thread_id());
DCHECK(!isolate->has_pending_exception()); DCHECK(!isolate->has_pending_exception());
DCHECK(!shared_info->HasBytecodeArray()); DCHECK(!shared_info->HasBytecodeArray());
VMState<BYTECODE_COMPILER> state(isolate); VMState<BYTECODE_COMPILER> state(isolate);
PostponeInterruptsScope postpone(isolate); PostponeInterruptsScope postpone(isolate);
TimerEventScope<TimerEventCompileCode> compile_timer(isolate); TimerEventScope<TimerEventCompileCode> compile_timer(isolate);
...@@ -1820,7 +1819,8 @@ bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info, ...@@ -1820,7 +1819,8 @@ bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info,
} }
// static // static
bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag, bool Compiler::Compile(Isolate* isolate, Handle<JSFunction> function,
ClearExceptionFlag flag,
IsCompiledScope* is_compiled_scope) { IsCompiledScope* is_compiled_scope) {
// We should never reach here if the function is already compiled or // We should never reach here if the function is already compiled or
// optimized. // optimized.
...@@ -1832,13 +1832,12 @@ bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag, ...@@ -1832,13 +1832,12 @@ bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag,
// flushed. // flushed.
function->ResetIfBytecodeFlushed(); function->ResetIfBytecodeFlushed();
Isolate* isolate = function->GetIsolate();
Handle<SharedFunctionInfo> shared_info = handle(function->shared(), isolate); Handle<SharedFunctionInfo> shared_info = handle(function->shared(), isolate);
// Ensure shared function info is compiled. // Ensure shared function info is compiled.
*is_compiled_scope = shared_info->is_compiled_scope(isolate); *is_compiled_scope = shared_info->is_compiled_scope(isolate);
if (!is_compiled_scope->is_compiled() && if (!is_compiled_scope->is_compiled() &&
!Compile(shared_info, flag, is_compiled_scope)) { !Compile(isolate, shared_info, flag, is_compiled_scope)) {
return false; return false;
} }
...@@ -1941,11 +1940,9 @@ bool Compiler::FinalizeBackgroundCompileTask( ...@@ -1941,11 +1940,9 @@ bool Compiler::FinalizeBackgroundCompileTask(
} }
// static // static
bool Compiler::CompileOptimized(Handle<JSFunction> function, bool Compiler::CompileOptimized(Isolate* isolate, Handle<JSFunction> function,
ConcurrencyMode mode, CodeKind code_kind) { ConcurrencyMode mode, CodeKind code_kind) {
DCHECK(CodeKindIsOptimizedJSFunction(code_kind)); DCHECK(CodeKindIsOptimizedJSFunction(code_kind));
Isolate* isolate = function->GetIsolate();
DCHECK(AllowCompilation::IsAllowed(isolate)); DCHECK(AllowCompilation::IsAllowed(isolate));
Handle<Code> code; Handle<Code> code;
......
...@@ -65,12 +65,13 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic { ...@@ -65,12 +65,13 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
// whereas successful compilation ensures the {is_compiled} predicate on the // whereas successful compilation ensures the {is_compiled} predicate on the
// given function holds (except for live-edit, which compiles the world). // given function holds (except for live-edit, which compiles the world).
static bool Compile(Handle<SharedFunctionInfo> shared, static bool Compile(Isolate* isolate, Handle<SharedFunctionInfo> shared,
ClearExceptionFlag flag, ClearExceptionFlag flag,
IsCompiledScope* is_compiled_scope); IsCompiledScope* is_compiled_scope);
static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag, static bool Compile(Isolate* isolate, Handle<JSFunction> function,
ClearExceptionFlag flag,
IsCompiledScope* is_compiled_scope); IsCompiledScope* is_compiled_scope);
static bool CompileOptimized(Handle<JSFunction> function, static bool CompileOptimized(Isolate* isolate, Handle<JSFunction> function,
ConcurrencyMode mode, CodeKind code_kind); ConcurrencyMode mode, CodeKind code_kind);
static MaybeHandle<SharedFunctionInfo> CompileToplevel( static MaybeHandle<SharedFunctionInfo> CompileToplevel(
ParseInfo* parse_info, Handle<Script> script, Isolate* isolate, ParseInfo* parse_info, Handle<Script> script, Isolate* isolate,
......
...@@ -7626,10 +7626,10 @@ std::pair<WasmImportCallKind, Handle<JSReceiver>> ResolveWasmImportCall( ...@@ -7626,10 +7626,10 @@ std::pair<WasmImportCallKind, Handle<JSReceiver>> ResolveWasmImportCall(
} }
// If function isn't compiled, compile it now. // If function isn't compiled, compile it now.
IsCompiledScope is_compiled_scope( Isolate* isolate = callable->GetIsolate();
shared->is_compiled_scope(callable->GetIsolate())); IsCompiledScope is_compiled_scope(shared->is_compiled_scope(isolate));
if (!is_compiled_scope.is_compiled()) { if (!is_compiled_scope.is_compiled()) {
Compiler::Compile(function, Compiler::CLEAR_EXCEPTION, Compiler::Compile(isolate, function, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope); &is_compiled_scope);
} }
......
...@@ -1461,7 +1461,8 @@ void Debug::InstallDebugBreakTrampoline() { ...@@ -1461,7 +1461,8 @@ void Debug::InstallDebugBreakTrampoline() {
// to shared code, we bypass CompileLazy. Perform CompileLazy here instead. // to shared code, we bypass CompileLazy. Perform CompileLazy here instead.
for (Handle<JSFunction> fun : needs_compile) { for (Handle<JSFunction> fun : needs_compile) {
IsCompiledScope is_compiled_scope; IsCompiledScope is_compiled_scope;
Compiler::Compile(fun, Compiler::CLEAR_EXCEPTION, &is_compiled_scope); Compiler::Compile(isolate_, fun, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope);
DCHECK(is_compiled_scope.is_compiled()); DCHECK(is_compiled_scope.is_compiled());
fun->set_code(*trampoline); fun->set_code(*trampoline);
} }
...@@ -1529,7 +1530,7 @@ bool Debug::GetPossibleBreakpoints(Handle<Script> script, int start_position, ...@@ -1529,7 +1530,7 @@ bool Debug::GetPossibleBreakpoints(Handle<Script> script, int start_position,
if (!is_compiled_scope.is_compiled()) { if (!is_compiled_scope.is_compiled()) {
// Code that cannot be compiled lazily are internal and not debuggable. // Code that cannot be compiled lazily are internal and not debuggable.
DCHECK(candidate->allows_lazy_compilation()); DCHECK(candidate->allows_lazy_compilation());
if (!Compiler::Compile(candidate, Compiler::CLEAR_EXCEPTION, if (!Compiler::Compile(isolate_, candidate, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope)) { &is_compiled_scope)) {
return false; return false;
} else { } else {
...@@ -1667,8 +1668,8 @@ Handle<Object> Debug::FindSharedFunctionInfoInScript(Handle<Script> script, ...@@ -1667,8 +1668,8 @@ Handle<Object> Debug::FindSharedFunctionInfoInScript(Handle<Script> script,
HandleScope scope(isolate_); HandleScope scope(isolate_);
// Code that cannot be compiled lazily are internal and not debuggable. // Code that cannot be compiled lazily are internal and not debuggable.
DCHECK(shared.allows_lazy_compilation()); DCHECK(shared.allows_lazy_compilation());
if (!Compiler::Compile(handle(shared, isolate_), Compiler::CLEAR_EXCEPTION, if (!Compiler::Compile(isolate_, handle(shared, isolate_),
&is_compiled_scope)) { Compiler::CLEAR_EXCEPTION, &is_compiled_scope)) {
break; break;
} }
} }
...@@ -1684,7 +1685,7 @@ bool Debug::EnsureBreakInfo(Handle<SharedFunctionInfo> shared) { ...@@ -1684,7 +1685,7 @@ bool Debug::EnsureBreakInfo(Handle<SharedFunctionInfo> shared) {
} }
IsCompiledScope is_compiled_scope = shared->is_compiled_scope(isolate_); IsCompiledScope is_compiled_scope = shared->is_compiled_scope(isolate_);
if (!is_compiled_scope.is_compiled() && if (!is_compiled_scope.is_compiled() &&
!Compiler::Compile(shared, Compiler::CLEAR_EXCEPTION, !Compiler::Compile(isolate_, shared, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope)) { &is_compiled_scope)) {
return false; return false;
} }
...@@ -2423,7 +2424,7 @@ bool Debug::PerformSideEffectCheck(Handle<JSFunction> function, ...@@ -2423,7 +2424,7 @@ bool Debug::PerformSideEffectCheck(Handle<JSFunction> function,
IsCompiledScope is_compiled_scope( IsCompiledScope is_compiled_scope(
function->shared().is_compiled_scope(isolate_)); function->shared().is_compiled_scope(isolate_));
if (!function->is_compiled() && if (!function->is_compiled() &&
!Compiler::Compile(function, Compiler::KEEP_EXCEPTION, !Compiler::Compile(isolate_, function, Compiler::KEEP_EXCEPTION,
&is_compiled_scope)) { &is_compiled_scope)) {
return false; return false;
} }
......
...@@ -967,7 +967,7 @@ int JSFunction::CalculateExpectedNofProperties(Isolate* isolate, ...@@ -967,7 +967,7 @@ int JSFunction::CalculateExpectedNofProperties(Isolate* isolate,
Handle<SharedFunctionInfo> shared(func->shared(), isolate); Handle<SharedFunctionInfo> shared(func->shared(), isolate);
IsCompiledScope is_compiled_scope(shared->is_compiled_scope(isolate)); IsCompiledScope is_compiled_scope(shared->is_compiled_scope(isolate));
if (is_compiled_scope.is_compiled() || if (is_compiled_scope.is_compiled() ||
Compiler::Compile(func, Compiler::CLEAR_EXCEPTION, Compiler::Compile(isolate, func, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope)) { &is_compiled_scope)) {
DCHECK(shared->is_compiled()); DCHECK(shared->is_compiled());
int count = shared->expected_nof_properties(); int count = shared->expected_nof_properties();
......
...@@ -31,9 +31,9 @@ namespace { ...@@ -31,9 +31,9 @@ namespace {
// Returns false iff an exception was thrown. // Returns false iff an exception was thrown.
bool MaybeSpawnNativeContextIndependentCompilationJob( bool MaybeSpawnNativeContextIndependentCompilationJob(
Handle<JSFunction> function, ConcurrencyMode mode) { Isolate* isolate, Handle<JSFunction> function, ConcurrencyMode mode) {
if (!FLAG_turbo_nci) return true; // Nothing to do. if (!FLAG_turbo_nci) return true; // Nothing to do.
return Compiler::CompileOptimized(function, mode, return Compiler::CompileOptimized(isolate, function, mode,
CodeKind::NATIVE_CONTEXT_INDEPENDENT); CodeKind::NATIVE_CONTEXT_INDEPENDENT);
} }
...@@ -45,12 +45,14 @@ Object CompileOptimized(Isolate* isolate, Handle<JSFunction> function, ...@@ -45,12 +45,14 @@ Object CompileOptimized(Isolate* isolate, Handle<JSFunction> function,
} }
// Compile for the next tier. // Compile for the next tier.
if (!Compiler::CompileOptimized(function, mode, function->NextTier())) { if (!Compiler::CompileOptimized(isolate, function, mode,
function->NextTier())) {
return ReadOnlyRoots(isolate).exception(); return ReadOnlyRoots(isolate).exception();
} }
// Possibly compile for NCI caching. // Possibly compile for NCI caching.
if (!MaybeSpawnNativeContextIndependentCompilationJob(function, mode)) { if (!MaybeSpawnNativeContextIndependentCompilationJob(isolate, function,
mode)) {
return ReadOnlyRoots(isolate).exception(); return ReadOnlyRoots(isolate).exception();
} }
...@@ -98,7 +100,7 @@ RUNTIME_FUNCTION(Runtime_CompileLazy) { ...@@ -98,7 +100,7 @@ RUNTIME_FUNCTION(Runtime_CompileLazy) {
return isolate->StackOverflow(); return isolate->StackOverflow();
} }
IsCompiledScope is_compiled_scope; IsCompiledScope is_compiled_scope;
if (!Compiler::Compile(function, Compiler::KEEP_EXCEPTION, if (!Compiler::Compile(isolate, function, Compiler::KEEP_EXCEPTION,
&is_compiled_scope)) { &is_compiled_scope)) {
return ReadOnlyRoots(isolate).exception(); return ReadOnlyRoots(isolate).exception();
} }
...@@ -356,9 +358,10 @@ RUNTIME_FUNCTION(Runtime_CompileForOnStackReplacement) { ...@@ -356,9 +358,10 @@ RUNTIME_FUNCTION(Runtime_CompileForOnStackReplacement) {
// Possibly compile for NCI caching. // Possibly compile for NCI caching.
if (!MaybeSpawnNativeContextIndependentCompilationJob( if (!MaybeSpawnNativeContextIndependentCompilationJob(
function, isolate->concurrent_recompilation_enabled() isolate, function,
? ConcurrencyMode::kConcurrent isolate->concurrent_recompilation_enabled()
: ConcurrencyMode::kNotConcurrent)) { ? ConcurrencyMode::kConcurrent
: ConcurrencyMode::kNotConcurrent)) {
return Object(); return Object();
} }
} }
...@@ -446,7 +449,7 @@ RUNTIME_FUNCTION(Runtime_CompileBaseline) { ...@@ -446,7 +449,7 @@ RUNTIME_FUNCTION(Runtime_CompileBaseline) {
return *function; return *function;
} }
if (!is_compiled_scope.is_compiled()) { if (!is_compiled_scope.is_compiled()) {
if (!Compiler::Compile(function, Compiler::KEEP_EXCEPTION, if (!Compiler::Compile(isolate, function, Compiler::KEEP_EXCEPTION,
&is_compiled_scope)) { &is_compiled_scope)) {
return ReadOnlyRoots(isolate).exception(); return ReadOnlyRoots(isolate).exception();
} }
......
...@@ -294,7 +294,7 @@ Object OptimizeFunctionOnNextCall(RuntimeArguments& args, Isolate* isolate, ...@@ -294,7 +294,7 @@ Object OptimizeFunctionOnNextCall(RuntimeArguments& args, Isolate* isolate,
IsCompiledScope is_compiled_scope( IsCompiledScope is_compiled_scope(
function->shared().is_compiled_scope(isolate)); function->shared().is_compiled_scope(isolate));
if (!is_compiled_scope.is_compiled() && if (!is_compiled_scope.is_compiled() &&
!Compiler::Compile(function, Compiler::CLEAR_EXCEPTION, !Compiler::Compile(isolate, function, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope)) { &is_compiled_scope)) {
return CrashUnlessFuzzing(isolate); return CrashUnlessFuzzing(isolate);
} }
...@@ -356,7 +356,7 @@ Object OptimizeFunctionOnNextCall(RuntimeArguments& args, Isolate* isolate, ...@@ -356,7 +356,7 @@ Object OptimizeFunctionOnNextCall(RuntimeArguments& args, Isolate* isolate,
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
} }
bool EnsureFeedbackVector(Handle<JSFunction> function) { bool EnsureFeedbackVector(Isolate* isolate, Handle<JSFunction> function) {
// Check function allows lazy compilation. // Check function allows lazy compilation.
if (!function->shared().allows_lazy_compilation()) return false; if (!function->shared().allows_lazy_compilation()) return false;
...@@ -372,7 +372,7 @@ bool EnsureFeedbackVector(Handle<JSFunction> function) { ...@@ -372,7 +372,7 @@ bool EnsureFeedbackVector(Handle<JSFunction> function) {
bool needs_compilation = bool needs_compilation =
!function->is_compiled() && !function->has_closure_feedback_cell_array(); !function->is_compiled() && !function->has_closure_feedback_cell_array();
if (needs_compilation && if (needs_compilation &&
!Compiler::Compile(function, Compiler::CLEAR_EXCEPTION, !Compiler::Compile(isolate, function, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope)) { &is_compiled_scope)) {
return false; return false;
} }
...@@ -400,7 +400,7 @@ RUNTIME_FUNCTION(Runtime_EnsureFeedbackVectorForFunction) { ...@@ -400,7 +400,7 @@ RUNTIME_FUNCTION(Runtime_EnsureFeedbackVectorForFunction) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
EnsureFeedbackVector(function); EnsureFeedbackVector(isolate, function);
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
} }
...@@ -422,7 +422,7 @@ RUNTIME_FUNCTION(Runtime_PrepareFunctionForOptimization) { ...@@ -422,7 +422,7 @@ RUNTIME_FUNCTION(Runtime_PrepareFunctionForOptimization) {
} }
} }
if (!EnsureFeedbackVector(function)) { if (!EnsureFeedbackVector(isolate, function)) {
return CrashUnlessFuzzing(isolate); return CrashUnlessFuzzing(isolate);
} }
...@@ -971,7 +971,8 @@ RUNTIME_FUNCTION(Runtime_DisassembleFunction) { ...@@ -971,7 +971,8 @@ RUNTIME_FUNCTION(Runtime_DisassembleFunction) {
CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0); CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0);
IsCompiledScope is_compiled_scope; IsCompiledScope is_compiled_scope;
CHECK(func->is_compiled() || CHECK(func->is_compiled() ||
Compiler::Compile(func, Compiler::KEEP_EXCEPTION, &is_compiled_scope)); Compiler::Compile(isolate, func, Compiler::KEEP_EXCEPTION,
&is_compiled_scope));
StdoutStream os; StdoutStream os;
func->code().Print(os); func->code().Print(os);
os << std::endl; os << std::endl;
......
...@@ -264,7 +264,7 @@ i::Handle<i::JSFunction> Optimize( ...@@ -264,7 +264,7 @@ i::Handle<i::JSFunction> Optimize(
i::Handle<i::SharedFunctionInfo> shared(function->shared(), isolate); i::Handle<i::SharedFunctionInfo> shared(function->shared(), isolate);
i::IsCompiledScope is_compiled_scope(shared->is_compiled_scope(isolate)); i::IsCompiledScope is_compiled_scope(shared->is_compiled_scope(isolate));
CHECK(is_compiled_scope.is_compiled() || CHECK(is_compiled_scope.is_compiled() ||
i::Compiler::Compile(function, i::Compiler::CLEAR_EXCEPTION, i::Compiler::Compile(isolate, function, i::Compiler::CLEAR_EXCEPTION,
&is_compiled_scope)); &is_compiled_scope));
CHECK_NOT_NULL(zone); CHECK_NOT_NULL(zone);
......
...@@ -76,8 +76,8 @@ TEST_F(OptimizingCompileDispatcherTest, NonBlockingFlush) { ...@@ -76,8 +76,8 @@ TEST_F(OptimizingCompileDispatcherTest, NonBlockingFlush) {
Handle<JSFunction> fun = Handle<JSFunction> fun =
RunJS<JSFunction>("function f() { function g() {}; return g;}; f();"); RunJS<JSFunction>("function f() { function g() {}; return g;}; f();");
IsCompiledScope is_compiled_scope; IsCompiledScope is_compiled_scope;
ASSERT_TRUE( ASSERT_TRUE(Compiler::Compile(i_isolate(), fun, Compiler::CLEAR_EXCEPTION,
Compiler::Compile(fun, Compiler::CLEAR_EXCEPTION, &is_compiled_scope)); &is_compiled_scope));
BlockingCompilationJob* job = new BlockingCompilationJob(i_isolate(), fun); BlockingCompilationJob* job = new BlockingCompilationJob(i_isolate(), fun);
OptimizingCompileDispatcher dispatcher(i_isolate()); OptimizingCompileDispatcher dispatcher(i_isolate());
......
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