From 3c31e109eac88f2ab01d12aeb1cc8e24f7c9b6e9 Mon Sep 17 00:00:00 2001 From: Ross McIlroy Date: Mon, 31 Jul 2017 12:25:00 +0100 Subject: [PATCH] [Interpreter] Internalize AST before print-ast is triggered Print AST needs access to the internalized strings, so make sure AST is internalized before we print it. BUG=v8:5203 Change-Id: Ia4995147feb7ec466523a0c4a89620749b23dcab Reviewed-on: https://chromium-review.googlesource.com/593648 Reviewed-by: Georg Neis Commit-Queue: Ross McIlroy Cr-Commit-Position: refs/heads/master@{#47006} --- src/codegen.cc | 9 +++++++++ src/interpreter/interpreter.cc | 1 + test/mjsunit/ignition/print-ast.js | 13 +++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 test/mjsunit/ignition/print-ast.js diff --git a/src/codegen.cc b/src/codegen.cc index 3a58415e01..5760a730f4 100644 --- a/src/codegen.cc +++ b/src/codegen.cc @@ -17,6 +17,7 @@ #include "src/debug/debug.h" #include "src/eh-frame.h" #include "src/objects-inl.h" +#include "src/parsing/parse-info.h" #include "src/runtime/runtime.h" namespace v8 { @@ -96,6 +97,14 @@ void CodeGenerator::MakeCodePrologue(CompilationInfo* info, const char* kind) { ftype = "user-defined"; } + if (!FLAG_trace_codegen && !print_ast) return; + + // Requires internalizing the AST, so make sure we are on the main thread. + DCHECK(ThreadId::Current().Equals(info->isolate()->thread_id())); + AllowDeferredHandleDereference allow_deref; + AllowHeapAllocation allow_gc; + info->parse_info()->ast_value_factory()->Internalize(info->isolate()); + if (FLAG_trace_codegen || print_ast) { std::unique_ptr name = info->GetDebugName(); PrintF("[generating %s code for %s function: %s]\n", kind, ftype, diff --git a/src/interpreter/interpreter.cc b/src/interpreter/interpreter.cc index cd0dfd9854..023053903c 100644 --- a/src/interpreter/interpreter.cc +++ b/src/interpreter/interpreter.cc @@ -150,6 +150,7 @@ InterpreterCompilationJob::InterpreterCompilationJob(CompilationInfo* info) background_execute_counter_("CompileBackgroundIgnition") {} InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() { + // TODO(5203): Move code out of codegen.cc once FCG goes away. CodeGenerator::MakeCodePrologue(info(), "interpreter"); return SUCCEEDED; } diff --git a/test/mjsunit/ignition/print-ast.js b/test/mjsunit/ignition/print-ast.js new file mode 100644 index 0000000000..4a77e9a557 --- /dev/null +++ b/test/mjsunit/ignition/print-ast.js @@ -0,0 +1,13 @@ +// Copyright 2017 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --print-ast + +// Ensures that the --print-ast flag doesn't crash. +function foo(a) { + var b = 2; + return function bar() { return a + b; }; +} + +foo()();