• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_DEBUG_LIVEEDIT_H_
6 #define V8_DEBUG_LIVEEDIT_H_
7 
8 #include <vector>
9 
10 #include "src/globals.h"
11 #include "src/handles.h"
12 
13 namespace v8 {
14 namespace debug {
15 struct LiveEditResult;
16 }
17 namespace internal {
18 
19 class Script;
20 class String;
21 class Debug;
22 class JavaScriptFrame;
23 
24 struct SourceChangeRange {
25   int start_position;
26   int end_position;
27   int new_start_position;
28   int new_end_position;
29 };
30 
31 /**
32   Liveedit step-by-step:
33   1. calculate diff between old source and new source,
34   2. map function literals from old source to new source,
35   3. create new script for new_source,
36   4. mark literals with changed code as changed, all others as unchanged,
37   5. check that for changed literals there are no:
38     - running generators in the heap,
39     - non droppable frames (e.g. running generator) above them on stack.
40   6. mark the bottom most frame with changed function as scheduled for restart
41      if any,
42   7. for unchanged functions:
43     - deoptimize,
44     - remove from cache,
45     - update source positions,
46     - move to new script,
47     - reset feedback information and preparsed scope information if any,
48     - replace any sfi in constant pool with changed one if any.
49   8. for changed functions:
50     - deoptimize
51     - remove from cache,
52     - reset feedback information,
53     - update all links from js functions to old shared with new one.
54   9. swap scripts.
55  */
56 
57 class LiveEdit : AllStatic {
58  public:
59   static void InitializeThreadLocal(Debug* debug);
60 
61   // Restarts the call frame and completely drops all frames above it.
62   static bool RestartFrame(JavaScriptFrame* frame);
63 
64   static void CompareStrings(Isolate* isolate, Handle<String> a,
65                              Handle<String> b,
66                              std::vector<SourceChangeRange>* diffs);
67   static int TranslatePosition(const std::vector<SourceChangeRange>& changed,
68                                int position);
69   static void PatchScript(Isolate* isolate, Handle<Script> script,
70                           Handle<String> source, bool preview,
71                           debug::LiveEditResult* result);
72   // Architecture-specific constant.
73   static const bool kFrameDropperSupported;
74 };
75 }  // namespace internal
76 }  // namespace v8
77 
78 #endif  // V8_DEBUG_LIVEEDIT_H_
79