Commit b3ff2837 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Compiler] Use shared_ptr for ast_value_factory in ParseInfo.

Rather than using an ad-hock ownership model for ast_value_factory, use a
shared_ptr.

BUG=v8:5203

Change-Id: I5f2a573c8b175a3138ad8b01aa78bddadd16e6d3
Reviewed-on: https://chromium-review.googlesource.com/582628
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46874}
parent c7854ed9
......@@ -3058,9 +3058,6 @@ class AstNodeFactory final BASE_EMBEDDED {
: zone_(zone), ast_value_factory_(ast_value_factory) {}
AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
void set_ast_value_factory(AstValueFactory* ast_value_factory) {
ast_value_factory_ = ast_value_factory;
}
VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
Scope* scope, int pos) {
......
......@@ -501,11 +501,9 @@ bool CompileUnoptimizedInnerFunctions(
parse_info.set_literal(literal);
parse_info.set_function_literal_id(shared->function_literal_id());
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);
parse_info.set_source_range_map(
outer_info->parse_info()->source_range_map());
parse_info.ShareAstValueFactory(outer_info->parse_info());
if (will_serialize) info.PrepareForSerializing();
if (is_debug) info.MarkAsDebug();
......
......@@ -93,14 +93,6 @@ ParseInfo::ParseInfo(Handle<Script> script)
set_collect_type_profile(FLAG_type_profile && script->IsUserJavaScript());
}
ParseInfo::~ParseInfo() {
if (ast_value_factory_owned()) {
delete ast_value_factory_;
set_ast_value_factory_owned(false);
}
ast_value_factory_ = nullptr;
}
// static
ParseInfo* ParseInfo::AllocateWithoutScript(Handle<SharedFunctionInfo> shared) {
Isolate* isolate = shared->GetIsolate();
......@@ -201,6 +193,19 @@ std::map<int, ParseInfo*> ParseInfo::child_infos() const {
return rv;
}
AstValueFactory* ParseInfo::GetOrCreateAstValueFactory() {
if (!ast_value_factory_.get()) {
ast_value_factory_.reset(
new AstValueFactory(zone(), ast_string_constants(), hash_seed()));
}
return ast_value_factory();
}
void ParseInfo::ShareAstValueFactory(ParseInfo* other) {
DCHECK(!ast_value_factory_.get());
ast_value_factory_ = other->ast_value_factory_;
}
#ifdef DEBUG
bool ParseInfo::script_is_native() const {
return script_->type() == Script::TYPE_NATIVE;
......
......@@ -42,12 +42,19 @@ class V8_EXPORT_PRIVATE ParseInfo : public CompileJobFinishCallback {
ParseInfo(Handle<Script> script);
ParseInfo(Handle<SharedFunctionInfo> shared);
~ParseInfo();
~ParseInfo() {}
void InitFromIsolate(Isolate* isolate);
static ParseInfo* AllocateWithoutScript(Handle<SharedFunctionInfo> shared);
// Either returns the ast-value-factory associcated with this ParseInfo, or
// creates and returns a new factory if none exists.
AstValueFactory* GetOrCreateAstValueFactory();
// Sets this parse info to share the same ast value factory as |other|.
void ShareAstValueFactory(ParseInfo* other);
Zone* zone() const { return zone_.get(); }
std::shared_ptr<Zone> zone_shared() const { return zone_; }
......@@ -70,8 +77,6 @@ class V8_EXPORT_PRIVATE ParseInfo : public CompileJobFinishCallback {
FLAG_ACCESSOR(kNative, is_native, set_native)
FLAG_ACCESSOR(kModule, is_module, set_module)
FLAG_ACCESSOR(kAllowLazyParsing, allow_lazy_parsing, set_allow_lazy_parsing)
FLAG_ACCESSOR(kAstValueFactoryOwned, ast_value_factory_owned,
set_ast_value_factory_owned)
FLAG_ACCESSOR(kIsNamedExpression, is_named_expression,
set_is_named_expression)
FLAG_ACCESSOR(kDebug, is_debug, set_is_debug)
......@@ -136,9 +141,9 @@ class V8_EXPORT_PRIVATE ParseInfo : public CompileJobFinishCallback {
asm_function_scope_ = scope;
}
AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
void set_ast_value_factory(AstValueFactory* ast_value_factory) {
ast_value_factory_ = ast_value_factory;
AstValueFactory* ast_value_factory() const {
DCHECK(ast_value_factory_.get());
return ast_value_factory_.get();
}
const AstRawString* function_name() const { return function_name_; }
......@@ -270,7 +275,6 @@ class V8_EXPORT_PRIVATE ParseInfo : public CompileJobFinishCallback {
kIsNamedExpression = 1 << 8,
kDebug = 1 << 9,
kSerializing = 1 << 10,
kAstValueFactoryOwned = 1 << 11,
kCollectTypeProfile = 1 << 12,
};
......@@ -301,7 +305,7 @@ class V8_EXPORT_PRIVATE ParseInfo : public CompileJobFinishCallback {
//----------- Inputs+Outputs of parsing and scope analysis -----------------
ScriptData** cached_data_; // used if available, populated if requested.
ConsumedPreParsedScopeData consumed_preparsed_scope_data_;
AstValueFactory* ast_value_factory_; // used if available, otherwise new.
std::shared_ptr<AstValueFactory> ast_value_factory_;
const class AstStringConstants* ast_string_constants_;
const AstRawString* function_name_;
RuntimeCallStats* runtime_call_stats_;
......
......@@ -478,7 +478,7 @@ Expression* Parser::NewV8Intrinsic(const AstRawString* name,
Parser::Parser(ParseInfo* info)
: ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(),
info->extension(), info->ast_value_factory(),
info->extension(), info->GetOrCreateAstValueFactory(),
info->runtime_call_stats(), true),
scanner_(info->unicode_cache()),
reusable_preparser_(nullptr),
......@@ -529,14 +529,6 @@ Parser::Parser(ParseInfo* info)
++feature) {
use_counts_[feature] = 0;
}
if (info->ast_value_factory() == NULL) {
// info takes ownership of AstValueFactory.
info->set_ast_value_factory(new AstValueFactory(
zone(), info->ast_string_constants(), info->hash_seed()));
info->set_ast_value_factory_owned();
ast_value_factory_ = info->ast_value_factory();
ast_node_factory_.set_ast_value_factory(ast_value_factory_);
}
}
void Parser::DeserializeScopeChain(
......
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