libv8 3.16.14.19-universal-darwin-17 → 6.2.414.42.1-universal-darwin-17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libv8/arch.rb +10 -33
- data/ext/libv8/location.rb +15 -7
- data/ext/libv8/paths.rb +3 -3
- data/lib/libv8/version.rb +1 -1
- data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
- data/vendor/v8/include/libplatform/libplatform.h +83 -0
- data/vendor/v8/include/libplatform/v8-tracing.h +284 -0
- data/vendor/v8/include/v8-debug.h +104 -257
- data/vendor/v8/include/v8-inspector-protocol.h +13 -0
- data/vendor/v8/include/v8-inspector.h +267 -0
- data/vendor/v8/include/v8-platform.h +241 -0
- data/vendor/v8/include/v8-profiler.h +514 -185
- data/vendor/v8/include/v8-testing.h +5 -62
- data/vendor/v8/include/v8-util.h +655 -0
- data/vendor/v8/include/v8-value-serializer-version.h +24 -0
- data/vendor/v8/include/v8-version-string.h +33 -0
- data/vendor/v8/include/v8-version.h +20 -0
- data/vendor/v8/include/v8.h +8944 -3504
- data/vendor/v8/include/v8config.h +417 -0
- data/vendor/v8/out/x64.release/libv8_base.a +0 -0
- data/vendor/v8/out/x64.release/libv8_builtins_generators.a +0 -0
- data/vendor/v8/out/x64.release/libv8_builtins_setup.a +0 -0
- data/vendor/v8/out/x64.release/libv8_libbase.a +0 -0
- data/vendor/v8/out/x64.release/libv8_libplatform.a +0 -0
- data/vendor/v8/out/x64.release/libv8_libsampler.a +0 -0
- data/vendor/v8/out/x64.release/libv8_nosnapshot.a +0 -0
- data/vendor/v8/out/x64.release/libv8_snapshot.a +0 -0
- metadata +22 -23
- data/vendor/v8/include/v8-preparser.h +0 -118
- data/vendor/v8/include/v8stdint.h +0 -54
- data/vendor/v8/out/x64.release/libpreparser_lib.a +0 -0
@@ -1,82 +1,170 @@
|
|
1
1
|
// Copyright 2010 the V8 project authors. All rights reserved.
|
2
|
-
//
|
3
|
-
//
|
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
|
8
|
+
#include <unordered_set>
|
9
|
+
#include <vector>
|
10
|
+
#include "v8.h" // NOLINT(build/include)
|
32
11
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
12
|
+
/**
|
13
|
+
* Profiler support for the V8 JavaScript engine.
|
14
|
+
*/
|
15
|
+
namespace v8 {
|
40
16
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
#else
|
46
|
-
#define V8EXPORT
|
47
|
-
#endif
|
17
|
+
class HeapGraphNode;
|
18
|
+
struct HeapStatsUpdate;
|
19
|
+
|
20
|
+
typedef uint32_t SnapshotObjectId;
|
48
21
|
|
49
|
-
#else // _WIN32
|
50
22
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
23
|
+
struct CpuProfileDeoptFrame {
|
24
|
+
int script_id;
|
25
|
+
size_t position;
|
26
|
+
};
|
27
|
+
|
28
|
+
} // namespace v8
|
29
|
+
|
30
|
+
#ifdef V8_OS_WIN
|
31
|
+
template class V8_EXPORT std::vector<v8::CpuProfileDeoptFrame>;
|
58
32
|
#endif
|
59
33
|
|
60
|
-
|
34
|
+
namespace v8 {
|
35
|
+
|
36
|
+
struct V8_EXPORT CpuProfileDeoptInfo {
|
37
|
+
/** A pointer to a static string owned by v8. */
|
38
|
+
const char* deopt_reason;
|
39
|
+
std::vector<CpuProfileDeoptFrame> stack;
|
40
|
+
};
|
61
41
|
|
42
|
+
} // namespace v8
|
43
|
+
|
44
|
+
#ifdef V8_OS_WIN
|
45
|
+
template class V8_EXPORT std::vector<v8::CpuProfileDeoptInfo>;
|
46
|
+
#endif
|
47
|
+
|
48
|
+
namespace v8 {
|
62
49
|
|
63
50
|
/**
|
64
|
-
*
|
51
|
+
* TracingCpuProfiler monitors tracing being enabled/disabled
|
52
|
+
* and emits CpuProfile trace events once v8.cpu_profiler tracing category
|
53
|
+
* is enabled. It has no overhead unless the category is enabled.
|
65
54
|
*/
|
66
|
-
|
55
|
+
class V8_EXPORT TracingCpuProfiler {
|
56
|
+
public:
|
57
|
+
static std::unique_ptr<TracingCpuProfiler> Create(Isolate*);
|
58
|
+
virtual ~TracingCpuProfiler() = default;
|
67
59
|
|
68
|
-
|
60
|
+
protected:
|
61
|
+
TracingCpuProfiler() = default;
|
62
|
+
};
|
63
|
+
|
64
|
+
// TickSample captures the information collected for each sample.
|
65
|
+
struct TickSample {
|
66
|
+
// Internal profiling (with --prof + tools/$OS-tick-processor) wants to
|
67
|
+
// include the runtime function we're calling. Externally exposed tick
|
68
|
+
// samples don't care.
|
69
|
+
enum RecordCEntryFrame { kIncludeCEntryFrame, kSkipCEntryFrame };
|
70
|
+
|
71
|
+
TickSample()
|
72
|
+
: state(OTHER),
|
73
|
+
pc(nullptr),
|
74
|
+
external_callback_entry(nullptr),
|
75
|
+
frames_count(0),
|
76
|
+
has_external_callback(false),
|
77
|
+
update_stats(true) {}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Initialize a tick sample from the isolate.
|
81
|
+
* \param isolate The isolate.
|
82
|
+
* \param state Execution state.
|
83
|
+
* \param record_c_entry_frame Include or skip the runtime function.
|
84
|
+
* \param update_stats Whether update the sample to the aggregated stats.
|
85
|
+
* \param use_simulator_reg_state When set to true and V8 is running under a
|
86
|
+
* simulator, the method will use the simulator
|
87
|
+
* register state rather than the one provided
|
88
|
+
* with |state| argument. Otherwise the method
|
89
|
+
* will use provided register |state| as is.
|
90
|
+
*/
|
91
|
+
void Init(Isolate* isolate, const v8::RegisterState& state,
|
92
|
+
RecordCEntryFrame record_c_entry_frame, bool update_stats,
|
93
|
+
bool use_simulator_reg_state = true);
|
94
|
+
/**
|
95
|
+
* Get a call stack sample from the isolate.
|
96
|
+
* \param isolate The isolate.
|
97
|
+
* \param state Register state.
|
98
|
+
* \param record_c_entry_frame Include or skip the runtime function.
|
99
|
+
* \param frames Caller allocated buffer to store stack frames.
|
100
|
+
* \param frames_limit Maximum number of frames to capture. The buffer must
|
101
|
+
* be large enough to hold the number of frames.
|
102
|
+
* \param sample_info The sample info is filled up by the function
|
103
|
+
* provides number of actual captured stack frames and
|
104
|
+
* the current VM state.
|
105
|
+
* \param use_simulator_reg_state When set to true and V8 is running under a
|
106
|
+
* simulator, the method will use the simulator
|
107
|
+
* register state rather than the one provided
|
108
|
+
* with |state| argument. Otherwise the method
|
109
|
+
* will use provided register |state| as is.
|
110
|
+
* \note GetStackSample is thread and signal safe and should only be called
|
111
|
+
* when the JS thread is paused or interrupted.
|
112
|
+
* Otherwise the behavior is undefined.
|
113
|
+
*/
|
114
|
+
static bool GetStackSample(Isolate* isolate, v8::RegisterState* state,
|
115
|
+
RecordCEntryFrame record_c_entry_frame,
|
116
|
+
void** frames, size_t frames_limit,
|
117
|
+
v8::SampleInfo* sample_info,
|
118
|
+
bool use_simulator_reg_state = true);
|
119
|
+
StateTag state; // The state of the VM.
|
120
|
+
void* pc; // Instruction pointer.
|
121
|
+
union {
|
122
|
+
void* tos; // Top stack value (*sp).
|
123
|
+
void* external_callback_entry;
|
124
|
+
};
|
125
|
+
static const unsigned kMaxFramesCountLog2 = 8;
|
126
|
+
static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1;
|
127
|
+
void* stack[kMaxFramesCount]; // Call stack.
|
128
|
+
unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames.
|
129
|
+
bool has_external_callback : 1;
|
130
|
+
bool update_stats : 1; // Whether the sample should update aggregated stats.
|
131
|
+
};
|
69
132
|
|
70
133
|
/**
|
71
134
|
* CpuProfileNode represents a node in a call graph.
|
72
135
|
*/
|
73
|
-
class
|
136
|
+
class V8_EXPORT CpuProfileNode {
|
74
137
|
public:
|
138
|
+
struct LineTick {
|
139
|
+
/** The 1-based number of the source line where the function originates. */
|
140
|
+
int line;
|
141
|
+
|
142
|
+
/** The count of samples associated with the source line. */
|
143
|
+
unsigned int hit_count;
|
144
|
+
};
|
145
|
+
|
75
146
|
/** Returns function name (empty string for anonymous functions.) */
|
76
|
-
|
147
|
+
Local<String> GetFunctionName() const;
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Returns function name (empty string for anonymous functions.)
|
151
|
+
* The string ownership is *not* passed to the caller. It stays valid until
|
152
|
+
* profile is deleted. The function is thread safe.
|
153
|
+
*/
|
154
|
+
const char* GetFunctionNameStr() const;
|
155
|
+
|
156
|
+
/** Returns id of the script where function is located. */
|
157
|
+
int GetScriptId() const;
|
77
158
|
|
78
159
|
/** Returns resource name for script from where the function originates. */
|
79
|
-
|
160
|
+
Local<String> GetScriptResourceName() const;
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Returns resource name for script from where the function originates.
|
164
|
+
* The string ownership is *not* passed to the caller. It stays valid until
|
165
|
+
* profile is deleted. The function is thread safe.
|
166
|
+
*/
|
167
|
+
const char* GetScriptResourceNameStr() const;
|
80
168
|
|
81
169
|
/**
|
82
170
|
* Returns the number, 1-based, of the line where the function originates.
|
@@ -85,25 +173,40 @@ class V8EXPORT CpuProfileNode {
|
|
85
173
|
int GetLineNumber() const;
|
86
174
|
|
87
175
|
/**
|
88
|
-
* Returns
|
89
|
-
*
|
176
|
+
* Returns 1-based number of the column where the function originates.
|
177
|
+
* kNoColumnNumberInfo if no column number information is available.
|
90
178
|
*/
|
91
|
-
|
179
|
+
int GetColumnNumber() const;
|
92
180
|
|
93
181
|
/**
|
94
|
-
* Returns
|
95
|
-
* estimated by samples count.
|
182
|
+
* Returns the number of the function's source lines that collect the samples.
|
96
183
|
*/
|
97
|
-
|
184
|
+
unsigned int GetHitLineCount() const;
|
98
185
|
|
99
|
-
/** Returns the
|
100
|
-
|
186
|
+
/** Returns the set of source lines that collect the samples.
|
187
|
+
* The caller allocates buffer and responsible for releasing it.
|
188
|
+
* True if all available entries are copied, otherwise false.
|
189
|
+
* The function copies nothing if buffer is not large enough.
|
190
|
+
*/
|
191
|
+
bool GetLineTicks(LineTick* entries, unsigned int length) const;
|
101
192
|
|
102
|
-
/** Returns
|
103
|
-
|
193
|
+
/** Returns bailout reason for the function
|
194
|
+
* if the optimization was disabled for it.
|
195
|
+
*/
|
196
|
+
const char* GetBailoutReason() const;
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Returns the count of samples where the function was currently executing.
|
200
|
+
*/
|
201
|
+
unsigned GetHitCount() const;
|
104
202
|
|
105
203
|
/** Returns function entry UID. */
|
106
|
-
|
204
|
+
V8_DEPRECATE_SOON(
|
205
|
+
"Use GetScriptId, GetLineNumber, and GetColumnNumber instead.",
|
206
|
+
unsigned GetCallUid() const);
|
207
|
+
|
208
|
+
/** Returns id of the node. The id is unique within the tree */
|
209
|
+
unsigned GetNodeId() const;
|
107
210
|
|
108
211
|
/** Returns child nodes count of the node. */
|
109
212
|
int GetChildrenCount() const;
|
@@ -111,70 +214,89 @@ class V8EXPORT CpuProfileNode {
|
|
111
214
|
/** Retrieves a child node by index. */
|
112
215
|
const CpuProfileNode* GetChild(int index) const;
|
113
216
|
|
217
|
+
/** Retrieves deopt infos for the node. */
|
218
|
+
const std::vector<CpuProfileDeoptInfo>& GetDeoptInfos() const;
|
219
|
+
|
114
220
|
static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
|
221
|
+
static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
|
115
222
|
};
|
116
223
|
|
117
224
|
|
118
225
|
/**
|
119
|
-
* CpuProfile contains a CPU profile in a form of
|
120
|
-
*
|
121
|
-
* - bottom-up call graph (in backward direction).
|
226
|
+
* CpuProfile contains a CPU profile in a form of top-down call tree
|
227
|
+
* (from main() down to functions that do all the work).
|
122
228
|
*/
|
123
|
-
class
|
229
|
+
class V8_EXPORT CpuProfile {
|
124
230
|
public:
|
125
|
-
/** Returns CPU profile UID (assigned by the profiler.) */
|
126
|
-
unsigned GetUid() const;
|
127
|
-
|
128
231
|
/** Returns CPU profile title. */
|
129
|
-
|
130
|
-
|
131
|
-
/** Returns the root node of the bottom up call tree. */
|
132
|
-
const CpuProfileNode* GetBottomUpRoot() const;
|
232
|
+
Local<String> GetTitle() const;
|
133
233
|
|
134
234
|
/** Returns the root node of the top down call tree. */
|
135
235
|
const CpuProfileNode* GetTopDownRoot() const;
|
136
236
|
|
237
|
+
/**
|
238
|
+
* Returns number of samples recorded. The samples are not recorded unless
|
239
|
+
* |record_samples| parameter of CpuProfiler::StartCpuProfiling is true.
|
240
|
+
*/
|
241
|
+
int GetSamplesCount() const;
|
242
|
+
|
243
|
+
/**
|
244
|
+
* Returns profile node corresponding to the top frame the sample at
|
245
|
+
* the given index.
|
246
|
+
*/
|
247
|
+
const CpuProfileNode* GetSample(int index) const;
|
248
|
+
|
249
|
+
/**
|
250
|
+
* Returns the timestamp of the sample. The timestamp is the number of
|
251
|
+
* microseconds since some unspecified starting point.
|
252
|
+
* The point is equal to the starting point used by GetStartTime.
|
253
|
+
*/
|
254
|
+
int64_t GetSampleTimestamp(int index) const;
|
255
|
+
|
256
|
+
/**
|
257
|
+
* Returns time when the profile recording was started (in microseconds)
|
258
|
+
* since some unspecified starting point.
|
259
|
+
*/
|
260
|
+
int64_t GetStartTime() const;
|
261
|
+
|
262
|
+
/**
|
263
|
+
* Returns time when the profile recording was stopped (in microseconds)
|
264
|
+
* since some unspecified starting point.
|
265
|
+
* The point is equal to the starting point used by GetStartTime.
|
266
|
+
*/
|
267
|
+
int64_t GetEndTime() const;
|
268
|
+
|
137
269
|
/**
|
138
270
|
* Deletes the profile and removes it from CpuProfiler's list.
|
139
271
|
* 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
272
|
*/
|
145
273
|
void Delete();
|
146
274
|
};
|
147
275
|
|
148
|
-
|
149
276
|
/**
|
150
|
-
* Interface for controlling CPU profiling.
|
277
|
+
* Interface for controlling CPU profiling. Instance of the
|
278
|
+
* profiler can be created using v8::CpuProfiler::New method.
|
151
279
|
*/
|
152
|
-
class
|
280
|
+
class V8_EXPORT CpuProfiler {
|
153
281
|
public:
|
154
282
|
/**
|
155
|
-
*
|
156
|
-
*
|
157
|
-
*
|
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.
|
283
|
+
* Creates a new CPU profiler for the |isolate|. The isolate must be
|
284
|
+
* initialized. The profiler object must be disposed after use by calling
|
285
|
+
* |Dispose| method.
|
161
286
|
*/
|
287
|
+
static CpuProfiler* New(Isolate* isolate);
|
162
288
|
|
163
289
|
/**
|
164
|
-
*
|
165
|
-
* profiles that are being collected at the moment of call.)
|
290
|
+
* Disposes the CPU profiler object.
|
166
291
|
*/
|
167
|
-
|
168
|
-
|
169
|
-
/** Returns a profile by index. */
|
170
|
-
static const CpuProfile* GetProfile(
|
171
|
-
int index,
|
172
|
-
Handle<Value> security_token = Handle<Value>());
|
292
|
+
void Dispose();
|
173
293
|
|
174
|
-
/**
|
175
|
-
|
176
|
-
|
177
|
-
|
294
|
+
/**
|
295
|
+
* Changes default CPU profiler sampling interval to the specified number
|
296
|
+
* of microseconds. Default interval is 1000us. This method must be called
|
297
|
+
* when there are no profiles being recorded.
|
298
|
+
*/
|
299
|
+
void SetSamplingInterval(int us);
|
178
300
|
|
179
301
|
/**
|
180
302
|
* Starts collecting CPU profile. Title may be an empty string. It
|
@@ -183,34 +305,43 @@ class V8EXPORT CpuProfiler {
|
|
183
305
|
* title are silently ignored. While collecting a profile, functions
|
184
306
|
* from all security contexts are included in it. The token-based
|
185
307
|
* filtering is only performed when querying for a profile.
|
308
|
+
*
|
309
|
+
* |record_samples| parameter controls whether individual samples should
|
310
|
+
* be recorded in addition to the aggregated tree.
|
186
311
|
*/
|
187
|
-
|
312
|
+
void StartProfiling(Local<String> title, bool record_samples = false);
|
188
313
|
|
189
314
|
/**
|
190
315
|
* Stops collecting CPU profile with a given title and returns it.
|
191
316
|
* If the title given is empty, finishes the last profile started.
|
192
317
|
*/
|
193
|
-
|
194
|
-
Handle<String> title,
|
195
|
-
Handle<Value> security_token = Handle<Value>());
|
318
|
+
CpuProfile* StopProfiling(Local<String> title);
|
196
319
|
|
197
320
|
/**
|
198
|
-
*
|
199
|
-
*
|
200
|
-
*
|
321
|
+
* Force collection of a sample. Must be called on the VM thread.
|
322
|
+
* Recording the forced sample does not contribute to the aggregated
|
323
|
+
* profile statistics.
|
201
324
|
*/
|
202
|
-
|
203
|
-
};
|
325
|
+
void CollectSample();
|
204
326
|
|
327
|
+
/**
|
328
|
+
* Tells the profiler whether the embedder is idle.
|
329
|
+
*/
|
330
|
+
void SetIdle(bool is_idle);
|
205
331
|
|
206
|
-
|
332
|
+
private:
|
333
|
+
CpuProfiler();
|
334
|
+
~CpuProfiler();
|
335
|
+
CpuProfiler(const CpuProfiler&);
|
336
|
+
CpuProfiler& operator=(const CpuProfiler&);
|
337
|
+
};
|
207
338
|
|
208
339
|
|
209
340
|
/**
|
210
341
|
* HeapSnapshotEdge represents a directed connection between heap
|
211
342
|
* graph nodes: from retainers to retained nodes.
|
212
343
|
*/
|
213
|
-
class
|
344
|
+
class V8_EXPORT HeapGraphEdge {
|
214
345
|
public:
|
215
346
|
enum Type {
|
216
347
|
kContextVariable = 0, // A variable from a function context.
|
@@ -233,7 +364,7 @@ class V8EXPORT HeapGraphEdge {
|
|
233
364
|
* Returns edge name. This can be a variable name, an element index, or
|
234
365
|
* a property name.
|
235
366
|
*/
|
236
|
-
|
367
|
+
Local<Value> GetName() const;
|
237
368
|
|
238
369
|
/** Returns origin node. */
|
239
370
|
const HeapGraphNode* GetFromNode() const;
|
@@ -246,20 +377,23 @@ class V8EXPORT HeapGraphEdge {
|
|
246
377
|
/**
|
247
378
|
* HeapGraphNode represents a node in a heap graph.
|
248
379
|
*/
|
249
|
-
class
|
380
|
+
class V8_EXPORT HeapGraphNode {
|
250
381
|
public:
|
251
382
|
enum Type {
|
252
|
-
kHidden = 0,
|
253
|
-
kArray = 1,
|
254
|
-
kString = 2,
|
255
|
-
kObject = 3,
|
256
|
-
kCode = 4,
|
257
|
-
kClosure = 5,
|
258
|
-
kRegExp = 6,
|
259
|
-
kHeapNumber = 7,
|
260
|
-
kNative = 8,
|
261
|
-
kSynthetic = 9
|
262
|
-
|
383
|
+
kHidden = 0, // Hidden node, may be filtered when shown to user.
|
384
|
+
kArray = 1, // An array of elements.
|
385
|
+
kString = 2, // A string.
|
386
|
+
kObject = 3, // A JS object (except for arrays and strings).
|
387
|
+
kCode = 4, // Compiled code.
|
388
|
+
kClosure = 5, // Function closure.
|
389
|
+
kRegExp = 6, // RegExp.
|
390
|
+
kHeapNumber = 7, // Number stored in the heap.
|
391
|
+
kNative = 8, // Native object (not from V8 heap).
|
392
|
+
kSynthetic = 9, // Synthetic object, usually used for grouping
|
393
|
+
// snapshot items together.
|
394
|
+
kConsString = 10, // Concatenated string. A pair of pointers to strings.
|
395
|
+
kSlicedString = 11, // Sliced string. A fragment of another string.
|
396
|
+
kSymbol = 12 // A Symbol (ES6).
|
263
397
|
};
|
264
398
|
|
265
399
|
/** Returns node type (see HeapGraphNode::Type). */
|
@@ -270,7 +404,7 @@ class V8EXPORT HeapGraphNode {
|
|
270
404
|
* of the constructor (for objects), the name of the function (for
|
271
405
|
* closures), string value, or an empty string (for compiled code).
|
272
406
|
*/
|
273
|
-
|
407
|
+
Local<String> GetName() const;
|
274
408
|
|
275
409
|
/**
|
276
410
|
* Returns node id. For the same heap object, the id remains the same
|
@@ -279,43 +413,56 @@ class V8EXPORT HeapGraphNode {
|
|
279
413
|
SnapshotObjectId GetId() const;
|
280
414
|
|
281
415
|
/** Returns node's own size, in bytes. */
|
282
|
-
|
416
|
+
size_t GetShallowSize() const;
|
283
417
|
|
284
418
|
/** Returns child nodes count of the node. */
|
285
419
|
int GetChildrenCount() const;
|
286
420
|
|
287
421
|
/** Retrieves a child by index. */
|
288
422
|
const HeapGraphEdge* GetChild(int index) const;
|
423
|
+
};
|
424
|
+
|
289
425
|
|
426
|
+
/**
|
427
|
+
* An interface for exporting data from V8, using "push" model.
|
428
|
+
*/
|
429
|
+
class V8_EXPORT OutputStream { // NOLINT
|
430
|
+
public:
|
431
|
+
enum WriteResult {
|
432
|
+
kContinue = 0,
|
433
|
+
kAbort = 1
|
434
|
+
};
|
435
|
+
virtual ~OutputStream() {}
|
436
|
+
/** Notify about the end of stream. */
|
437
|
+
virtual void EndOfStream() = 0;
|
438
|
+
/** Get preferred output chunk size. Called only once. */
|
439
|
+
virtual int GetChunkSize() { return 1024; }
|
440
|
+
/**
|
441
|
+
* Writes the next chunk of snapshot data into the stream. Writing
|
442
|
+
* can be stopped by returning kAbort as function result. EndOfStream
|
443
|
+
* will not be called in case writing was aborted.
|
444
|
+
*/
|
445
|
+
virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
|
290
446
|
/**
|
291
|
-
*
|
292
|
-
*
|
447
|
+
* Writes the next chunk of heap stats data into the stream. Writing
|
448
|
+
* can be stopped by returning kAbort as function result. EndOfStream
|
449
|
+
* will not be called in case writing was aborted.
|
293
450
|
*/
|
294
|
-
|
451
|
+
virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
|
452
|
+
return kAbort;
|
453
|
+
}
|
295
454
|
};
|
296
455
|
|
297
456
|
|
298
457
|
/**
|
299
458
|
* HeapSnapshots record the state of the JS heap at some moment.
|
300
459
|
*/
|
301
|
-
class
|
460
|
+
class V8_EXPORT HeapSnapshot {
|
302
461
|
public:
|
303
|
-
enum Type {
|
304
|
-
kFull = 0 // Heap snapshot with all instances and references.
|
305
|
-
};
|
306
462
|
enum SerializationFormat {
|
307
463
|
kJSON = 0 // See format description near 'Serialize' method.
|
308
464
|
};
|
309
465
|
|
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
466
|
/** Returns the root node of the heap graph. */
|
320
467
|
const HeapGraphNode* GetRoot() const;
|
321
468
|
|
@@ -364,40 +511,176 @@ class V8EXPORT HeapSnapshot {
|
|
364
511
|
* Nodes reference strings, other nodes, and edges by their indexes
|
365
512
|
* in corresponding arrays.
|
366
513
|
*/
|
367
|
-
void Serialize(OutputStream* stream,
|
514
|
+
void Serialize(OutputStream* stream,
|
515
|
+
SerializationFormat format = kJSON) const;
|
516
|
+
};
|
517
|
+
|
518
|
+
|
519
|
+
/**
|
520
|
+
* An interface for reporting progress and controlling long-running
|
521
|
+
* activities.
|
522
|
+
*/
|
523
|
+
class V8_EXPORT ActivityControl { // NOLINT
|
524
|
+
public:
|
525
|
+
enum ControlOption {
|
526
|
+
kContinue = 0,
|
527
|
+
kAbort = 1
|
528
|
+
};
|
529
|
+
virtual ~ActivityControl() {}
|
530
|
+
/**
|
531
|
+
* Notify about current progress. The activity can be stopped by
|
532
|
+
* returning kAbort as the callback result.
|
533
|
+
*/
|
534
|
+
virtual ControlOption ReportProgressValue(int done, int total) = 0;
|
368
535
|
};
|
369
536
|
|
370
537
|
|
371
|
-
|
538
|
+
/**
|
539
|
+
* AllocationProfile is a sampled profile of allocations done by the program.
|
540
|
+
* This is structured as a call-graph.
|
541
|
+
*/
|
542
|
+
class V8_EXPORT AllocationProfile {
|
543
|
+
public:
|
544
|
+
struct Allocation {
|
545
|
+
/**
|
546
|
+
* Size of the sampled allocation object.
|
547
|
+
*/
|
548
|
+
size_t size;
|
549
|
+
|
550
|
+
/**
|
551
|
+
* The number of objects of such size that were sampled.
|
552
|
+
*/
|
553
|
+
unsigned int count;
|
554
|
+
};
|
555
|
+
|
556
|
+
/**
|
557
|
+
* Represents a node in the call-graph.
|
558
|
+
*/
|
559
|
+
struct Node {
|
560
|
+
/**
|
561
|
+
* Name of the function. May be empty for anonymous functions or if the
|
562
|
+
* script corresponding to this function has been unloaded.
|
563
|
+
*/
|
564
|
+
Local<String> name;
|
565
|
+
|
566
|
+
/**
|
567
|
+
* Name of the script containing the function. May be empty if the script
|
568
|
+
* name is not available, or if the script has been unloaded.
|
569
|
+
*/
|
570
|
+
Local<String> script_name;
|
571
|
+
|
572
|
+
/**
|
573
|
+
* id of the script where the function is located. May be equal to
|
574
|
+
* v8::UnboundScript::kNoScriptId in cases where the script doesn't exist.
|
575
|
+
*/
|
576
|
+
int script_id;
|
577
|
+
|
578
|
+
/**
|
579
|
+
* Start position of the function in the script.
|
580
|
+
*/
|
581
|
+
int start_position;
|
582
|
+
|
583
|
+
/**
|
584
|
+
* 1-indexed line number where the function starts. May be
|
585
|
+
* kNoLineNumberInfo if no line number information is available.
|
586
|
+
*/
|
587
|
+
int line_number;
|
588
|
+
|
589
|
+
/**
|
590
|
+
* 1-indexed column number where the function starts. May be
|
591
|
+
* kNoColumnNumberInfo if no line number information is available.
|
592
|
+
*/
|
593
|
+
int column_number;
|
594
|
+
|
595
|
+
/**
|
596
|
+
* List of callees called from this node for which we have sampled
|
597
|
+
* allocations. The lifetime of the children is scoped to the containing
|
598
|
+
* AllocationProfile.
|
599
|
+
*/
|
600
|
+
std::vector<Node*> children;
|
601
|
+
|
602
|
+
/**
|
603
|
+
* List of self allocations done by this node in the call-graph.
|
604
|
+
*/
|
605
|
+
std::vector<Allocation> allocations;
|
606
|
+
};
|
607
|
+
|
608
|
+
/**
|
609
|
+
* Returns the root node of the call-graph. The root node corresponds to an
|
610
|
+
* empty JS call-stack. The lifetime of the returned Node* is scoped to the
|
611
|
+
* containing AllocationProfile.
|
612
|
+
*/
|
613
|
+
virtual Node* GetRootNode() = 0;
|
614
|
+
|
615
|
+
virtual ~AllocationProfile() {}
|
616
|
+
|
617
|
+
static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
|
618
|
+
static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
|
619
|
+
};
|
620
|
+
|
372
621
|
|
373
622
|
/**
|
374
|
-
* Interface for controlling heap profiling.
|
623
|
+
* Interface for controlling heap profiling. Instance of the
|
624
|
+
* profiler can be retrieved using v8::Isolate::GetHeapProfiler.
|
375
625
|
*/
|
376
|
-
class
|
626
|
+
class V8_EXPORT HeapProfiler {
|
377
627
|
public:
|
628
|
+
enum SamplingFlags {
|
629
|
+
kSamplingNoFlags = 0,
|
630
|
+
kSamplingForceGC = 1 << 0,
|
631
|
+
};
|
632
|
+
|
633
|
+
typedef std::unordered_set<const v8::PersistentBase<v8::Value>*>
|
634
|
+
RetainerChildren;
|
635
|
+
typedef std::vector<std::pair<v8::RetainedObjectInfo*, RetainerChildren>>
|
636
|
+
RetainerGroups;
|
637
|
+
typedef std::vector<std::pair<const v8::PersistentBase<v8::Value>*,
|
638
|
+
const v8::PersistentBase<v8::Value>*>>
|
639
|
+
RetainerEdges;
|
640
|
+
|
641
|
+
struct RetainerInfos {
|
642
|
+
RetainerGroups groups;
|
643
|
+
RetainerEdges edges;
|
644
|
+
};
|
645
|
+
|
646
|
+
/**
|
647
|
+
* Callback function invoked to retrieve all RetainerInfos from the embedder.
|
648
|
+
*/
|
649
|
+
typedef RetainerInfos (*GetRetainerInfosCallback)(v8::Isolate* isolate);
|
650
|
+
|
378
651
|
/**
|
379
652
|
* Callback function invoked for obtaining RetainedObjectInfo for
|
380
653
|
* the given JavaScript wrapper object. It is prohibited to enter V8
|
381
654
|
* while the callback is running: only getters on the handle and
|
382
655
|
* GetPointerFromInternalField on the objects are allowed.
|
383
656
|
*/
|
384
|
-
typedef RetainedObjectInfo* (*WrapperInfoCallback)
|
385
|
-
|
657
|
+
typedef RetainedObjectInfo* (*WrapperInfoCallback)(uint16_t class_id,
|
658
|
+
Local<Value> wrapper);
|
386
659
|
|
387
660
|
/** Returns the number of snapshots taken. */
|
388
|
-
|
661
|
+
int GetSnapshotCount();
|
389
662
|
|
390
663
|
/** Returns a snapshot by index. */
|
391
|
-
|
392
|
-
|
393
|
-
/** Returns a profile by uid. */
|
394
|
-
static const HeapSnapshot* FindSnapshot(unsigned uid);
|
664
|
+
const HeapSnapshot* GetHeapSnapshot(int index);
|
395
665
|
|
396
666
|
/**
|
397
667
|
* Returns SnapshotObjectId for a heap object referenced by |value| if
|
398
668
|
* it has been seen by the heap profiler, kUnknownObjectId otherwise.
|
399
669
|
*/
|
400
|
-
|
670
|
+
SnapshotObjectId GetObjectId(Local<Value> value);
|
671
|
+
|
672
|
+
/**
|
673
|
+
* Returns heap object with given SnapshotObjectId if the object is alive,
|
674
|
+
* otherwise empty handle is returned.
|
675
|
+
*/
|
676
|
+
Local<Value> FindObjectById(SnapshotObjectId id);
|
677
|
+
|
678
|
+
/**
|
679
|
+
* Clears internal map from SnapshotObjectId to heap object. The new objects
|
680
|
+
* will not be added into it unless a heap snapshot is taken or heap object
|
681
|
+
* tracking is kicked off.
|
682
|
+
*/
|
683
|
+
void ClearObjectIds();
|
401
684
|
|
402
685
|
/**
|
403
686
|
* A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
|
@@ -410,23 +693,21 @@ class V8EXPORT HeapProfiler {
|
|
410
693
|
* Callback interface for retrieving user friendly names of global objects.
|
411
694
|
*/
|
412
695
|
class ObjectNameResolver {
|
413
|
-
|
696
|
+
public:
|
414
697
|
/**
|
415
698
|
* Returns name to be used in the heap snapshot for given node. Returned
|
416
699
|
* string must stay alive until snapshot collection is completed.
|
417
700
|
*/
|
418
|
-
virtual const char* GetName(
|
419
|
-
|
701
|
+
virtual const char* GetName(Local<Object> object) = 0;
|
702
|
+
|
703
|
+
protected:
|
420
704
|
virtual ~ObjectNameResolver() {}
|
421
705
|
};
|
422
706
|
|
423
707
|
/**
|
424
|
-
* Takes a heap snapshot and returns it.
|
425
|
-
* See HeapSnapshot::Type for types description.
|
708
|
+
* Takes a heap snapshot and returns it.
|
426
709
|
*/
|
427
|
-
|
428
|
-
Handle<String> title,
|
429
|
-
HeapSnapshot::Type type = HeapSnapshot::kFull,
|
710
|
+
const HeapSnapshot* TakeHeapSnapshot(
|
430
711
|
ActivityControl* control = NULL,
|
431
712
|
ObjectNameResolver* global_object_name_resolver = NULL);
|
432
713
|
|
@@ -434,8 +715,12 @@ class V8EXPORT HeapProfiler {
|
|
434
715
|
* Starts tracking of heap objects population statistics. After calling
|
435
716
|
* this method, all heap objects relocations done by the garbage collector
|
436
717
|
* are being registered.
|
718
|
+
*
|
719
|
+
* |track_allocations| parameter controls whether stack trace of each
|
720
|
+
* allocation in the heap will be recorded and reported as part of
|
721
|
+
* HeapSnapshot.
|
437
722
|
*/
|
438
|
-
|
723
|
+
void StartTrackingHeapObjects(bool track_allocations = false);
|
439
724
|
|
440
725
|
/**
|
441
726
|
* Adds a new time interval entry to the aggregated statistics array. The
|
@@ -444,31 +729,79 @@ class V8EXPORT HeapProfiler {
|
|
444
729
|
* reports updates for all previous time intervals via the OutputStream
|
445
730
|
* object. Updates on each time interval are provided as a stream of the
|
446
731
|
* HeapStatsUpdate structure instances.
|
447
|
-
*
|
732
|
+
* If |timestamp_us| is supplied, timestamp of the new entry will be written
|
733
|
+
* into it. The return value of the function is the last seen heap object Id.
|
448
734
|
*
|
449
|
-
*
|
735
|
+
* StartTrackingHeapObjects must be called before the first call to this
|
450
736
|
* method.
|
451
737
|
*/
|
452
|
-
|
738
|
+
SnapshotObjectId GetHeapStats(OutputStream* stream,
|
739
|
+
int64_t* timestamp_us = NULL);
|
453
740
|
|
454
741
|
/**
|
455
742
|
* Stops tracking of heap objects population statistics, cleans up all
|
456
743
|
* collected data. StartHeapObjectsTracking must be called again prior to
|
457
|
-
* calling
|
744
|
+
* calling GetHeapStats next time.
|
745
|
+
*/
|
746
|
+
void StopTrackingHeapObjects();
|
747
|
+
|
748
|
+
/**
|
749
|
+
* Starts gathering a sampling heap profile. A sampling heap profile is
|
750
|
+
* similar to tcmalloc's heap profiler and Go's mprof. It samples object
|
751
|
+
* allocations and builds an online 'sampling' heap profile. At any point in
|
752
|
+
* time, this profile is expected to be a representative sample of objects
|
753
|
+
* currently live in the system. Each sampled allocation includes the stack
|
754
|
+
* trace at the time of allocation, which makes this really useful for memory
|
755
|
+
* leak detection.
|
756
|
+
*
|
757
|
+
* This mechanism is intended to be cheap enough that it can be used in
|
758
|
+
* production with minimal performance overhead.
|
759
|
+
*
|
760
|
+
* Allocations are sampled using a randomized Poisson process. On average, one
|
761
|
+
* allocation will be sampled every |sample_interval| bytes allocated. The
|
762
|
+
* |stack_depth| parameter controls the maximum number of stack frames to be
|
763
|
+
* captured on each allocation.
|
764
|
+
*
|
765
|
+
* NOTE: This is a proof-of-concept at this point. Right now we only sample
|
766
|
+
* newspace allocations. Support for paged space allocation (e.g. pre-tenured
|
767
|
+
* objects, large objects, code objects, etc.) and native allocations
|
768
|
+
* doesn't exist yet, but is anticipated in the future.
|
769
|
+
*
|
770
|
+
* Objects allocated before the sampling is started will not be included in
|
771
|
+
* the profile.
|
772
|
+
*
|
773
|
+
* Returns false if a sampling heap profiler is already running.
|
774
|
+
*/
|
775
|
+
bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024,
|
776
|
+
int stack_depth = 16,
|
777
|
+
SamplingFlags flags = kSamplingNoFlags);
|
778
|
+
|
779
|
+
/**
|
780
|
+
* Stops the sampling heap profile and discards the current profile.
|
781
|
+
*/
|
782
|
+
void StopSamplingHeapProfiler();
|
783
|
+
|
784
|
+
/**
|
785
|
+
* Returns the sampled profile of allocations allocated (and still live) since
|
786
|
+
* StartSamplingHeapProfiler was called. The ownership of the pointer is
|
787
|
+
* transferred to the caller. Returns nullptr if sampling heap profiler is not
|
788
|
+
* active.
|
458
789
|
*/
|
459
|
-
|
790
|
+
AllocationProfile* GetAllocationProfile();
|
460
791
|
|
461
792
|
/**
|
462
793
|
* Deletes all snapshots taken. All previously returned pointers to
|
463
794
|
* snapshots and their contents become invalid after this call.
|
464
795
|
*/
|
465
|
-
|
796
|
+
void DeleteAllHeapSnapshots();
|
466
797
|
|
467
798
|
/** Binds a callback to embedder's class ID. */
|
468
|
-
|
799
|
+
void SetWrapperClassInfoProvider(
|
469
800
|
uint16_t class_id,
|
470
801
|
WrapperInfoCallback callback);
|
471
802
|
|
803
|
+
void SetGetRetainerInfosCallback(GetRetainerInfosCallback callback);
|
804
|
+
|
472
805
|
/**
|
473
806
|
* Default value of persistent handle class ID. Must not be used to
|
474
807
|
* define a class. Can be used to reset a class of a persistent
|
@@ -476,14 +809,13 @@ class V8EXPORT HeapProfiler {
|
|
476
809
|
*/
|
477
810
|
static const uint16_t kPersistentHandleNoClassId = 0;
|
478
811
|
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
812
|
+
private:
|
813
|
+
HeapProfiler();
|
814
|
+
~HeapProfiler();
|
815
|
+
HeapProfiler(const HeapProfiler&);
|
816
|
+
HeapProfiler& operator=(const HeapProfiler&);
|
484
817
|
};
|
485
818
|
|
486
|
-
|
487
819
|
/**
|
488
820
|
* Interface for providing information about embedder's objects
|
489
821
|
* held by global handles. This information is reported in two ways:
|
@@ -498,17 +830,17 @@ class V8EXPORT HeapProfiler {
|
|
498
830
|
* were not previously reported via AddObjectGroup.
|
499
831
|
*
|
500
832
|
* Thus, if an embedder wants to provide information about native
|
501
|
-
* objects for heap snapshots,
|
833
|
+
* objects for heap snapshots, it can do it in a GC prologue
|
502
834
|
* handler, and / or by assigning wrapper class ids in the following way:
|
503
835
|
*
|
504
|
-
* 1. Bind a callback to class id by calling
|
836
|
+
* 1. Bind a callback to class id by calling SetWrapperClassInfoProvider.
|
505
837
|
* 2. Call SetWrapperClassId on certain persistent handles.
|
506
838
|
*
|
507
839
|
* V8 takes ownership of RetainedObjectInfo instances passed to it and
|
508
840
|
* keeps them alive only during snapshot collection. Afterwards, they
|
509
841
|
* are freed by calling the Dispose class function.
|
510
842
|
*/
|
511
|
-
class
|
843
|
+
class V8_EXPORT RetainedObjectInfo { // NOLINT
|
512
844
|
public:
|
513
845
|
/** Called by V8 when it no longer needs an instance. */
|
514
846
|
virtual void Dispose() = 0;
|
@@ -560,7 +892,7 @@ class V8EXPORT RetainedObjectInfo { // NOLINT
|
|
560
892
|
|
561
893
|
/**
|
562
894
|
* A struct for exporting HeapStats data from V8, using "push" model.
|
563
|
-
* See HeapProfiler::
|
895
|
+
* See HeapProfiler::GetHeapStats.
|
564
896
|
*/
|
565
897
|
struct HeapStatsUpdate {
|
566
898
|
HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
|
@@ -574,7 +906,4 @@ struct HeapStatsUpdate {
|
|
574
906
|
} // namespace v8
|
575
907
|
|
576
908
|
|
577
|
-
#undef V8EXPORT
|
578
|
-
|
579
|
-
|
580
909
|
#endif // V8_V8_PROFILER_H_
|