summaryrefslogtreecommitdiff
path: root/deps/v8/src/debug/liveedit.h
blob: 578cf292548b3f0c878361c24dfda5fa4287abcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2012 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.

#ifndef V8_DEBUG_LIVEEDIT_H_
#define V8_DEBUG_LIVEEDIT_H_

#include <vector>

#include "src/common/globals.h"
#include "src/handles/handles.h"

namespace v8 {
namespace debug {
struct LiveEditResult;
}
namespace internal {

class Script;
class String;
class Debug;
class JavaScriptFrame;

struct SourceChangeRange {
  int start_position;
  int end_position;
  int new_start_position;
  int new_end_position;
};

/**
  Liveedit step-by-step:
  1. calculate diff between old source and new source,
  2. map function literals from old source to new source,
  3. create new script for new_source,
  4. mark literals with changed code as changed, all others as unchanged,
  5. check that for changed literals there are no:
    - running generators in the heap,
    - non droppable frames (e.g. running generator) above them on stack.
  6. mark the bottom most frame with changed function as scheduled for restart
     if any,
  7. for unchanged functions:
    - deoptimize,
    - remove from cache,
    - update source positions,
    - move to new script,
    - reset feedback information and preparsed scope information if any,
    - replace any sfi in constant pool with changed one if any.
  8. for changed functions:
    - deoptimize
    - remove from cache,
    - reset feedback information,
    - update all links from js functions to old shared with new one.
  9. swap scripts.
 */

class V8_EXPORT_PRIVATE LiveEdit : AllStatic {
 public:
  static void InitializeThreadLocal(Debug* debug);

  // Restarts the call frame and completely drops all frames above it.
  static bool RestartFrame(JavaScriptFrame* frame);

  static void CompareStrings(Isolate* isolate, Handle<String> a,
                             Handle<String> b,
                             std::vector<SourceChangeRange>* diffs);
  static int TranslatePosition(const std::vector<SourceChangeRange>& changed,
                               int position);
  static void PatchScript(Isolate* isolate, Handle<Script> script,
                          Handle<String> source, bool preview,
                          debug::LiveEditResult* result);
  // Architecture-specific constant.
  static const bool kFrameDropperSupported;
};
}  // namespace internal
}  // namespace v8

#endif  // V8_DEBUG_LIVEEDIT_H_