Commit 048f89c8 authored by Wiktor Garbacz's avatar Wiktor Garbacz Committed by Commit Bot

Do NOT get isolate from ParseInfo in compiler.cc

A step towards removing isolate from ParseInfo.
Removing isolate from ParseInfo will make it easier to create and
execute parse tasks on background threads.

BUG=v8:6093

Change-Id: Ief4eb3c9873026a93338d5556985f31c9abe17e6
Reviewed-on: https://chromium-review.googlesource.com/458005
Commit-Queue: Wiktor Garbacz <wiktorg@google.com>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarDaniel Vogelheim <vogelheim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44173}
parent 64948a89
......@@ -172,7 +172,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
new_func_scope = new (info->zone()) DeclarationScope(
info->zone(), decl->fun()->scope()->outer_scope(), FUNCTION_SCOPE);
info->set_asm_function_scope(new_func_scope);
if (!Compiler::ParseAndAnalyze(info.get())) {
if (!Compiler::ParseAndAnalyze(info.get(), info_->isolate())) {
decl->fun()->scope()->outer_scope()->RemoveInnerScope(new_func_scope);
if (isolate_->has_pending_exception()) {
isolate_->clear_pending_exception();
......
......@@ -327,7 +327,7 @@ bool CompilerDispatcherJob::AnalyzeOnMainThread() {
DeferredHandleScope scope(isolate_);
{
if (Compiler::Analyze(parse_info_.get())) {
if (Compiler::Analyze(compile_info_.get())) {
status_ = CompileJobStatus::kAnalyzed;
} else {
status_ = CompileJobStatus::kFailed;
......
......@@ -614,7 +614,7 @@ bool CompileUnoptimizedCode(CompilationInfo* info,
if (inner_function_mode == Compiler::CONCURRENT) {
compilation_handle_scope.reset(new CompilationHandleScope(info));
}
if (!Compiler::Analyze(info->parse_info(), &inner_literals)) {
if (!Compiler::Analyze(info, &inner_literals)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return false;
}
......@@ -647,7 +647,7 @@ bool CompileUnoptimizedCode(CompilationInfo* info,
return true;
}
void EnsureSharedFunctionInfosArrayOnScript(ParseInfo* info) {
void EnsureSharedFunctionInfosArrayOnScript(ParseInfo* info, Isolate* isolate) {
DCHECK(info->is_toplevel());
DCHECK(!info->script().is_null());
if (info->script()->shared_function_infos()->length() > 0) {
......@@ -655,12 +655,16 @@ void EnsureSharedFunctionInfosArrayOnScript(ParseInfo* info) {
info->max_function_literal_id() + 1);
return;
}
Isolate* isolate = info->isolate();
Handle<FixedArray> infos(
isolate->factory()->NewFixedArray(info->max_function_literal_id() + 1));
info->script()->set_shared_function_infos(*infos);
}
void EnsureSharedFunctionInfosArrayOnScript(CompilationInfo* info) {
return EnsureSharedFunctionInfosArrayOnScript(info->parse_info(),
info->isolate());
}
MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(
CompilationInfo* info, Compiler::ConcurrencyMode inner_function_mode) {
RuntimeCallTimerScope runtimeTimer(
......@@ -683,7 +687,7 @@ MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(
}
if (info->parse_info()->is_toplevel()) {
EnsureSharedFunctionInfosArrayOnScript(info->parse_info());
EnsureSharedFunctionInfosArrayOnScript(info);
}
DCHECK_EQ(info->shared_info()->language_mode(),
info->literal()->language_mode());
......@@ -745,7 +749,7 @@ bool GetOptimizedCodeNow(CompilationJob* job) {
// Parsing is not required when optimizing from existing bytecode.
if (!info->is_optimizing_from_bytecode()) {
if (!Compiler::ParseAndAnalyze(info->parse_info())) return false;
if (!Compiler::ParseAndAnalyze(info)) return false;
EnsureFeedbackMetadata(info);
}
......@@ -810,7 +814,7 @@ bool GetOptimizedCodeLater(CompilationJob* job) {
// Parsing is not required when optimizing from existing bytecode.
if (!info->is_optimizing_from_bytecode()) {
if (!Compiler::ParseAndAnalyze(info->parse_info())) return false;
if (!Compiler::ParseAndAnalyze(info)) return false;
EnsureFeedbackMetadata(info);
}
......@@ -1133,7 +1137,7 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
}
}
EnsureSharedFunctionInfosArrayOnScript(parse_info);
EnsureSharedFunctionInfosArrayOnScript(info);
// Measure how long it takes to do the compilation; only take the
// rest of the function into account to avoid overlap with the
......@@ -1188,12 +1192,11 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
// ----------------------------------------------------------------------------
// Implementation of Compiler
bool Compiler::Analyze(ParseInfo* info,
bool Compiler::Analyze(ParseInfo* info, Isolate* isolate,
EagerInnerFunctionLiterals* eager_literals) {
DCHECK_NOT_NULL(info->literal());
RuntimeCallTimerScope runtimeTimer(info->runtime_call_stats(),
RuntimeCallTimerScope runtimeTimer(isolate,
&RuntimeCallStats::CompileAnalyse);
Isolate* isolate = info->isolate();
if (!Rewriter::Rewrite(info, isolate)) return false;
DeclarationScope::Analyze(info, isolate, AnalyzeMode::kRegular);
if (!Renumber(info, eager_literals)) {
......@@ -1203,15 +1206,26 @@ bool Compiler::Analyze(ParseInfo* info,
return true;
}
bool Compiler::ParseAndAnalyze(ParseInfo* info) {
bool Compiler::Analyze(CompilationInfo* info,
EagerInnerFunctionLiterals* eager_literals) {
return Compiler::Analyze(info->parse_info(), info->isolate(), eager_literals);
}
bool Compiler::ParseAndAnalyze(ParseInfo* info, Isolate* isolate) {
if (!parsing::ParseAny(info)) return false;
if (info->is_toplevel()) EnsureSharedFunctionInfosArrayOnScript(info);
if (!Compiler::Analyze(info)) return false;
if (info->is_toplevel()) {
EnsureSharedFunctionInfosArrayOnScript(info, isolate);
}
if (!Compiler::Analyze(info, isolate)) return false;
DCHECK_NOT_NULL(info->literal());
DCHECK_NOT_NULL(info->scope());
return true;
}
bool Compiler::ParseAndAnalyze(CompilationInfo* info) {
return Compiler::ParseAndAnalyze(info->parse_info(), info->isolate());
}
bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) {
if (function->is_compiled()) return true;
Isolate* isolate = function->GetIsolate();
......
......@@ -69,10 +69,15 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
EagerInnerFunctionLiterals;
// Parser::Parse, then Compiler::Analyze.
static bool ParseAndAnalyze(ParseInfo* info);
static bool ParseAndAnalyze(ParseInfo* info, Isolate* isolate);
// Convenience function
static bool ParseAndAnalyze(CompilationInfo* info);
// Rewrite, analyze scopes, and renumber. If |eager_literals| is non-null, it
// is appended with inner function literals which should be eagerly compiled.
static bool Analyze(ParseInfo* info,
static bool Analyze(ParseInfo* info, Isolate* isolate,
EagerInnerFunctionLiterals* eager_literals = nullptr);
// Convenience function
static bool Analyze(CompilationInfo* info,
EagerInnerFunctionLiterals* eager_literals = nullptr);
// Adds deoptimization support, requires ParseAndAnalyze.
static bool EnsureDeoptimizationSupport(CompilationInfo* info);
......
......@@ -8114,7 +8114,7 @@ bool HOptimizedGraphBuilder::TryInline(Handle<JSFunction> target,
TraceInline(target, caller, "target is being debugged");
return false;
}
if (!Compiler::ParseAndAnalyze(target_info.parse_info())) {
if (!Compiler::ParseAndAnalyze(&target_info)) {
if (target_info.isolate()->has_pending_exception()) {
// Parse or scope error, never optimize this function.
SetStackOverflow();
......
......@@ -59,7 +59,7 @@ class AsmTyperHarnessBuilder {
info_.set_ast_value_factory_owned(false);
Parser parser(&info_);
if (!Compiler::ParseAndAnalyze(&info_)) {
if (!Compiler::ParseAndAnalyze(&info_, isolate_)) {
std::cerr << "Failed to parse:\n" << source_ << "\n";
CHECK(false);
}
......
......@@ -169,7 +169,7 @@ Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) {
if (info.shared_info()->HasBytecodeArray()) {
info.MarkAsOptimizeFromBytecode();
} else {
CHECK(Compiler::ParseAndAnalyze(info.parse_info()));
CHECK(Compiler::ParseAndAnalyze(&info));
CHECK(Compiler::EnsureDeoptimizationSupport(&info));
}
JSFunction::EnsureLiterals(function);
......
......@@ -624,7 +624,7 @@ TEST(PreParserScopeAnalysis) {
eager_normal.set_allow_lazy_parsing(false);
CHECK(i::parsing::ParseProgram(&eager_normal));
CHECK(i::Compiler::Analyze(&eager_normal));
CHECK(i::Compiler::Analyze(&eager_normal, isolate));
i::Scope* normal_scope =
eager_normal.literal()->scope()->inner_scope()->inner_scope();
......
......@@ -869,7 +869,7 @@ static void CheckParsesToNumber(const char* source, bool with_dot) {
info.set_allow_lazy_parsing(false);
info.set_toplevel(true);
CHECK(i::Compiler::ParseAndAnalyze(&info));
CHECK(i::Compiler::ParseAndAnalyze(&info, isolate));
CHECK_EQ(1, info.scope()->declarations()->LengthForTest());
i::Declaration* decl = info.scope()->declarations()->AtForTest(0);
......@@ -3368,7 +3368,7 @@ TEST(InnerAssignment) {
info->set_allow_lazy_parsing(false);
CHECK(i::parsing::ParseProgram(info.get()));
}
CHECK(i::Compiler::Analyze(info.get()));
CHECK(i::Compiler::Analyze(info.get(), isolate));
CHECK(info->literal() != NULL);
i::Scope* scope = info->literal()->scope();
......@@ -3472,7 +3472,7 @@ TEST(MaybeAssignedParameters) {
info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(shared));
info->set_allow_lazy_parsing(allow_lazy);
CHECK(i::parsing::ParseFunction(info.get()));
CHECK(i::Compiler::Analyze(info.get()));
CHECK(i::Compiler::Analyze(info.get(), isolate));
CHECK_NOT_NULL(info->literal());
i::Scope* scope = info->literal()->scope();
......@@ -3497,7 +3497,8 @@ struct Input {
static void TestMaybeAssigned(Input input, const char* variable, bool module,
bool allow_lazy_parsing) {
i::Factory* factory = CcTest::i_isolate()->factory();
i::Isolate* isolate = CcTest::i_isolate();
i::Factory* factory = isolate->factory();
i::Handle<i::String> string =
factory->InternalizeUtf8String(input.source.c_str());
string->PrintOn(stdout);
......@@ -3510,7 +3511,7 @@ static void TestMaybeAssigned(Input input, const char* variable, bool module,
info->set_allow_lazy_parsing(allow_lazy_parsing);
CHECK(i::parsing::ParseProgram(info.get()));
CHECK(i::Compiler::Analyze(info.get()));
CHECK(i::Compiler::Analyze(info.get(), isolate));
CHECK_NOT_NULL(info->literal());
i::Scope* scope = info->literal()->scope();
......@@ -6697,7 +6698,7 @@ TEST(ModuleParsingInternals) {
i::ParseInfo info(script);
info.set_module();
CHECK(i::parsing::ParseProgram(&info));
CHECK(i::Compiler::Analyze(&info));
CHECK(i::Compiler::Analyze(&info, isolate));
i::FunctionLiteral* func = info.literal();
i::ModuleScope* module_scope = func->scope()->AsModuleScope();
i::Scope* outer_scope = module_scope->outer_scope();
......@@ -9603,7 +9604,7 @@ TEST(NoPessimisticContextAllocation) {
i::ParseInfo info(script);
CHECK(i::parsing::ParseProgram(&info));
CHECK(i::Compiler::Analyze(&info));
CHECK(i::Compiler::Analyze(&info, isolate));
CHECK(info.literal() != NULL);
i::Scope* scope = info.literal()->scope()->inner_scope();
......
......@@ -863,7 +863,7 @@ TEST_F(CompilerDispatcherTest, EnqueueParsed) {
Handle<Script> script(Script::cast(shared->script()), i_isolate());
ParseInfo parse_info(shared);
ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info));
ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info, i_isolate()));
std::shared_ptr<DeferredHandles> handles;
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
......@@ -891,7 +891,7 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStepParsed) {
Handle<Script> script(Script::cast(shared->script()), i_isolate());
ParseInfo parse_info(shared);
ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info));
ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info, i_isolate()));
std::shared_ptr<DeferredHandles> handles;
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
......@@ -928,7 +928,7 @@ TEST_F(CompilerDispatcherTest, CompileParsedOutOfScope) {
ASSERT_TRUE(parsing::ParseAny(&parse_info));
DeferredHandleScope handles_scope(i_isolate());
{ ASSERT_TRUE(Compiler::Analyze(&parse_info)); }
{ ASSERT_TRUE(Compiler::Analyze(&parse_info, i_isolate())); }
std::shared_ptr<DeferredHandles> compilation_handles(
handles_scope.Detach());
......@@ -998,7 +998,7 @@ TEST_F(CompilerDispatcherTestWithoutContext, CompileExtensionWithoutContext) {
parse_info.max_function_literal_id() + 1));
parse_info.script()->set_shared_function_infos(*shared_infos_array);
DeferredHandleScope handles_scope(i_isolate());
{ ASSERT_TRUE(Compiler::Analyze(&parse_info)); }
{ ASSERT_TRUE(Compiler::Analyze(&parse_info, i_isolate())); }
std::shared_ptr<DeferredHandles> compilation_handles(
handles_scope.Detach());
......@@ -1084,7 +1084,7 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStepTwice) {
Handle<Script> script(Script::cast(shared->script()), i_isolate());
ParseInfo parse_info(shared);
ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info));
ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info, i_isolate()));
std::shared_ptr<DeferredHandles> handles;
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
......
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