Remove CompilationInfoWithZone from public API.
authormstarzinger <mstarzinger@chromium.org>
Tue, 24 Mar 2015 14:17:05 +0000 (07:17 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 24 Mar 2015 14:17:17 +0000 (14:17 +0000)
This removes the CompilationInfoWithZone class from the header file
because it is more than a pure convenience class and shouldn't be used
outside of the compiler at all.

R=titzer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27411}

src/compiler.cc
src/compiler.h
src/compiler/js-inlining.cc
test/cctest/compiler/function-tester.h
test/cctest/compiler/test-linkage.cc
test/cctest/compiler/test-pipeline.cc
test/cctest/compiler/test-run-stubs.cc

index a8120e33d547cb6268ea7095dd3128d733159b0e..0bf2c7b6a621ff9a38c3714e992bd3745fe5f528 100644 (file)
@@ -74,6 +74,28 @@ PARSE_INFO_GETTER(Handle<SharedFunctionInfo>, shared_info)
 #undef PARSE_INFO_GETTER_WITH_DEFAULT
 
 
+// Exactly like a CompilationInfo, except being allocated via {new} and it also
+// creates and enters a Zone on construction and deallocates it on destruction.
+class CompilationInfoWithZone : public CompilationInfo {
+ public:
+  explicit CompilationInfoWithZone(Handle<JSFunction> function)
+      : CompilationInfo(new ParseInfo(&zone_, function)) {}
+
+  // Virtual destructor because a CompilationInfoWithZone has to exit the
+  // zone scope and get rid of dependent maps even when the destructor is
+  // called when cast as a CompilationInfo.
+  virtual ~CompilationInfoWithZone() {
+    DisableFutureOptimization();
+    RollbackDependencies();
+    delete parse_info_;
+    parse_info_ = nullptr;
+  }
+
+ private:
+  Zone zone_;
+};
+
+
 bool CompilationInfo::has_shared_info() const {
   return parse_info_ && !parse_info_->shared_info().is_null();
 }
@@ -1007,7 +1029,9 @@ MaybeHandle<Code> Compiler::GetDebugCode(Handle<JSFunction> function) {
 
 void Compiler::CompileForLiveEdit(Handle<Script> script) {
   // TODO(635): support extensions.
-  CompilationInfoWithZone info(script);
+  Zone zone;
+  ParseInfo parse_info(&zone, script);
+  CompilationInfo info(&parse_info);
   PostponeInterruptsScope postpone(info.isolate());
   VMState<COMPILER> state(info.isolate());
 
@@ -1145,13 +1169,14 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
 
   if (!maybe_shared_info.ToHandle(&shared_info)) {
     Handle<Script> script = isolate->factory()->NewScript(source);
-    CompilationInfoWithZone info(script);
-    ParseInfo* parse_info = info.parse_info();
-    parse_info->set_eval();
-    if (context->IsNativeContext()) parse_info->set_global();
-    parse_info->set_language_mode(language_mode);
-    parse_info->set_parse_restriction(restriction);
-    parse_info->set_context(context);
+    Zone zone;
+    ParseInfo parse_info(&zone, script);
+    CompilationInfo info(&parse_info);
+    parse_info.set_eval();
+    if (context->IsNativeContext()) parse_info.set_global();
+    parse_info.set_language_mode(language_mode);
+    parse_info.set_parse_restriction(restriction);
+    parse_info.set_context(context);
 
     Debug::RecordEvalCaller(script);
 
@@ -1268,25 +1293,26 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
     }
 
     // Compile the function and add it to the cache.
-    CompilationInfoWithZone info(script);
-    ParseInfo* parse_info = info.parse_info();
+    Zone zone;
+    ParseInfo parse_info(&zone, script);
+    CompilationInfo info(&parse_info);
     if (FLAG_harmony_modules && is_module) {
-      parse_info->set_module();
+      parse_info.set_module();
     } else {
-      parse_info->set_global();
+      parse_info.set_global();
     }
     if (compile_options != ScriptCompiler::kNoCompileOptions) {
-      parse_info->set_cached_data(cached_data);
+      parse_info.set_cached_data(cached_data);
     }
-    parse_info->set_compile_options(compile_options);
-    parse_info->set_extension(extension);
-    parse_info->set_context(context);
+    parse_info.set_compile_options(compile_options);
+    parse_info.set_extension(extension);
+    parse_info.set_context(context);
     if (FLAG_serialize_toplevel &&
         compile_options == ScriptCompiler::kProduceCodeCache) {
       info.PrepareForSerializing();
     }
 
-    parse_info->set_language_mode(
+    parse_info.set_language_mode(
         static_cast<LanguageMode>(info.language_mode() | language_mode));
     result = CompileToplevel(&info);
     if (extension == NULL && !result.is_null() && !result->dont_cache()) {
@@ -1334,11 +1360,12 @@ Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(
     FunctionLiteral* literal, Handle<Script> script,
     CompilationInfo* outer_info) {
   // Precondition: code has been parsed and scopes have been analyzed.
-  CompilationInfoWithZone info(script);
-  ParseInfo* parse_info = info.parse_info();
-  parse_info->set_literal(literal);
-  parse_info->set_scope(literal->scope());
-  parse_info->set_language_mode(literal->scope()->language_mode());
+  Zone zone;
+  ParseInfo parse_info(&zone, script);
+  CompilationInfo info(&parse_info);
+  parse_info.set_literal(literal);
+  parse_info.set_scope(literal->scope());
+  parse_info.set_language_mode(literal->scope()->language_mode());
   if (outer_info->will_serialize()) info.PrepareForSerializing();
 
   Isolate* isolate = info.isolate();
@@ -1548,21 +1575,6 @@ bool CompilationPhase::ShouldProduceTraceOutput() const {
 }
 
 
-CompilationInfoWithZone::CompilationInfoWithZone(Handle<Script> script)
-    : CompilationInfo(new ParseInfo(&zone_, script)) {}
-
-
-CompilationInfoWithZone::CompilationInfoWithZone(Handle<JSFunction> function)
-    : CompilationInfo(new ParseInfo(&zone_, function)) {}
-
-
-CompilationInfoWithZone::~CompilationInfoWithZone() {
-  DisableFutureOptimization();
-  RollbackDependencies();
-  delete parse_info_;
-  parse_info_ = nullptr;
-}
-
 #if DEBUG
 void CompilationInfo::PrintAstForTesting() {
   PrintF("--- Source from AST ---\n%s\n",
index 2efff21c8504ed8da37b5803b48ba65770b37439..c358cce411816b2ca31476eef4e3c4f54c0ea2f6 100644 (file)
@@ -486,22 +486,6 @@ class CompilationInfo {
 };
 
 
-// Exactly like a CompilationInfo, except also creates and enters a
-// Zone on construction and deallocates it on exit.
-class CompilationInfoWithZone: public CompilationInfo {
- public:
-  explicit CompilationInfoWithZone(Handle<Script> script);
-  explicit CompilationInfoWithZone(Handle<JSFunction> closure);
-
-  // Virtual destructor because a CompilationInfoWithZone has to exit the
-  // zone scope and get rid of dependent maps even when the destructor is
-  // called when cast as a CompilationInfo.
-  virtual ~CompilationInfoWithZone();
-
- private:
-  Zone zone_;
-};
-
 // A wrapper around a CompilationInfo that detaches the Handles from
 // the underlying DeferredHandleScope and stores them in info_ on
 // destruction.
index 8d973c6ef01436330e839392f72e209c99886f4e..6c7b66681dec852471b938ef82b54c738db2c8ba 100644 (file)
@@ -320,7 +320,9 @@ Reduction JSInliner::Reduce(Node* node) {
     return NoChange();
   }
 
-  CompilationInfoWithZone info(function);
+  Zone zone;
+  ParseInfo parse_info(&zone, function);
+  CompilationInfo info(&parse_info);
 
   if (!Compiler::ParseAndAnalyze(info.parse_info())) return NoChange();
   if (!Compiler::EnsureDeoptimizationSupport(&info)) return NoChange();
index 56dc0a9e732beb1b68f74e6aa3d25e1985a05c3f..20efd1e304ad26096d2c94c4daf3b57c186b0b50 100644 (file)
@@ -150,7 +150,9 @@ class FunctionTester : public InitializedHandleScope {
   Handle<JSFunction> Compile(Handle<JSFunction> function) {
 // TODO(titzer): make this method private.
 #if V8_TURBOFAN_TARGET
-    CompilationInfoWithZone info(function);
+    Zone zone;
+    ParseInfo parse_info(&zone, function);
+    CompilationInfo info(&parse_info);
 
     CHECK(Parser::ParseStatic(info.parse_info()));
     info.SetOptimizing(BailoutId::None(), Handle<Code>(function->code()));
@@ -206,7 +208,9 @@ class FunctionTester : public InitializedHandleScope {
   // and replace the JSFunction's code with the result.
   Handle<JSFunction> CompileGraph(Graph* graph) {
     CHECK(Pipeline::SupportedTarget());
-    CompilationInfoWithZone info(function);
+    Zone zone;
+    ParseInfo parse_info(&zone, function);
+    CompilationInfo info(&parse_info);
 
     CHECK(Parser::ParseStatic(info.parse_info()));
     info.SetOptimizing(BailoutId::None(),
index 0c8e961166da6ba15cd9b6016c7203e2bb5f8764..212ff3a8f20c7f8bf17a951505a92dc1c713fad4 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "src/code-stubs.h"
 #include "src/compiler.h"
+#include "src/parser.h"
 #include "src/zone.h"
 
 #include "src/compiler/common-operator.h"
@@ -42,25 +43,25 @@ static Handle<JSFunction> Compile(const char* source) {
 
 
 TEST(TestLinkageCreate) {
-  InitializedHandleScope handles;
+  HandleAndZoneScope handles;
   Handle<JSFunction> function = Compile("a + b");
-  CompilationInfoWithZone info(function);
+  ParseInfo parse_info(handles.main_zone(), function);
+  CompilationInfo info(&parse_info);
   CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
   CHECK(descriptor);
 }
 
 
 TEST(TestLinkageJSFunctionIncoming) {
-  InitializedHandleScope handles;
-
   const char* sources[] = {"(function() { })", "(function(a) { })",
                            "(function(a,b) { })", "(function(a,b,c) { })"};
 
   for (int i = 0; i < 3; i++) {
-    i::HandleScope handles(CcTest::i_isolate());
+    HandleAndZoneScope handles;
     Handle<JSFunction> function = v8::Utils::OpenHandle(
         *v8::Handle<v8::Function>::Cast(CompileRun(sources[i])));
-    CompilationInfoWithZone info(function);
+    ParseInfo parse_info(handles.main_zone(), function);
+    CompilationInfo info(&parse_info);
     CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
     CHECK(descriptor);
 
@@ -89,7 +90,8 @@ TEST(TestLinkageCodeStubIncoming) {
 TEST(TestLinkageJSCall) {
   HandleAndZoneScope handles;
   Handle<JSFunction> function = Compile("a + c");
-  CompilationInfoWithZone info(function);
+  ParseInfo parse_info(handles.main_zone(), function);
+  CompilationInfo info(&parse_info);
 
   for (int i = 0; i < 32; i++) {
     CallDescriptor* descriptor = Linkage::GetJSCallDescriptor(
index e3710f77b48dabd50104fccd5b6f7661db50f0a8..b67af6ecf7d0047f45b1d689b3c3b1ca6fc02e9b 100644 (file)
@@ -17,13 +17,13 @@ using namespace v8::internal;
 using namespace v8::internal::compiler;
 
 TEST(PipelineAdd) {
-  InitializedHandleScope handles;
+  HandleAndZoneScope handles;
   const char* source = "(function(a,b) { return a + b; })";
   Handle<JSFunction> function = v8::Utils::OpenHandle(
       *v8::Handle<v8::Function>::Cast(CompileRun(source)));
-  CompilationInfoWithZone info(function);
-
-  CHECK(Compiler::ParseAndAnalyze(info.parse_info()));
+  ParseInfo parse_info(handles.main_zone(), function);
+  CHECK(Compiler::ParseAndAnalyze(&parse_info));
+  CompilationInfo info(&parse_info);
 
   Pipeline pipeline(&info);
 #if V8_TURBOFAN_TARGET
index 67c08b08d6452ae13eaff3d32e8cd5d48fcf3597..daf9a461b1d28959f033565cec349ed75c649a72 100644 (file)
@@ -42,8 +42,10 @@ class StringLengthStubTF : public CodeStub {
   };
 
   Handle<Code> GenerateCode() OVERRIDE {
+    Zone zone;
     // Build a "hybrid" CompilationInfo for a JSFunction/CodeStub pair.
-    CompilationInfoWithZone info(GetFunction(isolate(), "STRING_LENGTH_STUB"));
+    ParseInfo parse_info(&zone, GetFunction(isolate(), "STRING_LENGTH_STUB"));
+    CompilationInfo info(&parse_info);
     info.SetStub(this);
     // Run a "mini pipeline", extracted from compiler.cc.
     CHECK(Parser::ParseStatic(info.parse_info()));