Reuse AstValueFactory when optimizing.
authormarja@chromium.org <marja@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 16 Jun 2014 10:42:39 +0000 (10:42 +0000)
committermarja@chromium.org <marja@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 16 Jun 2014 10:42:39 +0000 (10:42 +0000)
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=
R=yangguo@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21851 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/compiler.cc
src/compiler.h
src/hydrogen.cc
src/parser.cc

index cbd9be6..a68c2f8 100644 (file)
@@ -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 9d91b21..fdb7900 100644 (file)
@@ -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 c75046d..35bbe4e 100644 (file)
@@ -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 722ed8b..b8855fd 100644 (file)
@@ -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);
 }