Commit 7db6c79a authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Interpreter] Don't require a CanonicalHandleScope for parse / renumbering

Removes the need for a CanonicalHandleScope for parsing and renumbering
phases when using Ignition. Since AST strings are canonicalized by the
AST value factory, we only need to make sure we use the same canonical
handles for any other handles we add to the bytecode generator.

This avoids a regression when enabling Ignition for all Turbofan code, and
improves CodeLoad on for Ignition by about 5%.

BUG=v8:4280

Review-Url: https://codereview.chromium.org/2448323004
Cr-Commit-Position: refs/heads/master@{#40595}
parent 038a8197
......@@ -2267,18 +2267,10 @@ MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context,
source->info->set_script(script);
{
// Create a canonical handle scope if compiling ignition bytecode. This is
// required by the constant array builder to de-duplicate objects without
// dereferencing handles.
std::unique_ptr<i::CanonicalHandleScope> canonical;
if (i::FLAG_ignition) canonical.reset(new i::CanonicalHandleScope(isolate));
// Do the parsing tasks which need to be done on the main thread. This will
// also handle parse errors.
source->parser->Internalize(isolate, script,
source->info->literal() == nullptr);
}
// Do the parsing tasks which need to be done on the main thread. This will
// also handle parse errors.
source->parser->Internalize(isolate, script,
source->info->literal() == nullptr);
source->parser->HandleSourceURLComments(isolate, script);
i::Handle<i::SharedFunctionInfo> result;
......
......@@ -150,17 +150,9 @@ bool CompilerDispatcherJob::FinalizeParsingOnMainThread() {
}
parse_info_->set_shared_info(shared_);
{
// Create a canonical handle scope if compiling ignition bytecode. This is
// required by the constant array builder to de-duplicate objects without
// dereferencing handles.
std::unique_ptr<CanonicalHandleScope> canonical;
if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_));
// Do the parsing tasks which need to be done on the main thread. This
// will also handle parse errors.
parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr);
}
// Do the parsing tasks which need to be done on the main thread. This
// will also handle parse errors.
parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr);
parser_->HandleSourceURLComments(isolate_, script);
parse_info_->set_character_stream(nullptr);
......
......@@ -251,16 +251,6 @@ void CompilationJob::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) {
namespace {
bool Parse(ParseInfo* info) {
// Create a canonical handle scope if compiling ignition bytecode. This is
// required by the constant array builder to de-duplicate objects without
// dereferencing handles.
std::unique_ptr<CanonicalHandleScope> canonical;
if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(info->isolate()));
return Parser::ParseStatic(info);
}
void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
CompilationInfo* info) {
// Log the code generation. If source information is available include
......@@ -439,7 +429,7 @@ MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) {
PostponeInterruptsScope postpone(info->isolate());
// Parse and update CompilationInfo with the results.
if (!Parse(info->parse_info())) return MaybeHandle<Code>();
if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>();
DCHECK_EQ(info->shared_info()->language_mode(),
info->literal()->language_mode());
......@@ -492,14 +482,6 @@ void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) {
}
bool Renumber(ParseInfo* parse_info) {
// Create a canonical handle scope if compiling ignition bytecode. This is
// required by the constant array builder to de-duplicate objects without
// dereferencing handles.
std::unique_ptr<CanonicalHandleScope> canonical;
if (FLAG_ignition) {
canonical.reset(new CanonicalHandleScope(parse_info->isolate()));
}
if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(),
parse_info->literal())) {
return false;
......@@ -926,7 +908,7 @@ MaybeHandle<Code> GetBaselineCode(Handle<JSFunction> function) {
}
// Parse and update CompilationInfo with the results.
if (!Parse(info.parse_info())) return MaybeHandle<Code>();
if (!Parser::ParseStatic(info.parse_info())) return MaybeHandle<Code>();
Handle<SharedFunctionInfo> shared = info.shared_info();
DCHECK_EQ(shared->language_mode(), info.literal()->language_mode());
......@@ -1054,7 +1036,7 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
Handle<SharedFunctionInfo> result;
{ VMState<COMPILER> state(info->isolate());
if (parse_info->literal() == nullptr && !Parse(parse_info)) {
if (parse_info->literal() == nullptr && !Parser::ParseStatic(parse_info)) {
return Handle<SharedFunctionInfo>::null();
}
......@@ -1118,7 +1100,7 @@ bool Compiler::Analyze(ParseInfo* info) {
}
bool Compiler::ParseAndAnalyze(ParseInfo* info) {
if (!Parse(info)) return false;
if (!Parser::ParseStatic(info)) return false;
if (!Compiler::Analyze(info)) return false;
DCHECK_NOT_NULL(info->literal());
DCHECK_NOT_NULL(info->scope());
......@@ -1708,6 +1690,10 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
parse_info.set_literal(literal);
parse_info.set_shared_info(result);
parse_info.set_language_mode(literal->scope()->language_mode());
parse_info.set_ast_value_factory(
outer_info->parse_info()->ast_value_factory());
parse_info.set_ast_value_factory_owned(false);
if (outer_info->will_serialize()) info.PrepareForSerializing();
if (outer_info->is_debug()) info.MarkAsDebug();
......
......@@ -14,6 +14,7 @@
#include "src/interpreter/bytecode-register-allocator.h"
#include "src/interpreter/control-flow-builders.h"
#include "src/objects.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/token.h"
namespace v8 {
......@@ -571,7 +572,11 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info)
generator_state_(),
loop_depth_(0),
home_object_symbol_(info->isolate()->factory()->home_object_symbol()),
prototype_string_(info->isolate()->factory()->prototype_string()) {
empty_fixed_array_(info->isolate()->factory()->empty_fixed_array()) {
AstValueFactory* ast_value_factory = info->parse_info()->ast_value_factory();
const AstRawString* prototype_string = ast_value_factory->prototype_string();
ast_value_factory->Internalize(info->isolate());
prototype_string_ = prototype_string->string();
}
Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) {
......@@ -1568,11 +1573,14 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
FastCloneShallowObjectStub::IsSupported(expr),
FastCloneShallowObjectStub::PropertiesCount(expr->properties_count()),
expr->ComputeFlags());
// Allocate in the outer scope since this register is used to return the
// expression's results to the caller.
// If constant properties is an empty fixed array, use our cached
// empty_fixed_array to ensure it's only added to the constant pool once.
Handle<FixedArray> constant_properties = expr->properties_count() == 0
? empty_fixed_array()
: expr->constant_properties();
Register literal = register_allocator()->NewRegister();
builder()->CreateObjectLiteral(expr->constant_properties(),
expr->literal_index(), flags, literal);
builder()->CreateObjectLiteral(constant_properties, expr->literal_index(),
flags, literal);
// Store computed values into the literal.
int property_index = 0;
......
......@@ -194,6 +194,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
Handle<Name> home_object_symbol() const { return home_object_symbol_; }
Handle<Name> prototype_string() const { return prototype_string_; }
Handle<FixedArray> empty_fixed_array() const { return empty_fixed_array_; }
Zone* zone_;
BytecodeArrayBuilder* builder_;
......@@ -216,6 +217,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
Handle<Name> home_object_symbol_;
Handle<Name> prototype_string_;
Handle<FixedArray> empty_fixed_array_;
};
} // namespace interpreter
......
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