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