v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
liveedit.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_LIVEEDIT_H_
29 #define V8_LIVEEDIT_H_
30 
31 
32 
33 // Live Edit feature implementation.
34 // User should be able to change script on already running VM. This feature
35 // matches hot swap features in other frameworks.
36 //
37 // The basic use-case is when user spots some mistake in function body
38 // from debugger and wishes to change the algorithm without restart.
39 //
40 // A single change always has a form of a simple replacement (in pseudo-code):
41 // script.source[positions, positions+length] = new_string;
42 // Implementation first determines, which function's body includes this
43 // change area. Then both old and new versions of script are fully compiled
44 // in order to analyze, whether the function changed its outer scope
45 // expectations (or number of parameters). If it didn't, function's code is
46 // patched with a newly compiled code. If it did change, enclosing function
47 // gets patched. All inner functions are left untouched, whatever happened
48 // to them in a new script version. However, new version of code will
49 // instantiate newly compiled functions.
50 
51 
52 #include "allocation.h"
53 #include "compiler.h"
54 
55 namespace v8 {
56 namespace internal {
57 
58 // This class collects some specific information on structure of functions
59 // in a particular script. It gets called from compiler all the time, but
60 // actually records any data only when liveedit operation is in process;
61 // in any other time this class is very cheap.
62 //
63 // The primary interest of the Tracker is to record function scope structures
64 // in order to analyze whether function code maybe safely patched (with new
65 // code successfully reading existing data from function scopes). The Tracker
66 // also collects compiled function codes.
68  public:
69  explicit LiveEditFunctionTracker(Isolate* isolate, FunctionLiteral* fun);
72  FunctionLiteral* lit, Zone* zone);
74 
75  static bool IsActive(Isolate* isolate);
76 
77  private:
78 #ifdef ENABLE_DEBUGGER_SUPPORT
79  Isolate* isolate_;
80 #endif
81 };
82 
83 #ifdef ENABLE_DEBUGGER_SUPPORT
84 
85 class LiveEdit : AllStatic {
86  public:
87  static JSArray* GatherCompileInfo(Handle<Script> script,
88  Handle<String> source);
89 
90  static void WrapSharedFunctionInfos(Handle<JSArray> array);
91 
92  MUST_USE_RESULT static MaybeObject* ReplaceFunctionCode(
93  Handle<JSArray> new_compile_info_array,
94  Handle<JSArray> shared_info_array);
95 
96  static MaybeObject* FunctionSourceUpdated(Handle<JSArray> shared_info_array);
97 
98  // Updates script field in FunctionSharedInfo.
99  static void SetFunctionScript(Handle<JSValue> function_wrapper,
100  Handle<Object> script_handle);
101 
102  MUST_USE_RESULT static MaybeObject* PatchFunctionPositions(
103  Handle<JSArray> shared_info_array, Handle<JSArray> position_change_array);
104 
105  // For a script updates its source field. If old_script_name is provided
106  // (i.e. is a String), also creates a copy of the script with its original
107  // source and sends notification to debugger.
108  static Object* ChangeScriptSource(Handle<Script> original_script,
109  Handle<String> new_source,
110  Handle<Object> old_script_name);
111 
112  // In a code of a parent function replaces original function as embedded
113  // object with a substitution one.
114  static void ReplaceRefToNestedFunction(Handle<JSValue> parent_function_shared,
115  Handle<JSValue> orig_function_shared,
116  Handle<JSValue> subst_function_shared);
117 
118  // Checks listed functions on stack and return array with corresponding
119  // FunctionPatchabilityStatus statuses; extra array element may
120  // contain general error message. Modifies the current stack and
121  // has restart the lowest found frames and drops all other frames above
122  // if possible and if do_drop is true.
123  static Handle<JSArray> CheckAndDropActivations(
124  Handle<JSArray> shared_info_array, bool do_drop);
125 
126  // Restarts the call frame and completely drops all frames above it.
127  // Return error message or NULL.
128  static const char* RestartFrame(JavaScriptFrame* frame);
129 
130  // A copy of this is in liveedit-debugger.js.
131  enum FunctionPatchabilityStatus {
132  FUNCTION_AVAILABLE_FOR_PATCH = 1,
133  FUNCTION_BLOCKED_ON_ACTIVE_STACK = 2,
134  FUNCTION_BLOCKED_ON_OTHER_STACK = 3,
135  FUNCTION_BLOCKED_UNDER_NATIVE_CODE = 4,
136  FUNCTION_REPLACED_ON_ACTIVE_STACK = 5
137  };
138 
139  // Compares 2 strings line-by-line, then token-wise and returns diff in form
140  // of array of triplets (pos1, pos1_end, pos2_end) describing list
141  // of diff chunks.
142  static Handle<JSArray> CompareStrings(Handle<String> s1,
144 };
145 
146 
147 // A general-purpose comparator between 2 arrays.
148 class Comparator {
149  public:
150  // Holds 2 arrays of some elements allowing to compare any pair of
151  // element from the first array and element from the second array.
152  class Input {
153  public:
154  virtual int GetLength1() = 0;
155  virtual int GetLength2() = 0;
156  virtual bool Equals(int index1, int index2) = 0;
157 
158  protected:
159  virtual ~Input() {}
160  };
161 
162  // Receives compare result as a series of chunks.
163  class Output {
164  public:
165  // Puts another chunk in result list. Note that technically speaking
166  // only 3 arguments actually needed with 4th being derivable.
167  virtual void AddChunk(int pos1, int pos2, int len1, int len2) = 0;
168 
169  protected:
170  virtual ~Output() {}
171  };
172 
173  // Finds the difference between 2 arrays of elements.
174  static void CalculateDifference(Input* input,
175  Output* result_writer);
176 };
177 
178 #endif // ENABLE_DEBUGGER_SUPPORT
179 
180 
181 } } // namespace v8::internal
182 
183 #endif /* V*_LIVEEDIT_H_ */
const SwVfpRegister s2
void RecordRootFunctionInfo(Handle< Code > code)
Definition: liveedit.cc:2124
static bool IsActive(Isolate *isolate)
Definition: liveedit.cc:2128
LiveEditFunctionTracker(Isolate *isolate, FunctionLiteral *fun)
Definition: liveedit.cc:2109
#define MUST_USE_RESULT
Definition: globals.h:381
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
void RecordFunctionInfo(Handle< SharedFunctionInfo > info, FunctionLiteral *lit, Zone *zone)
Definition: liveedit.cc:2118
const SwVfpRegister s1
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
Definition: flags.cc:317