libv8 3.16.14.19.1-x86_64-darwin → 8.4.255.0.1-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8/location.rb +15 -7
  3. data/ext/libv8/paths.rb +6 -19
  4. data/lib/libv8/version.rb +1 -1
  5. data/vendor/v8/include/cppgc/allocation.h +124 -0
  6. data/vendor/v8/include/cppgc/garbage-collected.h +192 -0
  7. data/vendor/v8/include/cppgc/heap.h +50 -0
  8. data/vendor/v8/include/cppgc/internal/accessors.h +26 -0
  9. data/vendor/v8/include/cppgc/internal/api-constants.h +44 -0
  10. data/vendor/v8/include/cppgc/internal/compiler-specific.h +26 -0
  11. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  12. data/vendor/v8/include/cppgc/internal/gc-info.h +43 -0
  13. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  14. data/vendor/v8/include/cppgc/internal/persistent-node.h +109 -0
  15. data/vendor/v8/include/cppgc/internal/pointer-policies.h +133 -0
  16. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +31 -0
  17. data/vendor/v8/include/cppgc/liveness-broker.h +50 -0
  18. data/vendor/v8/include/cppgc/macros.h +26 -0
  19. data/vendor/v8/include/cppgc/member.h +206 -0
  20. data/vendor/v8/include/cppgc/persistent.h +304 -0
  21. data/vendor/v8/include/cppgc/platform.h +31 -0
  22. data/vendor/v8/include/cppgc/prefinalizer.h +54 -0
  23. data/vendor/v8/include/cppgc/source-location.h +59 -0
  24. data/vendor/v8/include/cppgc/trace-trait.h +67 -0
  25. data/vendor/v8/include/cppgc/type-traits.h +109 -0
  26. data/vendor/v8/include/cppgc/visitor.h +137 -0
  27. data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
  28. data/vendor/v8/include/libplatform/libplatform.h +85 -0
  29. data/vendor/v8/include/libplatform/v8-tracing.h +332 -0
  30. data/vendor/v8/include/v8-fast-api-calls.h +412 -0
  31. data/vendor/v8/include/v8-inspector-protocol.h +13 -0
  32. data/vendor/v8/include/v8-inspector.h +327 -0
  33. data/vendor/v8/include/v8-internal.h +389 -0
  34. data/vendor/v8/include/v8-platform.h +577 -0
  35. data/vendor/v8/include/v8-profiler.h +744 -265
  36. data/vendor/v8/include/v8-util.h +652 -0
  37. data/vendor/v8/include/v8-value-serializer-version.h +24 -0
  38. data/vendor/v8/include/v8-version-string.h +38 -0
  39. data/vendor/v8/include/v8-version.h +20 -0
  40. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
  41. data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
  42. data/vendor/v8/include/v8.h +10228 -3147
  43. data/vendor/v8/include/v8config.h +465 -0
  44. data/vendor/v8/out.gn/libv8/obj/libv8_libbase.a +0 -0
  45. data/vendor/v8/out.gn/libv8/obj/libv8_libplatform.a +0 -0
  46. data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
  47. data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicui18n.a +0 -0
  48. data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicuuc.a +0 -0
  49. data/vendor/v8/out.gn/libv8/obj/third_party/zlib/google/libcompression_utils_portable.a +0 -0
  50. data/vendor/v8/out.gn/libv8/obj/third_party/zlib/libchrome_zlib.a +0 -0
  51. metadata +52 -32
  52. data/ext/libv8/arch.rb +0 -43
  53. data/vendor/v8/include/v8-debug.h +0 -408
  54. data/vendor/v8/include/v8-preparser.h +0 -118
  55. data/vendor/v8/include/v8-testing.h +0 -105
  56. data/vendor/v8/include/v8stdint.h +0 -54
  57. data/vendor/v8/out/x64.release/libpreparser_lib.a +0 -0
  58. data/vendor/v8/out/x64.release/libv8_base.a +0 -0
  59. data/vendor/v8/out/x64.release/libv8_nosnapshot.a +0 -0
  60. data/vendor/v8/out/x64.release/libv8_snapshot.a +0 -0
@@ -1,82 +1,114 @@
1
1
  // Copyright 2010 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.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
27
4
 
28
5
  #ifndef V8_V8_PROFILER_H_
29
6
  #define V8_V8_PROFILER_H_
30
7
 
31
- #include "v8.h"
8
+ #include <limits.h>
9
+ #include <memory>
10
+ #include <unordered_set>
11
+ #include <vector>
32
12
 
33
- #ifdef _WIN32
34
- // Setup for Windows DLL export/import. See v8.h in this directory for
35
- // information on how to build/use V8 as a DLL.
36
- #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
37
- #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
38
- build configuration to ensure that at most one of these is set
39
- #endif
13
+ #include "v8.h" // NOLINT(build/include_directory)
40
14
 
41
- #ifdef BUILDING_V8_SHARED
42
- #define V8EXPORT __declspec(dllexport)
43
- #elif USING_V8_SHARED
44
- #define V8EXPORT __declspec(dllimport)
45
- #else
46
- #define V8EXPORT
47
- #endif
15
+ /**
16
+ * Profiler support for the V8 JavaScript engine.
17
+ */
18
+ namespace v8 {
19
+
20
+ class HeapGraphNode;
21
+ struct HeapStatsUpdate;
48
22
 
49
- #else // _WIN32
23
+ using NativeObject = void*;
24
+ using SnapshotObjectId = uint32_t;
50
25
 
51
- // Setup for Linux shared library export. See v8.h in this directory for
52
- // information on how to build/use V8 as shared library.
53
- #if defined(__GNUC__) && ((__GNUC__ >= 4) || \
54
- (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED)
55
- #define V8EXPORT __attribute__ ((visibility("default")))
56
- #else
57
- #define V8EXPORT
58
- #endif
26
+ struct CpuProfileDeoptFrame {
27
+ int script_id;
28
+ size_t position;
29
+ };
59
30
 
60
- #endif // _WIN32
31
+ namespace internal {
32
+ class CpuProfile;
33
+ } // namespace internal
61
34
 
35
+ } // namespace v8
36
+
37
+ #ifdef V8_OS_WIN
38
+ template class V8_EXPORT std::vector<v8::CpuProfileDeoptFrame>;
39
+ #endif
62
40
 
63
- /**
64
- * Profiler support for the V8 JavaScript engine.
65
- */
66
41
  namespace v8 {
67
42
 
68
- typedef uint32_t SnapshotObjectId;
43
+ struct V8_EXPORT CpuProfileDeoptInfo {
44
+ /** A pointer to a static string owned by v8. */
45
+ const char* deopt_reason;
46
+ std::vector<CpuProfileDeoptFrame> stack;
47
+ };
48
+
49
+ } // namespace v8
50
+
51
+ #ifdef V8_OS_WIN
52
+ template class V8_EXPORT std::vector<v8::CpuProfileDeoptInfo>;
53
+ #endif
54
+
55
+ namespace v8 {
69
56
 
70
57
  /**
71
58
  * CpuProfileNode represents a node in a call graph.
72
59
  */
73
- class V8EXPORT CpuProfileNode {
60
+ class V8_EXPORT CpuProfileNode {
74
61
  public:
62
+ struct LineTick {
63
+ /** The 1-based number of the source line where the function originates. */
64
+ int line;
65
+
66
+ /** The count of samples associated with the source line. */
67
+ unsigned int hit_count;
68
+ };
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
+
75
84
  /** Returns function name (empty string for anonymous functions.) */
76
- Handle<String> GetFunctionName() const;
85
+ Local<String> GetFunctionName() const;
86
+
87
+ /**
88
+ * Returns function name (empty string for anonymous functions.)
89
+ * The string ownership is *not* passed to the caller. It stays valid until
90
+ * profile is deleted. The function is thread safe.
91
+ */
92
+ const char* GetFunctionNameStr() const;
93
+
94
+ /** Returns id of the script where function is located. */
95
+ int GetScriptId() const;
77
96
 
78
97
  /** Returns resource name for script from where the function originates. */
79
- Handle<String> GetScriptResourceName() const;
98
+ Local<String> GetScriptResourceName() const;
99
+
100
+ /**
101
+ * Returns resource name for script from where the function originates.
102
+ * The string ownership is *not* passed to the caller. It stays valid until
103
+ * profile is deleted. The function is thread safe.
104
+ */
105
+ const char* GetScriptResourceNameStr() const;
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;
80
112
 
81
113
  /**
82
114
  * Returns the number, 1-based, of the line where the function originates.
@@ -85,25 +117,40 @@ class V8EXPORT CpuProfileNode {
85
117
  int GetLineNumber() const;
86
118
 
87
119
  /**
88
- * Returns total (self + children) execution time of the function,
89
- * in milliseconds, estimated by samples count.
120
+ * Returns 1-based number of the column where the function originates.
121
+ * kNoColumnNumberInfo if no column number information is available.
90
122
  */
91
- double GetTotalTime() const;
123
+ int GetColumnNumber() const;
92
124
 
93
125
  /**
94
- * Returns self execution time of the function, in milliseconds,
95
- * estimated by samples count.
126
+ * Returns the number of the function's source lines that collect the samples.
96
127
  */
97
- double GetSelfTime() const;
128
+ unsigned int GetHitLineCount() const;
98
129
 
99
- /** Returns the count of samples where function exists. */
100
- double GetTotalSamplesCount() const;
130
+ /** Returns the set of source lines that collect the samples.
131
+ * The caller allocates buffer and responsible for releasing it.
132
+ * True if all available entries are copied, otherwise false.
133
+ * The function copies nothing if buffer is not large enough.
134
+ */
135
+ bool GetLineTicks(LineTick* entries, unsigned int length) const;
101
136
 
102
- /** Returns the count of samples where function was currently executing. */
103
- double GetSelfSamplesCount() const;
137
+ /** Returns bailout reason for the function
138
+ * if the optimization was disabled for it.
139
+ */
140
+ const char* GetBailoutReason() const;
104
141
 
105
- /** Returns function entry UID. */
106
- unsigned GetCallUid() const;
142
+ /**
143
+ * Returns the count of samples where the function was currently executing.
144
+ */
145
+ unsigned GetHitCount() const;
146
+
147
+ /** Returns id of the node. The id is unique within the tree */
148
+ unsigned GetNodeId() const;
149
+
150
+ /**
151
+ * Gets the type of the source which the node was captured from.
152
+ */
153
+ SourceType GetSourceType() const;
107
154
 
108
155
  /** Returns child nodes count of the node. */
109
156
  int GetChildrenCount() const;
@@ -111,106 +158,233 @@ class V8EXPORT CpuProfileNode {
111
158
  /** Retrieves a child node by index. */
112
159
  const CpuProfileNode* GetChild(int index) const;
113
160
 
161
+ /** Retrieves the ancestor node, or null if the root. */
162
+ const CpuProfileNode* GetParent() const;
163
+
164
+ /** Retrieves deopt infos for the node. */
165
+ const std::vector<CpuProfileDeoptInfo>& GetDeoptInfos() const;
166
+
114
167
  static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
168
+ static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
115
169
  };
116
170
 
117
171
 
118
172
  /**
119
- * CpuProfile contains a CPU profile in a form of two call trees:
120
- * - top-down (from main() down to functions that do all the work);
121
- * - bottom-up call graph (in backward direction).
173
+ * CpuProfile contains a CPU profile in a form of top-down call tree
174
+ * (from main() down to functions that do all the work).
122
175
  */
123
- class V8EXPORT CpuProfile {
176
+ class V8_EXPORT CpuProfile {
124
177
  public:
125
- /** Returns CPU profile UID (assigned by the profiler.) */
126
- unsigned GetUid() const;
127
-
128
178
  /** Returns CPU profile title. */
129
- Handle<String> GetTitle() const;
130
-
131
- /** Returns the root node of the bottom up call tree. */
132
- const CpuProfileNode* GetBottomUpRoot() const;
179
+ Local<String> GetTitle() const;
133
180
 
134
181
  /** Returns the root node of the top down call tree. */
135
182
  const CpuProfileNode* GetTopDownRoot() const;
136
183
 
184
+ /**
185
+ * Returns number of samples recorded. The samples are not recorded unless
186
+ * |record_samples| parameter of CpuProfiler::StartCpuProfiling is true.
187
+ */
188
+ int GetSamplesCount() const;
189
+
190
+ /**
191
+ * Returns profile node corresponding to the top frame the sample at
192
+ * the given index.
193
+ */
194
+ const CpuProfileNode* GetSample(int index) const;
195
+
196
+ /**
197
+ * Returns the timestamp of the sample. The timestamp is the number of
198
+ * microseconds since some unspecified starting point.
199
+ * The point is equal to the starting point used by GetStartTime.
200
+ */
201
+ int64_t GetSampleTimestamp(int index) const;
202
+
203
+ /**
204
+ * Returns time when the profile recording was started (in microseconds)
205
+ * since some unspecified starting point.
206
+ */
207
+ int64_t GetStartTime() const;
208
+
209
+ /**
210
+ * Returns time when the profile recording was stopped (in microseconds)
211
+ * since some unspecified starting point.
212
+ * The point is equal to the starting point used by GetStartTime.
213
+ */
214
+ int64_t GetEndTime() const;
215
+
137
216
  /**
138
217
  * Deletes the profile and removes it from CpuProfiler's list.
139
218
  * All pointers to nodes previously returned become invalid.
140
- * Profiles with the same uid but obtained using different
141
- * security token are not deleted, but become inaccessible
142
- * using FindProfile method. It is embedder's responsibility
143
- * to call Delete on these profiles.
144
219
  */
145
220
  void Delete();
146
221
  };
147
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
+ };
148
250
 
149
251
  /**
150
- * Interface for controlling CPU profiling.
252
+ * Optional profiling attributes.
151
253
  */
152
- class V8EXPORT CpuProfiler {
254
+ class V8_EXPORT CpuProfilingOptions {
153
255
  public:
256
+ // Indicates that the sample buffer size should not be explicitly limited.
257
+ static const unsigned kNoSampleLimit = UINT_MAX;
258
+
154
259
  /**
155
- * A note on security tokens usage. As scripts from different
156
- * origins can run inside a single V8 instance, it is possible to
157
- * have functions from different security contexts intermixed in a
158
- * single CPU profile. To avoid exposing function names belonging to
159
- * other contexts, filtering by security token is performed while
160
- * obtaining profiling results.
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.
161
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_; }
162
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
+
293
+ /**
294
+ * Interface for controlling CPU profiling. Instance of the
295
+ * profiler can be created using v8::CpuProfiler::New method.
296
+ */
297
+ class V8_EXPORT CpuProfiler {
298
+ public:
163
299
  /**
164
- * Returns the number of profiles collected (doesn't include
165
- * profiles that are being collected at the moment of call.)
300
+ * Creates a new CPU profiler for the |isolate|. The isolate must be
301
+ * initialized. The profiler object must be disposed after use by calling
302
+ * |Dispose| method.
166
303
  */
167
- static int GetProfilesCount();
304
+ static CpuProfiler* New(Isolate* isolate,
305
+ CpuProfilingNamingMode = kDebugNaming,
306
+ CpuProfilingLoggingMode = kLazyLogging);
168
307
 
169
- /** Returns a profile by index. */
170
- static const CpuProfile* GetProfile(
171
- int index,
172
- Handle<Value> security_token = Handle<Value>());
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);
173
314
 
174
- /** Returns a profile by uid. */
175
- static const CpuProfile* FindProfile(
176
- unsigned uid,
177
- Handle<Value> security_token = Handle<Value>());
315
+ /**
316
+ * Disposes the CPU profiler object.
317
+ */
318
+ void Dispose();
178
319
 
179
320
  /**
180
- * Starts collecting CPU profile. Title may be an empty string. It
181
- * is allowed to have several profiles being collected at
182
- * once. Attempts to start collecting several profiles with the same
183
- * title are silently ignored. While collecting a profile, functions
184
- * from all security contexts are included in it. The token-based
185
- * filtering is only performed when querying for a profile.
321
+ * Changes default CPU profiler sampling interval to the specified number
322
+ * of microseconds. Default interval is 1000us. This method must be called
323
+ * when there are no profiles being recorded.
186
324
  */
187
- static void StartProfiling(Handle<String> title);
325
+ void SetSamplingInterval(int us);
188
326
 
189
327
  /**
190
- * Stops collecting CPU profile with a given title and returns it.
191
- * If the title given is empty, finishes the last profile started.
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.
192
333
  */
193
- static const CpuProfile* StopProfiling(
194
- Handle<String> title,
195
- Handle<Value> security_token = Handle<Value>());
334
+ void SetUsePreciseSampling(bool);
196
335
 
197
336
  /**
198
- * Deletes all existing profiles, also cancelling all profiling
199
- * activity. All previously returned pointers to profiles and their
200
- * contents become invalid after this call.
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.
201
340
  */
202
- static void DeleteAllProfiles();
203
- };
341
+ void StartProfiling(Local<String> title, CpuProfilingOptions options);
204
342
 
343
+ /**
344
+ * Starts profiling with the same semantics as above, except with expanded
345
+ * parameters.
346
+ *
347
+ * |record_samples| parameter controls whether individual samples should
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.
361
+ */
362
+ void StartProfiling(Local<String> title, bool record_samples = false);
205
363
 
206
- class HeapGraphNode;
364
+ /**
365
+ * Stops collecting CPU profile with a given title and returns it.
366
+ * If the title given is empty, finishes the last profile started.
367
+ */
368
+ CpuProfile* StopProfiling(Local<String> title);
207
369
 
370
+ /**
371
+ * Generate more detailed source positions to code objects. This results in
372
+ * better results when mapping profiling samples to script source.
373
+ */
374
+ static void UseDetailedSourcePositionsForProfiling(Isolate* isolate);
375
+
376
+ private:
377
+ CpuProfiler();
378
+ ~CpuProfiler();
379
+ CpuProfiler(const CpuProfiler&);
380
+ CpuProfiler& operator=(const CpuProfiler&);
381
+ };
208
382
 
209
383
  /**
210
384
  * HeapSnapshotEdge represents a directed connection between heap
211
385
  * graph nodes: from retainers to retained nodes.
212
386
  */
213
- class V8EXPORT HeapGraphEdge {
387
+ class V8_EXPORT HeapGraphEdge {
214
388
  public:
215
389
  enum Type {
216
390
  kContextVariable = 0, // A variable from a function context.
@@ -233,7 +407,7 @@ class V8EXPORT HeapGraphEdge {
233
407
  * Returns edge name. This can be a variable name, an element index, or
234
408
  * a property name.
235
409
  */
236
- Handle<Value> GetName() const;
410
+ Local<Value> GetName() const;
237
411
 
238
412
  /** Returns origin node. */
239
413
  const HeapGraphNode* GetFromNode() const;
@@ -246,20 +420,24 @@ class V8EXPORT HeapGraphEdge {
246
420
  /**
247
421
  * HeapGraphNode represents a node in a heap graph.
248
422
  */
249
- class V8EXPORT HeapGraphNode {
423
+ class V8_EXPORT HeapGraphNode {
250
424
  public:
251
425
  enum Type {
252
- kHidden = 0, // Hidden node, may be filtered when shown to user.
253
- kArray = 1, // An array of elements.
254
- kString = 2, // A string.
255
- kObject = 3, // A JS object (except for arrays and strings).
256
- kCode = 4, // Compiled code.
257
- kClosure = 5, // Function closure.
258
- kRegExp = 6, // RegExp.
259
- kHeapNumber = 7, // Number stored in the heap.
260
- kNative = 8, // Native object (not from V8 heap).
261
- kSynthetic = 9 // Synthetic object, usualy used for grouping
262
- // snapshot items together.
426
+ kHidden = 0, // Hidden node, may be filtered when shown to user.
427
+ kArray = 1, // An array of elements.
428
+ kString = 2, // A string.
429
+ kObject = 3, // A JS object (except for arrays and strings).
430
+ kCode = 4, // Compiled code.
431
+ kClosure = 5, // Function closure.
432
+ kRegExp = 6, // RegExp.
433
+ kHeapNumber = 7, // Number stored in the heap.
434
+ kNative = 8, // Native object (not from V8 heap).
435
+ kSynthetic = 9, // Synthetic object, usually used for grouping
436
+ // snapshot items together.
437
+ kConsString = 10, // Concatenated string. A pair of pointers to strings.
438
+ kSlicedString = 11, // Sliced string. A fragment of another string.
439
+ kSymbol = 12, // A Symbol (ES6).
440
+ kBigInt = 13 // BigInt.
263
441
  };
264
442
 
265
443
  /** Returns node type (see HeapGraphNode::Type). */
@@ -270,7 +448,7 @@ class V8EXPORT HeapGraphNode {
270
448
  * of the constructor (for objects), the name of the function (for
271
449
  * closures), string value, or an empty string (for compiled code).
272
450
  */
273
- Handle<String> GetName() const;
451
+ Local<String> GetName() const;
274
452
 
275
453
  /**
276
454
  * Returns node id. For the same heap object, the id remains the same
@@ -279,43 +457,56 @@ class V8EXPORT HeapGraphNode {
279
457
  SnapshotObjectId GetId() const;
280
458
 
281
459
  /** Returns node's own size, in bytes. */
282
- int GetSelfSize() const;
460
+ size_t GetShallowSize() const;
283
461
 
284
462
  /** Returns child nodes count of the node. */
285
463
  int GetChildrenCount() const;
286
464
 
287
465
  /** Retrieves a child by index. */
288
466
  const HeapGraphEdge* GetChild(int index) const;
467
+ };
468
+
289
469
 
470
+ /**
471
+ * An interface for exporting data from V8, using "push" model.
472
+ */
473
+ class V8_EXPORT OutputStream { // NOLINT
474
+ public:
475
+ enum WriteResult {
476
+ kContinue = 0,
477
+ kAbort = 1
478
+ };
479
+ virtual ~OutputStream() = default;
480
+ /** Notify about the end of stream. */
481
+ virtual void EndOfStream() = 0;
482
+ /** Get preferred output chunk size. Called only once. */
483
+ virtual int GetChunkSize() { return 1024; }
290
484
  /**
291
- * Finds and returns a value from the heap corresponding to this node,
292
- * if the value is still reachable.
485
+ * Writes the next chunk of snapshot data into the stream. Writing
486
+ * can be stopped by returning kAbort as function result. EndOfStream
487
+ * will not be called in case writing was aborted.
293
488
  */
294
- Handle<Value> GetHeapValue() const;
489
+ virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
490
+ /**
491
+ * Writes the next chunk of heap stats data into the stream. Writing
492
+ * can be stopped by returning kAbort as function result. EndOfStream
493
+ * will not be called in case writing was aborted.
494
+ */
495
+ virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
496
+ return kAbort;
497
+ }
295
498
  };
296
499
 
297
500
 
298
501
  /**
299
502
  * HeapSnapshots record the state of the JS heap at some moment.
300
503
  */
301
- class V8EXPORT HeapSnapshot {
504
+ class V8_EXPORT HeapSnapshot {
302
505
  public:
303
- enum Type {
304
- kFull = 0 // Heap snapshot with all instances and references.
305
- };
306
506
  enum SerializationFormat {
307
507
  kJSON = 0 // See format description near 'Serialize' method.
308
508
  };
309
509
 
310
- /** Returns heap snapshot type. */
311
- Type GetType() const;
312
-
313
- /** Returns heap snapshot UID (assigned by the profiler.) */
314
- unsigned GetUid() const;
315
-
316
- /** Returns heap snapshot title. */
317
- Handle<String> GetTitle() const;
318
-
319
510
  /** Returns the root node of the heap graph. */
320
511
  const HeapGraphNode* GetRoot() const;
321
512
 
@@ -364,40 +555,267 @@ class V8EXPORT HeapSnapshot {
364
555
  * Nodes reference strings, other nodes, and edges by their indexes
365
556
  * in corresponding arrays.
366
557
  */
367
- void Serialize(OutputStream* stream, SerializationFormat format) const;
558
+ void Serialize(OutputStream* stream,
559
+ SerializationFormat format = kJSON) const;
560
+ };
561
+
562
+
563
+ /**
564
+ * An interface for reporting progress and controlling long-running
565
+ * activities.
566
+ */
567
+ class V8_EXPORT ActivityControl { // NOLINT
568
+ public:
569
+ enum ControlOption {
570
+ kContinue = 0,
571
+ kAbort = 1
572
+ };
573
+ virtual ~ActivityControl() = default;
574
+ /**
575
+ * Notify about current progress. The activity can be stopped by
576
+ * returning kAbort as the callback result.
577
+ */
578
+ virtual ControlOption ReportProgressValue(int done, int total) = 0;
579
+ };
580
+
581
+
582
+ /**
583
+ * AllocationProfile is a sampled profile of allocations done by the program.
584
+ * This is structured as a call-graph.
585
+ */
586
+ class V8_EXPORT AllocationProfile {
587
+ public:
588
+ struct Allocation {
589
+ /**
590
+ * Size of the sampled allocation object.
591
+ */
592
+ size_t size;
593
+
594
+ /**
595
+ * The number of objects of such size that were sampled.
596
+ */
597
+ unsigned int count;
598
+ };
599
+
600
+ /**
601
+ * Represents a node in the call-graph.
602
+ */
603
+ struct Node {
604
+ /**
605
+ * Name of the function. May be empty for anonymous functions or if the
606
+ * script corresponding to this function has been unloaded.
607
+ */
608
+ Local<String> name;
609
+
610
+ /**
611
+ * Name of the script containing the function. May be empty if the script
612
+ * name is not available, or if the script has been unloaded.
613
+ */
614
+ Local<String> script_name;
615
+
616
+ /**
617
+ * id of the script where the function is located. May be equal to
618
+ * v8::UnboundScript::kNoScriptId in cases where the script doesn't exist.
619
+ */
620
+ int script_id;
621
+
622
+ /**
623
+ * Start position of the function in the script.
624
+ */
625
+ int start_position;
626
+
627
+ /**
628
+ * 1-indexed line number where the function starts. May be
629
+ * kNoLineNumberInfo if no line number information is available.
630
+ */
631
+ int line_number;
632
+
633
+ /**
634
+ * 1-indexed column number where the function starts. May be
635
+ * kNoColumnNumberInfo if no line number information is available.
636
+ */
637
+ int column_number;
638
+
639
+ /**
640
+ * Unique id of the node.
641
+ */
642
+ uint32_t node_id;
643
+
644
+ /**
645
+ * List of callees called from this node for which we have sampled
646
+ * allocations. The lifetime of the children is scoped to the containing
647
+ * AllocationProfile.
648
+ */
649
+ std::vector<Node*> children;
650
+
651
+ /**
652
+ * List of self allocations done by this node in the call-graph.
653
+ */
654
+ std::vector<Allocation> allocations;
655
+ };
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
+
683
+ /**
684
+ * Returns the root node of the call-graph. The root node corresponds to an
685
+ * empty JS call-stack. The lifetime of the returned Node* is scoped to the
686
+ * containing AllocationProfile.
687
+ */
688
+ virtual Node* GetRootNode() = 0;
689
+ virtual const std::vector<Sample>& GetSamples() = 0;
690
+
691
+ virtual ~AllocationProfile() = default;
692
+
693
+ static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
694
+ static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
368
695
  };
369
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; }
370
738
 
371
- class RetainedObjectInfo;
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
+ };
372
767
 
373
768
  /**
374
- * Interface for controlling heap profiling.
769
+ * Interface for controlling heap profiling. Instance of the
770
+ * profiler can be retrieved using v8::Isolate::GetHeapProfiler.
375
771
  */
376
- class V8EXPORT HeapProfiler {
772
+ class V8_EXPORT HeapProfiler {
377
773
  public:
774
+ enum SamplingFlags {
775
+ kSamplingNoFlags = 0,
776
+ kSamplingForceGC = 1 << 0,
777
+ };
778
+
378
779
  /**
379
- * Callback function invoked for obtaining RetainedObjectInfo for
380
- * the given JavaScript wrapper object. It is prohibited to enter V8
381
- * while the callback is running: only getters on the handle and
382
- * GetPointerFromInternalField on the objects are allowed.
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.
383
784
  */
384
- typedef RetainedObjectInfo* (*WrapperInfoCallback)
385
- (uint16_t class_id, Handle<Value> wrapper);
785
+ typedef void (*BuildEmbedderGraphCallback)(v8::Isolate* isolate,
786
+ v8::EmbedderGraph* graph,
787
+ void* data);
386
788
 
387
789
  /** Returns the number of snapshots taken. */
388
- static int GetSnapshotsCount();
790
+ int GetSnapshotCount();
389
791
 
390
792
  /** Returns a snapshot by index. */
391
- static const HeapSnapshot* GetSnapshot(int index);
392
-
393
- /** Returns a profile by uid. */
394
- static const HeapSnapshot* FindSnapshot(unsigned uid);
793
+ const HeapSnapshot* GetHeapSnapshot(int index);
395
794
 
396
795
  /**
397
796
  * Returns SnapshotObjectId for a heap object referenced by |value| if
398
797
  * it has been seen by the heap profiler, kUnknownObjectId otherwise.
399
798
  */
400
- static SnapshotObjectId GetSnapshotObjectId(Handle<Value> value);
799
+ SnapshotObjectId GetObjectId(Local<Value> value);
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
+
807
+ /**
808
+ * Returns heap object with given SnapshotObjectId if the object is alive,
809
+ * otherwise empty handle is returned.
810
+ */
811
+ Local<Value> FindObjectById(SnapshotObjectId id);
812
+
813
+ /**
814
+ * Clears internal map from SnapshotObjectId to heap object. The new objects
815
+ * will not be added into it unless a heap snapshot is taken or heap object
816
+ * tracking is kicked off.
817
+ */
818
+ void ClearObjectIds();
401
819
 
402
820
  /**
403
821
  * A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
@@ -410,32 +828,35 @@ class V8EXPORT HeapProfiler {
410
828
  * Callback interface for retrieving user friendly names of global objects.
411
829
  */
412
830
  class ObjectNameResolver {
413
- public:
831
+ public:
414
832
  /**
415
833
  * Returns name to be used in the heap snapshot for given node. Returned
416
834
  * string must stay alive until snapshot collection is completed.
417
835
  */
418
- virtual const char* GetName(Handle<Object> object) = 0;
419
- protected:
420
- virtual ~ObjectNameResolver() {}
836
+ virtual const char* GetName(Local<Object> object) = 0;
837
+
838
+ protected:
839
+ virtual ~ObjectNameResolver() = default;
421
840
  };
422
841
 
423
842
  /**
424
- * Takes a heap snapshot and returns it. Title may be an empty string.
425
- * See HeapSnapshot::Type for types description.
843
+ * Takes a heap snapshot and returns it.
426
844
  */
427
- static const HeapSnapshot* TakeSnapshot(
428
- Handle<String> title,
429
- HeapSnapshot::Type type = HeapSnapshot::kFull,
430
- ActivityControl* control = NULL,
431
- ObjectNameResolver* global_object_name_resolver = NULL);
845
+ const HeapSnapshot* TakeHeapSnapshot(
846
+ ActivityControl* control = nullptr,
847
+ ObjectNameResolver* global_object_name_resolver = nullptr,
848
+ bool treat_global_objects_as_roots = true);
432
849
 
433
850
  /**
434
851
  * Starts tracking of heap objects population statistics. After calling
435
852
  * this method, all heap objects relocations done by the garbage collector
436
853
  * are being registered.
854
+ *
855
+ * |track_allocations| parameter controls whether stack trace of each
856
+ * allocation in the heap will be recorded and reported as part of
857
+ * HeapSnapshot.
437
858
  */
438
- static void StartHeapObjectsTracking();
859
+ void StartTrackingHeapObjects(bool track_allocations = false);
439
860
 
440
861
  /**
441
862
  * Adds a new time interval entry to the aggregated statistics array. The
@@ -444,30 +865,76 @@ class V8EXPORT HeapProfiler {
444
865
  * reports updates for all previous time intervals via the OutputStream
445
866
  * object. Updates on each time interval are provided as a stream of the
446
867
  * HeapStatsUpdate structure instances.
447
- * The return value of the function is the last seen heap object Id.
868
+ * If |timestamp_us| is supplied, timestamp of the new entry will be written
869
+ * into it. The return value of the function is the last seen heap object Id.
448
870
  *
449
- * StartHeapObjectsTracking must be called before the first call to this
871
+ * StartTrackingHeapObjects must be called before the first call to this
450
872
  * method.
451
873
  */
452
- static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
874
+ SnapshotObjectId GetHeapStats(OutputStream* stream,
875
+ int64_t* timestamp_us = nullptr);
453
876
 
454
877
  /**
455
878
  * Stops tracking of heap objects population statistics, cleans up all
456
879
  * collected data. StartHeapObjectsTracking must be called again prior to
457
- * calling PushHeapObjectsStats next time.
880
+ * calling GetHeapStats next time.
458
881
  */
459
- static void StopHeapObjectsTracking();
882
+ void StopTrackingHeapObjects();
883
+
884
+ /**
885
+ * Starts gathering a sampling heap profile. A sampling heap profile is
886
+ * similar to tcmalloc's heap profiler and Go's mprof. It samples object
887
+ * allocations and builds an online 'sampling' heap profile. At any point in
888
+ * time, this profile is expected to be a representative sample of objects
889
+ * currently live in the system. Each sampled allocation includes the stack
890
+ * trace at the time of allocation, which makes this really useful for memory
891
+ * leak detection.
892
+ *
893
+ * This mechanism is intended to be cheap enough that it can be used in
894
+ * production with minimal performance overhead.
895
+ *
896
+ * Allocations are sampled using a randomized Poisson process. On average, one
897
+ * allocation will be sampled every |sample_interval| bytes allocated. The
898
+ * |stack_depth| parameter controls the maximum number of stack frames to be
899
+ * captured on each allocation.
900
+ *
901
+ * NOTE: This is a proof-of-concept at this point. Right now we only sample
902
+ * newspace allocations. Support for paged space allocation (e.g. pre-tenured
903
+ * objects, large objects, code objects, etc.) and native allocations
904
+ * doesn't exist yet, but is anticipated in the future.
905
+ *
906
+ * Objects allocated before the sampling is started will not be included in
907
+ * the profile.
908
+ *
909
+ * Returns false if a sampling heap profiler is already running.
910
+ */
911
+ bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024,
912
+ int stack_depth = 16,
913
+ SamplingFlags flags = kSamplingNoFlags);
914
+
915
+ /**
916
+ * Stops the sampling heap profile and discards the current profile.
917
+ */
918
+ void StopSamplingHeapProfiler();
919
+
920
+ /**
921
+ * Returns the sampled profile of allocations allocated (and still live) since
922
+ * StartSamplingHeapProfiler was called. The ownership of the pointer is
923
+ * transferred to the caller. Returns nullptr if sampling heap profiler is not
924
+ * active.
925
+ */
926
+ AllocationProfile* GetAllocationProfile();
460
927
 
461
928
  /**
462
929
  * Deletes all snapshots taken. All previously returned pointers to
463
930
  * snapshots and their contents become invalid after this call.
464
931
  */
465
- static void DeleteAllSnapshots();
932
+ void DeleteAllHeapSnapshots();
466
933
 
467
- /** Binds a callback to embedder's class ID. */
468
- static void DefineWrapperClass(
469
- uint16_t class_id,
470
- WrapperInfoCallback callback);
934
+ void AddBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback,
935
+ void* data);
936
+ void RemoveBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback,
937
+ void* data);
471
938
 
472
939
  /**
473
940
  * Default value of persistent handle class ID. Must not be used to
@@ -476,105 +943,117 @@ class V8EXPORT HeapProfiler {
476
943
  */
477
944
  static const uint16_t kPersistentHandleNoClassId = 0;
478
945
 
479
- /** Returns the number of currently existing persistent handles. */
480
- static int GetPersistentHandleCount();
946
+ private:
947
+ HeapProfiler();
948
+ ~HeapProfiler();
949
+ HeapProfiler(const HeapProfiler&);
950
+ HeapProfiler& operator=(const HeapProfiler&);
951
+ };
481
952
 
482
- /** Returns memory used for profiler internal data and snapshots. */
483
- static size_t GetMemorySizeUsedByProfiler();
953
+ /**
954
+ * A struct for exporting HeapStats data from V8, using "push" model.
955
+ * See HeapProfiler::GetHeapStats.
956
+ */
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.
484
963
  };
485
964
 
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)
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
+ };
486
989
 
487
990
  /**
488
- * Interface for providing information about embedder's objects
489
- * held by global handles. This information is reported in two ways:
490
- *
491
- * 1. When calling AddObjectGroup, an embedder may pass
492
- * RetainedObjectInfo instance describing the group. To collect
493
- * this information while taking a heap snapshot, V8 calls GC
494
- * prologue and epilogue callbacks.
495
- *
496
- * 2. When a heap snapshot is collected, V8 additionally
497
- * requests RetainedObjectInfos for persistent handles that
498
- * were not previously reported via AddObjectGroup.
499
- *
500
- * Thus, if an embedder wants to provide information about native
501
- * objects for heap snapshots, he can do it in a GC prologue
502
- * handler, and / or by assigning wrapper class ids in the following way:
503
- *
504
- * 1. Bind a callback to class id by calling DefineWrapperClass.
505
- * 2. Call SetWrapperClassId on certain persistent handles.
506
- *
507
- * V8 takes ownership of RetainedObjectInfo instances passed to it and
508
- * keeps them alive only during snapshot collection. Afterwards, they
509
- * are freed by calling the Dispose class function.
991
+ * Representation of a code creation event
510
992
  */
511
- class V8EXPORT RetainedObjectInfo { // NOLINT
993
+ class V8_EXPORT CodeEvent {
512
994
  public:
513
- /** Called by V8 when it no longer needs an instance. */
514
- virtual void Dispose() = 0;
995
+ uintptr_t GetCodeStartAddress();
996
+ size_t GetCodeSize();
997
+ Local<String> GetFunctionName();
998
+ Local<String> GetScriptName();
999
+ int GetScriptLine();
1000
+ int GetScriptColumn();
1001
+ /**
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*.
1005
+ */
1006
+ CodeEventType GetCodeType();
1007
+ const char* GetComment();
515
1008
 
516
- /** Returns whether two instances are equivalent. */
517
- virtual bool IsEquivalent(RetainedObjectInfo* other) = 0;
1009
+ static const char* GetCodeEventTypeName(CodeEventType code_event_type);
1010
+
1011
+ uintptr_t GetPreviousCodeStartAddress();
1012
+ };
518
1013
 
1014
+ /**
1015
+ * Interface to listen to code creation and code relocation events.
1016
+ */
1017
+ class V8_EXPORT CodeEventHandler {
1018
+ public:
519
1019
  /**
520
- * Returns hash value for the instance. Equivalent instances
521
- * must have the same hash value.
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.
522
1023
  */
523
- virtual intptr_t GetHash() = 0;
1024
+ explicit CodeEventHandler(Isolate* isolate);
1025
+ virtual ~CodeEventHandler();
524
1026
 
525
1027
  /**
526
- * Returns human-readable label. It must be a null-terminated UTF-8
527
- * encoded string. V8 copies its contents during a call to GetLabel.
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()`.
528
1034
  */
529
- virtual const char* GetLabel() = 0;
1035
+ virtual void Handle(CodeEvent* code_event) = 0;
530
1036
 
531
1037
  /**
532
- * Returns human-readable group label. It must be a null-terminated UTF-8
533
- * encoded string. V8 copies its contents during a call to GetGroupLabel.
534
- * Heap snapshot generator will collect all the group names, create
535
- * top level entries with these names and attach the objects to the
536
- * corresponding top level group objects. There is a default
537
- * implementation which is required because embedders don't have their
538
- * own implementation yet.
1038
+ * Call `Enable()` to starts listening to code creation and code relocation
1039
+ * events. These events will be handled by `Handle()`.
539
1040
  */
540
- virtual const char* GetGroupLabel() { return GetLabel(); }
1041
+ void Enable();
541
1042
 
542
1043
  /**
543
- * Returns element count in case if a global handle retains
544
- * a subgraph by holding one of its nodes.
1044
+ * Call `Disable()` to stop listening to code creation and code relocation
1045
+ * events.
545
1046
  */
546
- virtual intptr_t GetElementCount() { return -1; }
547
-
548
- /** Returns embedder's object size in bytes. */
549
- virtual intptr_t GetSizeInBytes() { return -1; }
550
-
551
- protected:
552
- RetainedObjectInfo() {}
553
- virtual ~RetainedObjectInfo() {}
1047
+ void Disable();
554
1048
 
555
1049
  private:
556
- RetainedObjectInfo(const RetainedObjectInfo&);
557
- RetainedObjectInfo& operator=(const RetainedObjectInfo&);
1050
+ CodeEventHandler();
1051
+ CodeEventHandler(const CodeEventHandler&);
1052
+ CodeEventHandler& operator=(const CodeEventHandler&);
1053
+ void* internal_listener_;
558
1054
  };
559
1055
 
560
-
561
- /**
562
- * A struct for exporting HeapStats data from V8, using "push" model.
563
- * See HeapProfiler::PushHeapObjectsStats.
564
- */
565
- struct HeapStatsUpdate {
566
- HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
567
- : index(index), count(count), size(size) { }
568
- uint32_t index; // Index of the time interval that was changed.
569
- uint32_t count; // New value of count field for the interval with this index.
570
- uint32_t size; // New value of size field for the interval with this index.
571
- };
572
-
573
-
574
1056
  } // namespace v8
575
1057
 
576
1058
 
577
- #undef V8EXPORT
578
-
579
-
580
1059
  #endif // V8_V8_PROFILER_H_