Commit 3d323c69 authored by vitalyr@chromium.org's avatar vitalyr@chromium.org

Avoid TLS load in AstNode constructor.

R=ager@chromium.org

Review URL: http://codereview.chromium.org/7383013

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8664 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9481e594
......@@ -138,7 +138,7 @@ Assignment::Assignment(Token::Value op,
ASSERT(Token::IsAssignmentOp(op));
if (is_compound()) {
binary_operation_ =
new BinaryOperation(binary_op(), target, value, pos + 1);
new(ZONE) BinaryOperation(binary_op(), target, value, pos + 1);
compound_load_id_ = GetNextId();
}
}
......@@ -187,7 +187,7 @@ ObjectLiteral::Property::Property(Literal* key, Expression* value) {
ObjectLiteral::Property::Property(bool is_getter, FunctionLiteral* value) {
emit_store_ = true;
key_ = new Literal(value->name());
key_ = new(ZONE) Literal(value->name());
value_ = value;
kind_ = is_getter ? GETTER : SETTER;
}
......
......@@ -134,11 +134,15 @@ class AstNode: public ZoneObject {
static const int kNoNumber = -1;
static const int kFunctionEntryId = 2; // Using 0 could disguise errors.
AstNode() {
Isolate* isolate = Isolate::Current();
// Override ZoneObject's new to count allocated AST nodes.
void* operator new(size_t size, Zone* zone) {
Isolate* isolate = zone->isolate();
isolate->set_ast_node_count(isolate->ast_node_count() + 1);
return zone->New(size);
}
AstNode() {}
virtual ~AstNode() { }
virtual void Accept(AstVisitor* v) = 0;
......@@ -173,6 +177,11 @@ class AstNode: public ZoneObject {
return tmp;
}
private:
// Hidden to prevent accidental usage. It would have to load the
// current zone from the TLS.
void* operator new(size_t size);
friend class CaseClause; // Generates AST IDs.
};
......
......@@ -2868,7 +2868,7 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack,
// Consume one of the new prefixes (already parsed).
ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
int last = stack->pop();
result = new CallNew(result, args, last);
result = new(zone()) CallNew(result, args, last);
break;
}
default:
......
......@@ -668,7 +668,7 @@ class Parser {
Expression* NewCall(Expression* expression,
ZoneList<Expression*>* arguments,
int pos) {
return new Call(expression, arguments, pos);
return new(zone()) Call(expression, arguments, pos);
}
......
......@@ -66,9 +66,10 @@ class Processor: public AstVisitor {
Expression* SetResult(Expression* value) {
result_assigned_ = true;
VariableProxy* result_proxy = new VariableProxy(result_);
return new Assignment(Token::ASSIGN, result_proxy, value,
RelocInfo::kNoPosition);
Zone* zone = isolate()->zone();
VariableProxy* result_proxy = new(zone) VariableProxy(result_);
return new(zone) Assignment(Token::ASSIGN, result_proxy, value,
RelocInfo::kNoPosition);
}
// Node visitors.
......@@ -229,8 +230,9 @@ bool Rewriter::Rewrite(CompilationInfo* info) {
if (processor.HasStackOverflow()) return false;
if (processor.result_assigned()) {
VariableProxy* result_proxy = new VariableProxy(result);
body->Add(new ReturnStatement(result_proxy));
Zone* zone = info->isolate()->zone();
VariableProxy* result_proxy = new(zone) VariableProxy(result);
body->Add(new(zone) ReturnStatement(result_proxy));
}
}
......
......@@ -116,25 +116,27 @@ Variable* VariableMap::Lookup(Handle<String> name) {
// Dummy constructor
Scope::Scope(Type type)
: inner_scopes_(0),
variables_(false),
temps_(0),
params_(0),
unresolved_(0),
decls_(0),
already_resolved_(false) {
: isolate_(Isolate::Current()),
inner_scopes_(0),
variables_(false),
temps_(0),
params_(0),
unresolved_(0),
decls_(0),
already_resolved_(false) {
SetDefaults(type, NULL, Handle<SerializedScopeInfo>::null());
}
Scope::Scope(Scope* outer_scope, Type type)
: inner_scopes_(4),
variables_(),
temps_(4),
params_(4),
unresolved_(16),
decls_(4),
already_resolved_(false) {
: isolate_(Isolate::Current()),
inner_scopes_(4),
variables_(),
temps_(4),
params_(4),
unresolved_(16),
decls_(4),
already_resolved_(false) {
SetDefaults(type, outer_scope, Handle<SerializedScopeInfo>::null());
// At some point we might want to provide outer scopes to
// eval scopes (by walking the stack and reading the scope info).
......@@ -145,13 +147,14 @@ Scope::Scope(Scope* outer_scope, Type type)
Scope::Scope(Scope* inner_scope, Handle<SerializedScopeInfo> scope_info)
: inner_scopes_(4),
variables_(),
temps_(4),
params_(4),
unresolved_(16),
decls_(4),
already_resolved_(true) {
: isolate_(Isolate::Current()),
inner_scopes_(4),
variables_(),
temps_(4),
params_(4),
unresolved_(16),
decls_(4),
already_resolved_(true) {
ASSERT(!scope_info.is_null());
SetDefaults(FUNCTION_SCOPE, NULL, scope_info);
if (scope_info->HasHeapAllocatedLocals()) {
......@@ -162,7 +165,8 @@ Scope::Scope(Scope* inner_scope, Handle<SerializedScopeInfo> scope_info)
Scope::Scope(Scope* inner_scope, Handle<String> catch_variable_name)
: inner_scopes_(1),
: isolate_(Isolate::Current()),
inner_scopes_(1),
variables_(),
temps_(0),
params_(0),
......@@ -186,7 +190,7 @@ void Scope::SetDefaults(Type type,
Handle<SerializedScopeInfo> scope_info) {
outer_scope_ = outer_scope;
type_ = type;
scope_name_ = FACTORY->empty_symbol();
scope_name_ = isolate_->factory()->empty_symbol();
dynamics_ = NULL;
receiver_ = NULL;
function_ = NULL;
......@@ -295,9 +299,12 @@ void Scope::Initialize(bool inside_with) {
receiver_ = outer_scope()->receiver();
} else {
Variable* var =
variables_.Declare(this, FACTORY->this_symbol(), Variable::VAR,
false, Variable::THIS);
var->set_rewrite(new Slot(var, Slot::PARAMETER, -1));
variables_.Declare(this,
isolate_->factory()->this_symbol(),
Variable::VAR,
false,
Variable::THIS);
var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::PARAMETER, -1));
receiver_ = var;
}
......@@ -305,8 +312,11 @@ void Scope::Initialize(bool inside_with) {
// Declare 'arguments' variable which exists in all functions.
// Note that it might never be accessed, in which case it won't be
// allocated during variable allocation.
variables_.Declare(this, FACTORY->arguments_symbol(), Variable::VAR,
true, Variable::ARGUMENTS);
variables_.Declare(this,
isolate_->factory()->arguments_symbol(),
Variable::VAR,
true,
Variable::ARGUMENTS);
}
}
......@@ -320,7 +330,7 @@ Variable* Scope::LocalLookup(Handle<String> name) {
//
// We should never lookup 'arguments' in this scope as it is implicitly
// present in every scope.
ASSERT(*name != *FACTORY->arguments_symbol());
ASSERT(*name != *isolate_->factory()->arguments_symbol());
// There should be no local slot with the given name.
ASSERT(scope_info_->StackSlotIndex(*name) < 0);
......@@ -340,7 +350,7 @@ Variable* Scope::LocalLookup(Handle<String> name) {
Variable* var =
variables_.Declare(this, name, mode, true, Variable::NORMAL);
var->set_rewrite(new Slot(var, Slot::CONTEXT, index));
var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::CONTEXT, index));
return var;
}
......@@ -397,7 +407,8 @@ VariableProxy* Scope::NewUnresolved(Handle<String> name,
// the same name because they may be removed selectively via
// RemoveUnresolved().
ASSERT(!already_resolved());
VariableProxy* proxy = new VariableProxy(name, false, inside_with, position);
VariableProxy* proxy =
new(isolate_->zone()) VariableProxy(name, false, inside_with, position);
unresolved_.Add(proxy);
return proxy;
}
......@@ -697,7 +708,7 @@ Variable* Scope::NonLocal(Handle<String> name, Variable::Mode mode) {
// Declare a new non-local.
var = map->Declare(NULL, name, mode, true, Variable::NORMAL);
// Allocate it by giving it a dynamic lookup.
var->set_rewrite(new Slot(var, Slot::LOOKUP, -1));
var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::LOOKUP, -1));
}
return var;
}
......@@ -943,26 +954,30 @@ bool Scope::MustAllocateInContext(Variable* var) {
bool Scope::HasArgumentsParameter() {
for (int i = 0; i < params_.length(); i++) {
if (params_[i]->name().is_identical_to(FACTORY->arguments_symbol()))
if (params_[i]->name().is_identical_to(
isolate_->factory()->arguments_symbol())) {
return true;
}
}
return false;
}
void Scope::AllocateStackSlot(Variable* var) {
var->set_rewrite(new Slot(var, Slot::LOCAL, num_stack_slots_++));
var->set_rewrite(
new(isolate_->zone()) Slot(var, Slot::LOCAL, num_stack_slots_++));
}
void Scope::AllocateHeapSlot(Variable* var) {
var->set_rewrite(new Slot(var, Slot::CONTEXT, num_heap_slots_++));
var->set_rewrite(
new(isolate_->zone()) Slot(var, Slot::CONTEXT, num_heap_slots_++));
}
void Scope::AllocateParameterLocals() {
ASSERT(is_function_scope());
Variable* arguments = LocalLookup(FACTORY->arguments_symbol());
Variable* arguments = LocalLookup(isolate_->factory()->arguments_symbol());
ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly
bool uses_nonstrict_arguments = false;
......@@ -1009,7 +1024,7 @@ void Scope::AllocateParameterLocals() {
} else {
ASSERT(var->rewrite() == NULL || var->IsParameter());
if (var->rewrite() == NULL) {
var->set_rewrite(new Slot(var, Slot::PARAMETER, i));
var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::PARAMETER, i));
}
}
}
......@@ -1020,7 +1035,7 @@ void Scope::AllocateParameterLocals() {
void Scope::AllocateNonParameterLocal(Variable* var) {
ASSERT(var->scope() == this);
ASSERT(var->rewrite() == NULL ||
!var->IsVariable(FACTORY->result_symbol()) ||
!var->IsVariable(isolate_->factory()->result_symbol()) ||
var->AsSlot() == NULL ||
var->AsSlot()->type() != Slot::LOCAL);
if (var->rewrite() == NULL && MustAllocate(var)) {
......
......@@ -319,6 +319,8 @@ class Scope: public ZoneObject {
explicit Scope(Type type);
Isolate* const isolate_;
// Scope tree.
Scope* outer_scope_; // the immediately enclosing outer scope, or NULL
ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes
......
......@@ -74,6 +74,8 @@ class Zone {
inline void adjust_segment_bytes_allocated(int delta);
inline Isolate* isolate() { return isolate_; }
static unsigned allocation_size_;
private:
......
......@@ -40,7 +40,7 @@ TEST(List) {
CHECK_EQ(0, list->length());
ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT);
AstNode* node = new EmptyStatement();
AstNode* node = new(ZONE) EmptyStatement();
list->Add(node);
CHECK_EQ(1, list->length());
CHECK_EQ(node, list->at(0));
......
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