Revision: 8664
Author:   [email protected]
Date:     Fri Jul 15 09:57:35 2011
Log:      Avoid TLS load in AstNode constructor.

[email protected]

Review URL: http://codereview.chromium.org/7383013
http://code.google.com/p/v8/source/detail?r=8664

Modified:
 /branches/bleeding_edge/src/ast.cc
 /branches/bleeding_edge/src/ast.h
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/src/parser.h
 /branches/bleeding_edge/src/rewriter.cc
 /branches/bleeding_edge/src/scopes.cc
 /branches/bleeding_edge/src/scopes.h
 /branches/bleeding_edge/src/zone.h
 /branches/bleeding_edge/test/cctest/test-ast.cc

=======================================
--- /branches/bleeding_edge/src/ast.cc  Fri Jun 24 07:30:10 2011
+++ /branches/bleeding_edge/src/ast.cc  Fri Jul 15 09:57:35 2011
@@ -138,7 +138,7 @@
   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(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;
 }
=======================================
--- /branches/bleeding_edge/src/ast.h   Tue Jul  5 06:21:29 2011
+++ /branches/bleeding_edge/src/ast.h   Fri Jul 15 09:57:35 2011
@@ -134,10 +134,14 @@
   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() { }

@@ -172,6 +176,11 @@
     isolate->set_ast_node_id(tmp + n);
     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.
 };
=======================================
--- /branches/bleeding_edge/src/parser.cc       Wed Jul  6 10:21:32 2011
+++ /branches/bleeding_edge/src/parser.cc       Fri Jul 15 09:57:35 2011
@@ -2868,7 +2868,7 @@
         // 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:
=======================================
--- /branches/bleeding_edge/src/parser.h        Mon Jul  4 02:34:47 2011
+++ /branches/bleeding_edge/src/parser.h        Fri Jul 15 09:57:35 2011
@@ -668,7 +668,7 @@
   Expression* NewCall(Expression* expression,
                       ZoneList<Expression*>* arguments,
                       int pos) {
-    return new Call(expression, arguments, pos);
+    return new(zone()) Call(expression, arguments, pos);
   }


=======================================
--- /branches/bleeding_edge/src/rewriter.cc     Thu Jun 30 07:37:55 2011
+++ /branches/bleeding_edge/src/rewriter.cc     Fri Jul 15 09:57:35 2011
@@ -66,9 +66,10 @@

   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 @@
     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));
     }
   }

=======================================
--- /branches/bleeding_edge/src/scopes.cc       Tue Jul 12 01:03:19 2011
+++ /branches/bleeding_edge/src/scopes.cc       Fri Jul 15 09:57:35 2011
@@ -116,25 +116,27 @@

 // 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* 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<String> catch_variable_name)
-    : inner_scopes_(1),
+    : isolate_(Isolate::Current()),
+      inner_scopes_(1),
       variables_(),
       temps_(0),
       params_(0),
@@ -186,7 +190,7 @@
                         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 @@
     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 @@
     // 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 @@
   //
   // 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* 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 @@
   // 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 @@
     // 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::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 @@
       } 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::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)) {
=======================================
--- /branches/bleeding_edge/src/scopes.h        Mon Jul  4 02:34:47 2011
+++ /branches/bleeding_edge/src/scopes.h        Fri Jul 15 09:57:35 2011
@@ -319,6 +319,8 @@

   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
=======================================
--- /branches/bleeding_edge/src/zone.h  Tue Jul 12 01:03:19 2011
+++ /branches/bleeding_edge/src/zone.h  Fri Jul 15 09:57:35 2011
@@ -73,6 +73,8 @@
   inline bool excess_allocation();

   inline void adjust_segment_bytes_allocated(int delta);
+
+  inline Isolate* isolate() { return isolate_; }

   static unsigned allocation_size_;

=======================================
--- /branches/bleeding_edge/test/cctest/test-ast.cc     Mon May 23 15:23:50 2011
+++ /branches/bleeding_edge/test/cctest/test-ast.cc     Fri Jul 15 09:57:35 2011
@@ -40,7 +40,7 @@
   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));

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to