Commit 77d06401 authored by marja@chromium.org's avatar marja@chromium.org

Take ast node id counting away from Isolate.

When we're going to parse multiple scripts in parallel, we cannot have the
Isolate count the ast node ids.

Now the counter is stored in CompilationInfo instead. This is because we need to
add ast nodes after parsing too.

R=rossberg@chromium.org
BUG=

Review URL: https://codereview.chromium.org/490173002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23301 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2229575b
......@@ -59,8 +59,9 @@ bool Expression::IsUndefinedLiteral(Isolate* isolate) const {
}
VariableProxy::VariableProxy(Zone* zone, Variable* var, int position)
: Expression(zone, position),
VariableProxy::VariableProxy(Zone* zone, Variable* var, int position,
IdGen* id_gen)
: Expression(zone, position, id_gen),
name_(var->raw_name()),
var_(NULL), // Will be set by the call to BindTo.
is_this_(var->is_this()),
......@@ -71,19 +72,15 @@ VariableProxy::VariableProxy(Zone* zone, Variable* var, int position)
}
VariableProxy::VariableProxy(Zone* zone,
const AstRawString* name,
bool is_this,
Interface* interface,
int position)
: Expression(zone, position),
VariableProxy::VariableProxy(Zone* zone, const AstRawString* name, bool is_this,
Interface* interface, int position, IdGen* id_gen)
: Expression(zone, position, id_gen),
name_(name),
var_(NULL),
is_this_(is_this),
is_assigned_(false),
interface_(interface),
variable_feedback_slot_(kInvalidFeedbackSlot) {
}
variable_feedback_slot_(kInvalidFeedbackSlot) {}
void VariableProxy::BindTo(Variable* var) {
......@@ -101,19 +98,16 @@ void VariableProxy::BindTo(Variable* var) {
}
Assignment::Assignment(Zone* zone,
Token::Value op,
Expression* target,
Expression* value,
int pos)
: Expression(zone, pos),
Assignment::Assignment(Zone* zone, Token::Value op, Expression* target,
Expression* value, int pos, IdGen* id_gen)
: Expression(zone, pos, id_gen),
op_(op),
target_(target),
value_(value),
binary_operation_(NULL),
assignment_id_(GetNextId(zone)),
assignment_id_(id_gen->GetNextId()),
is_uninitialized_(false),
store_mode_(STANDARD_STORE) { }
store_mode_(STANDARD_STORE) {}
Token::Value Assignment::binary_op() const {
......@@ -993,17 +987,14 @@ RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes)
}
CaseClause::CaseClause(Zone* zone,
Expression* label,
ZoneList<Statement*>* statements,
int pos)
: Expression(zone, pos),
CaseClause::CaseClause(Zone* zone, Expression* label,
ZoneList<Statement*>* statements, int pos, IdGen* id_gen)
: Expression(zone, pos, id_gen),
label_(label),
statements_(statements),
compare_type_(Type::None(zone)),
compare_id_(AstNode::GetNextId(zone)),
entry_id_(AstNode::GetNextId(zone)) {
}
compare_id_(id_gen->GetNextId()),
entry_id_(id_gen->GetNextId()) {}
#define REGULAR_NODE(NodeType) \
......
This diff is collapsed.
......@@ -44,8 +44,7 @@ ScriptData::ScriptData(const byte* data, int length)
}
CompilationInfo::CompilationInfo(Handle<Script> script,
Zone* zone)
CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone)
: flags_(StrictModeField::encode(SLOPPY)),
script_(script),
osr_ast_id_(BailoutId::None()),
......@@ -86,8 +85,7 @@ CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
}
CompilationInfo::CompilationInfo(Handle<JSFunction> closure,
Zone* zone)
CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone)
: flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)),
closure_(closure),
shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
......@@ -103,8 +101,7 @@ CompilationInfo::CompilationInfo(Handle<JSFunction> closure,
}
CompilationInfo::CompilationInfo(HydrogenCodeStub* stub,
Isolate* isolate,
CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate,
Zone* zone)
: flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)),
osr_ast_id_(BailoutId::None()),
......
......@@ -365,6 +365,8 @@ class CompilationInfo {
ast_value_factory_owned_ = owned;
}
AstNode::IdGen* ast_node_id_gen() { return &ast_node_id_gen_; }
protected:
CompilationInfo(Handle<Script> script,
Zone* zone);
......@@ -511,6 +513,7 @@ class CompilationInfo {
AstValueFactory* ast_value_factory_;
bool ast_value_factory_owned_;
AstNode::IdGen ast_node_id_gen_;
DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
};
......
......@@ -357,9 +357,6 @@ typedef List<HeapObject*> DebugObjectCache;
V(Object*, string_stream_current_security_token, NULL) \
/* Serializer state. */ \
V(ExternalReferenceTable*, external_reference_table, NULL) \
/* AstNode state. */ \
V(int, ast_node_id, 0) \
V(unsigned, ast_node_count, 0) \
V(int, pending_microtask_count, 0) \
V(bool, autorun_microtasks, true) \
V(HStatistics*, hstatistics, NULL) \
......
......@@ -345,19 +345,18 @@ class ParserTraits::Checkpoint
: public ParserBase<ParserTraits>::CheckpointBase {
public:
explicit Checkpoint(ParserBase<ParserTraits>* parser)
: CheckpointBase(parser) {
isolate_ = parser->zone()->isolate();
saved_ast_node_id_ = isolate_->ast_node_id();
: CheckpointBase(parser), parser_(parser) {
saved_ast_node_id_gen_ = *parser_->ast_node_id_gen_;
}
void Restore() {
CheckpointBase::Restore();
isolate_->set_ast_node_id(saved_ast_node_id_);
*parser_->ast_node_id_gen_ = saved_ast_node_id_gen_;
}
private:
Isolate* isolate_;
int saved_ast_node_id_;
ParserBase<ParserTraits>* parser_;
AstNode::IdGen saved_ast_node_id_gen_;
};
......@@ -732,9 +731,9 @@ FunctionLiteral* ParserTraits::ParseFunctionLiteral(
Parser::Parser(CompilationInfo* info)
: ParserBase<ParserTraits>(&scanner_,
info->isolate()->stack_guard()->real_climit(),
info->extension(), NULL, info->zone(), this),
: ParserBase<ParserTraits>(
&scanner_, info->isolate()->stack_guard()->real_climit(),
info->extension(), NULL, info->zone(), info->ast_node_id_gen(), this),
isolate_(info->isolate()),
script_(info->script()),
scanner_(isolate_->unicode_cache()),
......@@ -749,7 +748,6 @@ Parser::Parser(CompilationInfo* info)
pending_error_arg_(NULL),
pending_error_char_arg_(NULL) {
DCHECK(!script_.is_null());
isolate_->set_ast_node_id(0);
set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
set_allow_modules(!info->is_native() && FLAG_harmony_modules);
set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
......@@ -861,7 +859,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
// Enters 'scope'.
FunctionState function_state(&function_state_, &scope_, scope, zone(),
ast_value_factory_);
ast_value_factory_, info->ast_node_id_gen());
scope_->SetStrictMode(info->strict_mode());
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
......@@ -979,7 +977,7 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
}
original_scope_ = scope;
FunctionState function_state(&function_state_, &scope_, scope, zone(),
ast_value_factory_);
ast_value_factory_, info()->ast_node_id_gen());
DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
DCHECK(info()->strict_mode() == shared_info->strict_mode());
scope->SetStrictMode(shared_info->strict_mode());
......@@ -3442,7 +3440,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Parse function body.
{
FunctionState function_state(&function_state_, &scope_, scope, zone(),
ast_value_factory_);
ast_value_factory_, info()->ast_node_id_gen());
scope_->SetScopeName(function_name);
if (is_generator) {
......
......@@ -378,17 +378,17 @@ class ParserTraits {
explicit ParserTraits(Parser* parser) : parser_(parser) {}
// Custom operations executed when FunctionStates are created and destructed.
template<typename FunctionState>
static void SetUpFunctionState(FunctionState* function_state, Zone* zone) {
Isolate* isolate = zone->isolate();
function_state->saved_ast_node_id_ = isolate->ast_node_id();
isolate->set_ast_node_id(BailoutId::FirstUsable().ToInt());
template <typename FunctionState>
static void SetUpFunctionState(FunctionState* function_state) {
function_state->saved_id_gen_ = *function_state->ast_node_id_gen_;
*function_state->ast_node_id_gen_ =
AstNode::IdGen(BailoutId::FirstUsable().ToInt());
}
template<typename FunctionState>
static void TearDownFunctionState(FunctionState* function_state, Zone* zone) {
template <typename FunctionState>
static void TearDownFunctionState(FunctionState* function_state) {
if (function_state->outer_function_state_ != NULL) {
zone->isolate()->set_ast_node_id(function_state->saved_ast_node_id_);
*function_state->ast_node_id_gen_ = function_state->saved_id_gen_;
}
}
......
......@@ -68,6 +68,7 @@ class ParserBase : public Traits {
ParserBase(Scanner* scanner, uintptr_t stack_limit, v8::Extension* extension,
ParserRecorder* log, typename Traits::Type::Zone* zone,
AstNode::IdGen* ast_node_id_gen,
typename Traits::Type::Parser this_object)
: Traits(this_object),
parenthesized_function_(false),
......@@ -84,7 +85,8 @@ class ParserBase : public Traits {
allow_natives_syntax_(false),
allow_generators_(false),
allow_arrow_functions_(false),
zone_(zone) {}
zone_(zone),
ast_node_id_gen_(ast_node_id_gen) {}
// Getters that indicate whether certain syntactical constructs are
// allowed to be parsed by this instance of the parser.
......@@ -156,17 +158,18 @@ class ParserBase : public Traits {
class FunctionState BASE_EMBEDDED {
public:
FunctionState(
FunctionState** function_state_stack,
typename Traits::Type::Scope** scope_stack,
typename Traits::Type::Scope* scope,
typename Traits::Type::Zone* zone = NULL,
AstValueFactory* ast_value_factory = NULL);
FunctionState(FunctionState** function_state_stack,
typename Traits::Type::Scope** scope_stack,
typename Traits::Type::Scope* scope,
typename Traits::Type::Zone* zone = NULL,
AstValueFactory* ast_value_factory = NULL,
AstNode::IdGen* ast_node_id_gen = NULL);
FunctionState(FunctionState** function_state_stack,
typename Traits::Type::Scope** scope_stack,
typename Traits::Type::Scope** scope,
typename Traits::Type::Zone* zone = NULL,
AstValueFactory* ast_value_factory = NULL);
AstValueFactory* ast_value_factory = NULL,
AstNode::IdGen* ast_node_id_gen = NULL);
~FunctionState();
int NextMaterializedLiteralIndex() {
......@@ -222,7 +225,8 @@ class ParserBase : public Traits {
FunctionState* outer_function_state_;
typename Traits::Type::Scope** scope_stack_;
typename Traits::Type::Scope* outer_scope_;
int saved_ast_node_id_; // Only used by ParserTraits.
AstNode::IdGen* ast_node_id_gen_; // Only used by ParserTraits.
AstNode::IdGen saved_id_gen_; // Ditto.
typename Traits::Type::Zone* extra_param_;
typename Traits::Type::Factory factory_;
......@@ -281,6 +285,7 @@ class ParserBase : public Traits {
void set_stack_overflow() { stack_overflow_ = true; }
Mode mode() const { return mode_; }
typename Traits::Type::Zone* zone() const { return zone_; }
AstNode::IdGen* ast_node_id_gen() const { return ast_node_id_gen_; }
INLINE(Token::Value peek()) {
if (stack_overflow_) return Token::ILLEGAL;
......@@ -576,6 +581,7 @@ class ParserBase : public Traits {
bool allow_arrow_functions_;
typename Traits::Type::Zone* zone_; // Only used by Parser.
AstNode::IdGen* ast_node_id_gen_;
};
......@@ -940,7 +946,7 @@ class PreParserScope {
class PreParserFactory {
public:
explicit PreParserFactory(void* extra_param1, void* extra_param2) {}
PreParserFactory(void*, void*, void*) {}
PreParserExpression NewStringLiteral(PreParserIdentifier identifier,
int pos) {
return PreParserExpression::Default();
......@@ -1106,10 +1112,10 @@ class PreParserTraits {
// Custom operations executed when FunctionStates are created and
// destructed. (The PreParser doesn't need to do anything.)
template<typename FunctionState>
static void SetUpFunctionState(FunctionState* function_state, void*) {}
template<typename FunctionState>
static void TearDownFunctionState(FunctionState* function_state, void*) {}
template <typename FunctionState>
static void SetUpFunctionState(FunctionState* function_state) {}
template <typename FunctionState>
static void TearDownFunctionState(FunctionState* function_state) {}
// Helper functions for recursive descent.
static bool IsEvalOrArguments(PreParserIdentifier identifier) {
......@@ -1362,7 +1368,7 @@ class PreParser : public ParserBase<PreParserTraits> {
};
PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit)
: ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL,
: ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, NULL,
this) {}
// Pre-parse the program from the character stream; returns true on
......@@ -1497,13 +1503,12 @@ PreParserStatementList PreParserTraits::ParseEagerFunctionBody(
}
template<class Traits>
template <class Traits>
ParserBase<Traits>::FunctionState::FunctionState(
FunctionState** function_state_stack,
typename Traits::Type::Scope** scope_stack,
typename Traits::Type::Scope* scope,
typename Traits::Type::Zone* extra_param,
AstValueFactory* ast_value_factory)
typename Traits::Type::Scope* scope, typename Traits::Type::Zone* zone,
AstValueFactory* ast_value_factory, AstNode::IdGen* ast_node_id_gen)
: next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
next_handler_index_(0),
expected_property_count_(0),
......@@ -1513,12 +1518,11 @@ ParserBase<Traits>::FunctionState::FunctionState(
outer_function_state_(*function_state_stack),
scope_stack_(scope_stack),
outer_scope_(*scope_stack),
saved_ast_node_id_(0),
extra_param_(extra_param),
factory_(extra_param, ast_value_factory) {
ast_node_id_gen_(ast_node_id_gen),
factory_(zone, ast_value_factory, ast_node_id_gen) {
*scope_stack_ = scope;
*function_state_stack = this;
Traits::SetUpFunctionState(this, extra_param);
Traits::SetUpFunctionState(this);
}
......@@ -1526,9 +1530,8 @@ template <class Traits>
ParserBase<Traits>::FunctionState::FunctionState(
FunctionState** function_state_stack,
typename Traits::Type::Scope** scope_stack,
typename Traits::Type::Scope** scope,
typename Traits::Type::Zone* extra_param,
AstValueFactory* ast_value_factory)
typename Traits::Type::Scope** scope, typename Traits::Type::Zone* zone,
AstValueFactory* ast_value_factory, AstNode::IdGen* ast_node_id_gen)
: next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
next_handler_index_(0),
expected_property_count_(0),
......@@ -1538,12 +1541,11 @@ ParserBase<Traits>::FunctionState::FunctionState(
outer_function_state_(*function_state_stack),
scope_stack_(scope_stack),
outer_scope_(*scope_stack),
saved_ast_node_id_(0),
extra_param_(extra_param),
factory_(extra_param, ast_value_factory) {
ast_node_id_gen_(ast_node_id_gen),
factory_(zone, ast_value_factory, ast_node_id_gen) {
*scope_stack_ = *scope;
*function_state_stack = this;
Traits::SetUpFunctionState(this, extra_param);
Traits::SetUpFunctionState(this);
}
......@@ -1551,7 +1553,7 @@ template <class Traits>
ParserBase<Traits>::FunctionState::~FunctionState() {
*scope_stack_ = outer_scope_;
*function_state_stack_ = outer_function_state_;
Traits::TearDownFunctionState(this, extra_param_);
Traits::TearDownFunctionState(this);
}
......@@ -2514,7 +2516,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<
{
FunctionState function_state(&function_state_, &scope_, &scope, zone(),
this->ast_value_factory());
this->ast_value_factory(), ast_node_id_gen_);
Scanner::Location dupe_error_loc = Scanner::Location::invalid();
num_parameters = Traits::DeclareArrowParametersFromExpression(
params_ast, scope_, &dupe_error_loc, ok);
......
......@@ -15,14 +15,14 @@ namespace internal {
class Processor: public AstVisitor {
public:
Processor(Variable* result, Zone* zone)
Processor(Variable* result, Zone* zone, AstNode::IdGen* ast_node_id_gen)
: result_(result),
result_assigned_(false),
is_set_(false),
in_try_(false),
// Passing a null AstValueFactory is fine, because Processor doesn't
// need to create strings or literals.
factory_(zone, NULL) {
factory_(zone, NULL, ast_node_id_gen) {
InitializeAstVisitor(zone);
}
......@@ -240,7 +240,7 @@ bool Rewriter::Rewrite(CompilationInfo* info) {
scope->NewTemporary(info->ast_value_factory()->dot_result_string());
// The name string must be internalized at this point.
DCHECK(!result->name().is_null());
Processor processor(result, info->zone());
Processor processor(result, info->zone(), info->ast_node_id_gen());
processor.Process(body);
if (processor.HasStackOverflow()) return false;
......
......@@ -267,9 +267,8 @@ bool Scope::Analyze(CompilationInfo* info) {
// Allocate the variables.
{
// Passing NULL as AstValueFactory is ok, because AllocateVariables doesn't
// need to create new strings or values.
AstNodeFactory<AstNullVisitor> ast_node_factory(info->zone(), NULL);
AstNodeFactory<AstNullVisitor> ast_node_factory(
info->zone(), info->ast_value_factory(), info->ast_node_id_gen());
if (!top->AllocateVariables(info, &ast_node_factory)) return false;
}
......
......@@ -63,9 +63,9 @@ class Zone {
inline void adjust_segment_bytes_allocated(int delta);
inline unsigned allocation_size() { return allocation_size_; }
inline unsigned allocation_size() const { return allocation_size_; }
inline Isolate* isolate() { return isolate_; }
inline Isolate* isolate() const { return isolate_; }
private:
friend class Isolate;
......
......@@ -41,7 +41,8 @@ TEST(List) {
Isolate* isolate = CcTest::i_isolate();
Zone zone(isolate);
AstNodeFactory<AstNullVisitor> factory(&zone, NULL);
AstNode::IdGen id_gen;
AstNodeFactory<AstNullVisitor> factory(&zone, NULL, &id_gen);
AstNode* node = factory.NewEmptyStatement(RelocInfo::kNoPosition);
list->Add(node);
CHECK_EQ(1, list->length());
......
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