libv8 3.16.14.19.1-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,118 @@
1
+ // Copyright 2011 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 PREPARSER_H
29
+ #define PREPARSER_H
30
+
31
+ #include "v8stdint.h"
32
+
33
+ #ifdef _WIN32
34
+
35
+ // Setup for Windows DLL export/import. When building the V8 DLL the
36
+ // BUILDING_V8_SHARED needs to be defined. When building a program which uses
37
+ // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
38
+ // static library or building a program which uses the V8 static library neither
39
+ // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
40
+ #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
41
+ #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
42
+ build configuration to ensure that at most one of these is set
43
+ #endif
44
+
45
+ #ifdef BUILDING_V8_SHARED
46
+ #define V8EXPORT __declspec(dllexport)
47
+ #elif USING_V8_SHARED
48
+ #define V8EXPORT __declspec(dllimport)
49
+ #else
50
+ #define V8EXPORT
51
+ #endif // BUILDING_V8_SHARED
52
+
53
+ #else // _WIN32
54
+
55
+ // Setup for Linux shared library export. There is no need to distinguish
56
+ // between building or using the V8 shared library, but we should not
57
+ // export symbols when we are building a static library.
58
+ #if defined(__GNUC__) && ((__GNUC__ >= 4) || \
59
+ (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED)
60
+ #define V8EXPORT __attribute__ ((visibility("default")))
61
+ #else
62
+ #define V8EXPORT
63
+ #endif
64
+
65
+ #endif // _WIN32
66
+
67
+
68
+ namespace v8 {
69
+
70
+ // The result of preparsing is either a stack overflow error, or an opaque
71
+ // blob of data that can be passed back into the parser.
72
+ class V8EXPORT PreParserData {
73
+ public:
74
+ PreParserData(size_t size, const uint8_t* data)
75
+ : data_(data), size_(size) { }
76
+
77
+ // Create a PreParserData value where stack_overflow reports true.
78
+ static PreParserData StackOverflow() { return PreParserData(0, NULL); }
79
+
80
+ // Whether the pre-parser stopped due to a stack overflow.
81
+ // If this is the case, size() and data() should not be used.
82
+ bool stack_overflow() { return size_ == 0u; }
83
+
84
+ // The size of the data in bytes.
85
+ size_t size() const { return size_; }
86
+
87
+ // Pointer to the data.
88
+ const uint8_t* data() const { return data_; }
89
+
90
+ private:
91
+ const uint8_t* const data_;
92
+ const size_t size_;
93
+ };
94
+
95
+
96
+ // Interface for a stream of Unicode characters.
97
+ class V8EXPORT UnicodeInputStream { // NOLINT - Thinks V8EXPORT is class name.
98
+ public:
99
+ virtual ~UnicodeInputStream();
100
+
101
+ // Returns the next Unicode code-point in the input, or a negative value when
102
+ // there is no more input in the stream.
103
+ virtual int32_t Next() = 0;
104
+ };
105
+
106
+
107
+ // Preparse a JavaScript program. The source code is provided as a
108
+ // UnicodeInputStream. The max_stack_size limits the amount of stack
109
+ // space that the preparser is allowed to use. If the preparser uses
110
+ // more stack space than the limit provided, the result's stack_overflow()
111
+ // method will return true. Otherwise the result contains preparser
112
+ // data that can be used by the V8 parser to speed up parsing.
113
+ PreParserData V8EXPORT Preparse(UnicodeInputStream* input,
114
+ size_t max_stack_size);
115
+
116
+ } // namespace v8.
117
+
118
+ #endif // PREPARSER_H
@@ -0,0 +1,580 @@
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.
27
+
28
+ #ifndef V8_V8_PROFILER_H_
29
+ #define V8_V8_PROFILER_H_
30
+
31
+ #include "v8.h"
32
+
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
40
+
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
48
+
49
+ #else // _WIN32
50
+
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
59
+
60
+ #endif // _WIN32
61
+
62
+
63
+ /**
64
+ * Profiler support for the V8 JavaScript engine.
65
+ */
66
+ namespace v8 {
67
+
68
+ typedef uint32_t SnapshotObjectId;
69
+
70
+ /**
71
+ * CpuProfileNode represents a node in a call graph.
72
+ */
73
+ class V8EXPORT CpuProfileNode {
74
+ public:
75
+ /** Returns function name (empty string for anonymous functions.) */
76
+ Handle<String> GetFunctionName() const;
77
+
78
+ /** Returns resource name for script from where the function originates. */
79
+ Handle<String> GetScriptResourceName() const;
80
+
81
+ /**
82
+ * Returns the number, 1-based, of the line where the function originates.
83
+ * kNoLineNumberInfo if no line number information is available.
84
+ */
85
+ int GetLineNumber() const;
86
+
87
+ /**
88
+ * Returns total (self + children) execution time of the function,
89
+ * in milliseconds, estimated by samples count.
90
+ */
91
+ double GetTotalTime() const;
92
+
93
+ /**
94
+ * Returns self execution time of the function, in milliseconds,
95
+ * estimated by samples count.
96
+ */
97
+ double GetSelfTime() const;
98
+
99
+ /** Returns the count of samples where function exists. */
100
+ double GetTotalSamplesCount() const;
101
+
102
+ /** Returns the count of samples where function was currently executing. */
103
+ double GetSelfSamplesCount() const;
104
+
105
+ /** Returns function entry UID. */
106
+ unsigned GetCallUid() const;
107
+
108
+ /** Returns child nodes count of the node. */
109
+ int GetChildrenCount() const;
110
+
111
+ /** Retrieves a child node by index. */
112
+ const CpuProfileNode* GetChild(int index) const;
113
+
114
+ static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
115
+ };
116
+
117
+
118
+ /**
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).
122
+ */
123
+ class V8EXPORT CpuProfile {
124
+ public:
125
+ /** Returns CPU profile UID (assigned by the profiler.) */
126
+ unsigned GetUid() const;
127
+
128
+ /** 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;
133
+
134
+ /** Returns the root node of the top down call tree. */
135
+ const CpuProfileNode* GetTopDownRoot() const;
136
+
137
+ /**
138
+ * Deletes the profile and removes it from CpuProfiler's list.
139
+ * 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
+ */
145
+ void Delete();
146
+ };
147
+
148
+
149
+ /**
150
+ * Interface for controlling CPU profiling.
151
+ */
152
+ class V8EXPORT CpuProfiler {
153
+ public:
154
+ /**
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.
161
+ */
162
+
163
+ /**
164
+ * Returns the number of profiles collected (doesn't include
165
+ * profiles that are being collected at the moment of call.)
166
+ */
167
+ static int GetProfilesCount();
168
+
169
+ /** Returns a profile by index. */
170
+ static const CpuProfile* GetProfile(
171
+ int index,
172
+ Handle<Value> security_token = Handle<Value>());
173
+
174
+ /** Returns a profile by uid. */
175
+ static const CpuProfile* FindProfile(
176
+ unsigned uid,
177
+ Handle<Value> security_token = Handle<Value>());
178
+
179
+ /**
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.
186
+ */
187
+ static void StartProfiling(Handle<String> title);
188
+
189
+ /**
190
+ * Stops collecting CPU profile with a given title and returns it.
191
+ * If the title given is empty, finishes the last profile started.
192
+ */
193
+ static const CpuProfile* StopProfiling(
194
+ Handle<String> title,
195
+ Handle<Value> security_token = Handle<Value>());
196
+
197
+ /**
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.
201
+ */
202
+ static void DeleteAllProfiles();
203
+ };
204
+
205
+
206
+ class HeapGraphNode;
207
+
208
+
209
+ /**
210
+ * HeapSnapshotEdge represents a directed connection between heap
211
+ * graph nodes: from retainers to retained nodes.
212
+ */
213
+ class V8EXPORT HeapGraphEdge {
214
+ public:
215
+ enum Type {
216
+ kContextVariable = 0, // A variable from a function context.
217
+ kElement = 1, // An element of an array.
218
+ kProperty = 2, // A named object property.
219
+ kInternal = 3, // A link that can't be accessed from JS,
220
+ // thus, its name isn't a real property name
221
+ // (e.g. parts of a ConsString).
222
+ kHidden = 4, // A link that is needed for proper sizes
223
+ // calculation, but may be hidden from user.
224
+ kShortcut = 5, // A link that must not be followed during
225
+ // sizes calculation.
226
+ kWeak = 6 // A weak reference (ignored by the GC).
227
+ };
228
+
229
+ /** Returns edge type (see HeapGraphEdge::Type). */
230
+ Type GetType() const;
231
+
232
+ /**
233
+ * Returns edge name. This can be a variable name, an element index, or
234
+ * a property name.
235
+ */
236
+ Handle<Value> GetName() const;
237
+
238
+ /** Returns origin node. */
239
+ const HeapGraphNode* GetFromNode() const;
240
+
241
+ /** Returns destination node. */
242
+ const HeapGraphNode* GetToNode() const;
243
+ };
244
+
245
+
246
+ /**
247
+ * HeapGraphNode represents a node in a heap graph.
248
+ */
249
+ class V8EXPORT HeapGraphNode {
250
+ public:
251
+ 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.
263
+ };
264
+
265
+ /** Returns node type (see HeapGraphNode::Type). */
266
+ Type GetType() const;
267
+
268
+ /**
269
+ * Returns node name. Depending on node's type this can be the name
270
+ * of the constructor (for objects), the name of the function (for
271
+ * closures), string value, or an empty string (for compiled code).
272
+ */
273
+ Handle<String> GetName() const;
274
+
275
+ /**
276
+ * Returns node id. For the same heap object, the id remains the same
277
+ * across all snapshots.
278
+ */
279
+ SnapshotObjectId GetId() const;
280
+
281
+ /** Returns node's own size, in bytes. */
282
+ int GetSelfSize() const;
283
+
284
+ /** Returns child nodes count of the node. */
285
+ int GetChildrenCount() const;
286
+
287
+ /** Retrieves a child by index. */
288
+ const HeapGraphEdge* GetChild(int index) const;
289
+
290
+ /**
291
+ * Finds and returns a value from the heap corresponding to this node,
292
+ * if the value is still reachable.
293
+ */
294
+ Handle<Value> GetHeapValue() const;
295
+ };
296
+
297
+
298
+ /**
299
+ * HeapSnapshots record the state of the JS heap at some moment.
300
+ */
301
+ class V8EXPORT HeapSnapshot {
302
+ public:
303
+ enum Type {
304
+ kFull = 0 // Heap snapshot with all instances and references.
305
+ };
306
+ enum SerializationFormat {
307
+ kJSON = 0 // See format description near 'Serialize' method.
308
+ };
309
+
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
+ /** Returns the root node of the heap graph. */
320
+ const HeapGraphNode* GetRoot() const;
321
+
322
+ /** Returns a node by its id. */
323
+ const HeapGraphNode* GetNodeById(SnapshotObjectId id) const;
324
+
325
+ /** Returns total nodes count in the snapshot. */
326
+ int GetNodesCount() const;
327
+
328
+ /** Returns a node by index. */
329
+ const HeapGraphNode* GetNode(int index) const;
330
+
331
+ /** Returns a max seen JS object Id. */
332
+ SnapshotObjectId GetMaxSnapshotJSObjectId() const;
333
+
334
+ /**
335
+ * Deletes the snapshot and removes it from HeapProfiler's list.
336
+ * All pointers to nodes, edges and paths previously returned become
337
+ * invalid.
338
+ */
339
+ void Delete();
340
+
341
+ /**
342
+ * Prepare a serialized representation of the snapshot. The result
343
+ * is written into the stream provided in chunks of specified size.
344
+ * The total length of the serialized snapshot is unknown in
345
+ * advance, it can be roughly equal to JS heap size (that means,
346
+ * it can be really big - tens of megabytes).
347
+ *
348
+ * For the JSON format, heap contents are represented as an object
349
+ * with the following structure:
350
+ *
351
+ * {
352
+ * snapshot: {
353
+ * title: "...",
354
+ * uid: nnn,
355
+ * meta: { meta-info },
356
+ * node_count: nnn,
357
+ * edge_count: nnn
358
+ * },
359
+ * nodes: [nodes array],
360
+ * edges: [edges array],
361
+ * strings: [strings array]
362
+ * }
363
+ *
364
+ * Nodes reference strings, other nodes, and edges by their indexes
365
+ * in corresponding arrays.
366
+ */
367
+ void Serialize(OutputStream* stream, SerializationFormat format) const;
368
+ };
369
+
370
+
371
+ class RetainedObjectInfo;
372
+
373
+ /**
374
+ * Interface for controlling heap profiling.
375
+ */
376
+ class V8EXPORT HeapProfiler {
377
+ public:
378
+ /**
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.
383
+ */
384
+ typedef RetainedObjectInfo* (*WrapperInfoCallback)
385
+ (uint16_t class_id, Handle<Value> wrapper);
386
+
387
+ /** Returns the number of snapshots taken. */
388
+ static int GetSnapshotsCount();
389
+
390
+ /** 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);
395
+
396
+ /**
397
+ * Returns SnapshotObjectId for a heap object referenced by |value| if
398
+ * it has been seen by the heap profiler, kUnknownObjectId otherwise.
399
+ */
400
+ static SnapshotObjectId GetSnapshotObjectId(Handle<Value> value);
401
+
402
+ /**
403
+ * A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
404
+ * it in case heap profiler cannot find id for the object passed as
405
+ * parameter. HeapSnapshot::GetNodeById will always return NULL for such id.
406
+ */
407
+ static const SnapshotObjectId kUnknownObjectId = 0;
408
+
409
+ /**
410
+ * Callback interface for retrieving user friendly names of global objects.
411
+ */
412
+ class ObjectNameResolver {
413
+ public:
414
+ /**
415
+ * Returns name to be used in the heap snapshot for given node. Returned
416
+ * string must stay alive until snapshot collection is completed.
417
+ */
418
+ virtual const char* GetName(Handle<Object> object) = 0;
419
+ protected:
420
+ virtual ~ObjectNameResolver() {}
421
+ };
422
+
423
+ /**
424
+ * Takes a heap snapshot and returns it. Title may be an empty string.
425
+ * See HeapSnapshot::Type for types description.
426
+ */
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);
432
+
433
+ /**
434
+ * Starts tracking of heap objects population statistics. After calling
435
+ * this method, all heap objects relocations done by the garbage collector
436
+ * are being registered.
437
+ */
438
+ static void StartHeapObjectsTracking();
439
+
440
+ /**
441
+ * Adds a new time interval entry to the aggregated statistics array. The
442
+ * time interval entry contains information on the current heap objects
443
+ * population size. The method also updates aggregated statistics and
444
+ * reports updates for all previous time intervals via the OutputStream
445
+ * object. Updates on each time interval are provided as a stream of the
446
+ * HeapStatsUpdate structure instances.
447
+ * The return value of the function is the last seen heap object Id.
448
+ *
449
+ * StartHeapObjectsTracking must be called before the first call to this
450
+ * method.
451
+ */
452
+ static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
453
+
454
+ /**
455
+ * Stops tracking of heap objects population statistics, cleans up all
456
+ * collected data. StartHeapObjectsTracking must be called again prior to
457
+ * calling PushHeapObjectsStats next time.
458
+ */
459
+ static void StopHeapObjectsTracking();
460
+
461
+ /**
462
+ * Deletes all snapshots taken. All previously returned pointers to
463
+ * snapshots and their contents become invalid after this call.
464
+ */
465
+ static void DeleteAllSnapshots();
466
+
467
+ /** Binds a callback to embedder's class ID. */
468
+ static void DefineWrapperClass(
469
+ uint16_t class_id,
470
+ WrapperInfoCallback callback);
471
+
472
+ /**
473
+ * Default value of persistent handle class ID. Must not be used to
474
+ * define a class. Can be used to reset a class of a persistent
475
+ * handle.
476
+ */
477
+ static const uint16_t kPersistentHandleNoClassId = 0;
478
+
479
+ /** Returns the number of currently existing persistent handles. */
480
+ static int GetPersistentHandleCount();
481
+
482
+ /** Returns memory used for profiler internal data and snapshots. */
483
+ static size_t GetMemorySizeUsedByProfiler();
484
+ };
485
+
486
+
487
+ /**
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.
510
+ */
511
+ class V8EXPORT RetainedObjectInfo { // NOLINT
512
+ public:
513
+ /** Called by V8 when it no longer needs an instance. */
514
+ virtual void Dispose() = 0;
515
+
516
+ /** Returns whether two instances are equivalent. */
517
+ virtual bool IsEquivalent(RetainedObjectInfo* other) = 0;
518
+
519
+ /**
520
+ * Returns hash value for the instance. Equivalent instances
521
+ * must have the same hash value.
522
+ */
523
+ virtual intptr_t GetHash() = 0;
524
+
525
+ /**
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.
528
+ */
529
+ virtual const char* GetLabel() = 0;
530
+
531
+ /**
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.
539
+ */
540
+ virtual const char* GetGroupLabel() { return GetLabel(); }
541
+
542
+ /**
543
+ * Returns element count in case if a global handle retains
544
+ * a subgraph by holding one of its nodes.
545
+ */
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() {}
554
+
555
+ private:
556
+ RetainedObjectInfo(const RetainedObjectInfo&);
557
+ RetainedObjectInfo& operator=(const RetainedObjectInfo&);
558
+ };
559
+
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
+ } // namespace v8
575
+
576
+
577
+ #undef V8EXPORT
578
+
579
+
580
+ #endif // V8_V8_PROFILER_H_