libv8 3.16.14.19-amd64-freebsd-11 → 5.3.332.38.3-amd64-freebsd-11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8/arch.rb +10 -33
  3. data/ext/libv8/location.rb +15 -7
  4. data/ext/libv8/paths.rb +3 -3
  5. data/lib/libv8/version.rb +1 -1
  6. data/vendor/v8/include/libplatform/libplatform.h +38 -0
  7. data/vendor/v8/include/v8-debug.h +84 -191
  8. data/vendor/v8/include/v8-experimental.h +54 -0
  9. data/vendor/v8/include/v8-platform.h +171 -0
  10. data/vendor/v8/include/v8-profiler.h +395 -188
  11. data/vendor/v8/include/v8-testing.h +5 -62
  12. data/vendor/v8/include/v8-util.h +654 -0
  13. data/vendor/v8/include/v8-version.h +20 -0
  14. data/vendor/v8/include/v8.h +6925 -2960
  15. data/vendor/v8/include/v8config.h +432 -0
  16. data/vendor/v8/out/x64.release/libv8_base.a +0 -0
  17. data/vendor/v8/out/x64.release/libv8_libbase.a +0 -0
  18. data/vendor/v8/out/x64.release/libv8_libplatform.a +0 -0
  19. data/vendor/v8/out/x64.release/libv8_libsampler.a +0 -0
  20. data/vendor/v8/out/x64.release/libv8_nosnapshot.a +0 -0
  21. data/vendor/v8/out/x64.release/libv8_snapshot.a +0 -0
  22. data/vendor/v8/out/x64.release/obj.target/src/libv8_base.a +0 -0
  23. data/vendor/v8/out/x64.release/obj.target/src/libv8_libbase.a +0 -0
  24. data/vendor/v8/out/x64.release/obj.target/src/libv8_libplatform.a +0 -0
  25. data/vendor/v8/out/x64.release/obj.target/src/libv8_libsampler.a +0 -0
  26. data/vendor/v8/out/x64.release/obj.target/src/libv8_nosnapshot.a +0 -0
  27. data/vendor/v8/out/x64.release/obj.target/src/libv8_snapshot.a +0 -0
  28. metadata +25 -27
  29. data/vendor/v8/include/v8-preparser.h +0 -118
  30. data/vendor/v8/include/v8stdint.h +0 -54
  31. data/vendor/v8/out/x64.release/obj.target/tools/gyp/libpreparser_lib.a +0 -0
  32. data/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a +0 -0
  33. data/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_nosnapshot.a +0 -0
  34. data/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_snapshot.a +0 -0
@@ -0,0 +1,54 @@
1
+ // Copyright 2015 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
+ /**
6
+ * This header contains a set of experimental V8 APIs. We hope these will
7
+ * become a part of standard V8, but they may also be removed if we deem the
8
+ * experiment to not be successul.
9
+ */
10
+ #ifndef V8_INCLUDE_V8_EXPERIMENTAL_H_
11
+ #define V8_INCLUDE_V8_EXPERIMENTAL_H_
12
+
13
+ #include "v8.h" // NOLINT(build/include)
14
+
15
+ namespace v8 {
16
+ namespace experimental {
17
+
18
+ // Allow the embedder to construct accessors that V8 can compile and use
19
+ // directly, without jumping into the runtime.
20
+ class V8_EXPORT FastAccessorBuilder {
21
+ public:
22
+ struct ValueId {
23
+ size_t value_id;
24
+ };
25
+ struct LabelId {
26
+ size_t label_id;
27
+ };
28
+
29
+ static FastAccessorBuilder* New(Isolate* isolate);
30
+
31
+ ValueId IntegerConstant(int int_constant);
32
+ ValueId GetReceiver();
33
+ ValueId LoadInternalField(ValueId value_id, int field_no);
34
+ ValueId LoadValue(ValueId value_id, int offset);
35
+ ValueId LoadObject(ValueId value_id, int offset);
36
+ void ReturnValue(ValueId value_id);
37
+ void CheckFlagSetOrReturnNull(ValueId value_id, int mask);
38
+ void CheckNotZeroOrReturnNull(ValueId value_id);
39
+ LabelId MakeLabel();
40
+ void SetLabel(LabelId label_id);
41
+ void CheckNotZeroOrJump(ValueId value_id, LabelId label_id);
42
+ ValueId Call(v8::FunctionCallback callback, ValueId value_id);
43
+
44
+ private:
45
+ FastAccessorBuilder() = delete;
46
+ FastAccessorBuilder(const FastAccessorBuilder&) = delete;
47
+ ~FastAccessorBuilder() = delete;
48
+ void operator=(const FastAccessorBuilder&) = delete;
49
+ };
50
+
51
+ } // namespace experimental
52
+ } // namespace v8
53
+
54
+ #endif // V8_INCLUDE_V8_EXPERIMENTAL_H_
@@ -0,0 +1,171 @@
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
+ #include <stddef.h>
9
+ #include <stdint.h>
10
+
11
+ namespace v8 {
12
+
13
+ class Isolate;
14
+
15
+ /**
16
+ * A Task represents a unit of work.
17
+ */
18
+ class Task {
19
+ public:
20
+ virtual ~Task() {}
21
+
22
+ virtual void Run() = 0;
23
+ };
24
+
25
+
26
+ /**
27
+ * An IdleTask represents a unit of work to be performed in idle time.
28
+ * The Run method is invoked with an argument that specifies the deadline in
29
+ * seconds returned by MonotonicallyIncreasingTime().
30
+ * The idle task is expected to complete by this deadline.
31
+ */
32
+ class IdleTask {
33
+ public:
34
+ virtual ~IdleTask() {}
35
+ virtual void Run(double deadline_in_seconds) = 0;
36
+ };
37
+
38
+
39
+ /**
40
+ * V8 Platform abstraction layer.
41
+ *
42
+ * The embedder has to provide an implementation of this interface before
43
+ * initializing the rest of V8.
44
+ */
45
+ class Platform {
46
+ public:
47
+ /**
48
+ * This enum is used to indicate whether a task is potentially long running,
49
+ * or causes a long wait. The embedder might want to use this hint to decide
50
+ * whether to execute the task on a dedicated thread.
51
+ */
52
+ enum ExpectedRuntime {
53
+ kShortRunningTask,
54
+ kLongRunningTask
55
+ };
56
+
57
+ virtual ~Platform() {}
58
+
59
+ /**
60
+ * Gets the number of threads that are used to execute background tasks. Is
61
+ * used to estimate the number of tasks a work package should be split into.
62
+ * A return value of 0 means that there are no background threads available.
63
+ * Note that a value of 0 won't prohibit V8 from posting tasks using
64
+ * |CallOnBackgroundThread|.
65
+ */
66
+ virtual size_t NumberOfAvailableBackgroundThreads() { return 0; }
67
+
68
+ /**
69
+ * Schedules a task to be invoked on a background thread. |expected_runtime|
70
+ * indicates that the task will run a long time. The Platform implementation
71
+ * takes ownership of |task|. There is no guarantee about order of execution
72
+ * of tasks wrt order of scheduling, nor is there a guarantee about the
73
+ * thread the task will be run on.
74
+ */
75
+ virtual void CallOnBackgroundThread(Task* task,
76
+ ExpectedRuntime expected_runtime) = 0;
77
+
78
+ /**
79
+ * Schedules a task to be invoked on a foreground thread wrt a specific
80
+ * |isolate|. Tasks posted for the same isolate should be execute in order of
81
+ * scheduling. The definition of "foreground" is opaque to V8.
82
+ */
83
+ virtual void CallOnForegroundThread(Isolate* isolate, Task* task) = 0;
84
+
85
+ /**
86
+ * Schedules a task to be invoked on a foreground thread wrt a specific
87
+ * |isolate| after the given number of seconds |delay_in_seconds|.
88
+ * Tasks posted for the same isolate should be execute in order of
89
+ * scheduling. The definition of "foreground" is opaque to V8.
90
+ */
91
+ virtual void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
92
+ double delay_in_seconds) = 0;
93
+
94
+ /**
95
+ * Schedules a task to be invoked on a foreground thread wrt a specific
96
+ * |isolate| when the embedder is idle.
97
+ * Requires that SupportsIdleTasks(isolate) is true.
98
+ * Idle tasks may be reordered relative to other task types and may be
99
+ * starved for an arbitrarily long time if no idle time is available.
100
+ * The definition of "foreground" is opaque to V8.
101
+ */
102
+ virtual void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) {
103
+ // TODO(ulan): Make this function abstract after V8 roll in Chromium.
104
+ }
105
+
106
+ /**
107
+ * Returns true if idle tasks are enabled for the given |isolate|.
108
+ */
109
+ virtual bool IdleTasksEnabled(Isolate* isolate) {
110
+ // TODO(ulan): Make this function abstract after V8 roll in Chromium.
111
+ return false;
112
+ }
113
+
114
+ /**
115
+ * Monotonically increasing time in seconds from an arbitrary fixed point in
116
+ * the past. This function is expected to return at least
117
+ * millisecond-precision values. For this reason,
118
+ * it is recommended that the fixed point be no further in the past than
119
+ * the epoch.
120
+ **/
121
+ virtual double MonotonicallyIncreasingTime() = 0;
122
+
123
+ /**
124
+ * Called by TRACE_EVENT* macros, don't call this directly.
125
+ * The name parameter is a category group for example:
126
+ * TRACE_EVENT0("v8,parse", "V8.Parse")
127
+ * The pointer returned points to a value with zero or more of the bits
128
+ * defined in CategoryGroupEnabledFlags.
129
+ **/
130
+ virtual const uint8_t* GetCategoryGroupEnabled(const char* name) {
131
+ static uint8_t no = 0;
132
+ return &no;
133
+ }
134
+
135
+ /**
136
+ * Gets the category group name of the given category_enabled_flag pointer.
137
+ * Usually used while serliazing TRACE_EVENTs.
138
+ **/
139
+ virtual const char* GetCategoryGroupName(
140
+ const uint8_t* category_enabled_flag) {
141
+ static const char dummy[] = "dummy";
142
+ return dummy;
143
+ }
144
+
145
+ /**
146
+ * Adds a trace event to the platform tracing system. This function call is
147
+ * usually the result of a TRACE_* macro from trace_event_common.h when
148
+ * tracing and the category of the particular trace are enabled. It is not
149
+ * advisable to call this function on its own; it is really only meant to be
150
+ * used by the trace macros. The returned handle can be used by
151
+ * UpdateTraceEventDuration to update the duration of COMPLETE events.
152
+ */
153
+ virtual uint64_t AddTraceEvent(
154
+ char phase, const uint8_t* category_enabled_flag, const char* name,
155
+ const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
156
+ const char** arg_names, const uint8_t* arg_types,
157
+ const uint64_t* arg_values, unsigned int flags) {
158
+ return 0;
159
+ }
160
+
161
+ /**
162
+ * Sets the duration field of a COMPLETE trace event. It must be called with
163
+ * the handle returned from AddTraceEvent().
164
+ **/
165
+ virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
166
+ const char* name, uint64_t handle) {}
167
+ };
168
+
169
+ } // namespace v8
170
+
171
+ #endif // V8_V8_PLATFORM_H_
@@ -1,82 +1,72 @@
1
1
  // Copyright 2010 the V8 project authors. All rights reserved.
2
- // Redistribution and use in source and binary forms, with or without
3
- // modification, are permitted provided that the following conditions are
4
- // met:
5
- //
6
- // * Redistributions of source code must retain the above copyright
7
- // notice, this list of conditions and the following disclaimer.
8
- // * Redistributions in binary form must reproduce the above
9
- // copyright notice, this list of conditions and the following
10
- // disclaimer in the documentation and/or other materials provided
11
- // with the distribution.
12
- // * Neither the name of Google Inc. nor the names of its
13
- // contributors may be used to endorse or promote products derived
14
- // from this software without specific prior written permission.
15
- //
16
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
27
4
 
28
5
  #ifndef V8_V8_PROFILER_H_
29
6
  #define V8_V8_PROFILER_H_
30
7
 
31
- #include "v8.h"
8
+ #include <vector>
9
+ #include "v8.h" // NOLINT(build/include)
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
- Handle<String> GetFunctionName() const;
63
+ Local<String> GetFunctionName() const;
64
+
65
+ /** Returns id of the script where function is located. */
66
+ int GetScriptId() const;
77
67
 
78
68
  /** Returns resource name for script from where the function originates. */
79
- Handle<String> GetScriptResourceName() const;
69
+ Local<String> GetScriptResourceName() const;
80
70
 
81
71
  /**
82
72
  * Returns the number, 1-based, of the line where the function originates.
@@ -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
- Handle<String> GetTitle() const;
130
-
131
- /** Returns the root node of the bottom up call tree. */
132
- const CpuProfileNode* GetBottomUpRoot() const;
132
+ Local<String> GetTitle() const;
133
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,43 @@ 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(Local<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(Local<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
+ * Force collection of a sample. Must be called on the VM thread.
211
+ * Recording the forced sample does not contribute to the aggregated
212
+ * profile statistics.
201
213
  */
202
- static void DeleteAllProfiles();
203
- };
214
+ void CollectSample();
204
215
 
216
+ /**
217
+ * Tells the profiler whether the embedder is idle.
218
+ */
219
+ void SetIdle(bool is_idle);
205
220
 
206
- class HeapGraphNode;
221
+ private:
222
+ CpuProfiler();
223
+ ~CpuProfiler();
224
+ CpuProfiler(const CpuProfiler&);
225
+ CpuProfiler& operator=(const CpuProfiler&);
226
+ };
207
227
 
208
228
 
209
229
  /**
210
230
  * HeapSnapshotEdge represents a directed connection between heap
211
231
  * graph nodes: from retainers to retained nodes.
212
232
  */
213
- class V8EXPORT HeapGraphEdge {
233
+ class V8_EXPORT HeapGraphEdge {
214
234
  public:
215
235
  enum Type {
216
236
  kContextVariable = 0, // A variable from a function context.
@@ -233,7 +253,7 @@ class V8EXPORT HeapGraphEdge {
233
253
  * Returns edge name. This can be a variable name, an element index, or
234
254
  * a property name.
235
255
  */
236
- Handle<Value> GetName() const;
256
+ Local<Value> GetName() const;
237
257
 
238
258
  /** Returns origin node. */
239
259
  const HeapGraphNode* GetFromNode() const;
@@ -246,20 +266,24 @@ class V8EXPORT HeapGraphEdge {
246
266
  /**
247
267
  * HeapGraphNode represents a node in a heap graph.
248
268
  */
249
- class V8EXPORT HeapGraphNode {
269
+ class V8_EXPORT HeapGraphNode {
250
270
  public:
251
271
  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.
272
+ kHidden = 0, // Hidden node, may be filtered when shown to user.
273
+ kArray = 1, // An array of elements.
274
+ kString = 2, // A string.
275
+ kObject = 3, // A JS object (except for arrays and strings).
276
+ kCode = 4, // Compiled code.
277
+ kClosure = 5, // Function closure.
278
+ kRegExp = 6, // RegExp.
279
+ kHeapNumber = 7, // Number stored in the heap.
280
+ kNative = 8, // Native object (not from V8 heap).
281
+ kSynthetic = 9, // Synthetic object, usualy used for grouping
282
+ // snapshot items together.
283
+ kConsString = 10, // Concatenated string. A pair of pointers to strings.
284
+ kSlicedString = 11, // Sliced string. A fragment of another string.
285
+ kSymbol = 12, // A Symbol (ES6).
286
+ kSimdValue = 13 // A SIMD value stored in the heap (Proposed ES7).
263
287
  };
264
288
 
265
289
  /** Returns node type (see HeapGraphNode::Type). */
@@ -270,7 +294,7 @@ class V8EXPORT HeapGraphNode {
270
294
  * of the constructor (for objects), the name of the function (for
271
295
  * closures), string value, or an empty string (for compiled code).
272
296
  */
273
- Handle<String> GetName() const;
297
+ Local<String> GetName() const;
274
298
 
275
299
  /**
276
300
  * Returns node id. For the same heap object, the id remains the same
@@ -279,43 +303,56 @@ class V8EXPORT HeapGraphNode {
279
303
  SnapshotObjectId GetId() const;
280
304
 
281
305
  /** Returns node's own size, in bytes. */
282
- int GetSelfSize() const;
306
+ size_t GetShallowSize() const;
283
307
 
284
308
  /** Returns child nodes count of the node. */
285
309
  int GetChildrenCount() const;
286
310
 
287
311
  /** Retrieves a child by index. */
288
312
  const HeapGraphEdge* GetChild(int index) const;
313
+ };
314
+
289
315
 
316
+ /**
317
+ * An interface for exporting data from V8, using "push" model.
318
+ */
319
+ class V8_EXPORT OutputStream { // NOLINT
320
+ public:
321
+ enum WriteResult {
322
+ kContinue = 0,
323
+ kAbort = 1
324
+ };
325
+ virtual ~OutputStream() {}
326
+ /** Notify about the end of stream. */
327
+ virtual void EndOfStream() = 0;
328
+ /** Get preferred output chunk size. Called only once. */
329
+ virtual int GetChunkSize() { return 1024; }
330
+ /**
331
+ * Writes the next chunk of snapshot data into the stream. Writing
332
+ * can be stopped by returning kAbort as function result. EndOfStream
333
+ * will not be called in case writing was aborted.
334
+ */
335
+ virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
290
336
  /**
291
- * Finds and returns a value from the heap corresponding to this node,
292
- * if the value is still reachable.
337
+ * Writes the next chunk of heap stats data into the stream. Writing
338
+ * can be stopped by returning kAbort as function result. EndOfStream
339
+ * will not be called in case writing was aborted.
293
340
  */
294
- Handle<Value> GetHeapValue() const;
341
+ virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
342
+ return kAbort;
343
+ }
295
344
  };
296
345
 
297
346
 
298
347
  /**
299
348
  * HeapSnapshots record the state of the JS heap at some moment.
300
349
  */
301
- class V8EXPORT HeapSnapshot {
350
+ class V8_EXPORT HeapSnapshot {
302
351
  public:
303
- enum Type {
304
- kFull = 0 // Heap snapshot with all instances and references.
305
- };
306
352
  enum SerializationFormat {
307
353
  kJSON = 0 // See format description near 'Serialize' method.
308
354
  };
309
355
 
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
356
  /** Returns the root node of the heap graph. */
320
357
  const HeapGraphNode* GetRoot() const;
321
358
 
@@ -364,40 +401,158 @@ class V8EXPORT HeapSnapshot {
364
401
  * Nodes reference strings, other nodes, and edges by their indexes
365
402
  * in corresponding arrays.
366
403
  */
367
- void Serialize(OutputStream* stream, SerializationFormat format) const;
404
+ void Serialize(OutputStream* stream,
405
+ SerializationFormat format = kJSON) const;
368
406
  };
369
407
 
370
408
 
371
- class RetainedObjectInfo;
409
+ /**
410
+ * An interface for reporting progress and controlling long-running
411
+ * activities.
412
+ */
413
+ class V8_EXPORT ActivityControl { // NOLINT
414
+ public:
415
+ enum ControlOption {
416
+ kContinue = 0,
417
+ kAbort = 1
418
+ };
419
+ virtual ~ActivityControl() {}
420
+ /**
421
+ * Notify about current progress. The activity can be stopped by
422
+ * returning kAbort as the callback result.
423
+ */
424
+ virtual ControlOption ReportProgressValue(int done, int total) = 0;
425
+ };
426
+
372
427
 
373
428
  /**
374
- * Interface for controlling heap profiling.
429
+ * AllocationProfile is a sampled profile of allocations done by the program.
430
+ * This is structured as a call-graph.
375
431
  */
376
- class V8EXPORT HeapProfiler {
432
+ class V8_EXPORT AllocationProfile {
377
433
  public:
434
+ struct Allocation {
435
+ /**
436
+ * Size of the sampled allocation object.
437
+ */
438
+ size_t size;
439
+
440
+ /**
441
+ * The number of objects of such size that were sampled.
442
+ */
443
+ unsigned int count;
444
+ };
445
+
446
+ /**
447
+ * Represents a node in the call-graph.
448
+ */
449
+ struct Node {
450
+ /**
451
+ * Name of the function. May be empty for anonymous functions or if the
452
+ * script corresponding to this function has been unloaded.
453
+ */
454
+ Local<String> name;
455
+
456
+ /**
457
+ * Name of the script containing the function. May be empty if the script
458
+ * name is not available, or if the script has been unloaded.
459
+ */
460
+ Local<String> script_name;
461
+
462
+ /**
463
+ * id of the script where the function is located. May be equal to
464
+ * v8::UnboundScript::kNoScriptId in cases where the script doesn't exist.
465
+ */
466
+ int script_id;
467
+
468
+ /**
469
+ * Start position of the function in the script.
470
+ */
471
+ int start_position;
472
+
473
+ /**
474
+ * 1-indexed line number where the function starts. May be
475
+ * kNoLineNumberInfo if no line number information is available.
476
+ */
477
+ int line_number;
478
+
479
+ /**
480
+ * 1-indexed column number where the function starts. May be
481
+ * kNoColumnNumberInfo if no line number information is available.
482
+ */
483
+ int column_number;
484
+
485
+ /**
486
+ * List of callees called from this node for which we have sampled
487
+ * allocations. The lifetime of the children is scoped to the containing
488
+ * AllocationProfile.
489
+ */
490
+ std::vector<Node*> children;
491
+
492
+ /**
493
+ * List of self allocations done by this node in the call-graph.
494
+ */
495
+ std::vector<Allocation> allocations;
496
+ };
497
+
498
+ /**
499
+ * Returns the root node of the call-graph. The root node corresponds to an
500
+ * empty JS call-stack. The lifetime of the returned Node* is scoped to the
501
+ * containing AllocationProfile.
502
+ */
503
+ virtual Node* GetRootNode() = 0;
504
+
505
+ virtual ~AllocationProfile() {}
506
+
507
+ static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
508
+ static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
509
+ };
510
+
511
+
512
+ /**
513
+ * Interface for controlling heap profiling. Instance of the
514
+ * profiler can be retrieved using v8::Isolate::GetHeapProfiler.
515
+ */
516
+ class V8_EXPORT HeapProfiler {
517
+ public:
518
+ enum SamplingFlags {
519
+ kSamplingNoFlags = 0,
520
+ kSamplingForceGC = 1 << 0,
521
+ };
522
+
378
523
  /**
379
524
  * Callback function invoked for obtaining RetainedObjectInfo for
380
525
  * the given JavaScript wrapper object. It is prohibited to enter V8
381
526
  * while the callback is running: only getters on the handle and
382
527
  * GetPointerFromInternalField on the objects are allowed.
383
528
  */
384
- typedef RetainedObjectInfo* (*WrapperInfoCallback)
385
- (uint16_t class_id, Handle<Value> wrapper);
529
+ typedef RetainedObjectInfo* (*WrapperInfoCallback)(uint16_t class_id,
530
+ Local<Value> wrapper);
386
531
 
387
532
  /** Returns the number of snapshots taken. */
388
- static int GetSnapshotsCount();
533
+ int GetSnapshotCount();
389
534
 
390
535
  /** 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);
536
+ const HeapSnapshot* GetHeapSnapshot(int index);
395
537
 
396
538
  /**
397
539
  * Returns SnapshotObjectId for a heap object referenced by |value| if
398
540
  * it has been seen by the heap profiler, kUnknownObjectId otherwise.
399
541
  */
400
- static SnapshotObjectId GetSnapshotObjectId(Handle<Value> value);
542
+ SnapshotObjectId GetObjectId(Local<Value> value);
543
+
544
+ /**
545
+ * Returns heap object with given SnapshotObjectId if the object is alive,
546
+ * otherwise empty handle is returned.
547
+ */
548
+ Local<Value> FindObjectById(SnapshotObjectId id);
549
+
550
+ /**
551
+ * Clears internal map from SnapshotObjectId to heap object. The new objects
552
+ * will not be added into it unless a heap snapshot is taken or heap object
553
+ * tracking is kicked off.
554
+ */
555
+ void ClearObjectIds();
401
556
 
402
557
  /**
403
558
  * A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
@@ -410,23 +565,21 @@ class V8EXPORT HeapProfiler {
410
565
  * Callback interface for retrieving user friendly names of global objects.
411
566
  */
412
567
  class ObjectNameResolver {
413
- public:
568
+ public:
414
569
  /**
415
570
  * Returns name to be used in the heap snapshot for given node. Returned
416
571
  * string must stay alive until snapshot collection is completed.
417
572
  */
418
- virtual const char* GetName(Handle<Object> object) = 0;
419
- protected:
573
+ virtual const char* GetName(Local<Object> object) = 0;
574
+
575
+ protected:
420
576
  virtual ~ObjectNameResolver() {}
421
577
  };
422
578
 
423
579
  /**
424
- * Takes a heap snapshot and returns it. Title may be an empty string.
425
- * See HeapSnapshot::Type for types description.
580
+ * Takes a heap snapshot and returns it.
426
581
  */
427
- static const HeapSnapshot* TakeSnapshot(
428
- Handle<String> title,
429
- HeapSnapshot::Type type = HeapSnapshot::kFull,
582
+ const HeapSnapshot* TakeHeapSnapshot(
430
583
  ActivityControl* control = NULL,
431
584
  ObjectNameResolver* global_object_name_resolver = NULL);
432
585
 
@@ -434,8 +587,12 @@ class V8EXPORT HeapProfiler {
434
587
  * Starts tracking of heap objects population statistics. After calling
435
588
  * this method, all heap objects relocations done by the garbage collector
436
589
  * are being registered.
590
+ *
591
+ * |track_allocations| parameter controls whether stack trace of each
592
+ * allocation in the heap will be recorded and reported as part of
593
+ * HeapSnapshot.
437
594
  */
438
- static void StartHeapObjectsTracking();
595
+ void StartTrackingHeapObjects(bool track_allocations = false);
439
596
 
440
597
  /**
441
598
  * Adds a new time interval entry to the aggregated statistics array. The
@@ -444,28 +601,74 @@ class V8EXPORT HeapProfiler {
444
601
  * reports updates for all previous time intervals via the OutputStream
445
602
  * object. Updates on each time interval are provided as a stream of the
446
603
  * HeapStatsUpdate structure instances.
447
- * The return value of the function is the last seen heap object Id.
604
+ * If |timestamp_us| is supplied, timestamp of the new entry will be written
605
+ * into it. The return value of the function is the last seen heap object Id.
448
606
  *
449
- * StartHeapObjectsTracking must be called before the first call to this
607
+ * StartTrackingHeapObjects must be called before the first call to this
450
608
  * method.
451
609
  */
452
- static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
610
+ SnapshotObjectId GetHeapStats(OutputStream* stream,
611
+ int64_t* timestamp_us = NULL);
453
612
 
454
613
  /**
455
614
  * Stops tracking of heap objects population statistics, cleans up all
456
615
  * collected data. StartHeapObjectsTracking must be called again prior to
457
- * calling PushHeapObjectsStats next time.
616
+ * calling GetHeapStats next time.
617
+ */
618
+ void StopTrackingHeapObjects();
619
+
620
+ /**
621
+ * Starts gathering a sampling heap profile. A sampling heap profile is
622
+ * similar to tcmalloc's heap profiler and Go's mprof. It samples object
623
+ * allocations and builds an online 'sampling' heap profile. At any point in
624
+ * time, this profile is expected to be a representative sample of objects
625
+ * currently live in the system. Each sampled allocation includes the stack
626
+ * trace at the time of allocation, which makes this really useful for memory
627
+ * leak detection.
628
+ *
629
+ * This mechanism is intended to be cheap enough that it can be used in
630
+ * production with minimal performance overhead.
631
+ *
632
+ * Allocations are sampled using a randomized Poisson process. On average, one
633
+ * allocation will be sampled every |sample_interval| bytes allocated. The
634
+ * |stack_depth| parameter controls the maximum number of stack frames to be
635
+ * captured on each allocation.
636
+ *
637
+ * NOTE: This is a proof-of-concept at this point. Right now we only sample
638
+ * newspace allocations. Support for paged space allocation (e.g. pre-tenured
639
+ * objects, large objects, code objects, etc.) and native allocations
640
+ * doesn't exist yet, but is anticipated in the future.
641
+ *
642
+ * Objects allocated before the sampling is started will not be included in
643
+ * the profile.
644
+ *
645
+ * Returns false if a sampling heap profiler is already running.
646
+ */
647
+ bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024,
648
+ int stack_depth = 16,
649
+ SamplingFlags flags = kSamplingNoFlags);
650
+
651
+ /**
652
+ * Stops the sampling heap profile and discards the current profile.
653
+ */
654
+ void StopSamplingHeapProfiler();
655
+
656
+ /**
657
+ * Returns the sampled profile of allocations allocated (and still live) since
658
+ * StartSamplingHeapProfiler was called. The ownership of the pointer is
659
+ * transfered to the caller. Returns nullptr if sampling heap profiler is not
660
+ * active.
458
661
  */
459
- static void StopHeapObjectsTracking();
662
+ AllocationProfile* GetAllocationProfile();
460
663
 
461
664
  /**
462
665
  * Deletes all snapshots taken. All previously returned pointers to
463
666
  * snapshots and their contents become invalid after this call.
464
667
  */
465
- static void DeleteAllSnapshots();
668
+ void DeleteAllHeapSnapshots();
466
669
 
467
670
  /** Binds a callback to embedder's class ID. */
468
- static void DefineWrapperClass(
671
+ void SetWrapperClassInfoProvider(
469
672
  uint16_t class_id,
470
673
  WrapperInfoCallback callback);
471
674
 
@@ -476,13 +679,20 @@ class V8EXPORT HeapProfiler {
476
679
  */
477
680
  static const uint16_t kPersistentHandleNoClassId = 0;
478
681
 
479
- /** Returns the number of currently existing persistent handles. */
480
- static int GetPersistentHandleCount();
481
-
482
682
  /** Returns memory used for profiler internal data and snapshots. */
483
- static size_t GetMemorySizeUsedByProfiler();
484
- };
683
+ size_t GetProfilerMemorySize();
684
+
685
+ /**
686
+ * Sets a RetainedObjectInfo for an object group (see V8::SetObjectGroupId).
687
+ */
688
+ void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
485
689
 
690
+ private:
691
+ HeapProfiler();
692
+ ~HeapProfiler();
693
+ HeapProfiler(const HeapProfiler&);
694
+ HeapProfiler& operator=(const HeapProfiler&);
695
+ };
486
696
 
487
697
  /**
488
698
  * Interface for providing information about embedder's objects
@@ -498,17 +708,17 @@ class V8EXPORT HeapProfiler {
498
708
  * were not previously reported via AddObjectGroup.
499
709
  *
500
710
  * Thus, if an embedder wants to provide information about native
501
- * objects for heap snapshots, he can do it in a GC prologue
711
+ * objects for heap snapshots, it can do it in a GC prologue
502
712
  * handler, and / or by assigning wrapper class ids in the following way:
503
713
  *
504
- * 1. Bind a callback to class id by calling DefineWrapperClass.
714
+ * 1. Bind a callback to class id by calling SetWrapperClassInfoProvider.
505
715
  * 2. Call SetWrapperClassId on certain persistent handles.
506
716
  *
507
717
  * V8 takes ownership of RetainedObjectInfo instances passed to it and
508
718
  * keeps them alive only during snapshot collection. Afterwards, they
509
719
  * are freed by calling the Dispose class function.
510
720
  */
511
- class V8EXPORT RetainedObjectInfo { // NOLINT
721
+ class V8_EXPORT RetainedObjectInfo { // NOLINT
512
722
  public:
513
723
  /** Called by V8 when it no longer needs an instance. */
514
724
  virtual void Dispose() = 0;
@@ -560,7 +770,7 @@ class V8EXPORT RetainedObjectInfo { // NOLINT
560
770
 
561
771
  /**
562
772
  * A struct for exporting HeapStats data from V8, using "push" model.
563
- * See HeapProfiler::PushHeapObjectsStats.
773
+ * See HeapProfiler::GetHeapStats.
564
774
  */
565
775
  struct HeapStatsUpdate {
566
776
  HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
@@ -574,7 +784,4 @@ struct HeapStatsUpdate {
574
784
  } // namespace v8
575
785
 
576
786
 
577
- #undef V8EXPORT
578
-
579
-
580
787
  #endif // V8_V8_PROFILER_H_