OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 if (node->GetType() == v8::HeapGraphNode::kString) { | 120 if (node->GetType() == v8::HeapGraphNode::kString) { |
121 v8::String::AsciiValue node_name(node->GetName()); | 121 v8::String::AsciiValue node_name(node->GetName()); |
122 if (strcmp(contents, *node_name) == 0) return true; | 122 if (strcmp(contents, *node_name) == 0) return true; |
123 } | 123 } |
124 } | 124 } |
125 return false; | 125 return false; |
126 } | 126 } |
127 | 127 |
128 | 128 |
129 TEST(HeapSnapshot) { | 129 TEST(HeapSnapshot) { |
130 v8::HandleScope scope; | |
131 LocalContext env2; | 130 LocalContext env2; |
| 131 v8::HandleScope scope(env2->GetIsolate()); |
132 | 132 |
133 CompileRun( | 133 CompileRun( |
134 "function A2() {}\n" | 134 "function A2() {}\n" |
135 "function B2(x) { return function() { return typeof x; }; }\n" | 135 "function B2(x) { return function() { return typeof x; }; }\n" |
136 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" | 136 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" |
137 "var a2 = new A2();\n" | 137 "var a2 = new A2();\n" |
138 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" | 138 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" |
139 "var c2 = new C2(a2);"); | 139 "var c2 = new C2(a2);"); |
140 const v8::HeapSnapshot* snapshot_env2 = | 140 const v8::HeapSnapshot* snapshot_env2 = |
141 v8::HeapProfiler::TakeSnapshot(v8_str("env2")); | 141 v8::HeapProfiler::TakeSnapshot(v8_str("env2")); |
(...skipping 12 matching lines...) Expand all Loading... |
154 NamedEntriesDetector det; | 154 NamedEntriesDetector det; |
155 det.CheckAllReachables(const_cast<i::HeapEntry*>( | 155 det.CheckAllReachables(const_cast<i::HeapEntry*>( |
156 reinterpret_cast<const i::HeapEntry*>(global_env2))); | 156 reinterpret_cast<const i::HeapEntry*>(global_env2))); |
157 CHECK(det.has_A2); | 157 CHECK(det.has_A2); |
158 CHECK(det.has_B2); | 158 CHECK(det.has_B2); |
159 CHECK(det.has_C2); | 159 CHECK(det.has_C2); |
160 } | 160 } |
161 | 161 |
162 | 162 |
163 TEST(HeapSnapshotObjectSizes) { | 163 TEST(HeapSnapshotObjectSizes) { |
164 v8::HandleScope scope; | |
165 LocalContext env; | 164 LocalContext env; |
| 165 v8::HandleScope scope(env->GetIsolate()); |
166 | 166 |
167 // -a-> X1 --a | 167 // -a-> X1 --a |
168 // x -b-> X2 <-| | 168 // x -b-> X2 <-| |
169 CompileRun( | 169 CompileRun( |
170 "function X(a, b) { this.a = a; this.b = b; }\n" | 170 "function X(a, b) { this.a = a; this.b = b; }\n" |
171 "x = new X(new X(), new X());\n" | 171 "x = new X(new X(), new X());\n" |
172 "dummy = new X();\n" | 172 "dummy = new X();\n" |
173 "(function() { x.a.a = x.b; })();"); | 173 "(function() { x.a.a = x.b; })();"); |
174 const v8::HeapSnapshot* snapshot = | 174 const v8::HeapSnapshot* snapshot = |
175 v8::HeapProfiler::TakeSnapshot(v8_str("sizes")); | 175 v8::HeapProfiler::TakeSnapshot(v8_str("sizes")); |
176 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 176 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
177 const v8::HeapGraphNode* x = | 177 const v8::HeapGraphNode* x = |
178 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); | 178 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); |
179 CHECK_NE(NULL, x); | 179 CHECK_NE(NULL, x); |
180 const v8::HeapGraphNode* x1 = | 180 const v8::HeapGraphNode* x1 = |
181 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); | 181 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); |
182 CHECK_NE(NULL, x1); | 182 CHECK_NE(NULL, x1); |
183 const v8::HeapGraphNode* x2 = | 183 const v8::HeapGraphNode* x2 = |
184 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); | 184 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); |
185 CHECK_NE(NULL, x2); | 185 CHECK_NE(NULL, x2); |
186 | 186 |
187 // Test sizes. | 187 // Test sizes. |
188 CHECK_NE(0, x->GetSelfSize()); | 188 CHECK_NE(0, x->GetSelfSize()); |
189 CHECK_NE(0, x1->GetSelfSize()); | 189 CHECK_NE(0, x1->GetSelfSize()); |
190 CHECK_NE(0, x2->GetSelfSize()); | 190 CHECK_NE(0, x2->GetSelfSize()); |
191 } | 191 } |
192 | 192 |
193 | 193 |
194 TEST(BoundFunctionInSnapshot) { | 194 TEST(BoundFunctionInSnapshot) { |
195 v8::HandleScope scope; | |
196 LocalContext env; | 195 LocalContext env; |
| 196 v8::HandleScope scope(env->GetIsolate()); |
197 CompileRun( | 197 CompileRun( |
198 "function myFunction(a, b) { this.a = a; this.b = b; }\n" | 198 "function myFunction(a, b) { this.a = a; this.b = b; }\n" |
199 "function AAAAA() {}\n" | 199 "function AAAAA() {}\n" |
200 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); | 200 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); |
201 const v8::HeapSnapshot* snapshot = | 201 const v8::HeapSnapshot* snapshot = |
202 v8::HeapProfiler::TakeSnapshot(v8_str("sizes")); | 202 v8::HeapProfiler::TakeSnapshot(v8_str("sizes")); |
203 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 203 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
204 const v8::HeapGraphNode* f = | 204 const v8::HeapGraphNode* f = |
205 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction"); | 205 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction"); |
206 CHECK(f); | 206 CHECK(f); |
(...skipping 15 matching lines...) Expand all Loading... |
222 CHECK_EQ(v8::HeapGraphNode::kClosure, bound_function->GetType()); | 222 CHECK_EQ(v8::HeapGraphNode::kClosure, bound_function->GetType()); |
223 | 223 |
224 const v8::HeapGraphNode* bound_argument = GetProperty( | 224 const v8::HeapGraphNode* bound_argument = GetProperty( |
225 f, v8::HeapGraphEdge::kShortcut, "bound_argument_1"); | 225 f, v8::HeapGraphEdge::kShortcut, "bound_argument_1"); |
226 CHECK(bound_argument); | 226 CHECK(bound_argument); |
227 CHECK_EQ(v8::HeapGraphNode::kObject, bound_argument->GetType()); | 227 CHECK_EQ(v8::HeapGraphNode::kObject, bound_argument->GetType()); |
228 } | 228 } |
229 | 229 |
230 | 230 |
231 TEST(HeapSnapshotEntryChildren) { | 231 TEST(HeapSnapshotEntryChildren) { |
232 v8::HandleScope scope; | |
233 LocalContext env; | 232 LocalContext env; |
| 233 v8::HandleScope scope(env->GetIsolate()); |
234 | 234 |
235 CompileRun( | 235 CompileRun( |
236 "function A() { }\n" | 236 "function A() { }\n" |
237 "a = new A;"); | 237 "a = new A;"); |
238 const v8::HeapSnapshot* snapshot = | 238 const v8::HeapSnapshot* snapshot = |
239 v8::HeapProfiler::TakeSnapshot(v8_str("children")); | 239 v8::HeapProfiler::TakeSnapshot(v8_str("children")); |
240 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 240 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
241 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { | 241 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { |
242 const v8::HeapGraphEdge* prop = global->GetChild(i); | 242 const v8::HeapGraphEdge* prop = global->GetChild(i); |
243 CHECK_EQ(global, prop->GetFromNode()); | 243 CHECK_EQ(global, prop->GetFromNode()); |
244 } | 244 } |
245 const v8::HeapGraphNode* a = | 245 const v8::HeapGraphNode* a = |
246 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); | 246 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); |
247 CHECK_NE(NULL, a); | 247 CHECK_NE(NULL, a); |
248 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) { | 248 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) { |
249 const v8::HeapGraphEdge* prop = a->GetChild(i); | 249 const v8::HeapGraphEdge* prop = a->GetChild(i); |
250 CHECK_EQ(a, prop->GetFromNode()); | 250 CHECK_EQ(a, prop->GetFromNode()); |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
254 | 254 |
255 TEST(HeapSnapshotCodeObjects) { | 255 TEST(HeapSnapshotCodeObjects) { |
256 v8::HandleScope scope; | |
257 LocalContext env; | 256 LocalContext env; |
| 257 v8::HandleScope scope(env->GetIsolate()); |
258 | 258 |
259 CompileRun( | 259 CompileRun( |
260 "function lazy(x) { return x - 1; }\n" | 260 "function lazy(x) { return x - 1; }\n" |
261 "function compiled(x) { return x + 1; }\n" | 261 "function compiled(x) { return x + 1; }\n" |
262 "var anonymous = (function() { return function() { return 0; } })();\n" | 262 "var anonymous = (function() { return function() { return 0; } })();\n" |
263 "compiled(1)"); | 263 "compiled(1)"); |
264 const v8::HeapSnapshot* snapshot = | 264 const v8::HeapSnapshot* snapshot = |
265 v8::HeapProfiler::TakeSnapshot(v8_str("code")); | 265 v8::HeapProfiler::TakeSnapshot(v8_str("code")); |
266 | 266 |
267 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 267 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 break; | 311 break; |
312 } | 312 } |
313 } | 313 } |
314 } | 314 } |
315 CHECK(compiled_references_x); | 315 CHECK(compiled_references_x); |
316 CHECK(!lazy_references_x); | 316 CHECK(!lazy_references_x); |
317 } | 317 } |
318 | 318 |
319 | 319 |
320 TEST(HeapSnapshotHeapNumbers) { | 320 TEST(HeapSnapshotHeapNumbers) { |
321 v8::HandleScope scope; | |
322 LocalContext env; | 321 LocalContext env; |
| 322 v8::HandleScope scope(env->GetIsolate()); |
323 CompileRun( | 323 CompileRun( |
324 "a = 1; // a is Smi\n" | 324 "a = 1; // a is Smi\n" |
325 "b = 2.5; // b is HeapNumber"); | 325 "b = 2.5; // b is HeapNumber"); |
326 const v8::HeapSnapshot* snapshot = | 326 const v8::HeapSnapshot* snapshot = |
327 v8::HeapProfiler::TakeSnapshot(v8_str("numbers")); | 327 v8::HeapProfiler::TakeSnapshot(v8_str("numbers")); |
328 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 328 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
329 CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a")); | 329 CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a")); |
330 const v8::HeapGraphNode* b = | 330 const v8::HeapGraphNode* b = |
331 GetProperty(global, v8::HeapGraphEdge::kProperty, "b"); | 331 GetProperty(global, v8::HeapGraphEdge::kProperty, "b"); |
332 CHECK_NE(NULL, b); | 332 CHECK_NE(NULL, b); |
333 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType()); | 333 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType()); |
334 } | 334 } |
335 | 335 |
336 TEST(HeapSnapshotSlicedString) { | 336 TEST(HeapSnapshotSlicedString) { |
337 v8::HandleScope scope; | |
338 LocalContext env; | 337 LocalContext env; |
| 338 v8::HandleScope scope(env->GetIsolate()); |
339 CompileRun( | 339 CompileRun( |
340 "parent_string = \"123456789.123456789.123456789.123456789.123456789." | 340 "parent_string = \"123456789.123456789.123456789.123456789.123456789." |
341 "123456789.123456789.123456789.123456789.123456789." | 341 "123456789.123456789.123456789.123456789.123456789." |
342 "123456789.123456789.123456789.123456789.123456789." | 342 "123456789.123456789.123456789.123456789.123456789." |
343 "123456789.123456789.123456789.123456789.123456789.\";" | 343 "123456789.123456789.123456789.123456789.123456789.\";" |
344 "child_string = parent_string.slice(100);"); | 344 "child_string = parent_string.slice(100);"); |
345 const v8::HeapSnapshot* snapshot = | 345 const v8::HeapSnapshot* snapshot = |
346 v8::HeapProfiler::TakeSnapshot(v8_str("strings")); | 346 v8::HeapProfiler::TakeSnapshot(v8_str("strings")); |
347 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 347 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
348 const v8::HeapGraphNode* parent_string = | 348 const v8::HeapGraphNode* parent_string = |
349 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string"); | 349 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string"); |
350 CHECK_NE(NULL, parent_string); | 350 CHECK_NE(NULL, parent_string); |
351 const v8::HeapGraphNode* child_string = | 351 const v8::HeapGraphNode* child_string = |
352 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string"); | 352 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string"); |
353 CHECK_NE(NULL, child_string); | 353 CHECK_NE(NULL, child_string); |
354 const v8::HeapGraphNode* parent = | 354 const v8::HeapGraphNode* parent = |
355 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); | 355 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); |
356 CHECK_EQ(parent_string, parent); | 356 CHECK_EQ(parent_string, parent); |
357 } | 357 } |
358 | 358 |
359 TEST(HeapSnapshotInternalReferences) { | 359 TEST(HeapSnapshotInternalReferences) { |
360 v8::HandleScope scope; | 360 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
361 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 361 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
362 global_template->SetInternalFieldCount(2); | 362 global_template->SetInternalFieldCount(2); |
363 LocalContext env(NULL, global_template); | 363 LocalContext env(NULL, global_template); |
364 v8::Handle<v8::Object> global_proxy = env->Global(); | 364 v8::Handle<v8::Object> global_proxy = env->Global(); |
365 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 365 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
366 CHECK_EQ(2, global->InternalFieldCount()); | 366 CHECK_EQ(2, global->InternalFieldCount()); |
367 v8::Local<v8::Object> obj = v8::Object::New(); | 367 v8::Local<v8::Object> obj = v8::Object::New(); |
368 global->SetInternalField(0, v8_num(17)); | 368 global->SetInternalField(0, v8_num(17)); |
369 global->SetInternalField(1, obj); | 369 global->SetInternalField(1, obj); |
370 const v8::HeapSnapshot* snapshot = | 370 const v8::HeapSnapshot* snapshot = |
371 v8::HeapProfiler::TakeSnapshot(v8_str("internals")); | 371 v8::HeapProfiler::TakeSnapshot(v8_str("internals")); |
372 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); | 372 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); |
373 // The first reference will not present, because it's a Smi. | 373 // The first reference will not present, because it's a Smi. |
374 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); | 374 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); |
375 // The second reference is to an object. | 375 // The second reference is to an object. |
376 CHECK_NE(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1")); | 376 CHECK_NE(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1")); |
377 } | 377 } |
378 | 378 |
379 | 379 |
380 // Trying to introduce a check helper for uint32_t causes many | 380 // Trying to introduce a check helper for uint32_t causes many |
381 // overloading ambiguities, so it seems easier just to cast | 381 // overloading ambiguities, so it seems easier just to cast |
382 // them to a signed type. | 382 // them to a signed type. |
383 #define CHECK_EQ_SNAPSHOT_OBJECT_ID(a, b) \ | 383 #define CHECK_EQ_SNAPSHOT_OBJECT_ID(a, b) \ |
384 CHECK_EQ(static_cast<int32_t>(a), static_cast<int32_t>(b)) | 384 CHECK_EQ(static_cast<int32_t>(a), static_cast<int32_t>(b)) |
385 #define CHECK_NE_SNAPSHOT_OBJECT_ID(a, b) \ | 385 #define CHECK_NE_SNAPSHOT_OBJECT_ID(a, b) \ |
386 CHECK((a) != (b)) // NOLINT | 386 CHECK((a) != (b)) // NOLINT |
387 | 387 |
388 TEST(HeapSnapshotAddressReuse) { | 388 TEST(HeapSnapshotAddressReuse) { |
389 v8::HandleScope scope; | |
390 LocalContext env; | 389 LocalContext env; |
| 390 v8::HandleScope scope(env->GetIsolate()); |
391 | 391 |
392 CompileRun( | 392 CompileRun( |
393 "function A() {}\n" | 393 "function A() {}\n" |
394 "var a = [];\n" | 394 "var a = [];\n" |
395 "for (var i = 0; i < 10000; ++i)\n" | 395 "for (var i = 0; i < 10000; ++i)\n" |
396 " a[i] = new A();\n"); | 396 " a[i] = new A();\n"); |
397 const v8::HeapSnapshot* snapshot1 = | 397 const v8::HeapSnapshot* snapshot1 = |
398 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot1")); | 398 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot1")); |
399 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); | 399 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); |
400 | 400 |
(...skipping 16 matching lines...) Expand all Loading... |
417 continue; | 417 continue; |
418 v8::SnapshotObjectId id = prop->GetToNode()->GetId(); | 418 v8::SnapshotObjectId id = prop->GetToNode()->GetId(); |
419 if (id < maxId1) | 419 if (id < maxId1) |
420 ++wrong_count; | 420 ++wrong_count; |
421 } | 421 } |
422 CHECK_EQ(0, wrong_count); | 422 CHECK_EQ(0, wrong_count); |
423 } | 423 } |
424 | 424 |
425 | 425 |
426 TEST(HeapEntryIdsAndArrayShift) { | 426 TEST(HeapEntryIdsAndArrayShift) { |
427 v8::HandleScope scope; | |
428 LocalContext env; | 427 LocalContext env; |
| 428 v8::HandleScope scope(env->GetIsolate()); |
429 | 429 |
430 CompileRun( | 430 CompileRun( |
431 "function AnObject() {\n" | 431 "function AnObject() {\n" |
432 " this.first = 'first';\n" | 432 " this.first = 'first';\n" |
433 " this.second = 'second';\n" | 433 " this.second = 'second';\n" |
434 "}\n" | 434 "}\n" |
435 "var a = new Array();\n" | 435 "var a = new Array();\n" |
436 "for (var i = 0; i < 10; ++i)\n" | 436 "for (var i = 0; i < 10; ++i)\n" |
437 " a.push(new AnObject());\n"); | 437 " a.push(new AnObject());\n"); |
438 const v8::HeapSnapshot* snapshot1 = | 438 const v8::HeapSnapshot* snapshot1 = |
(...skipping 24 matching lines...) Expand all Loading... |
463 CHECK_NE(NULL, a2); | 463 CHECK_NE(NULL, a2); |
464 const v8::HeapGraphNode* k2 = | 464 const v8::HeapGraphNode* k2 = |
465 GetProperty(a2, v8::HeapGraphEdge::kInternal, "elements"); | 465 GetProperty(a2, v8::HeapGraphEdge::kInternal, "elements"); |
466 CHECK_NE(NULL, k2); | 466 CHECK_NE(NULL, k2); |
467 | 467 |
468 CHECK_EQ_SNAPSHOT_OBJECT_ID(a1->GetId(), a2->GetId()); | 468 CHECK_EQ_SNAPSHOT_OBJECT_ID(a1->GetId(), a2->GetId()); |
469 CHECK_EQ_SNAPSHOT_OBJECT_ID(k1->GetId(), k2->GetId()); | 469 CHECK_EQ_SNAPSHOT_OBJECT_ID(k1->GetId(), k2->GetId()); |
470 } | 470 } |
471 | 471 |
472 TEST(HeapEntryIdsAndGC) { | 472 TEST(HeapEntryIdsAndGC) { |
473 v8::HandleScope scope; | |
474 LocalContext env; | 473 LocalContext env; |
| 474 v8::HandleScope scope(env->GetIsolate()); |
475 | 475 |
476 CompileRun( | 476 CompileRun( |
477 "function A() {}\n" | 477 "function A() {}\n" |
478 "function B(x) { this.x = x; }\n" | 478 "function B(x) { this.x = x; }\n" |
479 "var a = new A();\n" | 479 "var a = new A();\n" |
480 "var b = new B(a);"); | 480 "var b = new B(a);"); |
481 v8::Local<v8::String> s1_str = v8_str("s1"); | 481 v8::Local<v8::String> s1_str = v8_str("s1"); |
482 v8::Local<v8::String> s2_str = v8_str("s2"); | 482 v8::Local<v8::String> s2_str = v8_str("s2"); |
483 const v8::HeapSnapshot* snapshot1 = | 483 const v8::HeapSnapshot* snapshot1 = |
484 v8::HeapProfiler::TakeSnapshot(s1_str); | 484 v8::HeapProfiler::TakeSnapshot(s1_str); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 CHECK_NE(NULL, b1); | 525 CHECK_NE(NULL, b1); |
526 const v8::HeapGraphNode* b2 = | 526 const v8::HeapGraphNode* b2 = |
527 GetProperty(global2, v8::HeapGraphEdge::kProperty, "b"); | 527 GetProperty(global2, v8::HeapGraphEdge::kProperty, "b"); |
528 CHECK_NE(NULL, b2); | 528 CHECK_NE(NULL, b2); |
529 CHECK_NE_SNAPSHOT_OBJECT_ID(0, b1->GetId()); | 529 CHECK_NE_SNAPSHOT_OBJECT_ID(0, b1->GetId()); |
530 CHECK_EQ_SNAPSHOT_OBJECT_ID(b1->GetId(), b2->GetId()); | 530 CHECK_EQ_SNAPSHOT_OBJECT_ID(b1->GetId(), b2->GetId()); |
531 } | 531 } |
532 | 532 |
533 | 533 |
534 TEST(HeapSnapshotRootPreservedAfterSorting) { | 534 TEST(HeapSnapshotRootPreservedAfterSorting) { |
535 v8::HandleScope scope; | |
536 LocalContext env; | 535 LocalContext env; |
| 536 v8::HandleScope scope(env->GetIsolate()); |
537 const v8::HeapSnapshot* snapshot = | 537 const v8::HeapSnapshot* snapshot = |
538 v8::HeapProfiler::TakeSnapshot(v8_str("s")); | 538 v8::HeapProfiler::TakeSnapshot(v8_str("s")); |
539 const v8::HeapGraphNode* root1 = snapshot->GetRoot(); | 539 const v8::HeapGraphNode* root1 = snapshot->GetRoot(); |
540 const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>( | 540 const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>( |
541 snapshot))->GetSortedEntriesList(); | 541 snapshot))->GetSortedEntriesList(); |
542 const v8::HeapGraphNode* root2 = snapshot->GetRoot(); | 542 const v8::HeapGraphNode* root2 = snapshot->GetRoot(); |
543 CHECK_EQ(root1, root2); | 543 CHECK_EQ(root1, root2); |
544 } | 544 } |
545 | 545 |
546 | 546 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 virtual const char* data() const { return data_; } | 583 virtual const char* data() const { return data_; } |
584 virtual size_t length() const { return length_; } | 584 virtual size_t length() const { return length_; } |
585 private: | 585 private: |
586 const char* data_; | 586 const char* data_; |
587 size_t length_; | 587 size_t length_; |
588 }; | 588 }; |
589 | 589 |
590 } // namespace | 590 } // namespace |
591 | 591 |
592 TEST(HeapSnapshotJSONSerialization) { | 592 TEST(HeapSnapshotJSONSerialization) { |
593 v8::HandleScope scope; | |
594 LocalContext env; | 593 LocalContext env; |
| 594 v8::HandleScope scope(env->GetIsolate()); |
595 | 595 |
596 #define STRING_LITERAL_FOR_TEST \ | 596 #define STRING_LITERAL_FOR_TEST \ |
597 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" | 597 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" |
598 CompileRun( | 598 CompileRun( |
599 "function A(s) { this.s = s; }\n" | 599 "function A(s) { this.s = s; }\n" |
600 "function B(x) { this.x = x; }\n" | 600 "function B(x) { this.x = x; }\n" |
601 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n" | 601 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n" |
602 "var b = new B(a);"); | 602 "var b = new B(a);"); |
603 const v8::HeapSnapshot* snapshot = | 603 const v8::HeapSnapshot* snapshot = |
604 v8::HeapProfiler::TakeSnapshot(v8_str("json")); | 604 v8::HeapProfiler::TakeSnapshot(v8_str("json")); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 v8::Local<v8::String> string = strings_array->Get(string_index)->ToString(); | 685 v8::Local<v8::String> string = strings_array->Get(string_index)->ToString(); |
686 v8::Local<v8::String> ref_string = | 686 v8::Local<v8::String> ref_string = |
687 CompileRun(STRING_LITERAL_FOR_TEST)->ToString(); | 687 CompileRun(STRING_LITERAL_FOR_TEST)->ToString(); |
688 #undef STRING_LITERAL_FOR_TEST | 688 #undef STRING_LITERAL_FOR_TEST |
689 CHECK_EQ(*v8::String::Utf8Value(ref_string), | 689 CHECK_EQ(*v8::String::Utf8Value(ref_string), |
690 *v8::String::Utf8Value(string)); | 690 *v8::String::Utf8Value(string)); |
691 } | 691 } |
692 | 692 |
693 | 693 |
694 TEST(HeapSnapshotJSONSerializationAborting) { | 694 TEST(HeapSnapshotJSONSerializationAborting) { |
695 v8::HandleScope scope; | |
696 LocalContext env; | 695 LocalContext env; |
| 696 v8::HandleScope scope(env->GetIsolate()); |
697 const v8::HeapSnapshot* snapshot = | 697 const v8::HeapSnapshot* snapshot = |
698 v8::HeapProfiler::TakeSnapshot(v8_str("abort")); | 698 v8::HeapProfiler::TakeSnapshot(v8_str("abort")); |
699 TestJSONStream stream(5); | 699 TestJSONStream stream(5); |
700 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); | 700 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); |
701 CHECK_GT(stream.size(), 0); | 701 CHECK_GT(stream.size(), 0); |
702 CHECK_EQ(0, stream.eos_signaled()); | 702 CHECK_EQ(0, stream.eos_signaled()); |
703 } | 703 } |
704 | 704 |
705 namespace { | 705 namespace { |
706 | 706 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 v8::SnapshotObjectId last_seen_id = | 766 v8::SnapshotObjectId last_seen_id = |
767 v8::HeapProfiler::PushHeapObjectsStats(&stream); | 767 v8::HeapProfiler::PushHeapObjectsStats(&stream); |
768 if (object_id) | 768 if (object_id) |
769 *object_id = last_seen_id; | 769 *object_id = last_seen_id; |
770 CHECK_EQ(1, stream.eos_signaled()); | 770 CHECK_EQ(1, stream.eos_signaled()); |
771 return stream; | 771 return stream; |
772 } | 772 } |
773 | 773 |
774 | 774 |
775 TEST(HeapSnapshotObjectsStats) { | 775 TEST(HeapSnapshotObjectsStats) { |
776 v8::HandleScope scope; | |
777 LocalContext env; | 776 LocalContext env; |
| 777 v8::HandleScope scope(env->GetIsolate()); |
778 | 778 |
779 v8::HeapProfiler::StartHeapObjectsTracking(); | 779 v8::HeapProfiler::StartHeapObjectsTracking(); |
780 // We have to call GC 6 times. In other case the garbage will be | 780 // We have to call GC 6 times. In other case the garbage will be |
781 // the reason of flakiness. | 781 // the reason of flakiness. |
782 for (int i = 0; i < 6; ++i) { | 782 for (int i = 0; i < 6; ++i) { |
783 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 783 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
784 } | 784 } |
785 | 785 |
786 v8::SnapshotObjectId initial_id; | 786 v8::SnapshotObjectId initial_id; |
787 { | 787 { |
788 // Single chunk of data expected in update. Initial data. | 788 // Single chunk of data expected in update. Initial data. |
789 TestStatsStream stats_update = GetHeapStatsUpdate(&initial_id); | 789 TestStatsStream stats_update = GetHeapStatsUpdate(&initial_id); |
790 CHECK_EQ(1, stats_update.intervals_count()); | 790 CHECK_EQ(1, stats_update.intervals_count()); |
791 CHECK_EQ(1, stats_update.updates_written()); | 791 CHECK_EQ(1, stats_update.updates_written()); |
792 CHECK_LT(0, stats_update.entries_size()); | 792 CHECK_LT(0, stats_update.entries_size()); |
793 CHECK_EQ(0, stats_update.first_interval_index()); | 793 CHECK_EQ(0, stats_update.first_interval_index()); |
794 } | 794 } |
795 | 795 |
796 // No data expected in update because nothing has happened. | 796 // No data expected in update because nothing has happened. |
797 v8::SnapshotObjectId same_id; | 797 v8::SnapshotObjectId same_id; |
798 CHECK_EQ(0, GetHeapStatsUpdate(&same_id).updates_written()); | 798 CHECK_EQ(0, GetHeapStatsUpdate(&same_id).updates_written()); |
799 CHECK_EQ_SNAPSHOT_OBJECT_ID(initial_id, same_id); | 799 CHECK_EQ_SNAPSHOT_OBJECT_ID(initial_id, same_id); |
800 | 800 |
801 { | 801 { |
802 v8::SnapshotObjectId additional_string_id; | 802 v8::SnapshotObjectId additional_string_id; |
803 v8::HandleScope inner_scope_1; | 803 v8::HandleScope inner_scope_1(env->GetIsolate()); |
804 v8_str("string1"); | 804 v8_str("string1"); |
805 { | 805 { |
806 // Single chunk of data with one new entry expected in update. | 806 // Single chunk of data with one new entry expected in update. |
807 TestStatsStream stats_update = GetHeapStatsUpdate(&additional_string_id); | 807 TestStatsStream stats_update = GetHeapStatsUpdate(&additional_string_id); |
808 CHECK_LT(same_id, additional_string_id); | 808 CHECK_LT(same_id, additional_string_id); |
809 CHECK_EQ(1, stats_update.intervals_count()); | 809 CHECK_EQ(1, stats_update.intervals_count()); |
810 CHECK_EQ(1, stats_update.updates_written()); | 810 CHECK_EQ(1, stats_update.updates_written()); |
811 CHECK_LT(0, stats_update.entries_size()); | 811 CHECK_LT(0, stats_update.entries_size()); |
812 CHECK_EQ(1, stats_update.entries_count()); | 812 CHECK_EQ(1, stats_update.entries_count()); |
813 CHECK_EQ(2, stats_update.first_interval_index()); | 813 CHECK_EQ(2, stats_update.first_interval_index()); |
814 } | 814 } |
815 | 815 |
816 // No data expected in update because nothing happened. | 816 // No data expected in update because nothing happened. |
817 v8::SnapshotObjectId last_id; | 817 v8::SnapshotObjectId last_id; |
818 CHECK_EQ(0, GetHeapStatsUpdate(&last_id).updates_written()); | 818 CHECK_EQ(0, GetHeapStatsUpdate(&last_id).updates_written()); |
819 CHECK_EQ_SNAPSHOT_OBJECT_ID(additional_string_id, last_id); | 819 CHECK_EQ_SNAPSHOT_OBJECT_ID(additional_string_id, last_id); |
820 | 820 |
821 { | 821 { |
822 v8::HandleScope inner_scope_2; | 822 v8::HandleScope inner_scope_2(env->GetIsolate()); |
823 v8_str("string2"); | 823 v8_str("string2"); |
824 | 824 |
825 uint32_t entries_size; | 825 uint32_t entries_size; |
826 { | 826 { |
827 v8::HandleScope inner_scope_3; | 827 v8::HandleScope inner_scope_3(env->GetIsolate()); |
828 v8_str("string3"); | 828 v8_str("string3"); |
829 v8_str("string4"); | 829 v8_str("string4"); |
830 | 830 |
831 { | 831 { |
832 // Single chunk of data with three new entries expected in update. | 832 // Single chunk of data with three new entries expected in update. |
833 TestStatsStream stats_update = GetHeapStatsUpdate(); | 833 TestStatsStream stats_update = GetHeapStatsUpdate(); |
834 CHECK_EQ(1, stats_update.intervals_count()); | 834 CHECK_EQ(1, stats_update.intervals_count()); |
835 CHECK_EQ(1, stats_update.updates_written()); | 835 CHECK_EQ(1, stats_update.updates_written()); |
836 CHECK_LT(0, entries_size = stats_update.entries_size()); | 836 CHECK_LT(0, entries_size = stats_update.entries_size()); |
837 CHECK_EQ(3, stats_update.entries_count()); | 837 CHECK_EQ(3, stats_update.entries_count()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 const v8::HeapGraphNode* child = | 919 const v8::HeapGraphNode* child = |
920 snapshot->GetNodeById(prop->GetToNode()->GetId()); | 920 snapshot->GetNodeById(prop->GetToNode()->GetId()); |
921 CHECK_EQ_SNAPSHOT_OBJECT_ID(prop->GetToNode()->GetId(), child->GetId()); | 921 CHECK_EQ_SNAPSHOT_OBJECT_ID(prop->GetToNode()->GetId(), child->GetId()); |
922 CHECK_EQ(prop->GetToNode(), child); | 922 CHECK_EQ(prop->GetToNode(), child); |
923 CheckChildrenIds(snapshot, child, level + 1, max_level); | 923 CheckChildrenIds(snapshot, child, level + 1, max_level); |
924 } | 924 } |
925 } | 925 } |
926 | 926 |
927 | 927 |
928 TEST(HeapSnapshotGetNodeById) { | 928 TEST(HeapSnapshotGetNodeById) { |
929 v8::HandleScope scope; | |
930 LocalContext env; | 929 LocalContext env; |
| 930 v8::HandleScope scope(env->GetIsolate()); |
931 | 931 |
932 const v8::HeapSnapshot* snapshot = | 932 const v8::HeapSnapshot* snapshot = |
933 v8::HeapProfiler::TakeSnapshot(v8_str("id")); | 933 v8::HeapProfiler::TakeSnapshot(v8_str("id")); |
934 const v8::HeapGraphNode* root = snapshot->GetRoot(); | 934 const v8::HeapGraphNode* root = snapshot->GetRoot(); |
935 CheckChildrenIds(snapshot, root, 0, 3); | 935 CheckChildrenIds(snapshot, root, 0, 3); |
936 // Check a big id, which should not exist yet. | 936 // Check a big id, which should not exist yet. |
937 CHECK_EQ(NULL, snapshot->GetNodeById(0x1000000UL)); | 937 CHECK_EQ(NULL, snapshot->GetNodeById(0x1000000UL)); |
938 } | 938 } |
939 | 939 |
940 | 940 |
941 TEST(HeapSnapshotGetSnapshotObjectId) { | 941 TEST(HeapSnapshotGetSnapshotObjectId) { |
942 v8::HandleScope scope; | |
943 LocalContext env; | 942 LocalContext env; |
| 943 v8::HandleScope scope(env->GetIsolate()); |
944 CompileRun("globalObject = {};\n"); | 944 CompileRun("globalObject = {};\n"); |
945 const v8::HeapSnapshot* snapshot = | 945 const v8::HeapSnapshot* snapshot = |
946 v8::HeapProfiler::TakeSnapshot(v8_str("get_snapshot_object_id")); | 946 v8::HeapProfiler::TakeSnapshot(v8_str("get_snapshot_object_id")); |
947 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 947 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
948 const v8::HeapGraphNode* global_object = | 948 const v8::HeapGraphNode* global_object = |
949 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject"); | 949 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject"); |
950 CHECK(global_object); | 950 CHECK(global_object); |
951 | 951 |
952 v8::Local<v8::Value> globalObjectHandle = | 952 v8::Local<v8::Value> globalObjectHandle = |
953 env->Global()->Get(v8::String::New("globalObject")); | 953 env->Global()->Get(v8::String::New("globalObject")); |
954 CHECK(!globalObjectHandle.IsEmpty()); | 954 CHECK(!globalObjectHandle.IsEmpty()); |
955 CHECK(globalObjectHandle->IsObject()); | 955 CHECK(globalObjectHandle->IsObject()); |
956 | 956 |
957 v8::SnapshotObjectId id = | 957 v8::SnapshotObjectId id = |
958 v8::HeapProfiler::GetSnapshotObjectId(globalObjectHandle); | 958 v8::HeapProfiler::GetSnapshotObjectId(globalObjectHandle); |
959 CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId), | 959 CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId), |
960 id); | 960 id); |
961 CHECK_EQ(static_cast<int>(id), global_object->GetId()); | 961 CHECK_EQ(static_cast<int>(id), global_object->GetId()); |
962 } | 962 } |
963 | 963 |
964 | 964 |
965 TEST(HeapSnapshotUnknownSnapshotObjectId) { | 965 TEST(HeapSnapshotUnknownSnapshotObjectId) { |
966 v8::HandleScope scope; | |
967 LocalContext env; | 966 LocalContext env; |
| 967 v8::HandleScope scope(env->GetIsolate()); |
968 CompileRun("globalObject = {};\n"); | 968 CompileRun("globalObject = {};\n"); |
969 const v8::HeapSnapshot* snapshot = | 969 const v8::HeapSnapshot* snapshot = |
970 v8::HeapProfiler::TakeSnapshot(v8_str("unknown_object_id")); | 970 v8::HeapProfiler::TakeSnapshot(v8_str("unknown_object_id")); |
971 const v8::HeapGraphNode* node = | 971 const v8::HeapGraphNode* node = |
972 snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId); | 972 snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId); |
973 CHECK_EQ(NULL, node); | 973 CHECK_EQ(NULL, node); |
974 } | 974 } |
975 | 975 |
976 | 976 |
977 namespace { | 977 namespace { |
(...skipping 11 matching lines...) Expand all Loading... |
989 int total() { return total_; } | 989 int total() { return total_; } |
990 | 990 |
991 private: | 991 private: |
992 int done_; | 992 int done_; |
993 int total_; | 993 int total_; |
994 int abort_count_; | 994 int abort_count_; |
995 }; | 995 }; |
996 } | 996 } |
997 | 997 |
998 TEST(TakeHeapSnapshotAborting) { | 998 TEST(TakeHeapSnapshotAborting) { |
999 v8::HandleScope scope; | |
1000 LocalContext env; | 999 LocalContext env; |
| 1000 v8::HandleScope scope(env->GetIsolate()); |
1001 | 1001 |
1002 const int snapshots_count = v8::HeapProfiler::GetSnapshotsCount(); | 1002 const int snapshots_count = v8::HeapProfiler::GetSnapshotsCount(); |
1003 TestActivityControl aborting_control(1); | 1003 TestActivityControl aborting_control(1); |
1004 const v8::HeapSnapshot* no_snapshot = | 1004 const v8::HeapSnapshot* no_snapshot = |
1005 v8::HeapProfiler::TakeSnapshot(v8_str("abort"), | 1005 v8::HeapProfiler::TakeSnapshot(v8_str("abort"), |
1006 v8::HeapSnapshot::kFull, | 1006 v8::HeapSnapshot::kFull, |
1007 &aborting_control); | 1007 &aborting_control); |
1008 CHECK_EQ(NULL, no_snapshot); | 1008 CHECK_EQ(NULL, no_snapshot); |
1009 CHECK_EQ(snapshots_count, v8::HeapProfiler::GetSnapshotsCount()); | 1009 CHECK_EQ(snapshots_count, v8::HeapProfiler::GetSnapshotsCount()); |
1010 CHECK_GT(aborting_control.total(), aborting_control.done()); | 1010 CHECK_GT(aborting_control.total(), aborting_control.done()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 const_cast<i::HeapEntry*>( | 1099 const_cast<i::HeapEntry*>( |
1100 reinterpret_cast<const i::HeapEntry*>(node))->name()) == 0) { | 1100 reinterpret_cast<const i::HeapEntry*>(node))->name()) == 0) { |
1101 return node; | 1101 return node; |
1102 } | 1102 } |
1103 } | 1103 } |
1104 return NULL; | 1104 return NULL; |
1105 } | 1105 } |
1106 | 1106 |
1107 | 1107 |
1108 TEST(HeapSnapshotRetainedObjectInfo) { | 1108 TEST(HeapSnapshotRetainedObjectInfo) { |
1109 v8::HandleScope scope; | |
1110 LocalContext env; | 1109 LocalContext env; |
1111 v8::Isolate* isolate = env->GetIsolate(); | 1110 v8::Isolate* isolate = env->GetIsolate(); |
| 1111 v8::HandleScope scope(isolate); |
1112 | 1112 |
1113 v8::HeapProfiler::DefineWrapperClass( | 1113 v8::HeapProfiler::DefineWrapperClass( |
1114 1, TestRetainedObjectInfo::WrapperInfoCallback); | 1114 1, TestRetainedObjectInfo::WrapperInfoCallback); |
1115 v8::HeapProfiler::DefineWrapperClass( | 1115 v8::HeapProfiler::DefineWrapperClass( |
1116 2, TestRetainedObjectInfo::WrapperInfoCallback); | 1116 2, TestRetainedObjectInfo::WrapperInfoCallback); |
1117 v8::Persistent<v8::String> p_AAA = | 1117 v8::Persistent<v8::String> p_AAA = |
1118 v8::Persistent<v8::String>::New(isolate, v8_str("AAA")); | 1118 v8::Persistent<v8::String>::New(isolate, v8_str("AAA")); |
1119 p_AAA.SetWrapperClassId(isolate, 1); | 1119 p_AAA.SetWrapperClassId(isolate, 1); |
1120 v8::Persistent<v8::String> p_BBB = | 1120 v8::Persistent<v8::String> p_BBB = |
1121 v8::Persistent<v8::String>::New(isolate, v8_str("BBB")); | 1121 v8::Persistent<v8::String>::New(isolate, v8_str("BBB")); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 } | 1196 } |
1197 | 1197 |
1198 v8::Persistent<v8::Value> objects_[kObjectsCount]; | 1198 v8::Persistent<v8::Value> objects_[kObjectsCount]; |
1199 static GraphWithImplicitRefs* instance_; | 1199 static GraphWithImplicitRefs* instance_; |
1200 }; | 1200 }; |
1201 | 1201 |
1202 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL; | 1202 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL; |
1203 | 1203 |
1204 | 1204 |
1205 TEST(HeapSnapshotImplicitReferences) { | 1205 TEST(HeapSnapshotImplicitReferences) { |
1206 v8::HandleScope scope; | |
1207 LocalContext env; | 1206 LocalContext env; |
| 1207 v8::HandleScope scope(env->GetIsolate()); |
1208 | 1208 |
1209 GraphWithImplicitRefs graph(&env); | 1209 GraphWithImplicitRefs graph(&env); |
1210 v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); | 1210 v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); |
1211 | 1211 |
1212 const v8::HeapSnapshot* snapshot = | 1212 const v8::HeapSnapshot* snapshot = |
1213 v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs")); | 1213 v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs")); |
1214 | 1214 |
1215 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); | 1215 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); |
1216 const v8::HeapGraphNode* obj0 = GetProperty( | 1216 const v8::HeapGraphNode* obj0 = GetProperty( |
1217 global_object, v8::HeapGraphEdge::kProperty, "root_object"); | 1217 global_object, v8::HeapGraphEdge::kProperty, "root_object"); |
(...skipping 10 matching lines...) Expand all Loading... |
1228 strcmp("native", *prop_name) == 0) { | 1228 strcmp("native", *prop_name) == 0) { |
1229 ++implicit_targets_count; | 1229 ++implicit_targets_count; |
1230 } | 1230 } |
1231 } | 1231 } |
1232 CHECK_EQ(2, implicit_targets_count); | 1232 CHECK_EQ(2, implicit_targets_count); |
1233 v8::V8::RemoveGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); | 1233 v8::V8::RemoveGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); |
1234 } | 1234 } |
1235 | 1235 |
1236 | 1236 |
1237 TEST(DeleteAllHeapSnapshots) { | 1237 TEST(DeleteAllHeapSnapshots) { |
1238 v8::HandleScope scope; | |
1239 LocalContext env; | 1238 LocalContext env; |
| 1239 v8::HandleScope scope(env->GetIsolate()); |
1240 | 1240 |
1241 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); | 1241 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); |
1242 v8::HeapProfiler::DeleteAllSnapshots(); | 1242 v8::HeapProfiler::DeleteAllSnapshots(); |
1243 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); | 1243 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); |
1244 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1"))); | 1244 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1"))); |
1245 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); | 1245 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); |
1246 v8::HeapProfiler::DeleteAllSnapshots(); | 1246 v8::HeapProfiler::DeleteAllSnapshots(); |
1247 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); | 1247 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); |
1248 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1"))); | 1248 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1"))); |
1249 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("2"))); | 1249 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("2"))); |
1250 CHECK_EQ(2, v8::HeapProfiler::GetSnapshotsCount()); | 1250 CHECK_EQ(2, v8::HeapProfiler::GetSnapshotsCount()); |
1251 v8::HeapProfiler::DeleteAllSnapshots(); | 1251 v8::HeapProfiler::DeleteAllSnapshots(); |
1252 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); | 1252 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); |
1253 } | 1253 } |
1254 | 1254 |
1255 | 1255 |
1256 TEST(DeleteHeapSnapshot) { | 1256 TEST(DeleteHeapSnapshot) { |
1257 v8::HandleScope scope; | |
1258 LocalContext env; | 1257 LocalContext env; |
| 1258 v8::HandleScope scope(env->GetIsolate()); |
1259 | 1259 |
1260 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); | 1260 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); |
1261 const v8::HeapSnapshot* s1 = | 1261 const v8::HeapSnapshot* s1 = |
1262 v8::HeapProfiler::TakeSnapshot(v8_str("1")); | 1262 v8::HeapProfiler::TakeSnapshot(v8_str("1")); |
1263 CHECK_NE(NULL, s1); | 1263 CHECK_NE(NULL, s1); |
1264 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); | 1264 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); |
1265 unsigned uid1 = s1->GetUid(); | 1265 unsigned uid1 = s1->GetUid(); |
1266 CHECK_EQ(s1, v8::HeapProfiler::FindSnapshot(uid1)); | 1266 CHECK_EQ(s1, v8::HeapProfiler::FindSnapshot(uid1)); |
1267 const_cast<v8::HeapSnapshot*>(s1)->Delete(); | 1267 const_cast<v8::HeapSnapshot*>(s1)->Delete(); |
1268 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); | 1268 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); |
(...skipping 24 matching lines...) Expand all Loading... |
1293 | 1293 |
1294 | 1294 |
1295 class NameResolver : public v8::HeapProfiler::ObjectNameResolver { | 1295 class NameResolver : public v8::HeapProfiler::ObjectNameResolver { |
1296 public: | 1296 public: |
1297 virtual const char* GetName(v8::Handle<v8::Object> object) { | 1297 virtual const char* GetName(v8::Handle<v8::Object> object) { |
1298 return "Global object name"; | 1298 return "Global object name"; |
1299 } | 1299 } |
1300 }; | 1300 }; |
1301 | 1301 |
1302 TEST(GlobalObjectName) { | 1302 TEST(GlobalObjectName) { |
1303 v8::HandleScope scope; | |
1304 LocalContext env; | 1303 LocalContext env; |
| 1304 v8::HandleScope scope(env->GetIsolate()); |
1305 | 1305 |
1306 CompileRun("document = { URL:\"abcdefgh\" };"); | 1306 CompileRun("document = { URL:\"abcdefgh\" };"); |
1307 | 1307 |
1308 NameResolver name_resolver; | 1308 NameResolver name_resolver; |
1309 const v8::HeapSnapshot* snapshot = | 1309 const v8::HeapSnapshot* snapshot = |
1310 v8::HeapProfiler::TakeSnapshot(v8_str("document"), | 1310 v8::HeapProfiler::TakeSnapshot(v8_str("document"), |
1311 v8::HeapSnapshot::kFull, | 1311 v8::HeapSnapshot::kFull, |
1312 NULL, | 1312 NULL, |
1313 &name_resolver); | 1313 &name_resolver); |
1314 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1314 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1315 CHECK_NE(NULL, global); | 1315 CHECK_NE(NULL, global); |
1316 CHECK_EQ("Object / Global object name" , | 1316 CHECK_EQ("Object / Global object name" , |
1317 const_cast<i::HeapEntry*>( | 1317 const_cast<i::HeapEntry*>( |
1318 reinterpret_cast<const i::HeapEntry*>(global))->name()); | 1318 reinterpret_cast<const i::HeapEntry*>(global))->name()); |
1319 } | 1319 } |
1320 | 1320 |
1321 | 1321 |
1322 TEST(NoHandleLeaks) { | 1322 TEST(NoHandleLeaks) { |
1323 v8::HandleScope scope; | |
1324 LocalContext env; | 1323 LocalContext env; |
| 1324 v8::HandleScope scope(env->GetIsolate()); |
1325 | 1325 |
1326 CompileRun("document = { URL:\"abcdefgh\" };"); | 1326 CompileRun("document = { URL:\"abcdefgh\" };"); |
1327 | 1327 |
1328 v8::Handle<v8::String> name(v8_str("leakz")); | 1328 v8::Handle<v8::String> name(v8_str("leakz")); |
1329 i::Isolate* isolate = i::Isolate::Current(); | 1329 i::Isolate* isolate = i::Isolate::Current(); |
1330 int count_before = i::HandleScope::NumberOfHandles(isolate); | 1330 int count_before = i::HandleScope::NumberOfHandles(isolate); |
1331 v8::HeapProfiler::TakeSnapshot(name); | 1331 v8::HeapProfiler::TakeSnapshot(name); |
1332 int count_after = i::HandleScope::NumberOfHandles(isolate); | 1332 int count_after = i::HandleScope::NumberOfHandles(isolate); |
1333 CHECK_EQ(count_before, count_after); | 1333 CHECK_EQ(count_before, count_after); |
1334 } | 1334 } |
1335 | 1335 |
1336 | 1336 |
1337 TEST(NodesIteration) { | 1337 TEST(NodesIteration) { |
1338 v8::HandleScope scope; | |
1339 LocalContext env; | 1338 LocalContext env; |
| 1339 v8::HandleScope scope(env->GetIsolate()); |
1340 const v8::HeapSnapshot* snapshot = | 1340 const v8::HeapSnapshot* snapshot = |
1341 v8::HeapProfiler::TakeSnapshot(v8_str("iteration")); | 1341 v8::HeapProfiler::TakeSnapshot(v8_str("iteration")); |
1342 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1342 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1343 CHECK_NE(NULL, global); | 1343 CHECK_NE(NULL, global); |
1344 // Verify that we can find this object by iteration. | 1344 // Verify that we can find this object by iteration. |
1345 const int nodes_count = snapshot->GetNodesCount(); | 1345 const int nodes_count = snapshot->GetNodesCount(); |
1346 int count = 0; | 1346 int count = 0; |
1347 for (int i = 0; i < nodes_count; ++i) { | 1347 for (int i = 0; i < nodes_count; ++i) { |
1348 if (snapshot->GetNode(i) == global) | 1348 if (snapshot->GetNode(i) == global) |
1349 ++count; | 1349 ++count; |
1350 } | 1350 } |
1351 CHECK_EQ(1, count); | 1351 CHECK_EQ(1, count); |
1352 } | 1352 } |
1353 | 1353 |
1354 | 1354 |
1355 TEST(GetHeapValue) { | 1355 TEST(GetHeapValue) { |
1356 v8::HandleScope scope; | |
1357 LocalContext env; | 1356 LocalContext env; |
| 1357 v8::HandleScope scope(env->GetIsolate()); |
1358 | 1358 |
1359 CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };"); | 1359 CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };"); |
1360 const v8::HeapSnapshot* snapshot = | 1360 const v8::HeapSnapshot* snapshot = |
1361 v8::HeapProfiler::TakeSnapshot(v8_str("value")); | 1361 v8::HeapProfiler::TakeSnapshot(v8_str("value")); |
1362 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1362 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1363 CHECK(global->GetHeapValue()->IsObject()); | 1363 CHECK(global->GetHeapValue()->IsObject()); |
1364 v8::Local<v8::Object> js_global = | 1364 v8::Local<v8::Object> js_global = |
1365 env->Global()->GetPrototype().As<v8::Object>(); | 1365 env->Global()->GetPrototype().As<v8::Object>(); |
1366 CHECK(js_global == global->GetHeapValue()); | 1366 CHECK(js_global == global->GetHeapValue()); |
1367 const v8::HeapGraphNode* obj = GetProperty( | 1367 const v8::HeapGraphNode* obj = GetProperty( |
1368 global, v8::HeapGraphEdge::kProperty, "a"); | 1368 global, v8::HeapGraphEdge::kProperty, "a"); |
1369 CHECK(obj->GetHeapValue()->IsObject()); | 1369 CHECK(obj->GetHeapValue()->IsObject()); |
1370 v8::Local<v8::Object> js_obj = js_global->Get(v8_str("a")).As<v8::Object>(); | 1370 v8::Local<v8::Object> js_obj = js_global->Get(v8_str("a")).As<v8::Object>(); |
1371 CHECK(js_obj == obj->GetHeapValue()); | 1371 CHECK(js_obj == obj->GetHeapValue()); |
1372 const v8::HeapGraphNode* s_prop = | 1372 const v8::HeapGraphNode* s_prop = |
1373 GetProperty(obj, v8::HeapGraphEdge::kProperty, "s_prop"); | 1373 GetProperty(obj, v8::HeapGraphEdge::kProperty, "s_prop"); |
1374 v8::Local<v8::String> js_s_prop = | 1374 v8::Local<v8::String> js_s_prop = |
1375 js_obj->Get(v8_str("s_prop")).As<v8::String>(); | 1375 js_obj->Get(v8_str("s_prop")).As<v8::String>(); |
1376 CHECK(js_s_prop == s_prop->GetHeapValue()); | 1376 CHECK(js_s_prop == s_prop->GetHeapValue()); |
1377 const v8::HeapGraphNode* n_prop = | 1377 const v8::HeapGraphNode* n_prop = |
1378 GetProperty(obj, v8::HeapGraphEdge::kProperty, "n_prop"); | 1378 GetProperty(obj, v8::HeapGraphEdge::kProperty, "n_prop"); |
1379 v8::Local<v8::Number> js_n_prop = | 1379 v8::Local<v8::Number> js_n_prop = |
1380 js_obj->Get(v8_str("n_prop")).As<v8::Number>(); | 1380 js_obj->Get(v8_str("n_prop")).As<v8::Number>(); |
1381 CHECK(js_n_prop == n_prop->GetHeapValue()); | 1381 CHECK(js_n_prop == n_prop->GetHeapValue()); |
1382 } | 1382 } |
1383 | 1383 |
1384 | 1384 |
1385 TEST(GetHeapValueForDeletedObject) { | 1385 TEST(GetHeapValueForDeletedObject) { |
1386 v8::HandleScope scope; | |
1387 LocalContext env; | 1386 LocalContext env; |
| 1387 v8::HandleScope scope(env->GetIsolate()); |
1388 | 1388 |
1389 // It is impossible to delete a global property, so we are about to delete a | 1389 // It is impossible to delete a global property, so we are about to delete a |
1390 // property of the "a" object. Also, the "p" object can't be an empty one | 1390 // property of the "a" object. Also, the "p" object can't be an empty one |
1391 // because the empty object is static and isn't actually deleted. | 1391 // because the empty object is static and isn't actually deleted. |
1392 CompileRun("a = { p: { r: {} } };"); | 1392 CompileRun("a = { p: { r: {} } };"); |
1393 const v8::HeapSnapshot* snapshot = | 1393 const v8::HeapSnapshot* snapshot = |
1394 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); | 1394 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); |
1395 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1395 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1396 const v8::HeapGraphNode* obj = GetProperty( | 1396 const v8::HeapGraphNode* obj = GetProperty( |
1397 global, v8::HeapGraphEdge::kProperty, "a"); | 1397 global, v8::HeapGraphEdge::kProperty, "a"); |
1398 const v8::HeapGraphNode* prop = GetProperty( | 1398 const v8::HeapGraphNode* prop = GetProperty( |
1399 obj, v8::HeapGraphEdge::kProperty, "p"); | 1399 obj, v8::HeapGraphEdge::kProperty, "p"); |
1400 { | 1400 { |
1401 // Perform the check inside a nested local scope to avoid creating a | 1401 // Perform the check inside a nested local scope to avoid creating a |
1402 // reference to the object we are deleting. | 1402 // reference to the object we are deleting. |
1403 v8::HandleScope scope; | 1403 v8::HandleScope scope(env->GetIsolate()); |
1404 CHECK(prop->GetHeapValue()->IsObject()); | 1404 CHECK(prop->GetHeapValue()->IsObject()); |
1405 } | 1405 } |
1406 CompileRun("delete a.p;"); | 1406 CompileRun("delete a.p;"); |
1407 CHECK(prop->GetHeapValue()->IsUndefined()); | 1407 CHECK(prop->GetHeapValue()->IsUndefined()); |
1408 } | 1408 } |
1409 | 1409 |
1410 | 1410 |
1411 static int StringCmp(const char* ref, i::String* act) { | 1411 static int StringCmp(const char* ref, i::String* act) { |
1412 i::SmartArrayPointer<char> s_act = act->ToCString(); | 1412 i::SmartArrayPointer<char> s_act = act->ToCString(); |
1413 int result = strcmp(ref, *s_act); | 1413 int result = strcmp(ref, *s_act); |
1414 if (result != 0) | 1414 if (result != 0) |
1415 fprintf(stderr, "Expected: \"%s\", Actual: \"%s\"\n", ref, *s_act); | 1415 fprintf(stderr, "Expected: \"%s\", Actual: \"%s\"\n", ref, *s_act); |
1416 return result; | 1416 return result; |
1417 } | 1417 } |
1418 | 1418 |
1419 | 1419 |
1420 TEST(GetConstructorName) { | 1420 TEST(GetConstructorName) { |
1421 v8::HandleScope scope; | |
1422 LocalContext env; | 1421 LocalContext env; |
| 1422 v8::HandleScope scope(env->GetIsolate()); |
1423 | 1423 |
1424 CompileRun( | 1424 CompileRun( |
1425 "function Constructor1() {};\n" | 1425 "function Constructor1() {};\n" |
1426 "var obj1 = new Constructor1();\n" | 1426 "var obj1 = new Constructor1();\n" |
1427 "var Constructor2 = function() {};\n" | 1427 "var Constructor2 = function() {};\n" |
1428 "var obj2 = new Constructor2();\n" | 1428 "var obj2 = new Constructor2();\n" |
1429 "var obj3 = {};\n" | 1429 "var obj3 = {};\n" |
1430 "obj3.constructor = function Constructor3() {};\n" | 1430 "obj3.constructor = function Constructor3() {};\n" |
1431 "var obj4 = {};\n" | 1431 "var obj4 = {};\n" |
1432 "// Slow properties\n" | 1432 "// Slow properties\n" |
(...skipping 25 matching lines...) Expand all Loading... |
1458 CHECK_EQ(0, StringCmp( | 1458 CHECK_EQ(0, StringCmp( |
1459 "Object", i::V8HeapExplorer::GetConstructorName(*js_obj5))); | 1459 "Object", i::V8HeapExplorer::GetConstructorName(*js_obj5))); |
1460 v8::Local<v8::Object> obj6 = js_global->Get(v8_str("obj6")).As<v8::Object>(); | 1460 v8::Local<v8::Object> obj6 = js_global->Get(v8_str("obj6")).As<v8::Object>(); |
1461 i::Handle<i::JSObject> js_obj6 = v8::Utils::OpenHandle(*obj6); | 1461 i::Handle<i::JSObject> js_obj6 = v8::Utils::OpenHandle(*obj6); |
1462 CHECK_EQ(0, StringCmp( | 1462 CHECK_EQ(0, StringCmp( |
1463 "Object", i::V8HeapExplorer::GetConstructorName(*js_obj6))); | 1463 "Object", i::V8HeapExplorer::GetConstructorName(*js_obj6))); |
1464 } | 1464 } |
1465 | 1465 |
1466 | 1466 |
1467 TEST(FastCaseGetter) { | 1467 TEST(FastCaseGetter) { |
1468 v8::HandleScope scope; | |
1469 LocalContext env; | 1468 LocalContext env; |
| 1469 v8::HandleScope scope(env->GetIsolate()); |
1470 | 1470 |
1471 CompileRun("var obj1 = {};\n" | 1471 CompileRun("var obj1 = {};\n" |
1472 "obj1.__defineGetter__('propWithGetter', function Y() {\n" | 1472 "obj1.__defineGetter__('propWithGetter', function Y() {\n" |
1473 " return 42;\n" | 1473 " return 42;\n" |
1474 "});\n" | 1474 "});\n" |
1475 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" | 1475 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" |
1476 " return this.value_ = value;\n" | 1476 " return this.value_ = value;\n" |
1477 "});\n"); | 1477 "});\n"); |
1478 const v8::HeapSnapshot* snapshot = | 1478 const v8::HeapSnapshot* snapshot = |
1479 v8::HeapProfiler::TakeSnapshot(v8_str("fastCaseGetter")); | 1479 v8::HeapProfiler::TakeSnapshot(v8_str("fastCaseGetter")); |
1480 | 1480 |
1481 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1481 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1482 CHECK_NE(NULL, global); | 1482 CHECK_NE(NULL, global); |
1483 const v8::HeapGraphNode* obj1 = | 1483 const v8::HeapGraphNode* obj1 = |
1484 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); | 1484 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); |
1485 CHECK_NE(NULL, obj1); | 1485 CHECK_NE(NULL, obj1); |
1486 const v8::HeapGraphNode* getterFunction = | 1486 const v8::HeapGraphNode* getterFunction = |
1487 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get-propWithGetter"); | 1487 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get-propWithGetter"); |
1488 CHECK_NE(NULL, getterFunction); | 1488 CHECK_NE(NULL, getterFunction); |
1489 const v8::HeapGraphNode* setterFunction = | 1489 const v8::HeapGraphNode* setterFunction = |
1490 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set-propWithSetter"); | 1490 GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set-propWithSetter"); |
1491 CHECK_NE(NULL, setterFunction); | 1491 CHECK_NE(NULL, setterFunction); |
1492 } | 1492 } |
1493 | 1493 |
1494 TEST(HiddenPropertiesFastCase) { | 1494 TEST(HiddenPropertiesFastCase) { |
1495 v8::HandleScope scope; | |
1496 LocalContext env; | 1495 LocalContext env; |
| 1496 v8::HandleScope scope(env->GetIsolate()); |
1497 | 1497 |
1498 CompileRun( | 1498 CompileRun( |
1499 "function C(x) { this.a = this; this.b = x; }\n" | 1499 "function C(x) { this.a = this; this.b = x; }\n" |
1500 "c = new C(2012);\n"); | 1500 "c = new C(2012);\n"); |
1501 const v8::HeapSnapshot* snapshot = | 1501 const v8::HeapSnapshot* snapshot = |
1502 v8::HeapProfiler::TakeSnapshot(v8_str("HiddenPropertiesFastCase1")); | 1502 v8::HeapProfiler::TakeSnapshot(v8_str("HiddenPropertiesFastCase1")); |
1503 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1503 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1504 const v8::HeapGraphNode* c = | 1504 const v8::HeapGraphNode* c = |
1505 GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); | 1505 GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); |
1506 CHECK_NE(NULL, c); | 1506 CHECK_NE(NULL, c); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 | 1545 |
1546 | 1546 |
1547 static void PersistentHandleCallback(v8::Isolate* isolate, | 1547 static void PersistentHandleCallback(v8::Isolate* isolate, |
1548 v8::Persistent<v8::Value> handle, | 1548 v8::Persistent<v8::Value> handle, |
1549 void*) { | 1549 void*) { |
1550 handle.Dispose(isolate); | 1550 handle.Dispose(isolate); |
1551 } | 1551 } |
1552 | 1552 |
1553 | 1553 |
1554 TEST(WeakGlobalHandle) { | 1554 TEST(WeakGlobalHandle) { |
1555 v8::HandleScope scope; | |
1556 LocalContext env; | 1555 LocalContext env; |
| 1556 v8::HandleScope scope(env->GetIsolate()); |
1557 | 1557 |
1558 CHECK(!HasWeakGlobalHandle()); | 1558 CHECK(!HasWeakGlobalHandle()); |
1559 | 1559 |
1560 v8::Persistent<v8::Object> handle = | 1560 v8::Persistent<v8::Object> handle = |
1561 v8::Persistent<v8::Object>::New(env->GetIsolate(), v8::Object::New()); | 1561 v8::Persistent<v8::Object>::New(env->GetIsolate(), v8::Object::New()); |
1562 handle.MakeWeak(env->GetIsolate(), NULL, PersistentHandleCallback); | 1562 handle.MakeWeak(env->GetIsolate(), NULL, PersistentHandleCallback); |
1563 | 1563 |
1564 CHECK(HasWeakGlobalHandle()); | 1564 CHECK(HasWeakGlobalHandle()); |
1565 } | 1565 } |
1566 | 1566 |
1567 | 1567 |
1568 TEST(WeakNativeContextRefs) { | 1568 TEST(WeakNativeContextRefs) { |
1569 v8::HandleScope scope; | |
1570 LocalContext env; | 1569 LocalContext env; |
| 1570 v8::HandleScope scope(env->GetIsolate()); |
1571 | 1571 |
1572 const v8::HeapSnapshot* snapshot = | 1572 const v8::HeapSnapshot* snapshot = |
1573 v8::HeapProfiler::TakeSnapshot(v8_str("weaks")); | 1573 v8::HeapProfiler::TakeSnapshot(v8_str("weaks")); |
1574 const v8::HeapGraphNode* gc_roots = GetNode( | 1574 const v8::HeapGraphNode* gc_roots = GetNode( |
1575 snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)"); | 1575 snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)"); |
1576 CHECK_NE(NULL, gc_roots); | 1576 CHECK_NE(NULL, gc_roots); |
1577 const v8::HeapGraphNode* global_handles = GetNode( | 1577 const v8::HeapGraphNode* global_handles = GetNode( |
1578 gc_roots, v8::HeapGraphNode::kObject, "(Global handles)"); | 1578 gc_roots, v8::HeapGraphNode::kObject, "(Global handles)"); |
1579 CHECK_NE(NULL, global_handles); | 1579 CHECK_NE(NULL, global_handles); |
1580 const v8::HeapGraphNode* native_context = GetNode( | 1580 const v8::HeapGraphNode* native_context = GetNode( |
1581 global_handles, v8::HeapGraphNode::kHidden, "system / NativeContext"); | 1581 global_handles, v8::HeapGraphNode::kHidden, "system / NativeContext"); |
1582 CHECK_NE(NULL, native_context); | 1582 CHECK_NE(NULL, native_context); |
1583 CHECK(HasWeakEdge(native_context)); | 1583 CHECK(HasWeakEdge(native_context)); |
1584 } | 1584 } |
1585 | 1585 |
1586 | 1586 |
1587 TEST(SfiAndJsFunctionWeakRefs) { | 1587 TEST(SfiAndJsFunctionWeakRefs) { |
1588 v8::HandleScope scope; | |
1589 LocalContext env; | 1588 LocalContext env; |
| 1589 v8::HandleScope scope(env->GetIsolate()); |
1590 | 1590 |
1591 CompileRun( | 1591 CompileRun( |
1592 "fun = (function (x) { return function () { return x + 1; } })(1);"); | 1592 "fun = (function (x) { return function () { return x + 1; } })(1);"); |
1593 const v8::HeapSnapshot* snapshot = | 1593 const v8::HeapSnapshot* snapshot = |
1594 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); | 1594 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); |
1595 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1595 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1596 CHECK_NE(NULL, global); | 1596 CHECK_NE(NULL, global); |
1597 const v8::HeapGraphNode* fun = | 1597 const v8::HeapGraphNode* fun = |
1598 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); | 1598 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); |
1599 CHECK(HasWeakEdge(fun)); | 1599 CHECK(HasWeakEdge(fun)); |
1600 const v8::HeapGraphNode* shared = | 1600 const v8::HeapGraphNode* shared = |
1601 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); | 1601 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); |
1602 CHECK(HasWeakEdge(shared)); | 1602 CHECK(HasWeakEdge(shared)); |
1603 } | 1603 } |
1604 | 1604 |
1605 | 1605 |
1606 #ifdef ENABLE_DEBUGGER_SUPPORT | 1606 #ifdef ENABLE_DEBUGGER_SUPPORT |
1607 TEST(NoDebugObjectInSnapshot) { | 1607 TEST(NoDebugObjectInSnapshot) { |
1608 v8::HandleScope scope; | |
1609 LocalContext env; | 1608 LocalContext env; |
| 1609 v8::HandleScope scope(env->GetIsolate()); |
1610 | 1610 |
1611 v8::internal::Isolate::Current()->debug()->Load(); | 1611 v8::internal::Isolate::Current()->debug()->Load(); |
1612 CompileRun("foo = {};"); | 1612 CompileRun("foo = {};"); |
1613 const v8::HeapSnapshot* snapshot = | 1613 const v8::HeapSnapshot* snapshot = |
1614 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); | 1614 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); |
1615 const v8::HeapGraphNode* root = snapshot->GetRoot(); | 1615 const v8::HeapGraphNode* root = snapshot->GetRoot(); |
1616 int globals_count = 0; | 1616 int globals_count = 0; |
1617 for (int i = 0; i < root->GetChildrenCount(); ++i) { | 1617 for (int i = 0; i < root->GetChildrenCount(); ++i) { |
1618 const v8::HeapGraphEdge* edge = root->GetChild(i); | 1618 const v8::HeapGraphEdge* edge = root->GetChild(i); |
1619 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { | 1619 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { |
1620 ++globals_count; | 1620 ++globals_count; |
1621 const v8::HeapGraphNode* global = edge->GetToNode(); | 1621 const v8::HeapGraphNode* global = edge->GetToNode(); |
1622 const v8::HeapGraphNode* foo = | 1622 const v8::HeapGraphNode* foo = |
1623 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); | 1623 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); |
1624 CHECK_NE(NULL, foo); | 1624 CHECK_NE(NULL, foo); |
1625 } | 1625 } |
1626 } | 1626 } |
1627 CHECK_EQ(1, globals_count); | 1627 CHECK_EQ(1, globals_count); |
1628 } | 1628 } |
1629 #endif // ENABLE_DEBUGGER_SUPPORT | 1629 #endif // ENABLE_DEBUGGER_SUPPORT |
1630 | 1630 |
1631 | 1631 |
1632 TEST(PersistentHandleCount) { | 1632 TEST(PersistentHandleCount) { |
1633 v8::HandleScope scope; | |
1634 LocalContext env; | 1633 LocalContext env; |
1635 v8::Isolate* isolate = env->GetIsolate(); | 1634 v8::Isolate* isolate = env->GetIsolate(); |
| 1635 v8::HandleScope scope(isolate); |
1636 | 1636 |
1637 // V8 also uses global handles internally, so we can't test for an absolute | 1637 // V8 also uses global handles internally, so we can't test for an absolute |
1638 // number. | 1638 // number. |
1639 int global_handle_count = v8::HeapProfiler::GetPersistentHandleCount(); | 1639 int global_handle_count = v8::HeapProfiler::GetPersistentHandleCount(); |
1640 | 1640 |
1641 // Create some persistent handles. | 1641 // Create some persistent handles. |
1642 v8::Persistent<v8::String> p_AAA = | 1642 v8::Persistent<v8::String> p_AAA = |
1643 v8::Persistent<v8::String>::New(isolate, v8_str("AAA")); | 1643 v8::Persistent<v8::String>::New(isolate, v8_str("AAA")); |
1644 CHECK_EQ(global_handle_count + 1, | 1644 CHECK_EQ(global_handle_count + 1, |
1645 v8::HeapProfiler::GetPersistentHandleCount()); | 1645 v8::HeapProfiler::GetPersistentHandleCount()); |
(...skipping 12 matching lines...) Expand all Loading... |
1658 v8::HeapProfiler::GetPersistentHandleCount()); | 1658 v8::HeapProfiler::GetPersistentHandleCount()); |
1659 p_CCC.Dispose(env->GetIsolate()); | 1659 p_CCC.Dispose(env->GetIsolate()); |
1660 CHECK_EQ(global_handle_count + 1, | 1660 CHECK_EQ(global_handle_count + 1, |
1661 v8::HeapProfiler::GetPersistentHandleCount()); | 1661 v8::HeapProfiler::GetPersistentHandleCount()); |
1662 p_BBB.Dispose(env->GetIsolate()); | 1662 p_BBB.Dispose(env->GetIsolate()); |
1663 CHECK_EQ(global_handle_count, v8::HeapProfiler::GetPersistentHandleCount()); | 1663 CHECK_EQ(global_handle_count, v8::HeapProfiler::GetPersistentHandleCount()); |
1664 } | 1664 } |
1665 | 1665 |
1666 | 1666 |
1667 TEST(AllStrongGcRootsHaveNames) { | 1667 TEST(AllStrongGcRootsHaveNames) { |
1668 v8::HandleScope scope; | |
1669 LocalContext env; | 1668 LocalContext env; |
| 1669 v8::HandleScope scope(env->GetIsolate()); |
1670 | 1670 |
1671 CompileRun("foo = {};"); | 1671 CompileRun("foo = {};"); |
1672 const v8::HeapSnapshot* snapshot = | 1672 const v8::HeapSnapshot* snapshot = |
1673 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); | 1673 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); |
1674 const v8::HeapGraphNode* gc_roots = GetNode( | 1674 const v8::HeapGraphNode* gc_roots = GetNode( |
1675 snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)"); | 1675 snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)"); |
1676 CHECK_NE(NULL, gc_roots); | 1676 CHECK_NE(NULL, gc_roots); |
1677 const v8::HeapGraphNode* strong_roots = GetNode( | 1677 const v8::HeapGraphNode* strong_roots = GetNode( |
1678 gc_roots, v8::HeapGraphNode::kObject, "(Strong roots)"); | 1678 gc_roots, v8::HeapGraphNode::kObject, "(Strong roots)"); |
1679 CHECK_NE(NULL, strong_roots); | 1679 CHECK_NE(NULL, strong_roots); |
1680 for (int i = 0; i < strong_roots->GetChildrenCount(); ++i) { | 1680 for (int i = 0; i < strong_roots->GetChildrenCount(); ++i) { |
1681 const v8::HeapGraphEdge* edge = strong_roots->GetChild(i); | 1681 const v8::HeapGraphEdge* edge = strong_roots->GetChild(i); |
1682 CHECK_EQ(v8::HeapGraphEdge::kInternal, edge->GetType()); | 1682 CHECK_EQ(v8::HeapGraphEdge::kInternal, edge->GetType()); |
1683 v8::String::AsciiValue name(edge->GetName()); | 1683 v8::String::AsciiValue name(edge->GetName()); |
1684 CHECK(isalpha(**name)); | 1684 CHECK(isalpha(**name)); |
1685 } | 1685 } |
1686 } | 1686 } |
1687 | 1687 |
1688 | 1688 |
1689 TEST(NoRefsToNonEssentialEntries) { | 1689 TEST(NoRefsToNonEssentialEntries) { |
1690 v8::HandleScope scope; | |
1691 LocalContext env; | 1690 LocalContext env; |
| 1691 v8::HandleScope scope(env->GetIsolate()); |
1692 CompileRun("global_object = {};\n"); | 1692 CompileRun("global_object = {};\n"); |
1693 const v8::HeapSnapshot* snapshot = | 1693 const v8::HeapSnapshot* snapshot = |
1694 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); | 1694 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); |
1695 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1695 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1696 const v8::HeapGraphNode* global_object = | 1696 const v8::HeapGraphNode* global_object = |
1697 GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object"); | 1697 GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object"); |
1698 CHECK_NE(NULL, global_object); | 1698 CHECK_NE(NULL, global_object); |
1699 const v8::HeapGraphNode* properties = | 1699 const v8::HeapGraphNode* properties = |
1700 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "properties"); | 1700 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "properties"); |
1701 CHECK_EQ(NULL, properties); | 1701 CHECK_EQ(NULL, properties); |
1702 const v8::HeapGraphNode* elements = | 1702 const v8::HeapGraphNode* elements = |
1703 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "elements"); | 1703 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "elements"); |
1704 CHECK_EQ(NULL, elements); | 1704 CHECK_EQ(NULL, elements); |
1705 } | 1705 } |
1706 | 1706 |
1707 | 1707 |
1708 TEST(MapHasDescriptorsAndTransitions) { | 1708 TEST(MapHasDescriptorsAndTransitions) { |
1709 v8::HandleScope scope; | |
1710 LocalContext env; | 1709 LocalContext env; |
| 1710 v8::HandleScope scope(env->GetIsolate()); |
1711 CompileRun("obj = { a: 10 };\n"); | 1711 CompileRun("obj = { a: 10 };\n"); |
1712 const v8::HeapSnapshot* snapshot = | 1712 const v8::HeapSnapshot* snapshot = |
1713 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); | 1713 v8::HeapProfiler::TakeSnapshot(v8_str("snapshot")); |
1714 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1714 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1715 const v8::HeapGraphNode* global_object = | 1715 const v8::HeapGraphNode* global_object = |
1716 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); | 1716 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); |
1717 CHECK_NE(NULL, global_object); | 1717 CHECK_NE(NULL, global_object); |
1718 | 1718 |
1719 const v8::HeapGraphNode* map = | 1719 const v8::HeapGraphNode* map = |
1720 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); | 1720 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); |
1721 CHECK_NE(NULL, map); | 1721 CHECK_NE(NULL, map); |
1722 const v8::HeapGraphNode* own_descriptors = GetProperty( | 1722 const v8::HeapGraphNode* own_descriptors = GetProperty( |
1723 map, v8::HeapGraphEdge::kInternal, "descriptors"); | 1723 map, v8::HeapGraphEdge::kInternal, "descriptors"); |
1724 CHECK_NE(NULL, own_descriptors); | 1724 CHECK_NE(NULL, own_descriptors); |
1725 const v8::HeapGraphNode* own_transitions = GetProperty( | 1725 const v8::HeapGraphNode* own_transitions = GetProperty( |
1726 map, v8::HeapGraphEdge::kInternal, "transitions"); | 1726 map, v8::HeapGraphEdge::kInternal, "transitions"); |
1727 CHECK_EQ(NULL, own_transitions); | 1727 CHECK_EQ(NULL, own_transitions); |
1728 } | 1728 } |
OLD | NEW |