libv8 3.16.14.19-x86-linux → 4.5.95.5-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ // Copyright 2013 the V8 project authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef V8_V8_PLATFORM_H_
6
+ #define V8_V8_PLATFORM_H_
7
+
8
+ namespace v8 {
9
+
10
+ class Isolate;
11
+
12
+ /**
13
+ * A Task represents a unit of work.
14
+ */
15
+ class Task {
16
+ public:
17
+ virtual ~Task() {}
18
+
19
+ virtual void Run() = 0;
20
+ };
21
+
22
+ /**
23
+ * V8 Platform abstraction layer.
24
+ *
25
+ * The embedder has to provide an implementation of this interface before
26
+ * initializing the rest of V8.
27
+ */
28
+ class Platform {
29
+ public:
30
+ /**
31
+ * This enum is used to indicate whether a task is potentially long running,
32
+ * or causes a long wait. The embedder might want to use this hint to decide
33
+ * whether to execute the task on a dedicated thread.
34
+ */
35
+ enum ExpectedRuntime {
36
+ kShortRunningTask,
37
+ kLongRunningTask
38
+ };
39
+
40
+ virtual ~Platform() {}
41
+
42
+ /**
43
+ * Schedules a task to be invoked on a background thread. |expected_runtime|
44
+ * indicates that the task will run a long time. The Platform implementation
45
+ * takes ownership of |task|. There is no guarantee about order of execution
46
+ * of tasks wrt order of scheduling, nor is there a guarantee about the
47
+ * thread the task will be run on.
48
+ */
49
+ virtual void CallOnBackgroundThread(Task* task,
50
+ ExpectedRuntime expected_runtime) = 0;
51
+
52
+ /**
53
+ * Schedules a task to be invoked on a foreground thread wrt a specific
54
+ * |isolate|. Tasks posted for the same isolate should be execute in order of
55
+ * scheduling. The definition of "foreground" is opaque to V8.
56
+ */
57
+ virtual void CallOnForegroundThread(Isolate* isolate, Task* task) = 0;
58
+
59
+ /**
60
+ * Schedules a task to be invoked on a foreground thread wrt a specific
61
+ * |isolate| after the given number of seconds |delay_in_seconds|.
62
+ * Tasks posted for the same isolate should be execute in order of
63
+ * scheduling. The definition of "foreground" is opaque to V8.
64
+ */
65
+ virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
66
+ double delay_in_seconds) {
67
+ // TODO(ulan): Make this function abstract after V8 roll in Chromium.
68
+ }
69
+
70
+ /**
71
+ * Monotonically increasing time in seconds from an arbitrary fixed point in
72
+ * the past. This function is expected to return at least
73
+ * millisecond-precision values. For this reason,
74
+ * it is recommended that the fixed point be no further in the past than
75
+ * the epoch.
76
+ **/
77
+ virtual double MonotonicallyIncreasingTime() = 0;
78
+ };
79
+
80
+ } // namespace v8
81
+
82
+ #endif // V8_V8_PLATFORM_H_
@@ -1,80 +1,70 @@
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
 
8
+ #include <vector>
31
9
  #include "v8.h"
32
10
 
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
11
+ /**
12
+ * Profiler support for the V8 JavaScript engine.
13
+ */
14
+ namespace v8 {
40
15
 
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
16
+ class HeapGraphNode;
17
+ struct HeapStatsUpdate;
48
18
 
49
- #else // _WIN32
19
+ typedef uint32_t SnapshotObjectId;
50
20
 
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
21
 
60
- #endif // _WIN32
22
+ struct CpuProfileDeoptFrame {
23
+ int script_id;
24
+ size_t position;
25
+ };
61
26
 
27
+ } // namespace v8
28
+
29
+ #ifdef V8_OS_WIN
30
+ template class V8_EXPORT std::vector<v8::CpuProfileDeoptFrame>;
31
+ #endif
62
32
 
63
- /**
64
- * Profiler support for the V8 JavaScript engine.
65
- */
66
33
  namespace v8 {
67
34
 
68
- typedef uint32_t SnapshotObjectId;
35
+ struct V8_EXPORT CpuProfileDeoptInfo {
36
+ /** A pointer to a static string owned by v8. */
37
+ const char* deopt_reason;
38
+ std::vector<CpuProfileDeoptFrame> stack;
39
+ };
40
+
41
+ } // namespace v8
42
+
43
+ #ifdef V8_OS_WIN
44
+ template class V8_EXPORT std::vector<v8::CpuProfileDeoptInfo>;
45
+ #endif
46
+
47
+ namespace v8 {
69
48
 
70
49
  /**
71
50
  * CpuProfileNode represents a node in a call graph.
72
51
  */
73
- class V8EXPORT CpuProfileNode {
52
+ class V8_EXPORT CpuProfileNode {
74
53
  public:
54
+ struct LineTick {
55
+ /** The 1-based number of the source line where the function originates. */
56
+ int line;
57
+
58
+ /** The count of samples associated with the source line. */
59
+ unsigned int hit_count;
60
+ };
61
+
75
62
  /** Returns function name (empty string for anonymous functions.) */
76
63
  Handle<String> GetFunctionName() const;
77
64
 
65
+ /** Returns id of the script where function is located. */
66
+ int GetScriptId() const;
67
+
78
68
  /** Returns resource name for script from where the function originates. */
79
69
  Handle<String> GetScriptResourceName() const;
80
70
 
@@ -85,96 +75,117 @@ class V8EXPORT CpuProfileNode {
85
75
  int GetLineNumber() const;
86
76
 
87
77
  /**
88
- * Returns total (self + children) execution time of the function,
89
- * in milliseconds, estimated by samples count.
78
+ * Returns 1-based number of the column where the function originates.
79
+ * kNoColumnNumberInfo if no column number information is available.
90
80
  */
91
- double GetTotalTime() const;
81
+ int GetColumnNumber() const;
92
82
 
93
83
  /**
94
- * Returns self execution time of the function, in milliseconds,
95
- * estimated by samples count.
84
+ * Returns the number of the function's source lines that collect the samples.
96
85
  */
97
- double GetSelfTime() const;
86
+ unsigned int GetHitLineCount() const;
98
87
 
99
- /** Returns the count of samples where function exists. */
100
- double GetTotalSamplesCount() const;
88
+ /** Returns the set of source lines that collect the samples.
89
+ * The caller allocates buffer and responsible for releasing it.
90
+ * True if all available entries are copied, otherwise false.
91
+ * The function copies nothing if buffer is not large enough.
92
+ */
93
+ bool GetLineTicks(LineTick* entries, unsigned int length) const;
101
94
 
102
- /** Returns the count of samples where function was currently executing. */
103
- double GetSelfSamplesCount() const;
95
+ /** Returns bailout reason for the function
96
+ * if the optimization was disabled for it.
97
+ */
98
+ const char* GetBailoutReason() const;
99
+
100
+ /**
101
+ * Returns the count of samples where the function was currently executing.
102
+ */
103
+ unsigned GetHitCount() const;
104
104
 
105
105
  /** Returns function entry UID. */
106
106
  unsigned GetCallUid() const;
107
107
 
108
+ /** Returns id of the node. The id is unique within the tree */
109
+ unsigned GetNodeId() const;
110
+
108
111
  /** Returns child nodes count of the node. */
109
112
  int GetChildrenCount() const;
110
113
 
111
114
  /** Retrieves a child node by index. */
112
115
  const CpuProfileNode* GetChild(int index) const;
113
116
 
117
+ /** Retrieves deopt infos for the node. */
118
+ const std::vector<CpuProfileDeoptInfo>& GetDeoptInfos() const;
119
+
114
120
  static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
121
+ static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
115
122
  };
116
123
 
117
124
 
118
125
  /**
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).
126
+ * CpuProfile contains a CPU profile in a form of top-down call tree
127
+ * (from main() down to functions that do all the work).
122
128
  */
123
- class V8EXPORT CpuProfile {
129
+ class V8_EXPORT CpuProfile {
124
130
  public:
125
- /** Returns CPU profile UID (assigned by the profiler.) */
126
- unsigned GetUid() const;
127
-
128
131
  /** Returns CPU profile title. */
129
132
  Handle<String> GetTitle() const;
130
133
 
131
- /** Returns the root node of the bottom up call tree. */
132
- const CpuProfileNode* GetBottomUpRoot() const;
133
-
134
134
  /** Returns the root node of the top down call tree. */
135
135
  const CpuProfileNode* GetTopDownRoot() const;
136
136
 
137
+ /**
138
+ * Returns number of samples recorded. The samples are not recorded unless
139
+ * |record_samples| parameter of CpuProfiler::StartCpuProfiling is true.
140
+ */
141
+ int GetSamplesCount() const;
142
+
143
+ /**
144
+ * Returns profile node corresponding to the top frame the sample at
145
+ * the given index.
146
+ */
147
+ const CpuProfileNode* GetSample(int index) const;
148
+
149
+ /**
150
+ * Returns the timestamp of the sample. The timestamp is the number of
151
+ * microseconds since some unspecified starting point.
152
+ * The point is equal to the starting point used by GetStartTime.
153
+ */
154
+ int64_t GetSampleTimestamp(int index) const;
155
+
156
+ /**
157
+ * Returns time when the profile recording was started (in microseconds)
158
+ * since some unspecified starting point.
159
+ */
160
+ int64_t GetStartTime() const;
161
+
162
+ /**
163
+ * Returns time when the profile recording was stopped (in microseconds)
164
+ * since some unspecified starting point.
165
+ * The point is equal to the starting point used by GetStartTime.
166
+ */
167
+ int64_t GetEndTime() const;
168
+
137
169
  /**
138
170
  * Deletes the profile and removes it from CpuProfiler's list.
139
171
  * 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
172
  */
145
173
  void Delete();
146
174
  };
147
175
 
148
176
 
149
177
  /**
150
- * Interface for controlling CPU profiling.
178
+ * Interface for controlling CPU profiling. Instance of the
179
+ * profiler can be retrieved using v8::Isolate::GetCpuProfiler.
151
180
  */
152
- class V8EXPORT CpuProfiler {
181
+ class V8_EXPORT CpuProfiler {
153
182
  public:
154
183
  /**
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.
184
+ * Changes default CPU profiler sampling interval to the specified number
185
+ * of microseconds. Default interval is 1000us. This method must be called
186
+ * when there are no profiles being recorded.
161
187
  */
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>());
188
+ void SetSamplingInterval(int us);
178
189
 
179
190
  /**
180
191
  * Starts collecting CPU profile. Title may be an empty string. It
@@ -183,34 +194,36 @@ class V8EXPORT CpuProfiler {
183
194
  * title are silently ignored. While collecting a profile, functions
184
195
  * from all security contexts are included in it. The token-based
185
196
  * filtering is only performed when querying for a profile.
197
+ *
198
+ * |record_samples| parameter controls whether individual samples should
199
+ * be recorded in addition to the aggregated tree.
186
200
  */
187
- static void StartProfiling(Handle<String> title);
201
+ void StartProfiling(Handle<String> title, bool record_samples = false);
188
202
 
189
203
  /**
190
204
  * Stops collecting CPU profile with a given title and returns it.
191
205
  * If the title given is empty, finishes the last profile started.
192
206
  */
193
- static const CpuProfile* StopProfiling(
194
- Handle<String> title,
195
- Handle<Value> security_token = Handle<Value>());
207
+ CpuProfile* StopProfiling(Handle<String> title);
196
208
 
197
209
  /**
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.
210
+ * Tells the profiler whether the embedder is idle.
201
211
  */
202
- static void DeleteAllProfiles();
203
- };
212
+ void SetIdle(bool is_idle);
204
213
 
205
-
206
- class HeapGraphNode;
214
+ private:
215
+ CpuProfiler();
216
+ ~CpuProfiler();
217
+ CpuProfiler(const CpuProfiler&);
218
+ CpuProfiler& operator=(const CpuProfiler&);
219
+ };
207
220
 
208
221
 
209
222
  /**
210
223
  * HeapSnapshotEdge represents a directed connection between heap
211
224
  * graph nodes: from retainers to retained nodes.
212
225
  */
213
- class V8EXPORT HeapGraphEdge {
226
+ class V8_EXPORT HeapGraphEdge {
214
227
  public:
215
228
  enum Type {
216
229
  kContextVariable = 0, // A variable from a function context.
@@ -246,20 +259,24 @@ class V8EXPORT HeapGraphEdge {
246
259
  /**
247
260
  * HeapGraphNode represents a node in a heap graph.
248
261
  */
249
- class V8EXPORT HeapGraphNode {
262
+ class V8_EXPORT HeapGraphNode {
250
263
  public:
251
264
  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.
265
+ kHidden = 0, // Hidden node, may be filtered when shown to user.
266
+ kArray = 1, // An array of elements.
267
+ kString = 2, // A string.
268
+ kObject = 3, // A JS object (except for arrays and strings).
269
+ kCode = 4, // Compiled code.
270
+ kClosure = 5, // Function closure.
271
+ kRegExp = 6, // RegExp.
272
+ kHeapNumber = 7, // Number stored in the heap.
273
+ kNative = 8, // Native object (not from V8 heap).
274
+ kSynthetic = 9, // Synthetic object, usualy used for grouping
275
+ // snapshot items together.
276
+ kConsString = 10, // Concatenated string. A pair of pointers to strings.
277
+ kSlicedString = 11, // Sliced string. A fragment of another string.
278
+ kSymbol = 12, // A Symbol (ES6).
279
+ kSimdValue = 13 // A SIMD value stored in the heap (Proposed ES7).
263
280
  };
264
281
 
265
282
  /** Returns node type (see HeapGraphNode::Type). */
@@ -279,43 +296,56 @@ class V8EXPORT HeapGraphNode {
279
296
  SnapshotObjectId GetId() const;
280
297
 
281
298
  /** Returns node's own size, in bytes. */
282
- int GetSelfSize() const;
299
+ size_t GetShallowSize() const;
283
300
 
284
301
  /** Returns child nodes count of the node. */
285
302
  int GetChildrenCount() const;
286
303
 
287
304
  /** Retrieves a child by index. */
288
305
  const HeapGraphEdge* GetChild(int index) const;
306
+ };
307
+
289
308
 
309
+ /**
310
+ * An interface for exporting data from V8, using "push" model.
311
+ */
312
+ class V8_EXPORT OutputStream { // NOLINT
313
+ public:
314
+ enum WriteResult {
315
+ kContinue = 0,
316
+ kAbort = 1
317
+ };
318
+ virtual ~OutputStream() {}
319
+ /** Notify about the end of stream. */
320
+ virtual void EndOfStream() = 0;
321
+ /** Get preferred output chunk size. Called only once. */
322
+ virtual int GetChunkSize() { return 1024; }
323
+ /**
324
+ * Writes the next chunk of snapshot data into the stream. Writing
325
+ * can be stopped by returning kAbort as function result. EndOfStream
326
+ * will not be called in case writing was aborted.
327
+ */
328
+ virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
290
329
  /**
291
- * Finds and returns a value from the heap corresponding to this node,
292
- * if the value is still reachable.
330
+ * Writes the next chunk of heap stats data into the stream. Writing
331
+ * can be stopped by returning kAbort as function result. EndOfStream
332
+ * will not be called in case writing was aborted.
293
333
  */
294
- Handle<Value> GetHeapValue() const;
334
+ virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
335
+ return kAbort;
336
+ }
295
337
  };
296
338
 
297
339
 
298
340
  /**
299
341
  * HeapSnapshots record the state of the JS heap at some moment.
300
342
  */
301
- class V8EXPORT HeapSnapshot {
343
+ class V8_EXPORT HeapSnapshot {
302
344
  public:
303
- enum Type {
304
- kFull = 0 // Heap snapshot with all instances and references.
305
- };
306
345
  enum SerializationFormat {
307
346
  kJSON = 0 // See format description near 'Serialize' method.
308
347
  };
309
348
 
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
349
  /** Returns the root node of the heap graph. */
320
350
  const HeapGraphNode* GetRoot() const;
321
351
 
@@ -364,16 +394,35 @@ class V8EXPORT HeapSnapshot {
364
394
  * Nodes reference strings, other nodes, and edges by their indexes
365
395
  * in corresponding arrays.
366
396
  */
367
- void Serialize(OutputStream* stream, SerializationFormat format) const;
397
+ void Serialize(OutputStream* stream,
398
+ SerializationFormat format = kJSON) const;
368
399
  };
369
400
 
370
401
 
371
- class RetainedObjectInfo;
402
+ /**
403
+ * An interface for reporting progress and controlling long-running
404
+ * activities.
405
+ */
406
+ class V8_EXPORT ActivityControl { // NOLINT
407
+ public:
408
+ enum ControlOption {
409
+ kContinue = 0,
410
+ kAbort = 1
411
+ };
412
+ virtual ~ActivityControl() {}
413
+ /**
414
+ * Notify about current progress. The activity can be stopped by
415
+ * returning kAbort as the callback result.
416
+ */
417
+ virtual ControlOption ReportProgressValue(int done, int total) = 0;
418
+ };
419
+
372
420
 
373
421
  /**
374
- * Interface for controlling heap profiling.
422
+ * Interface for controlling heap profiling. Instance of the
423
+ * profiler can be retrieved using v8::Isolate::GetHeapProfiler.
375
424
  */
376
- class V8EXPORT HeapProfiler {
425
+ class V8_EXPORT HeapProfiler {
377
426
  public:
378
427
  /**
379
428
  * Callback function invoked for obtaining RetainedObjectInfo for
@@ -385,19 +434,29 @@ class V8EXPORT HeapProfiler {
385
434
  (uint16_t class_id, Handle<Value> wrapper);
386
435
 
387
436
  /** Returns the number of snapshots taken. */
388
- static int GetSnapshotsCount();
437
+ int GetSnapshotCount();
389
438
 
390
439
  /** 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);
440
+ const HeapSnapshot* GetHeapSnapshot(int index);
395
441
 
396
442
  /**
397
443
  * Returns SnapshotObjectId for a heap object referenced by |value| if
398
444
  * it has been seen by the heap profiler, kUnknownObjectId otherwise.
399
445
  */
400
- static SnapshotObjectId GetSnapshotObjectId(Handle<Value> value);
446
+ SnapshotObjectId GetObjectId(Handle<Value> value);
447
+
448
+ /**
449
+ * Returns heap object with given SnapshotObjectId if the object is alive,
450
+ * otherwise empty handle is returned.
451
+ */
452
+ Handle<Value> FindObjectById(SnapshotObjectId id);
453
+
454
+ /**
455
+ * Clears internal map from SnapshotObjectId to heap object. The new objects
456
+ * will not be added into it unless a heap snapshot is taken or heap object
457
+ * tracking is kicked off.
458
+ */
459
+ void ClearObjectIds();
401
460
 
402
461
  /**
403
462
  * A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
@@ -410,23 +469,20 @@ class V8EXPORT HeapProfiler {
410
469
  * Callback interface for retrieving user friendly names of global objects.
411
470
  */
412
471
  class ObjectNameResolver {
413
- public:
472
+ public:
414
473
  /**
415
474
  * Returns name to be used in the heap snapshot for given node. Returned
416
475
  * string must stay alive until snapshot collection is completed.
417
476
  */
418
477
  virtual const char* GetName(Handle<Object> object) = 0;
419
- protected:
478
+ protected:
420
479
  virtual ~ObjectNameResolver() {}
421
480
  };
422
481
 
423
482
  /**
424
- * Takes a heap snapshot and returns it. Title may be an empty string.
425
- * See HeapSnapshot::Type for types description.
483
+ * Takes a heap snapshot and returns it.
426
484
  */
427
- static const HeapSnapshot* TakeSnapshot(
428
- Handle<String> title,
429
- HeapSnapshot::Type type = HeapSnapshot::kFull,
485
+ const HeapSnapshot* TakeHeapSnapshot(
430
486
  ActivityControl* control = NULL,
431
487
  ObjectNameResolver* global_object_name_resolver = NULL);
432
488
 
@@ -434,8 +490,12 @@ class V8EXPORT HeapProfiler {
434
490
  * Starts tracking of heap objects population statistics. After calling
435
491
  * this method, all heap objects relocations done by the garbage collector
436
492
  * are being registered.
493
+ *
494
+ * |track_allocations| parameter controls whether stack trace of each
495
+ * allocation in the heap will be recorded and reported as part of
496
+ * HeapSnapshot.
437
497
  */
438
- static void StartHeapObjectsTracking();
498
+ void StartTrackingHeapObjects(bool track_allocations = false);
439
499
 
440
500
  /**
441
501
  * Adds a new time interval entry to the aggregated statistics array. The
@@ -444,28 +504,30 @@ class V8EXPORT HeapProfiler {
444
504
  * reports updates for all previous time intervals via the OutputStream
445
505
  * object. Updates on each time interval are provided as a stream of the
446
506
  * HeapStatsUpdate structure instances.
447
- * The return value of the function is the last seen heap object Id.
507
+ * If |timestamp_us| is supplied, timestamp of the new entry will be written
508
+ * into it. The return value of the function is the last seen heap object Id.
448
509
  *
449
- * StartHeapObjectsTracking must be called before the first call to this
510
+ * StartTrackingHeapObjects must be called before the first call to this
450
511
  * method.
451
512
  */
452
- static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
513
+ SnapshotObjectId GetHeapStats(OutputStream* stream,
514
+ int64_t* timestamp_us = NULL);
453
515
 
454
516
  /**
455
517
  * Stops tracking of heap objects population statistics, cleans up all
456
518
  * collected data. StartHeapObjectsTracking must be called again prior to
457
- * calling PushHeapObjectsStats next time.
519
+ * calling GetHeapStats next time.
458
520
  */
459
- static void StopHeapObjectsTracking();
521
+ void StopTrackingHeapObjects();
460
522
 
461
523
  /**
462
524
  * Deletes all snapshots taken. All previously returned pointers to
463
525
  * snapshots and their contents become invalid after this call.
464
526
  */
465
- static void DeleteAllSnapshots();
527
+ void DeleteAllHeapSnapshots();
466
528
 
467
529
  /** Binds a callback to embedder's class ID. */
468
- static void DefineWrapperClass(
530
+ void SetWrapperClassInfoProvider(
469
531
  uint16_t class_id,
470
532
  WrapperInfoCallback callback);
471
533
 
@@ -476,11 +538,19 @@ class V8EXPORT HeapProfiler {
476
538
  */
477
539
  static const uint16_t kPersistentHandleNoClassId = 0;
478
540
 
479
- /** Returns the number of currently existing persistent handles. */
480
- static int GetPersistentHandleCount();
481
-
482
541
  /** Returns memory used for profiler internal data and snapshots. */
483
- static size_t GetMemorySizeUsedByProfiler();
542
+ size_t GetProfilerMemorySize();
543
+
544
+ /**
545
+ * Sets a RetainedObjectInfo for an object group (see V8::SetObjectGroupId).
546
+ */
547
+ void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
548
+
549
+ private:
550
+ HeapProfiler();
551
+ ~HeapProfiler();
552
+ HeapProfiler(const HeapProfiler&);
553
+ HeapProfiler& operator=(const HeapProfiler&);
484
554
  };
485
555
 
486
556
 
@@ -501,14 +571,14 @@ class V8EXPORT HeapProfiler {
501
571
  * objects for heap snapshots, he can do it in a GC prologue
502
572
  * handler, and / or by assigning wrapper class ids in the following way:
503
573
  *
504
- * 1. Bind a callback to class id by calling DefineWrapperClass.
574
+ * 1. Bind a callback to class id by calling SetWrapperClassInfoProvider.
505
575
  * 2. Call SetWrapperClassId on certain persistent handles.
506
576
  *
507
577
  * V8 takes ownership of RetainedObjectInfo instances passed to it and
508
578
  * keeps them alive only during snapshot collection. Afterwards, they
509
579
  * are freed by calling the Dispose class function.
510
580
  */
511
- class V8EXPORT RetainedObjectInfo { // NOLINT
581
+ class V8_EXPORT RetainedObjectInfo { // NOLINT
512
582
  public:
513
583
  /** Called by V8 when it no longer needs an instance. */
514
584
  virtual void Dispose() = 0;
@@ -560,7 +630,7 @@ class V8EXPORT RetainedObjectInfo { // NOLINT
560
630
 
561
631
  /**
562
632
  * A struct for exporting HeapStats data from V8, using "push" model.
563
- * See HeapProfiler::PushHeapObjectsStats.
633
+ * See HeapProfiler::GetHeapStats.
564
634
  */
565
635
  struct HeapStatsUpdate {
566
636
  HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
@@ -574,7 +644,4 @@ struct HeapStatsUpdate {
574
644
  } // namespace v8
575
645
 
576
646
 
577
- #undef V8EXPORT
578
-
579
-
580
647
  #endif // V8_V8_PROFILER_H_