Commit 5bf36992 authored by jgruber's avatar jgruber Committed by Commit bot

[debugger] Refactor LiveEdit function info collection

This moves collection of function information from its previous spot in
the standard compiler pipeline (GetSharedFunctionInfo() and
CompileTopLevel()) to its new location in CompileForLiveEdit. Nesting
information is reconstructed by traversing the AST.

R=yangguo@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/1971683002
Cr-Commit-Position: refs/heads/master@{#36306}
parent dcc283e8
......@@ -1019,7 +1019,6 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
DCHECK(!info->is_debug() || !parse_info->allow_lazy_parsing());
FunctionLiteral* lit = parse_info->literal();
LiveEditFunctionTracker live_edit_tracker(isolate, lit);
// Measure how long it takes to do the compilation; only take the
// rest of the function into account to avoid overlap with the
......@@ -1068,8 +1067,6 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
if (!script.is_null())
script->set_compilation_state(Script::COMPILATION_STATE_COMPILED);
live_edit_tracker.RecordFunctionInfo(result, lit, info->zone());
}
return result;
......@@ -1228,7 +1225,7 @@ bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) {
return true;
}
bool Compiler::CompileForLiveEdit(Handle<Script> script) {
MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) {
Isolate* isolate = script->GetIsolate();
DCHECK(AllowCompilation::IsAllowed(isolate));
......@@ -1244,22 +1241,23 @@ bool Compiler::CompileForLiveEdit(Handle<Script> script) {
CompilationInfo info(&parse_info, Handle<JSFunction>::null());
parse_info.set_global();
info.MarkAsDebug();
// TODO(635): support extensions.
const bool compilation_succeeded = !CompileToplevel(&info).is_null();
Handle<JSArray> infos;
if (compilation_succeeded) {
// Check postconditions on success.
DCHECK(!isolate->has_pending_exception());
infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script,
&zone, isolate);
}
// Restore the original function info list in order to remain side-effect
// free as much as possible, since some code expects the old shared function
// infos to stick around.
script->set_shared_function_infos(*old_function_infos);
if (!compilation_succeeded) {
return false;
}
// Check postconditions on success.
DCHECK(!isolate->has_pending_exception());
return compilation_succeeded;
return infos;
}
// TODO(turbofan): In the future, unoptimized code with deopt support could
......@@ -1589,7 +1587,6 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
if (outer_info->will_serialize()) info.PrepareForSerializing();
if (outer_info->is_debug()) info.MarkAsDebug();
LiveEditFunctionTracker live_edit_tracker(isolate, literal);
// Determine if the function can be lazily compiled. This is necessary to
// allow some of our builtin JS files to be lazily compiled. These
// builtins cannot be handled lazily by the parser, since we have to know
......@@ -1632,7 +1629,6 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
if (maybe_existing.is_null()) {
RecordFunctionCompilation(Logger::FUNCTION_TAG, &info);
live_edit_tracker.RecordFunctionInfo(result, literal, info.zone());
}
return result;
......
......@@ -48,7 +48,7 @@ class Compiler : public AllStatic {
static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode);
static bool CompileDebugCode(Handle<JSFunction> function);
static bool CompileDebugCode(Handle<SharedFunctionInfo> shared);
static bool CompileForLiveEdit(Handle<Script> script);
static MaybeHandle<JSArray> CompileForLiveEdit(Handle<Script> script);
// Generate and install code from previously queued compilation job.
static void FinalizeCompilationJob(CompilationJob* job);
......
This diff is collapsed.
......@@ -32,25 +32,39 @@ namespace v8 {
namespace internal {
// This class collects some specific information on structure of functions
// in a particular script. It gets called from compiler all the time, but
// actually records any data only when liveedit operation is in process;
// in any other time this class is very cheap.
// in a particular script.
//
// The primary interest of the Tracker is to record function scope structures
// in order to analyze whether function code maybe safely patched (with new
// in order to analyze whether function code may be safely patched (with new
// code successfully reading existing data from function scopes). The Tracker
// also collects compiled function codes.
class LiveEditFunctionTracker {
class LiveEditFunctionTracker : public AstTraversalVisitor {
public:
explicit LiveEditFunctionTracker(Isolate* isolate, FunctionLiteral* fun);
~LiveEditFunctionTracker();
void RecordFunctionInfo(Handle<SharedFunctionInfo> info,
FunctionLiteral* lit, Zone* zone);
// Traverses the entire AST, and records information about all
// FunctionLiterals for further use by LiveEdit code patching. The collected
// information is returned as a serialized array.
static Handle<JSArray> Collect(FunctionLiteral* node, Handle<Script> script,
Zone* zone, Isolate* isolate);
static bool IsActive(Isolate* isolate);
virtual ~LiveEditFunctionTracker() {}
void VisitFunctionLiteral(FunctionLiteral* node) override;
private:
LiveEditFunctionTracker(Handle<Script> script, Zone* zone, Isolate* isolate);
void FunctionStarted(FunctionLiteral* fun);
void FunctionDone(Handle<SharedFunctionInfo> shared, Scope* scope);
Handle<Object> SerializeFunctionScope(Scope* scope);
Handle<Script> script_;
Zone* zone_;
Isolate* isolate_;
Handle<JSArray> result_;
int len_;
int current_parent_index_;
DISALLOW_COPY_AND_ASSIGN(LiveEditFunctionTracker);
};
......
......@@ -58,7 +58,6 @@ class EmptyStatement;
class ExternalCallbackScope;
class ExternalReferenceTable;
class Factory;
class FunctionInfoListener;
class HandleScopeImplementer;
class HeapProfiler;
class HStatistics;
......@@ -383,8 +382,6 @@ typedef List<HeapObject*> DebugObjectCache;
/* function cache of the native context. */ \
V(int, next_serial_number, 0) \
V(ExternalReferenceRedirectorPointer*, external_reference_redirector, NULL) \
/* Part of the state of liveedit. */ \
V(FunctionInfoListener*, active_function_info_listener, NULL) \
/* State for Relocatable. */ \
V(Relocatable*, relocatable_top, NULL) \
V(DebugObjectCache*, string_stream_debug_object_cache, NULL) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment