@@ -30,6 +30,7 @@ using v8::Array;
30
30
using v8::ArrayBuffer;
31
31
using v8::Context;
32
32
using v8::FunctionCallbackInfo;
33
+ using v8::HeapCodeStatistics;
33
34
using v8::HeapSpaceStatistics;
34
35
using v8::HeapStatistics;
35
36
using v8::Integer;
@@ -43,6 +44,7 @@ using v8::Uint32;
43
44
using v8::V8;
44
45
using v8::Value;
45
46
47
+
46
48
#define HEAP_STATISTICS_PROPERTIES (V ) \
47
49
V (0 , total_heap_size, kTotalHeapSizeIndex ) \
48
50
V (1 , total_heap_size_executable, kTotalHeapSizeExecutableIndex ) \
@@ -61,6 +63,7 @@ static const size_t kHeapStatisticsPropertiesCount =
61
63
HEAP_STATISTICS_PROPERTIES (V);
62
64
#undef V
63
65
66
+
64
67
#define HEAP_SPACE_STATISTICS_PROPERTIES (V ) \
65
68
V (0 , space_size, kSpaceSizeIndex ) \
66
69
V (1 , space_used_size, kSpaceUsedSizeIndex ) \
@@ -73,6 +76,16 @@ static const size_t kHeapSpaceStatisticsPropertiesCount =
73
76
#undef V
74
77
75
78
79
+ #define HEAP_CODE_STATISTICS_PROPERTIES (V ) \
80
+ V (0 , code_and_metadata_size, kCodeAndMetadataSizeIndex ) \
81
+ V (1 , bytecode_and_metadata_size, kBytecodeAndMetadataSizeIndex ) \
82
+ V (2 , external_script_source_size, kExternalScriptSourceSizeIndex )
83
+
84
+ #define V (a, b, c ) +1
85
+ static const size_t kHeapCodeStatisticsPropertiesCount =
86
+ HEAP_CODE_STATISTICS_PROPERTIES (V);
87
+ #undef V
88
+
76
89
void CachedDataVersionTag (const FunctionCallbackInfo<Value>& args) {
77
90
Environment* env = Environment::GetCurrent (args);
78
91
Local<Integer> result =
@@ -111,6 +124,18 @@ void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo<Value>& args) {
111
124
}
112
125
113
126
127
+ void UpdateHeapCodeStatisticsArrayBuffer (
128
+ const FunctionCallbackInfo<Value>& args) {
129
+ Environment* env = Environment::GetCurrent (args);
130
+ HeapCodeStatistics s;
131
+ env->isolate ()->GetHeapCodeAndMetadataStatistics (&s);
132
+ double * const buffer = env->heap_code_statistics_buffer ();
133
+ #define V (index, name, _ ) buffer[index] = static_cast <double >(s.name());
134
+ HEAP_CODE_STATISTICS_PROPERTIES (V)
135
+ #undef V
136
+ }
137
+
138
+
114
139
void SetFlagsFromString (const FunctionCallbackInfo<Value>& args) {
115
140
CHECK (args[0 ]->IsString ());
116
141
String::Utf8Value flags (args.GetIsolate (), args[0 ]);
@@ -127,6 +152,7 @@ void Initialize(Local<Object> target,
127
152
env->SetMethodNoSideEffect (target, " cachedDataVersionTag" ,
128
153
CachedDataVersionTag);
129
154
155
+ // Export symbols used by v8.getHeapStatistics()
130
156
env->SetMethod (target,
131
157
" updateHeapStatisticsArrayBuffer" ,
132
158
UpdateHeapStatisticsArrayBuffer);
@@ -151,6 +177,35 @@ void Initialize(Local<Object> target,
151
177
HEAP_STATISTICS_PROPERTIES (V)
152
178
#undef V
153
179
180
+ // Export symbols used by v8.getHeapCodeStatistics()
181
+ env->SetMethod (target,
182
+ " updateHeapCodeStatisticsArrayBuffer" ,
183
+ UpdateHeapCodeStatisticsArrayBuffer);
184
+
185
+ env->set_heap_code_statistics_buffer (
186
+ new double [kHeapCodeStatisticsPropertiesCount ]);
187
+
188
+ const size_t heap_code_statistics_buffer_byte_length =
189
+ sizeof (*env->heap_code_statistics_buffer ())
190
+ * kHeapCodeStatisticsPropertiesCount ;
191
+
192
+ target->Set (env->context (),
193
+ FIXED_ONE_BYTE_STRING (env->isolate (),
194
+ " heapCodeStatisticsArrayBuffer" ),
195
+ ArrayBuffer::New (env->isolate (),
196
+ env->heap_code_statistics_buffer (),
197
+ heap_code_statistics_buffer_byte_length))
198
+ .Check ();
199
+
200
+ #define V (i, _, name ) \
201
+ target->Set (env->context (), \
202
+ FIXED_ONE_BYTE_STRING (env->isolate (), #name), \
203
+ Uint32::NewFromUnsigned (env->isolate (), i)).Check ();
204
+
205
+ HEAP_CODE_STATISTICS_PROPERTIES (V)
206
+ #undef V
207
+
208
+ // Export symbols used by v8.getHeapSpaceStatistics()
154
209
target->Set (env->context (),
155
210
FIXED_ONE_BYTE_STRING (env->isolate (),
156
211
" kHeapSpaceStatisticsPropertiesCount" ),
@@ -205,6 +260,7 @@ void Initialize(Local<Object> target,
205
260
HEAP_SPACE_STATISTICS_PROPERTIES (V)
206
261
#undef V
207
262
263
+ // Export symbols used by v8.setFlagsFromString()
208
264
env->SetMethod (target, " setFlagsFromString" , SetFlagsFromString);
209
265
}
210
266
0 commit comments