libv8 6.2.414.42.0beta1-universal-darwin-15 → 8.4.255.0-universal-darwin-15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/ext/libv8/paths.rb +5 -18
  3. data/lib/libv8/version.rb +1 -1
  4. data/vendor/v8/include/cppgc/allocation.h +124 -0
  5. data/vendor/v8/include/cppgc/garbage-collected.h +192 -0
  6. data/vendor/v8/include/cppgc/heap.h +50 -0
  7. data/vendor/v8/include/cppgc/internal/accessors.h +26 -0
  8. data/vendor/v8/include/cppgc/internal/api-constants.h +44 -0
  9. data/vendor/v8/include/cppgc/internal/compiler-specific.h +26 -0
  10. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  11. data/vendor/v8/include/cppgc/internal/gc-info.h +43 -0
  12. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  13. data/vendor/v8/include/cppgc/internal/persistent-node.h +109 -0
  14. data/vendor/v8/include/cppgc/internal/pointer-policies.h +133 -0
  15. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +31 -0
  16. data/vendor/v8/include/cppgc/liveness-broker.h +50 -0
  17. data/vendor/v8/include/cppgc/macros.h +26 -0
  18. data/vendor/v8/include/cppgc/member.h +206 -0
  19. data/vendor/v8/include/cppgc/persistent.h +304 -0
  20. data/vendor/v8/include/cppgc/platform.h +31 -0
  21. data/vendor/v8/include/cppgc/prefinalizer.h +54 -0
  22. data/vendor/v8/include/cppgc/source-location.h +59 -0
  23. data/vendor/v8/include/cppgc/trace-trait.h +67 -0
  24. data/vendor/v8/include/cppgc/type-traits.h +109 -0
  25. data/vendor/v8/include/cppgc/visitor.h +137 -0
  26. data/vendor/v8/include/libplatform/libplatform.h +15 -13
  27. data/vendor/v8/include/libplatform/v8-tracing.h +69 -21
  28. data/vendor/v8/include/v8-fast-api-calls.h +412 -0
  29. data/vendor/v8/include/v8-inspector-protocol.h +4 -4
  30. data/vendor/v8/include/v8-inspector.h +95 -35
  31. data/vendor/v8/include/v8-internal.h +389 -0
  32. data/vendor/v8/include/v8-platform.h +388 -52
  33. data/vendor/v8/include/v8-profiler.h +363 -213
  34. data/vendor/v8/include/v8-util.h +33 -36
  35. data/vendor/v8/include/v8-version-string.h +10 -5
  36. data/vendor/v8/include/v8-version.h +4 -4
  37. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
  38. data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
  39. data/vendor/v8/include/v8.h +3566 -1925
  40. data/vendor/v8/include/v8config.h +162 -114
  41. data/vendor/v8/out.gn/libv8/obj/libv8_libbase.a +0 -0
  42. data/vendor/v8/out.gn/libv8/obj/libv8_libplatform.a +0 -0
  43. data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
  44. data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicui18n.a +0 -0
  45. data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicuuc.a +0 -0
  46. data/vendor/v8/out.gn/libv8/obj/third_party/zlib/google/libcompression_utils_portable.a +0 -0
  47. data/vendor/v8/out.gn/libv8/obj/third_party/zlib/libchrome_zlib.a +0 -0
  48. metadata +52 -31
  49. data/ext/libv8/arch.rb +0 -20
  50. data/vendor/v8/include/v8-debug.h +0 -255
  51. data/vendor/v8/include/v8-testing.h +0 -48
  52. data/vendor/v8/out/x64.release/libv8_base.a +0 -0
  53. data/vendor/v8/out/x64.release/libv8_builtins_generators.a +0 -0
  54. data/vendor/v8/out/x64.release/libv8_builtins_setup.a +0 -0
  55. data/vendor/v8/out/x64.release/libv8_libbase.a +0 -0
  56. data/vendor/v8/out/x64.release/libv8_libplatform.a +0 -0
  57. data/vendor/v8/out/x64.release/libv8_libsampler.a +0 -0
  58. data/vendor/v8/out/x64.release/libv8_nosnapshot.a +0 -0
  59. data/vendor/v8/out/x64.release/libv8_snapshot.a +0 -0
@@ -5,9 +5,12 @@
5
5
  #ifndef V8_V8_PROFILER_H_
6
6
  #define V8_V8_PROFILER_H_
7
7
 
8
+ #include <limits.h>
9
+ #include <memory>
8
10
  #include <unordered_set>
9
11
  #include <vector>
10
- #include "v8.h" // NOLINT(build/include)
12
+
13
+ #include "v8.h" // NOLINT(build/include_directory)
11
14
 
12
15
  /**
13
16
  * Profiler support for the V8 JavaScript engine.
@@ -17,14 +20,18 @@ namespace v8 {
17
20
  class HeapGraphNode;
18
21
  struct HeapStatsUpdate;
19
22
 
20
- typedef uint32_t SnapshotObjectId;
21
-
23
+ using NativeObject = void*;
24
+ using SnapshotObjectId = uint32_t;
22
25
 
23
26
  struct CpuProfileDeoptFrame {
24
27
  int script_id;
25
28
  size_t position;
26
29
  };
27
30
 
31
+ namespace internal {
32
+ class CpuProfile;
33
+ } // namespace internal
34
+
28
35
  } // namespace v8
29
36
 
30
37
  #ifdef V8_OS_WIN
@@ -47,89 +54,6 @@ template class V8_EXPORT std::vector;
47
54
 
48
55
  namespace v8 {
49
56
 
50
- /**
51
- * TracingCpuProfiler monitors tracing being enabled/disabled
52
- * and emits CpuProfile trace events once v8.cpu_profiler tracing category
53
- * is enabled. It has no overhead unless the category is enabled.
54
- */
55
- class V8_EXPORT TracingCpuProfiler {
56
- public:
57
- static std::unique_ptr<TracingCpuProfiler> Create(Isolate*);
58
- virtual ~TracingCpuProfiler() = default;
59
-
60
- protected:
61
- TracingCpuProfiler() = default;
62
- };
63
-
64
- // TickSample captures the information collected for each sample.
65
- struct TickSample {
66
- // Internal profiling (with --prof + tools/$OS-tick-processor) wants to
67
- // include the runtime function we're calling. Externally exposed tick
68
- // samples don't care.
69
- enum RecordCEntryFrame { kIncludeCEntryFrame, kSkipCEntryFrame };
70
-
71
- TickSample()
72
- : state(OTHER),
73
- pc(nullptr),
74
- external_callback_entry(nullptr),
75
- frames_count(0),
76
- has_external_callback(false),
77
- update_stats(true) {}
78
-
79
- /**
80
- * Initialize a tick sample from the isolate.
81
- * \param isolate The isolate.
82
- * \param state Execution state.
83
- * \param record_c_entry_frame Include or skip the runtime function.
84
- * \param update_stats Whether update the sample to the aggregated stats.
85
- * \param use_simulator_reg_state When set to true and V8 is running under a
86
- * simulator, the method will use the simulator
87
- * register state rather than the one provided
88
- * with |state| argument. Otherwise the method
89
- * will use provided register |state| as is.
90
- */
91
- void Init(Isolate* isolate, const v8::RegisterState& state,
92
- RecordCEntryFrame record_c_entry_frame, bool update_stats,
93
- bool use_simulator_reg_state = true);
94
- /**
95
- * Get a call stack sample from the isolate.
96
- * \param isolate The isolate.
97
- * \param state Register state.
98
- * \param record_c_entry_frame Include or skip the runtime function.
99
- * \param frames Caller allocated buffer to store stack frames.
100
- * \param frames_limit Maximum number of frames to capture. The buffer must
101
- * be large enough to hold the number of frames.
102
- * \param sample_info The sample info is filled up by the function
103
- * provides number of actual captured stack frames and
104
- * the current VM state.
105
- * \param use_simulator_reg_state When set to true and V8 is running under a
106
- * simulator, the method will use the simulator
107
- * register state rather than the one provided
108
- * with |state| argument. Otherwise the method
109
- * will use provided register |state| as is.
110
- * \note GetStackSample is thread and signal safe and should only be called
111
- * when the JS thread is paused or interrupted.
112
- * Otherwise the behavior is undefined.
113
- */
114
- static bool GetStackSample(Isolate* isolate, v8::RegisterState* state,
115
- RecordCEntryFrame record_c_entry_frame,
116
- void** frames, size_t frames_limit,
117
- v8::SampleInfo* sample_info,
118
- bool use_simulator_reg_state = true);
119
- StateTag state; // The state of the VM.
120
- void* pc; // Instruction pointer.
121
- union {
122
- void* tos; // Top stack value (*sp).
123
- void* external_callback_entry;
124
- };
125
- static const unsigned kMaxFramesCountLog2 = 8;
126
- static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1;
127
- void* stack[kMaxFramesCount]; // Call stack.
128
- unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames.
129
- bool has_external_callback : 1;
130
- bool update_stats : 1; // Whether the sample should update aggregated stats.
131
- };
132
-
133
57
  /**
134
58
  * CpuProfileNode represents a node in a call graph.
135
59
  */
@@ -143,6 +67,20 @@ class V8_EXPORT CpuProfileNode {
143
67
  unsigned int hit_count;
144
68
  };
145
69
 
70
+ // An annotation hinting at the source of a CpuProfileNode.
71
+ enum SourceType {
72
+ // User-supplied script with associated resource information.
73
+ kScript = 0,
74
+ // Native scripts and provided builtins.
75
+ kBuiltin = 1,
76
+ // Callbacks into native code.
77
+ kCallback = 2,
78
+ // VM-internal functions or state.
79
+ kInternal = 3,
80
+ // A node that failed to symbolize.
81
+ kUnresolved = 4,
82
+ };
83
+
146
84
  /** Returns function name (empty string for anonymous functions.) */
147
85
  Local<String> GetFunctionName() const;
148
86
 
@@ -166,6 +104,12 @@ class V8_EXPORT CpuProfileNode {
166
104
  */
167
105
  const char* GetScriptResourceNameStr() const;
168
106
 
107
+ /**
108
+ * Return true if the script from where the function originates is flagged as
109
+ * being shared cross-origin.
110
+ */
111
+ bool IsScriptSharedCrossOrigin() const;
112
+
169
113
  /**
170
114
  * Returns the number, 1-based, of the line where the function originates.
171
115
  * kNoLineNumberInfo if no line number information is available.
@@ -200,20 +144,23 @@ class V8_EXPORT CpuProfileNode {
200
144
  */
201
145
  unsigned GetHitCount() const;
202
146
 
203
- /** Returns function entry UID. */
204
- V8_DEPRECATE_SOON(
205
- "Use GetScriptId, GetLineNumber, and GetColumnNumber instead.",
206
- unsigned GetCallUid() const);
207
-
208
147
  /** Returns id of the node. The id is unique within the tree */
209
148
  unsigned GetNodeId() const;
210
149
 
150
+ /**
151
+ * Gets the type of the source which the node was captured from.
152
+ */
153
+ SourceType GetSourceType() const;
154
+
211
155
  /** Returns child nodes count of the node. */
212
156
  int GetChildrenCount() const;
213
157
 
214
158
  /** Retrieves a child node by index. */
215
159
  const CpuProfileNode* GetChild(int index) const;
216
160
 
161
+ /** Retrieves the ancestor node, or null if the root. */
162
+ const CpuProfileNode* GetParent() const;
163
+
217
164
  /** Retrieves deopt infos for the node. */
218
165
  const std::vector<CpuProfileDeoptInfo>& GetDeoptInfos() const;
219
166
 
@@ -273,6 +220,76 @@ class V8_EXPORT CpuProfile {
273
220
  void Delete();
274
221
  };
275
222
 
223
+ enum CpuProfilingMode {
224
+ // In the resulting CpuProfile tree, intermediate nodes in a stack trace
225
+ // (from the root to a leaf) will have line numbers that point to the start
226
+ // line of the function, rather than the line of the callsite of the child.
227
+ kLeafNodeLineNumbers,
228
+ // In the resulting CpuProfile tree, nodes are separated based on the line
229
+ // number of their callsite in their parent.
230
+ kCallerLineNumbers,
231
+ };
232
+
233
+ // Determines how names are derived for functions sampled.
234
+ enum CpuProfilingNamingMode {
235
+ // Use the immediate name of functions at compilation time.
236
+ kStandardNaming,
237
+ // Use more verbose naming for functions without names, inferred from scope
238
+ // where possible.
239
+ kDebugNaming,
240
+ };
241
+
242
+ enum CpuProfilingLoggingMode {
243
+ // Enables logging when a profile is active, and disables logging when all
244
+ // profiles are detached.
245
+ kLazyLogging,
246
+ // Enables logging for the lifetime of the CpuProfiler. Calls to
247
+ // StartRecording are faster, at the expense of runtime overhead.
248
+ kEagerLogging,
249
+ };
250
+
251
+ /**
252
+ * Optional profiling attributes.
253
+ */
254
+ class V8_EXPORT CpuProfilingOptions {
255
+ public:
256
+ // Indicates that the sample buffer size should not be explicitly limited.
257
+ static const unsigned kNoSampleLimit = UINT_MAX;
258
+
259
+ /**
260
+ * \param mode Type of computation of stack frame line numbers.
261
+ * \param max_samples The maximum number of samples that should be recorded by
262
+ * the profiler. Samples obtained after this limit will be
263
+ * discarded.
264
+ * \param sampling_interval_us controls the profile-specific target
265
+ * sampling interval. The provided sampling
266
+ * interval will be snapped to the next lowest
267
+ * non-zero multiple of the profiler's sampling
268
+ * interval, set via SetSamplingInterval(). If
269
+ * zero, the sampling interval will be equal to
270
+ * the profiler's sampling interval.
271
+ */
272
+ CpuProfilingOptions(
273
+ CpuProfilingMode mode = kLeafNodeLineNumbers,
274
+ unsigned max_samples = kNoSampleLimit, int sampling_interval_us = 0,
275
+ MaybeLocal<Context> filter_context = MaybeLocal<Context>());
276
+
277
+ CpuProfilingMode mode() const { return mode_; }
278
+ unsigned max_samples() const { return max_samples_; }
279
+ int sampling_interval_us() const { return sampling_interval_us_; }
280
+
281
+ private:
282
+ friend class internal::CpuProfile;
283
+
284
+ bool has_filter_context() const { return !filter_context_.IsEmpty(); }
285
+ void* raw_filter_context() const;
286
+
287
+ CpuProfilingMode mode_;
288
+ unsigned max_samples_;
289
+ int sampling_interval_us_;
290
+ CopyablePersistentTraits<Context>::CopyablePersistent filter_context_;
291
+ };
292
+
276
293
  /**
277
294
  * Interface for controlling CPU profiling. Instance of the
278
295
  * profiler can be created using v8::CpuProfiler::New method.
@@ -284,7 +301,16 @@ class V8_EXPORT CpuProfiler {
284
301
  * initialized. The profiler object must be disposed after use by calling
285
302
  * |Dispose| method.
286
303
  */
287
- static CpuProfiler* New(Isolate* isolate);
304
+ static CpuProfiler* New(Isolate* isolate,
305
+ CpuProfilingNamingMode = kDebugNaming,
306
+ CpuProfilingLoggingMode = kLazyLogging);
307
+
308
+ /**
309
+ * Synchronously collect current stack sample in all profilers attached to
310
+ * the |isolate|. The call does not affect number of ticks recorded for
311
+ * the current top node.
312
+ */
313
+ static void CollectSample(Isolate* isolate);
288
314
 
289
315
  /**
290
316
  * Disposes the CPU profiler object.
@@ -299,15 +325,39 @@ class V8_EXPORT CpuProfiler {
299
325
  void SetSamplingInterval(int us);
300
326
 
301
327
  /**
302
- * Starts collecting CPU profile. Title may be an empty string. It
303
- * is allowed to have several profiles being collected at
304
- * once. Attempts to start collecting several profiles with the same
305
- * title are silently ignored. While collecting a profile, functions
306
- * from all security contexts are included in it. The token-based
307
- * filtering is only performed when querying for a profile.
328
+ * Sets whether or not the profiler should prioritize consistency of sample
329
+ * periodicity on Windows. Disabling this can greatly reduce CPU usage, but
330
+ * may result in greater variance in sample timings from the platform's
331
+ * scheduler. Defaults to enabled. This method must be called when there are
332
+ * no profiles being recorded.
333
+ */
334
+ void SetUsePreciseSampling(bool);
335
+
336
+ /**
337
+ * Starts collecting a CPU profile. Title may be an empty string. Several
338
+ * profiles may be collected at once. Attempts to start collecting several
339
+ * profiles with the same title are silently ignored.
340
+ */
341
+ void StartProfiling(Local<String> title, CpuProfilingOptions options);
342
+
343
+ /**
344
+ * Starts profiling with the same semantics as above, except with expanded
345
+ * parameters.
308
346
  *
309
347
  * |record_samples| parameter controls whether individual samples should
310
348
  * be recorded in addition to the aggregated tree.
349
+ *
350
+ * |max_samples| controls the maximum number of samples that should be
351
+ * recorded by the profiler. Samples obtained after this limit will be
352
+ * discarded.
353
+ */
354
+ void StartProfiling(
355
+ Local<String> title, CpuProfilingMode mode, bool record_samples = false,
356
+ unsigned max_samples = CpuProfilingOptions::kNoSampleLimit);
357
+ /**
358
+ * The same as StartProfiling above, but the CpuProfilingMode defaults to
359
+ * kLeafNodeLineNumbers mode, which was the previous default behavior of the
360
+ * profiler.
311
361
  */
312
362
  void StartProfiling(Local<String> title, bool record_samples = false);
313
363
 
@@ -318,16 +368,10 @@ class V8_EXPORT CpuProfiler {
318
368
  CpuProfile* StopProfiling(Local<String> title);
319
369
 
320
370
  /**
321
- * Force collection of a sample. Must be called on the VM thread.
322
- * Recording the forced sample does not contribute to the aggregated
323
- * profile statistics.
371
+ * Generate more detailed source positions to code objects. This results in
372
+ * better results when mapping profiling samples to script source.
324
373
  */
325
- void CollectSample();
326
-
327
- /**
328
- * Tells the profiler whether the embedder is idle.
329
- */
330
- void SetIdle(bool is_idle);
374
+ static void UseDetailedSourcePositionsForProfiling(Isolate* isolate);
331
375
 
332
376
  private:
333
377
  CpuProfiler();
@@ -336,7 +380,6 @@ class V8_EXPORT CpuProfiler {
336
380
  CpuProfiler& operator=(const CpuProfiler&);
337
381
  };
338
382
 
339
-
340
383
  /**
341
384
  * HeapSnapshotEdge represents a directed connection between heap
342
385
  * graph nodes: from retainers to retained nodes.
@@ -393,7 +436,8 @@ class V8_EXPORT HeapGraphNode {
393
436
  // snapshot items together.
394
437
  kConsString = 10, // Concatenated string. A pair of pointers to strings.
395
438
  kSlicedString = 11, // Sliced string. A fragment of another string.
396
- kSymbol = 12 // A Symbol (ES6).
439
+ kSymbol = 12, // A Symbol (ES6).
440
+ kBigInt = 13 // BigInt.
397
441
  };
398
442
 
399
443
  /** Returns node type (see HeapGraphNode::Type). */
@@ -432,7 +476,7 @@ class V8_EXPORT OutputStream { // NOLINT
432
476
  kContinue = 0,
433
477
  kAbort = 1
434
478
  };
435
- virtual ~OutputStream() {}
479
+ virtual ~OutputStream() = default;
436
480
  /** Notify about the end of stream. */
437
481
  virtual void EndOfStream() = 0;
438
482
  /** Get preferred output chunk size. Called only once. */
@@ -526,7 +570,7 @@ class V8_EXPORT ActivityControl { // NOLINT
526
570
  kContinue = 0,
527
571
  kAbort = 1
528
572
  };
529
- virtual ~ActivityControl() {}
573
+ virtual ~ActivityControl() = default;
530
574
  /**
531
575
  * Notify about current progress. The activity can be stopped by
532
576
  * returning kAbort as the callback result.
@@ -592,6 +636,11 @@ class V8_EXPORT AllocationProfile {
592
636
  */
593
637
  int column_number;
594
638
 
639
+ /**
640
+ * Unique id of the node.
641
+ */
642
+ uint32_t node_id;
643
+
595
644
  /**
596
645
  * List of callees called from this node for which we have sampled
597
646
  * allocations. The lifetime of the children is scoped to the containing
@@ -605,19 +654,116 @@ class V8_EXPORT AllocationProfile {
605
654
  std::vector<Allocation> allocations;
606
655
  };
607
656
 
657
+ /**
658
+ * Represent a single sample recorded for an allocation.
659
+ */
660
+ struct Sample {
661
+ /**
662
+ * id of the node in the profile tree.
663
+ */
664
+ uint32_t node_id;
665
+
666
+ /**
667
+ * Size of the sampled allocation object.
668
+ */
669
+ size_t size;
670
+
671
+ /**
672
+ * The number of objects of such size that were sampled.
673
+ */
674
+ unsigned int count;
675
+
676
+ /**
677
+ * Unique time-ordered id of the allocation sample. Can be used to track
678
+ * what samples were added or removed between two snapshots.
679
+ */
680
+ uint64_t sample_id;
681
+ };
682
+
608
683
  /**
609
684
  * Returns the root node of the call-graph. The root node corresponds to an
610
685
  * empty JS call-stack. The lifetime of the returned Node* is scoped to the
611
686
  * containing AllocationProfile.
612
687
  */
613
688
  virtual Node* GetRootNode() = 0;
689
+ virtual const std::vector<Sample>& GetSamples() = 0;
614
690
 
615
- virtual ~AllocationProfile() {}
691
+ virtual ~AllocationProfile() = default;
616
692
 
617
693
  static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
618
694
  static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
619
695
  };
620
696
 
697
+ /**
698
+ * An object graph consisting of embedder objects and V8 objects.
699
+ * Edges of the graph are strong references between the objects.
700
+ * The embedder can build this graph during heap snapshot generation
701
+ * to include the embedder objects in the heap snapshot.
702
+ * Usage:
703
+ * 1) Define derived class of EmbedderGraph::Node for embedder objects.
704
+ * 2) Set the build embedder graph callback on the heap profiler using
705
+ * HeapProfiler::AddBuildEmbedderGraphCallback.
706
+ * 3) In the callback use graph->AddEdge(node1, node2) to add an edge from
707
+ * node1 to node2.
708
+ * 4) To represent references from/to V8 object, construct V8 nodes using
709
+ * graph->V8Node(value).
710
+ */
711
+ class V8_EXPORT EmbedderGraph {
712
+ public:
713
+ class Node {
714
+ public:
715
+ Node() = default;
716
+ virtual ~Node() = default;
717
+ virtual const char* Name() = 0;
718
+ virtual size_t SizeInBytes() = 0;
719
+ /**
720
+ * The corresponding V8 wrapper node if not null.
721
+ * During heap snapshot generation the embedder node and the V8 wrapper
722
+ * node will be merged into one node to simplify retaining paths.
723
+ */
724
+ virtual Node* WrapperNode() { return nullptr; }
725
+ virtual bool IsRootNode() { return false; }
726
+ /** Must return true for non-V8 nodes. */
727
+ virtual bool IsEmbedderNode() { return true; }
728
+ /**
729
+ * Optional name prefix. It is used in Chrome for tagging detached nodes.
730
+ */
731
+ virtual const char* NamePrefix() { return nullptr; }
732
+
733
+ /**
734
+ * Returns the NativeObject that can be used for querying the
735
+ * |HeapSnapshot|.
736
+ */
737
+ virtual NativeObject GetNativeObject() { return nullptr; }
738
+
739
+ Node(const Node&) = delete;
740
+ Node& operator=(const Node&) = delete;
741
+ };
742
+
743
+ /**
744
+ * Returns a node corresponding to the given V8 value. Ownership is not
745
+ * transferred. The result pointer is valid while the graph is alive.
746
+ */
747
+ virtual Node* V8Node(const v8::Local<v8::Value>& value) = 0;
748
+
749
+ /**
750
+ * Adds the given node to the graph and takes ownership of the node.
751
+ * Returns a raw pointer to the node that is valid while the graph is alive.
752
+ */
753
+ virtual Node* AddNode(std::unique_ptr<Node> node) = 0;
754
+
755
+ /**
756
+ * Adds an edge that represents a strong reference from the given
757
+ * node |from| to the given node |to|. The nodes must be added to the graph
758
+ * before calling this function.
759
+ *
760
+ * If name is nullptr, the edge will have auto-increment indexes, otherwise
761
+ * it will be named accordingly.
762
+ */
763
+ virtual void AddEdge(Node* from, Node* to, const char* name = nullptr) = 0;
764
+
765
+ virtual ~EmbedderGraph() = default;
766
+ };
621
767
 
622
768
  /**
623
769
  * Interface for controlling heap profiling. Instance of the
@@ -630,32 +776,15 @@ class V8_EXPORT HeapProfiler {
630
776
  kSamplingForceGC = 1 << 0,
631
777
  };
632
778
 
633
- typedef std::unordered_set<const v8::PersistentBase<v8::Value>*>
634
- RetainerChildren;
635
- typedef std::vector<std::pair<v8::RetainedObjectInfo*, RetainerChildren>>
636
- RetainerGroups;
637
- typedef std::vector<std::pair<const v8::PersistentBase<v8::Value>*,
638
- const v8::PersistentBase<v8::Value>*>>
639
- RetainerEdges;
640
-
641
- struct RetainerInfos {
642
- RetainerGroups groups;
643
- RetainerEdges edges;
644
- };
645
-
646
779
  /**
647
- * Callback function invoked to retrieve all RetainerInfos from the embedder.
780
+ * Callback function invoked during heap snapshot generation to retrieve
781
+ * the embedder object graph. The callback should use graph->AddEdge(..) to
782
+ * add references between the objects.
783
+ * The callback must not trigger garbage collection in V8.
648
784
  */
649
- typedef RetainerInfos (*GetRetainerInfosCallback)(v8::Isolate* isolate);
650
-
651
- /**
652
- * Callback function invoked for obtaining RetainedObjectInfo for
653
- * the given JavaScript wrapper object. It is prohibited to enter V8
654
- * while the callback is running: only getters on the handle and
655
- * GetPointerFromInternalField on the objects are allowed.
656
- */
657
- typedef RetainedObjectInfo* (*WrapperInfoCallback)(uint16_t class_id,
658
- Local<Value> wrapper);
785
+ typedef void (*BuildEmbedderGraphCallback)(v8::Isolate* isolate,
786
+ v8::EmbedderGraph* graph,
787
+ void* data);
659
788
 
660
789
  /** Returns the number of snapshots taken. */
661
790
  int GetSnapshotCount();
@@ -669,6 +798,12 @@ class V8_EXPORT HeapProfiler {
669
798
  */
670
799
  SnapshotObjectId GetObjectId(Local<Value> value);
671
800
 
801
+ /**
802
+ * Returns SnapshotObjectId for a native object referenced by |value| if it
803
+ * has been seen by the heap profiler, kUnknownObjectId otherwise.
804
+ */
805
+ SnapshotObjectId GetObjectId(NativeObject value);
806
+
672
807
  /**
673
808
  * Returns heap object with given SnapshotObjectId if the object is alive,
674
809
  * otherwise empty handle is returned.
@@ -701,15 +836,16 @@ class V8_EXPORT HeapProfiler {
701
836
  virtual const char* GetName(Local<Object> object) = 0;
702
837
 
703
838
  protected:
704
- virtual ~ObjectNameResolver() {}
839
+ virtual ~ObjectNameResolver() = default;
705
840
  };
706
841
 
707
842
  /**
708
843
  * Takes a heap snapshot and returns it.
709
844
  */
710
845
  const HeapSnapshot* TakeHeapSnapshot(
711
- ActivityControl* control = NULL,
712
- ObjectNameResolver* global_object_name_resolver = NULL);
846
+ ActivityControl* control = nullptr,
847
+ ObjectNameResolver* global_object_name_resolver = nullptr,
848
+ bool treat_global_objects_as_roots = true);
713
849
 
714
850
  /**
715
851
  * Starts tracking of heap objects population statistics. After calling
@@ -736,7 +872,7 @@ class V8_EXPORT HeapProfiler {
736
872
  * method.
737
873
  */
738
874
  SnapshotObjectId GetHeapStats(OutputStream* stream,
739
- int64_t* timestamp_us = NULL);
875
+ int64_t* timestamp_us = nullptr);
740
876
 
741
877
  /**
742
878
  * Stops tracking of heap objects population statistics, cleans up all
@@ -795,12 +931,10 @@ class V8_EXPORT HeapProfiler {
795
931
  */
796
932
  void DeleteAllHeapSnapshots();
797
933
 
798
- /** Binds a callback to embedder's class ID. */
799
- void SetWrapperClassInfoProvider(
800
- uint16_t class_id,
801
- WrapperInfoCallback callback);
802
-
803
- void SetGetRetainerInfosCallback(GetRetainerInfosCallback callback);
934
+ void AddBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback,
935
+ void* data);
936
+ void RemoveBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback,
937
+ void* data);
804
938
 
805
939
  /**
806
940
  * Default value of persistent handle class ID. Must not be used to
@@ -817,92 +951,108 @@ class V8_EXPORT HeapProfiler {
817
951
  };
818
952
 
819
953
  /**
820
- * Interface for providing information about embedder's objects
821
- * held by global handles. This information is reported in two ways:
822
- *
823
- * 1. When calling AddObjectGroup, an embedder may pass
824
- * RetainedObjectInfo instance describing the group. To collect
825
- * this information while taking a heap snapshot, V8 calls GC
826
- * prologue and epilogue callbacks.
827
- *
828
- * 2. When a heap snapshot is collected, V8 additionally
829
- * requests RetainedObjectInfos for persistent handles that
830
- * were not previously reported via AddObjectGroup.
831
- *
832
- * Thus, if an embedder wants to provide information about native
833
- * objects for heap snapshots, it can do it in a GC prologue
834
- * handler, and / or by assigning wrapper class ids in the following way:
835
- *
836
- * 1. Bind a callback to class id by calling SetWrapperClassInfoProvider.
837
- * 2. Call SetWrapperClassId on certain persistent handles.
838
- *
839
- * V8 takes ownership of RetainedObjectInfo instances passed to it and
840
- * keeps them alive only during snapshot collection. Afterwards, they
841
- * are freed by calling the Dispose class function.
954
+ * A struct for exporting HeapStats data from V8, using "push" model.
955
+ * See HeapProfiler::GetHeapStats.
842
956
  */
843
- class V8_EXPORT RetainedObjectInfo { // NOLINT
844
- public:
845
- /** Called by V8 when it no longer needs an instance. */
846
- virtual void Dispose() = 0;
957
+ struct HeapStatsUpdate {
958
+ HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
959
+ : index(index), count(count), size(size) { }
960
+ uint32_t index; // Index of the time interval that was changed.
961
+ uint32_t count; // New value of count field for the interval with this index.
962
+ uint32_t size; // New value of size field for the interval with this index.
963
+ };
847
964
 
848
- /** Returns whether two instances are equivalent. */
849
- virtual bool IsEquivalent(RetainedObjectInfo* other) = 0;
965
+ #define CODE_EVENTS_LIST(V) \
966
+ V(Builtin) \
967
+ V(Callback) \
968
+ V(Eval) \
969
+ V(Function) \
970
+ V(InterpretedFunction) \
971
+ V(Handler) \
972
+ V(BytecodeHandler) \
973
+ V(LazyCompile) \
974
+ V(RegExp) \
975
+ V(Script) \
976
+ V(Stub) \
977
+ V(Relocation)
850
978
 
979
+ /**
980
+ * Note that this enum may be extended in the future. Please include a default
981
+ * case if this enum is used in a switch statement.
982
+ */
983
+ enum CodeEventType {
984
+ kUnknownType = 0
985
+ #define V(Name) , k##Name##Type
986
+ CODE_EVENTS_LIST(V)
987
+ #undef V
988
+ };
989
+
990
+ /**
991
+ * Representation of a code creation event
992
+ */
993
+ class V8_EXPORT CodeEvent {
994
+ public:
995
+ uintptr_t GetCodeStartAddress();
996
+ size_t GetCodeSize();
997
+ Local<String> GetFunctionName();
998
+ Local<String> GetScriptName();
999
+ int GetScriptLine();
1000
+ int GetScriptColumn();
851
1001
  /**
852
- * Returns hash value for the instance. Equivalent instances
853
- * must have the same hash value.
1002
+ * NOTE (mmarchini): We can't allocate objects in the heap when we collect
1003
+ * existing code, and both the code type and the comment are not stored in the
1004
+ * heap, so we return those as const char*.
854
1005
  */
855
- virtual intptr_t GetHash() = 0;
1006
+ CodeEventType GetCodeType();
1007
+ const char* GetComment();
1008
+
1009
+ static const char* GetCodeEventTypeName(CodeEventType code_event_type);
856
1010
 
1011
+ uintptr_t GetPreviousCodeStartAddress();
1012
+ };
1013
+
1014
+ /**
1015
+ * Interface to listen to code creation and code relocation events.
1016
+ */
1017
+ class V8_EXPORT CodeEventHandler {
1018
+ public:
857
1019
  /**
858
- * Returns human-readable label. It must be a null-terminated UTF-8
859
- * encoded string. V8 copies its contents during a call to GetLabel.
1020
+ * Creates a new listener for the |isolate|. The isolate must be initialized.
1021
+ * The listener object must be disposed after use by calling |Dispose| method.
1022
+ * Multiple listeners can be created for the same isolate.
860
1023
  */
861
- virtual const char* GetLabel() = 0;
1024
+ explicit CodeEventHandler(Isolate* isolate);
1025
+ virtual ~CodeEventHandler();
862
1026
 
863
1027
  /**
864
- * Returns human-readable group label. It must be a null-terminated UTF-8
865
- * encoded string. V8 copies its contents during a call to GetGroupLabel.
866
- * Heap snapshot generator will collect all the group names, create
867
- * top level entries with these names and attach the objects to the
868
- * corresponding top level group objects. There is a default
869
- * implementation which is required because embedders don't have their
870
- * own implementation yet.
1028
+ * Handle is called every time a code object is created or moved. Information
1029
+ * about each code event will be available through the `code_event`
1030
+ * parameter.
1031
+ *
1032
+ * When the CodeEventType is kRelocationType, the code for this CodeEvent has
1033
+ * moved from `GetPreviousCodeStartAddress()` to `GetCodeStartAddress()`.
871
1034
  */
872
- virtual const char* GetGroupLabel() { return GetLabel(); }
1035
+ virtual void Handle(CodeEvent* code_event) = 0;
873
1036
 
874
1037
  /**
875
- * Returns element count in case if a global handle retains
876
- * a subgraph by holding one of its nodes.
1038
+ * Call `Enable()` to starts listening to code creation and code relocation
1039
+ * events. These events will be handled by `Handle()`.
877
1040
  */
878
- virtual intptr_t GetElementCount() { return -1; }
879
-
880
- /** Returns embedder's object size in bytes. */
881
- virtual intptr_t GetSizeInBytes() { return -1; }
1041
+ void Enable();
882
1042
 
883
- protected:
884
- RetainedObjectInfo() {}
885
- virtual ~RetainedObjectInfo() {}
1043
+ /**
1044
+ * Call `Disable()` to stop listening to code creation and code relocation
1045
+ * events.
1046
+ */
1047
+ void Disable();
886
1048
 
887
1049
  private:
888
- RetainedObjectInfo(const RetainedObjectInfo&);
889
- RetainedObjectInfo& operator=(const RetainedObjectInfo&);
1050
+ CodeEventHandler();
1051
+ CodeEventHandler(const CodeEventHandler&);
1052
+ CodeEventHandler& operator=(const CodeEventHandler&);
1053
+ void* internal_listener_;
890
1054
  };
891
1055
 
892
-
893
- /**
894
- * A struct for exporting HeapStats data from V8, using "push" model.
895
- * See HeapProfiler::GetHeapStats.
896
- */
897
- struct HeapStatsUpdate {
898
- HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
899
- : index(index), count(count), size(size) { }
900
- uint32_t index; // Index of the time interval that was changed.
901
- uint32_t count; // New value of count field for the interval with this index.
902
- uint32_t size; // New value of size field for the interval with this index.
903
- };
904
-
905
-
906
1056
  } // namespace v8
907
1057
 
908
1058