Reviewers: Yang,

Message:
Committed patchset #1 manually as r21851 (tree was closed).

Description:
Reuse AstValueFactory when optimizing.

HOptimizedGraphBuilder::TryInline creates a temporary CompilationInfo and
destroys it, but we don't want the AstValueFactory to be destroyed at the same
time. Reuse the upper CompilationInfo's AstValueFactory.

BUG=
[email protected]

Committed: https://code.google.com/p/v8/source/detail?r=21851

Please review this at https://codereview.chromium.org/334173003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+23, -9 lines):
  M src/compiler.h
  M src/compiler.cc
  M src/hydrogen.cc
  M src/parser.cc


Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index cbd9be649a142d32a259000bd50ba8e0ec3378d1..a68c2f893b5d22cc36a02c0117dd1995e1e30c36 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -39,7 +39,8 @@ CompilationInfo::CompilationInfo(Handle<Script> script,
       parameter_count_(0),
       this_has_uses_(true),
       optimization_id_(-1),
-      ast_value_factory_(NULL) {
+      ast_value_factory_(NULL),
+      ast_value_factory_owned_(false) {
   Initialize(script->GetIsolate(), BASE, zone);
 }

@@ -53,7 +54,8 @@ CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
       parameter_count_(0),
       this_has_uses_(true),
       optimization_id_(-1),
-      ast_value_factory_(NULL) {
+      ast_value_factory_(NULL),
+      ast_value_factory_owned_(false) {
   Initialize(script_->GetIsolate(), BASE, zone);
 }

@@ -69,7 +71,8 @@ CompilationInfo::CompilationInfo(Handle<JSFunction> closure,
       parameter_count_(0),
       this_has_uses_(true),
       optimization_id_(-1),
-      ast_value_factory_(NULL) {
+      ast_value_factory_(NULL),
+      ast_value_factory_owned_(false) {
   Initialize(script_->GetIsolate(), BASE, zone);
 }

@@ -82,7 +85,8 @@ CompilationInfo::CompilationInfo(HydrogenCodeStub* stub,
       parameter_count_(0),
       this_has_uses_(true),
       optimization_id_(-1),
-      ast_value_factory_(NULL) {
+      ast_value_factory_(NULL),
+      ast_value_factory_owned_(false) {
   Initialize(isolate, STUB, zone);
   code_stub_ = stub;
 }
@@ -135,7 +139,7 @@ void CompilationInfo::Initialize(Isolate* isolate,
 CompilationInfo::~CompilationInfo() {
   delete deferred_handles_;
   delete no_frame_ranges_;
-  delete ast_value_factory_;
+  if (ast_value_factory_owned_) delete ast_value_factory_;
 #ifdef DEBUG
// Check that no dependent maps have been added or added dependent maps have
   // been rolled back or committed.
Index: src/compiler.h
diff --git a/src/compiler.h b/src/compiler.h
index 9d91b21bd3d4851b9141ebbd0b145a23087a82ac..fdb79005085ed89dd97b2d0369cf52ba5eca8b67 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -323,8 +323,10 @@ class CompilationInfo {
   int optimization_id() const { return optimization_id_; }

   AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
-  void SetAstValueFactory(AstValueFactory* ast_value_factory) {
+  void SetAstValueFactory(AstValueFactory* ast_value_factory,
+                          bool owned = true) {
     ast_value_factory_ = ast_value_factory;
+    ast_value_factory_owned_ = owned;
   }

  protected:
@@ -471,6 +473,7 @@ class CompilationInfo {
   int optimization_id_;

   AstValueFactory* ast_value_factory_;
+  bool ast_value_factory_owned_;

   DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
 };
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 658cc5c2f92edeaf2fb44dc30bc3ec3aa2edd30c..9abc0b8006710981b1caf9e5bc7df3375df7cf18 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -7625,6 +7625,9 @@ bool HOptimizedGraphBuilder::TryInline(Handle<JSFunction> target,

   // Parse and allocate variables.
   CompilationInfo target_info(target, zone());
+ // Use the same AstValueFactory for creating strings in the sub-compilation
+  // step, but don't transfer ownership to target_info.
+  target_info.SetAstValueFactory(top_info()->ast_value_factory(), false);
   Handle<SharedFunctionInfo> target_shared(target->shared());
   if (!Parser::Parse(&target_info) || !Scope::Analyze(&target_info)) {
     if (target_info.isolate()->has_pending_exception()) {
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 722ed8beaf470288df7de99157ea58a191ec7c23..b8855fd8f0ac1c0d267a0c2c583ebd52bec9b892 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -4793,9 +4793,11 @@ bool RegExpParser::ParseRegExp(FlatStringReader* input,

 bool Parser::Parse() {
   ASSERT(info()->function() == NULL);
-  ASSERT(info()->ast_value_factory() == NULL);
   FunctionLiteral* result = NULL;
-  ast_value_factory_ = new AstValueFactory(zone());
+  ast_value_factory_ = info()->ast_value_factory();
+  if (ast_value_factory_ == NULL) {
+    ast_value_factory_ = new AstValueFactory(zone());
+  }
   if (allow_natives_syntax() || extension_ != NULL) {
// If intrinsics are allowed, the Parser cannot operate independent of the // V8 heap because of Rumtime. Tell the string table to internalize strings
@@ -4830,7 +4832,9 @@ bool Parser::Parse() {
   info()->SetFunction(result);
   ast_value_factory_->Internalize(isolate());
   // info takes ownership of ast_value_factory_.
-  info()->SetAstValueFactory(ast_value_factory_);
+  if (info()->ast_value_factory() == NULL) {
+    info()->SetAstValueFactory(ast_value_factory_);
+  }
   ast_value_factory_ = NULL;
   return (result != NULL);
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to