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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 v8::HandleScope scope(env2->GetIsolate()); | 176 v8::HandleScope scope(env2->GetIsolate()); |
177 v8::HeapProfiler* heap_profiler = env2->GetIsolate()->GetHeapProfiler(); | 177 v8::HeapProfiler* heap_profiler = env2->GetIsolate()->GetHeapProfiler(); |
178 | 178 |
179 CompileRun( | 179 CompileRun( |
180 "function A2() {}\n" | 180 "function A2() {}\n" |
181 "function B2(x) { return function() { return typeof x; }; }\n" | 181 "function B2(x) { return function() { return typeof x; }; }\n" |
182 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" | 182 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" |
183 "var a2 = new A2();\n" | 183 "var a2 = new A2();\n" |
184 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" | 184 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" |
185 "var c2 = new C2(a2);"); | 185 "var c2 = new C2(a2);"); |
186 const v8::HeapSnapshot* snapshot_env2 = | 186 const v8::HeapSnapshot* snapshot_env2 = heap_profiler->TakeHeapSnapshot(); |
187 heap_profiler->TakeHeapSnapshot(v8_str("env2")); | |
188 CHECK(ValidateSnapshot(snapshot_env2)); | 187 CHECK(ValidateSnapshot(snapshot_env2)); |
189 const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2); | 188 const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2); |
190 | 189 |
191 // Verify, that JS global object of env2 has '..2' properties. | 190 // Verify, that JS global object of env2 has '..2' properties. |
192 const v8::HeapGraphNode* a2_node = | 191 const v8::HeapGraphNode* a2_node = |
193 GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "a2"); | 192 GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "a2"); |
194 CHECK(a2_node); | 193 CHECK(a2_node); |
195 CHECK(GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_1")); | 194 CHECK(GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_1")); |
196 CHECK(GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_2")); | 195 CHECK(GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_2")); |
197 CHECK(GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "c2")); | 196 CHECK(GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "c2")); |
(...skipping 12 matching lines...) Expand all Loading... |
210 v8::HandleScope scope(env->GetIsolate()); | 209 v8::HandleScope scope(env->GetIsolate()); |
211 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 210 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
212 | 211 |
213 // -a-> X1 --a | 212 // -a-> X1 --a |
214 // x -b-> X2 <-| | 213 // x -b-> X2 <-| |
215 CompileRun( | 214 CompileRun( |
216 "function X(a, b) { this.a = a; this.b = b; }\n" | 215 "function X(a, b) { this.a = a; this.b = b; }\n" |
217 "x = new X(new X(), new X());\n" | 216 "x = new X(new X(), new X());\n" |
218 "dummy = new X();\n" | 217 "dummy = new X();\n" |
219 "(function() { x.a.a = x.b; })();"); | 218 "(function() { x.a.a = x.b; })();"); |
220 const v8::HeapSnapshot* snapshot = | 219 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
221 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); | |
222 CHECK(ValidateSnapshot(snapshot)); | 220 CHECK(ValidateSnapshot(snapshot)); |
223 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 221 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
224 const v8::HeapGraphNode* x = | 222 const v8::HeapGraphNode* x = |
225 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); | 223 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); |
226 CHECK(x); | 224 CHECK(x); |
227 const v8::HeapGraphNode* x1 = | 225 const v8::HeapGraphNode* x1 = |
228 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); | 226 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); |
229 CHECK(x1); | 227 CHECK(x1); |
230 const v8::HeapGraphNode* x2 = | 228 const v8::HeapGraphNode* x2 = |
231 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); | 229 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); |
232 CHECK(x2); | 230 CHECK(x2); |
233 | 231 |
234 // Test sizes. | 232 // Test sizes. |
235 CHECK_NE(0, static_cast<int>(x->GetShallowSize())); | 233 CHECK_NE(0, static_cast<int>(x->GetShallowSize())); |
236 CHECK_NE(0, static_cast<int>(x1->GetShallowSize())); | 234 CHECK_NE(0, static_cast<int>(x1->GetShallowSize())); |
237 CHECK_NE(0, static_cast<int>(x2->GetShallowSize())); | 235 CHECK_NE(0, static_cast<int>(x2->GetShallowSize())); |
238 } | 236 } |
239 | 237 |
240 | 238 |
241 TEST(BoundFunctionInSnapshot) { | 239 TEST(BoundFunctionInSnapshot) { |
242 LocalContext env; | 240 LocalContext env; |
243 v8::HandleScope scope(env->GetIsolate()); | 241 v8::HandleScope scope(env->GetIsolate()); |
244 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 242 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
245 CompileRun( | 243 CompileRun( |
246 "function myFunction(a, b) { this.a = a; this.b = b; }\n" | 244 "function myFunction(a, b) { this.a = a; this.b = b; }\n" |
247 "function AAAAA() {}\n" | 245 "function AAAAA() {}\n" |
248 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); | 246 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); |
249 const v8::HeapSnapshot* snapshot = | 247 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
250 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); | |
251 CHECK(ValidateSnapshot(snapshot)); | 248 CHECK(ValidateSnapshot(snapshot)); |
252 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 249 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
253 const v8::HeapGraphNode* f = | 250 const v8::HeapGraphNode* f = |
254 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction"); | 251 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction"); |
255 CHECK(f); | 252 CHECK(f); |
256 CHECK(v8::String::NewFromUtf8(env->GetIsolate(), "native_bind") | 253 CHECK(v8::String::NewFromUtf8(env->GetIsolate(), "native_bind") |
257 ->Equals(f->GetName())); | 254 ->Equals(f->GetName())); |
258 const v8::HeapGraphNode* bindings = | 255 const v8::HeapGraphNode* bindings = |
259 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings"); | 256 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings"); |
260 CHECK(bindings); | 257 CHECK(bindings); |
(...skipping 18 matching lines...) Expand all Loading... |
279 | 276 |
280 | 277 |
281 TEST(HeapSnapshotEntryChildren) { | 278 TEST(HeapSnapshotEntryChildren) { |
282 LocalContext env; | 279 LocalContext env; |
283 v8::HandleScope scope(env->GetIsolate()); | 280 v8::HandleScope scope(env->GetIsolate()); |
284 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 281 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
285 | 282 |
286 CompileRun( | 283 CompileRun( |
287 "function A() { }\n" | 284 "function A() { }\n" |
288 "a = new A;"); | 285 "a = new A;"); |
289 const v8::HeapSnapshot* snapshot = | 286 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
290 heap_profiler->TakeHeapSnapshot(v8_str("children")); | |
291 CHECK(ValidateSnapshot(snapshot)); | 287 CHECK(ValidateSnapshot(snapshot)); |
292 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 288 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
293 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { | 289 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { |
294 const v8::HeapGraphEdge* prop = global->GetChild(i); | 290 const v8::HeapGraphEdge* prop = global->GetChild(i); |
295 CHECK_EQ(global, prop->GetFromNode()); | 291 CHECK_EQ(global, prop->GetFromNode()); |
296 } | 292 } |
297 const v8::HeapGraphNode* a = | 293 const v8::HeapGraphNode* a = |
298 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); | 294 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); |
299 CHECK(a); | 295 CHECK(a); |
300 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) { | 296 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) { |
301 const v8::HeapGraphEdge* prop = a->GetChild(i); | 297 const v8::HeapGraphEdge* prop = a->GetChild(i); |
302 CHECK_EQ(a, prop->GetFromNode()); | 298 CHECK_EQ(a, prop->GetFromNode()); |
303 } | 299 } |
304 } | 300 } |
305 | 301 |
306 | 302 |
307 TEST(HeapSnapshotCodeObjects) { | 303 TEST(HeapSnapshotCodeObjects) { |
308 LocalContext env; | 304 LocalContext env; |
309 v8::HandleScope scope(env->GetIsolate()); | 305 v8::HandleScope scope(env->GetIsolate()); |
310 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 306 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
311 | 307 |
312 CompileRun( | 308 CompileRun( |
313 "function lazy(x) { return x - 1; }\n" | 309 "function lazy(x) { return x - 1; }\n" |
314 "function compiled(x) { return x + 1; }\n" | 310 "function compiled(x) { return x + 1; }\n" |
315 "var anonymous = (function() { return function() { return 0; } })();\n" | 311 "var anonymous = (function() { return function() { return 0; } })();\n" |
316 "compiled(1)"); | 312 "compiled(1)"); |
317 const v8::HeapSnapshot* snapshot = | 313 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
318 heap_profiler->TakeHeapSnapshot(v8_str("code")); | |
319 CHECK(ValidateSnapshot(snapshot)); | 314 CHECK(ValidateSnapshot(snapshot)); |
320 | 315 |
321 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 316 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
322 const v8::HeapGraphNode* compiled = | 317 const v8::HeapGraphNode* compiled = |
323 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled"); | 318 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled"); |
324 CHECK(compiled); | 319 CHECK(compiled); |
325 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType()); | 320 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType()); |
326 const v8::HeapGraphNode* lazy = | 321 const v8::HeapGraphNode* lazy = |
327 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy"); | 322 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy"); |
328 CHECK(lazy); | 323 CHECK(lazy); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 } | 375 } |
381 | 376 |
382 | 377 |
383 TEST(HeapSnapshotHeapNumbers) { | 378 TEST(HeapSnapshotHeapNumbers) { |
384 LocalContext env; | 379 LocalContext env; |
385 v8::HandleScope scope(env->GetIsolate()); | 380 v8::HandleScope scope(env->GetIsolate()); |
386 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 381 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
387 CompileRun( | 382 CompileRun( |
388 "a = 1; // a is Smi\n" | 383 "a = 1; // a is Smi\n" |
389 "b = 2.5; // b is HeapNumber"); | 384 "b = 2.5; // b is HeapNumber"); |
390 const v8::HeapSnapshot* snapshot = | 385 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
391 heap_profiler->TakeHeapSnapshot(v8_str("numbers")); | |
392 CHECK(ValidateSnapshot(snapshot)); | 386 CHECK(ValidateSnapshot(snapshot)); |
393 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 387 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
394 CHECK(!GetProperty(global, v8::HeapGraphEdge::kProperty, "a")); | 388 CHECK(!GetProperty(global, v8::HeapGraphEdge::kProperty, "a")); |
395 const v8::HeapGraphNode* b = | 389 const v8::HeapGraphNode* b = |
396 GetProperty(global, v8::HeapGraphEdge::kProperty, "b"); | 390 GetProperty(global, v8::HeapGraphEdge::kProperty, "b"); |
397 CHECK(b); | 391 CHECK(b); |
398 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType()); | 392 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType()); |
399 } | 393 } |
400 | 394 |
401 | 395 |
402 TEST(HeapSnapshotSlicedString) { | 396 TEST(HeapSnapshotSlicedString) { |
403 LocalContext env; | 397 LocalContext env; |
404 v8::HandleScope scope(env->GetIsolate()); | 398 v8::HandleScope scope(env->GetIsolate()); |
405 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 399 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
406 CompileRun( | 400 CompileRun( |
407 "parent_string = \"123456789.123456789.123456789.123456789.123456789." | 401 "parent_string = \"123456789.123456789.123456789.123456789.123456789." |
408 "123456789.123456789.123456789.123456789.123456789." | 402 "123456789.123456789.123456789.123456789.123456789." |
409 "123456789.123456789.123456789.123456789.123456789." | 403 "123456789.123456789.123456789.123456789.123456789." |
410 "123456789.123456789.123456789.123456789.123456789." | 404 "123456789.123456789.123456789.123456789.123456789." |
411 "123456789.123456789.123456789.123456789.123456789." | 405 "123456789.123456789.123456789.123456789.123456789." |
412 "123456789.123456789.123456789.123456789.123456789." | 406 "123456789.123456789.123456789.123456789.123456789." |
413 "123456789.123456789.123456789.123456789.123456789." | 407 "123456789.123456789.123456789.123456789.123456789." |
414 "123456789.123456789.123456789.123456789.123456789.\";" | 408 "123456789.123456789.123456789.123456789.123456789.\";" |
415 "child_string = parent_string.slice(100);"); | 409 "child_string = parent_string.slice(100);"); |
416 const v8::HeapSnapshot* snapshot = | 410 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
417 heap_profiler->TakeHeapSnapshot(v8_str("strings")); | |
418 CHECK(ValidateSnapshot(snapshot)); | 411 CHECK(ValidateSnapshot(snapshot)); |
419 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 412 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
420 const v8::HeapGraphNode* parent_string = | 413 const v8::HeapGraphNode* parent_string = |
421 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string"); | 414 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string"); |
422 CHECK(parent_string); | 415 CHECK(parent_string); |
423 const v8::HeapGraphNode* child_string = | 416 const v8::HeapGraphNode* child_string = |
424 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string"); | 417 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string"); |
425 CHECK(child_string); | 418 CHECK(child_string); |
426 CHECK_EQ(v8::HeapGraphNode::kSlicedString, child_string->GetType()); | 419 CHECK_EQ(v8::HeapGraphNode::kSlicedString, child_string->GetType()); |
427 const v8::HeapGraphNode* parent = | 420 const v8::HeapGraphNode* parent = |
(...skipping 16 matching lines...) Expand all Loading... |
444 | 437 |
445 i::Factory* factory = CcTest::i_isolate()->factory(); | 438 i::Factory* factory = CcTest::i_isolate()->factory(); |
446 i::Handle<i::String> first = factory->NewStringFromStaticChars("0123456789"); | 439 i::Handle<i::String> first = factory->NewStringFromStaticChars("0123456789"); |
447 i::Handle<i::String> second = factory->NewStringFromStaticChars("0123456789"); | 440 i::Handle<i::String> second = factory->NewStringFromStaticChars("0123456789"); |
448 i::Handle<i::String> cons_string = | 441 i::Handle<i::String> cons_string = |
449 factory->NewConsString(first, second).ToHandleChecked(); | 442 factory->NewConsString(first, second).ToHandleChecked(); |
450 | 443 |
451 global->SetInternalField(0, v8::ToApiHandle<v8::String>(cons_string)); | 444 global->SetInternalField(0, v8::ToApiHandle<v8::String>(cons_string)); |
452 | 445 |
453 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 446 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
454 const v8::HeapSnapshot* snapshot = | 447 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
455 heap_profiler->TakeHeapSnapshot(v8_str("cons_strings")); | |
456 CHECK(ValidateSnapshot(snapshot)); | 448 CHECK(ValidateSnapshot(snapshot)); |
457 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); | 449 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); |
458 | 450 |
459 const v8::HeapGraphNode* string_node = | 451 const v8::HeapGraphNode* string_node = |
460 GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0"); | 452 GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0"); |
461 CHECK(string_node); | 453 CHECK(string_node); |
462 CHECK_EQ(v8::HeapGraphNode::kConsString, string_node->GetType()); | 454 CHECK_EQ(v8::HeapGraphNode::kConsString, string_node->GetType()); |
463 | 455 |
464 const v8::HeapGraphNode* first_node = | 456 const v8::HeapGraphNode* first_node = |
465 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "first"); | 457 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "first"); |
466 CHECK_EQ(v8::HeapGraphNode::kString, first_node->GetType()); | 458 CHECK_EQ(v8::HeapGraphNode::kString, first_node->GetType()); |
467 | 459 |
468 const v8::HeapGraphNode* second_node = | 460 const v8::HeapGraphNode* second_node = |
469 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "second"); | 461 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "second"); |
470 CHECK_EQ(v8::HeapGraphNode::kString, second_node->GetType()); | 462 CHECK_EQ(v8::HeapGraphNode::kString, second_node->GetType()); |
471 | 463 |
472 heap_profiler->DeleteAllHeapSnapshots(); | 464 heap_profiler->DeleteAllHeapSnapshots(); |
473 } | 465 } |
474 | 466 |
475 | 467 |
476 TEST(HeapSnapshotSymbol) { | 468 TEST(HeapSnapshotSymbol) { |
477 LocalContext env; | 469 LocalContext env; |
478 v8::HandleScope scope(env->GetIsolate()); | 470 v8::HandleScope scope(env->GetIsolate()); |
479 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 471 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
480 | 472 |
481 CompileRun("a = Symbol('mySymbol');\n"); | 473 CompileRun("a = Symbol('mySymbol');\n"); |
482 const v8::HeapSnapshot* snapshot = | 474 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
483 heap_profiler->TakeHeapSnapshot(v8_str("Symbol")); | |
484 CHECK(ValidateSnapshot(snapshot)); | 475 CHECK(ValidateSnapshot(snapshot)); |
485 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 476 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
486 const v8::HeapGraphNode* a = | 477 const v8::HeapGraphNode* a = |
487 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); | 478 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); |
488 CHECK(a); | 479 CHECK(a); |
489 CHECK_EQ(a->GetType(), v8::HeapGraphNode::kSymbol); | 480 CHECK_EQ(a->GetType(), v8::HeapGraphNode::kSymbol); |
490 CHECK(v8_str("symbol")->Equals(a->GetName())); | 481 CHECK(v8_str("symbol")->Equals(a->GetName())); |
491 const v8::HeapGraphNode* name = | 482 const v8::HeapGraphNode* name = |
492 GetProperty(a, v8::HeapGraphEdge::kInternal, "name"); | 483 GetProperty(a, v8::HeapGraphEdge::kInternal, "name"); |
493 CHECK(name); | 484 CHECK(name); |
494 CHECK(v8_str("mySymbol")->Equals(name->GetName())); | 485 CHECK(v8_str("mySymbol")->Equals(name->GetName())); |
495 } | 486 } |
496 | 487 |
497 | 488 |
498 TEST(HeapSnapshotWeakCollection) { | 489 TEST(HeapSnapshotWeakCollection) { |
499 LocalContext env; | 490 LocalContext env; |
500 v8::HandleScope scope(env->GetIsolate()); | 491 v8::HandleScope scope(env->GetIsolate()); |
501 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 492 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
502 | 493 |
503 CompileRun( | 494 CompileRun( |
504 "k = {}; v = {}; s = 'str';\n" | 495 "k = {}; v = {}; s = 'str';\n" |
505 "ws = new WeakSet(); ws.add(k); ws.add(v); ws[s] = s;\n" | 496 "ws = new WeakSet(); ws.add(k); ws.add(v); ws[s] = s;\n" |
506 "wm = new WeakMap(); wm.set(k, v); wm[s] = s;\n"); | 497 "wm = new WeakMap(); wm.set(k, v); wm[s] = s;\n"); |
507 const v8::HeapSnapshot* snapshot = | 498 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
508 heap_profiler->TakeHeapSnapshot(v8_str("WeakCollections")); | |
509 CHECK(ValidateSnapshot(snapshot)); | 499 CHECK(ValidateSnapshot(snapshot)); |
510 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 500 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
511 const v8::HeapGraphNode* k = | 501 const v8::HeapGraphNode* k = |
512 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); | 502 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); |
513 CHECK(k); | 503 CHECK(k); |
514 const v8::HeapGraphNode* v = | 504 const v8::HeapGraphNode* v = |
515 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); | 505 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); |
516 CHECK(v); | 506 CHECK(v); |
517 const v8::HeapGraphNode* s = | 507 const v8::HeapGraphNode* s = |
518 GetProperty(global, v8::HeapGraphEdge::kProperty, "s"); | 508 GetProperty(global, v8::HeapGraphEdge::kProperty, "s"); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 561 |
572 TEST(HeapSnapshotCollection) { | 562 TEST(HeapSnapshotCollection) { |
573 LocalContext env; | 563 LocalContext env; |
574 v8::HandleScope scope(env->GetIsolate()); | 564 v8::HandleScope scope(env->GetIsolate()); |
575 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 565 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
576 | 566 |
577 CompileRun( | 567 CompileRun( |
578 "k = {}; v = {}; s = 'str';\n" | 568 "k = {}; v = {}; s = 'str';\n" |
579 "set = new Set(); set.add(k); set.add(v); set[s] = s;\n" | 569 "set = new Set(); set.add(k); set.add(v); set[s] = s;\n" |
580 "map = new Map(); map.set(k, v); map[s] = s;\n"); | 570 "map = new Map(); map.set(k, v); map[s] = s;\n"); |
581 const v8::HeapSnapshot* snapshot = | 571 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
582 heap_profiler->TakeHeapSnapshot(v8_str("Collections")); | |
583 CHECK(ValidateSnapshot(snapshot)); | 572 CHECK(ValidateSnapshot(snapshot)); |
584 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 573 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
585 const v8::HeapGraphNode* k = | 574 const v8::HeapGraphNode* k = |
586 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); | 575 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); |
587 CHECK(k); | 576 CHECK(k); |
588 const v8::HeapGraphNode* v = | 577 const v8::HeapGraphNode* v = |
589 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); | 578 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); |
590 CHECK(v); | 579 CHECK(v); |
591 const v8::HeapGraphNode* s = | 580 const v8::HeapGraphNode* s = |
592 GetProperty(global, v8::HeapGraphEdge::kProperty, "s"); | 581 GetProperty(global, v8::HeapGraphEdge::kProperty, "s"); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 v8::ObjectTemplate::New(isolate); | 638 v8::ObjectTemplate::New(isolate); |
650 global_template->SetInternalFieldCount(2); | 639 global_template->SetInternalFieldCount(2); |
651 LocalContext env(NULL, global_template); | 640 LocalContext env(NULL, global_template); |
652 v8::Handle<v8::Object> global_proxy = env->Global(); | 641 v8::Handle<v8::Object> global_proxy = env->Global(); |
653 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 642 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
654 CHECK_EQ(2, global->InternalFieldCount()); | 643 CHECK_EQ(2, global->InternalFieldCount()); |
655 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 644 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
656 global->SetInternalField(0, v8_num(17)); | 645 global->SetInternalField(0, v8_num(17)); |
657 global->SetInternalField(1, obj); | 646 global->SetInternalField(1, obj); |
658 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 647 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
659 const v8::HeapSnapshot* snapshot = | 648 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
660 heap_profiler->TakeHeapSnapshot(v8_str("internals")); | |
661 CHECK(ValidateSnapshot(snapshot)); | 649 CHECK(ValidateSnapshot(snapshot)); |
662 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); | 650 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); |
663 // The first reference will not present, because it's a Smi. | 651 // The first reference will not present, because it's a Smi. |
664 CHECK(!GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); | 652 CHECK(!GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); |
665 // The second reference is to an object. | 653 // The second reference is to an object. |
666 CHECK(GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1")); | 654 CHECK(GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1")); |
667 } | 655 } |
668 | 656 |
669 | 657 |
670 TEST(HeapSnapshotAddressReuse) { | 658 TEST(HeapSnapshotAddressReuse) { |
671 LocalContext env; | 659 LocalContext env; |
672 v8::HandleScope scope(env->GetIsolate()); | 660 v8::HandleScope scope(env->GetIsolate()); |
673 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 661 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
674 | 662 |
675 CompileRun( | 663 CompileRun( |
676 "function A() {}\n" | 664 "function A() {}\n" |
677 "var a = [];\n" | 665 "var a = [];\n" |
678 "for (var i = 0; i < 10000; ++i)\n" | 666 "for (var i = 0; i < 10000; ++i)\n" |
679 " a[i] = new A();\n"); | 667 " a[i] = new A();\n"); |
680 const v8::HeapSnapshot* snapshot1 = | 668 const v8::HeapSnapshot* snapshot1 = heap_profiler->TakeHeapSnapshot(); |
681 heap_profiler->TakeHeapSnapshot(v8_str("snapshot1")); | |
682 CHECK(ValidateSnapshot(snapshot1)); | 669 CHECK(ValidateSnapshot(snapshot1)); |
683 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); | 670 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); |
684 | 671 |
685 CompileRun( | 672 CompileRun( |
686 "for (var i = 0; i < 10000; ++i)\n" | 673 "for (var i = 0; i < 10000; ++i)\n" |
687 " a[i] = new A();\n"); | 674 " a[i] = new A();\n"); |
688 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 675 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
689 | 676 |
690 const v8::HeapSnapshot* snapshot2 = | 677 const v8::HeapSnapshot* snapshot2 = heap_profiler->TakeHeapSnapshot(); |
691 heap_profiler->TakeHeapSnapshot(v8_str("snapshot2")); | |
692 CHECK(ValidateSnapshot(snapshot2)); | 678 CHECK(ValidateSnapshot(snapshot2)); |
693 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); | 679 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
694 | 680 |
695 const v8::HeapGraphNode* array_node = | 681 const v8::HeapGraphNode* array_node = |
696 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); | 682 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); |
697 CHECK(array_node); | 683 CHECK(array_node); |
698 int wrong_count = 0; | 684 int wrong_count = 0; |
699 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) { | 685 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) { |
700 const v8::HeapGraphEdge* prop = array_node->GetChild(i); | 686 const v8::HeapGraphEdge* prop = array_node->GetChild(i); |
701 if (prop->GetType() != v8::HeapGraphEdge::kElement) | 687 if (prop->GetType() != v8::HeapGraphEdge::kElement) |
(...skipping 12 matching lines...) Expand all Loading... |
714 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 700 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
715 | 701 |
716 CompileRun( | 702 CompileRun( |
717 "function AnObject() {\n" | 703 "function AnObject() {\n" |
718 " this.first = 'first';\n" | 704 " this.first = 'first';\n" |
719 " this.second = 'second';\n" | 705 " this.second = 'second';\n" |
720 "}\n" | 706 "}\n" |
721 "var a = new Array();\n" | 707 "var a = new Array();\n" |
722 "for (var i = 0; i < 10; ++i)\n" | 708 "for (var i = 0; i < 10; ++i)\n" |
723 " a.push(new AnObject());\n"); | 709 " a.push(new AnObject());\n"); |
724 const v8::HeapSnapshot* snapshot1 = | 710 const v8::HeapSnapshot* snapshot1 = heap_profiler->TakeHeapSnapshot(); |
725 heap_profiler->TakeHeapSnapshot(v8_str("s1")); | |
726 CHECK(ValidateSnapshot(snapshot1)); | 711 CHECK(ValidateSnapshot(snapshot1)); |
727 | 712 |
728 CompileRun( | 713 CompileRun( |
729 "for (var i = 0; i < 1; ++i)\n" | 714 "for (var i = 0; i < 1; ++i)\n" |
730 " a.shift();\n"); | 715 " a.shift();\n"); |
731 | 716 |
732 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 717 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
733 | 718 |
734 const v8::HeapSnapshot* snapshot2 = | 719 const v8::HeapSnapshot* snapshot2 = heap_profiler->TakeHeapSnapshot(); |
735 heap_profiler->TakeHeapSnapshot(v8_str("s2")); | |
736 CHECK(ValidateSnapshot(snapshot2)); | 720 CHECK(ValidateSnapshot(snapshot2)); |
737 | 721 |
738 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); | 722 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); |
739 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); | 723 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
740 CHECK_NE(0u, global1->GetId()); | 724 CHECK_NE(0u, global1->GetId()); |
741 CHECK_EQ(global1->GetId(), global2->GetId()); | 725 CHECK_EQ(global1->GetId(), global2->GetId()); |
742 | 726 |
743 const v8::HeapGraphNode* a1 = | 727 const v8::HeapGraphNode* a1 = |
744 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a"); | 728 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a"); |
745 CHECK(a1); | 729 CHECK(a1); |
(...skipping 15 matching lines...) Expand all Loading... |
761 TEST(HeapEntryIdsAndGC) { | 745 TEST(HeapEntryIdsAndGC) { |
762 LocalContext env; | 746 LocalContext env; |
763 v8::HandleScope scope(env->GetIsolate()); | 747 v8::HandleScope scope(env->GetIsolate()); |
764 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 748 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
765 | 749 |
766 CompileRun( | 750 CompileRun( |
767 "function A() {}\n" | 751 "function A() {}\n" |
768 "function B(x) { this.x = x; }\n" | 752 "function B(x) { this.x = x; }\n" |
769 "var a = new A();\n" | 753 "var a = new A();\n" |
770 "var b = new B(a);"); | 754 "var b = new B(a);"); |
771 v8::Local<v8::String> s1_str = v8_str("s1"); | 755 const v8::HeapSnapshot* snapshot1 = heap_profiler->TakeHeapSnapshot(); |
772 v8::Local<v8::String> s2_str = v8_str("s2"); | |
773 const v8::HeapSnapshot* snapshot1 = | |
774 heap_profiler->TakeHeapSnapshot(s1_str); | |
775 CHECK(ValidateSnapshot(snapshot1)); | 756 CHECK(ValidateSnapshot(snapshot1)); |
776 | 757 |
777 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 758 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
778 | 759 |
779 const v8::HeapSnapshot* snapshot2 = | 760 const v8::HeapSnapshot* snapshot2 = heap_profiler->TakeHeapSnapshot(); |
780 heap_profiler->TakeHeapSnapshot(s2_str); | |
781 CHECK(ValidateSnapshot(snapshot2)); | 761 CHECK(ValidateSnapshot(snapshot2)); |
782 | 762 |
783 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000u); | 763 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000u); |
784 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= | 764 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= |
785 snapshot2->GetMaxSnapshotJSObjectId()); | 765 snapshot2->GetMaxSnapshotJSObjectId()); |
786 | 766 |
787 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); | 767 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); |
788 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); | 768 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
789 CHECK_NE(0u, global1->GetId()); | 769 CHECK_NE(0u, global1->GetId()); |
790 CHECK_EQ(global1->GetId(), global2->GetId()); | 770 CHECK_EQ(global1->GetId(), global2->GetId()); |
(...skipping 29 matching lines...) Expand all Loading... |
820 CHECK(b2); | 800 CHECK(b2); |
821 CHECK_NE(0u, b1->GetId()); | 801 CHECK_NE(0u, b1->GetId()); |
822 CHECK_EQ(b1->GetId(), b2->GetId()); | 802 CHECK_EQ(b1->GetId(), b2->GetId()); |
823 } | 803 } |
824 | 804 |
825 | 805 |
826 TEST(HeapSnapshotRootPreservedAfterSorting) { | 806 TEST(HeapSnapshotRootPreservedAfterSorting) { |
827 LocalContext env; | 807 LocalContext env; |
828 v8::HandleScope scope(env->GetIsolate()); | 808 v8::HandleScope scope(env->GetIsolate()); |
829 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 809 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
830 const v8::HeapSnapshot* snapshot = | 810 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
831 heap_profiler->TakeHeapSnapshot(v8_str("s")); | |
832 CHECK(ValidateSnapshot(snapshot)); | 811 CHECK(ValidateSnapshot(snapshot)); |
833 const v8::HeapGraphNode* root1 = snapshot->GetRoot(); | 812 const v8::HeapGraphNode* root1 = snapshot->GetRoot(); |
834 const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>( | 813 const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>( |
835 snapshot))->GetSortedEntriesList(); | 814 snapshot))->GetSortedEntriesList(); |
836 const v8::HeapGraphNode* root2 = snapshot->GetRoot(); | 815 const v8::HeapGraphNode* root2 = snapshot->GetRoot(); |
837 CHECK_EQ(root1, root2); | 816 CHECK_EQ(root1, root2); |
838 } | 817 } |
839 | 818 |
840 | 819 |
841 namespace { | 820 namespace { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 v8::HandleScope scope(isolate); | 868 v8::HandleScope scope(isolate); |
890 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 869 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
891 | 870 |
892 #define STRING_LITERAL_FOR_TEST \ | 871 #define STRING_LITERAL_FOR_TEST \ |
893 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" | 872 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" |
894 CompileRun( | 873 CompileRun( |
895 "function A(s) { this.s = s; }\n" | 874 "function A(s) { this.s = s; }\n" |
896 "function B(x) { this.x = x; }\n" | 875 "function B(x) { this.x = x; }\n" |
897 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n" | 876 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n" |
898 "var b = new B(a);"); | 877 "var b = new B(a);"); |
899 const v8::HeapSnapshot* snapshot = | 878 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
900 heap_profiler->TakeHeapSnapshot(v8_str("json")); | |
901 CHECK(ValidateSnapshot(snapshot)); | 879 CHECK(ValidateSnapshot(snapshot)); |
902 | 880 |
903 TestJSONStream stream; | 881 TestJSONStream stream; |
904 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); | 882 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); |
905 CHECK_GT(stream.size(), 0); | 883 CHECK_GT(stream.size(), 0); |
906 CHECK_EQ(1, stream.eos_signaled()); | 884 CHECK_EQ(1, stream.eos_signaled()); |
907 i::ScopedVector<char> json(stream.size()); | 885 i::ScopedVector<char> json(stream.size()); |
908 stream.WriteTo(json); | 886 stream.WriteTo(json); |
909 | 887 |
910 // Verify that snapshot string is valid JSON. | 888 // Verify that snapshot string is valid JSON. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 #undef STRING_LITERAL_FOR_TEST | 967 #undef STRING_LITERAL_FOR_TEST |
990 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(ref_string), | 968 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(ref_string), |
991 *v8::String::Utf8Value(string))); | 969 *v8::String::Utf8Value(string))); |
992 } | 970 } |
993 | 971 |
994 | 972 |
995 TEST(HeapSnapshotJSONSerializationAborting) { | 973 TEST(HeapSnapshotJSONSerializationAborting) { |
996 LocalContext env; | 974 LocalContext env; |
997 v8::HandleScope scope(env->GetIsolate()); | 975 v8::HandleScope scope(env->GetIsolate()); |
998 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 976 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
999 const v8::HeapSnapshot* snapshot = | 977 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1000 heap_profiler->TakeHeapSnapshot(v8_str("abort")); | |
1001 CHECK(ValidateSnapshot(snapshot)); | 978 CHECK(ValidateSnapshot(snapshot)); |
1002 TestJSONStream stream(5); | 979 TestJSONStream stream(5); |
1003 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); | 980 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); |
1004 CHECK_GT(stream.size(), 0); | 981 CHECK_GT(stream.size(), 0); |
1005 CHECK_EQ(0, stream.eos_signaled()); | 982 CHECK_EQ(0, stream.eos_signaled()); |
1006 } | 983 } |
1007 | 984 |
1008 namespace { | 985 namespace { |
1009 | 986 |
1010 class TestStatsStream : public v8::OutputStream { | 987 class TestStatsStream : public v8::OutputStream { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 CheckChildrenIds(snapshot, child, level + 1, max_level); | 1249 CheckChildrenIds(snapshot, child, level + 1, max_level); |
1273 } | 1250 } |
1274 } | 1251 } |
1275 | 1252 |
1276 | 1253 |
1277 TEST(HeapSnapshotGetNodeById) { | 1254 TEST(HeapSnapshotGetNodeById) { |
1278 LocalContext env; | 1255 LocalContext env; |
1279 v8::HandleScope scope(env->GetIsolate()); | 1256 v8::HandleScope scope(env->GetIsolate()); |
1280 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1257 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1281 | 1258 |
1282 const v8::HeapSnapshot* snapshot = | 1259 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1283 heap_profiler->TakeHeapSnapshot(v8_str("id")); | |
1284 CHECK(ValidateSnapshot(snapshot)); | 1260 CHECK(ValidateSnapshot(snapshot)); |
1285 const v8::HeapGraphNode* root = snapshot->GetRoot(); | 1261 const v8::HeapGraphNode* root = snapshot->GetRoot(); |
1286 CheckChildrenIds(snapshot, root, 0, 3); | 1262 CheckChildrenIds(snapshot, root, 0, 3); |
1287 // Check a big id, which should not exist yet. | 1263 // Check a big id, which should not exist yet. |
1288 CHECK(!snapshot->GetNodeById(0x1000000UL)); | 1264 CHECK(!snapshot->GetNodeById(0x1000000UL)); |
1289 } | 1265 } |
1290 | 1266 |
1291 | 1267 |
1292 TEST(HeapSnapshotGetSnapshotObjectId) { | 1268 TEST(HeapSnapshotGetSnapshotObjectId) { |
1293 LocalContext env; | 1269 LocalContext env; |
1294 v8::HandleScope scope(env->GetIsolate()); | 1270 v8::HandleScope scope(env->GetIsolate()); |
1295 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1271 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1296 CompileRun("globalObject = {};\n"); | 1272 CompileRun("globalObject = {};\n"); |
1297 const v8::HeapSnapshot* snapshot = | 1273 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1298 heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id")); | |
1299 CHECK(ValidateSnapshot(snapshot)); | 1274 CHECK(ValidateSnapshot(snapshot)); |
1300 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1275 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1301 const v8::HeapGraphNode* global_object = | 1276 const v8::HeapGraphNode* global_object = |
1302 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject"); | 1277 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject"); |
1303 CHECK(global_object); | 1278 CHECK(global_object); |
1304 | 1279 |
1305 v8::Local<v8::Value> globalObjectHandle = env->Global()->Get( | 1280 v8::Local<v8::Value> globalObjectHandle = env->Global()->Get( |
1306 v8::String::NewFromUtf8(env->GetIsolate(), "globalObject")); | 1281 v8::String::NewFromUtf8(env->GetIsolate(), "globalObject")); |
1307 CHECK(!globalObjectHandle.IsEmpty()); | 1282 CHECK(!globalObjectHandle.IsEmpty()); |
1308 CHECK(globalObjectHandle->IsObject()); | 1283 CHECK(globalObjectHandle->IsObject()); |
1309 | 1284 |
1310 v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle); | 1285 v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle); |
1311 CHECK_NE(v8::HeapProfiler::kUnknownObjectId, id); | 1286 CHECK_NE(v8::HeapProfiler::kUnknownObjectId, id); |
1312 CHECK_EQ(id, global_object->GetId()); | 1287 CHECK_EQ(id, global_object->GetId()); |
1313 } | 1288 } |
1314 | 1289 |
1315 | 1290 |
1316 TEST(HeapSnapshotUnknownSnapshotObjectId) { | 1291 TEST(HeapSnapshotUnknownSnapshotObjectId) { |
1317 LocalContext env; | 1292 LocalContext env; |
1318 v8::HandleScope scope(env->GetIsolate()); | 1293 v8::HandleScope scope(env->GetIsolate()); |
1319 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1294 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1320 CompileRun("globalObject = {};\n"); | 1295 CompileRun("globalObject = {};\n"); |
1321 const v8::HeapSnapshot* snapshot = | 1296 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1322 heap_profiler->TakeHeapSnapshot(v8_str("unknown_object_id")); | |
1323 CHECK(ValidateSnapshot(snapshot)); | 1297 CHECK(ValidateSnapshot(snapshot)); |
1324 const v8::HeapGraphNode* node = | 1298 const v8::HeapGraphNode* node = |
1325 snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId); | 1299 snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId); |
1326 CHECK(!node); | 1300 CHECK(!node); |
1327 } | 1301 } |
1328 | 1302 |
1329 | 1303 |
1330 namespace { | 1304 namespace { |
1331 | 1305 |
1332 class TestActivityControl : public v8::ActivityControl { | 1306 class TestActivityControl : public v8::ActivityControl { |
(...skipping 17 matching lines...) Expand all Loading... |
1350 | 1324 |
1351 | 1325 |
1352 TEST(TakeHeapSnapshotAborting) { | 1326 TEST(TakeHeapSnapshotAborting) { |
1353 LocalContext env; | 1327 LocalContext env; |
1354 v8::HandleScope scope(env->GetIsolate()); | 1328 v8::HandleScope scope(env->GetIsolate()); |
1355 | 1329 |
1356 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1330 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1357 const int snapshots_count = heap_profiler->GetSnapshotCount(); | 1331 const int snapshots_count = heap_profiler->GetSnapshotCount(); |
1358 TestActivityControl aborting_control(1); | 1332 TestActivityControl aborting_control(1); |
1359 const v8::HeapSnapshot* no_snapshot = | 1333 const v8::HeapSnapshot* no_snapshot = |
1360 heap_profiler->TakeHeapSnapshot(v8_str("abort"), | 1334 heap_profiler->TakeHeapSnapshot(&aborting_control); |
1361 &aborting_control); | |
1362 CHECK(!no_snapshot); | 1335 CHECK(!no_snapshot); |
1363 CHECK_EQ(snapshots_count, heap_profiler->GetSnapshotCount()); | 1336 CHECK_EQ(snapshots_count, heap_profiler->GetSnapshotCount()); |
1364 CHECK_GT(aborting_control.total(), aborting_control.done()); | 1337 CHECK_GT(aborting_control.total(), aborting_control.done()); |
1365 | 1338 |
1366 TestActivityControl control(-1); // Don't abort. | 1339 TestActivityControl control(-1); // Don't abort. |
1367 const v8::HeapSnapshot* snapshot = | 1340 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(&control); |
1368 heap_profiler->TakeHeapSnapshot(v8_str("full"), | |
1369 &control); | |
1370 CHECK(ValidateSnapshot(snapshot)); | 1341 CHECK(ValidateSnapshot(snapshot)); |
1371 | 1342 |
1372 CHECK(snapshot); | 1343 CHECK(snapshot); |
1373 CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount()); | 1344 CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount()); |
1374 CHECK_EQ(control.total(), control.done()); | 1345 CHECK_EQ(control.total(), control.done()); |
1375 CHECK_GT(control.total(), 0); | 1346 CHECK_GT(control.total(), 0); |
1376 } | 1347 } |
1377 | 1348 |
1378 | 1349 |
1379 namespace { | 1350 namespace { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 1, TestRetainedObjectInfo::WrapperInfoCallback); | 1441 1, TestRetainedObjectInfo::WrapperInfoCallback); |
1471 heap_profiler->SetWrapperClassInfoProvider( | 1442 heap_profiler->SetWrapperClassInfoProvider( |
1472 2, TestRetainedObjectInfo::WrapperInfoCallback); | 1443 2, TestRetainedObjectInfo::WrapperInfoCallback); |
1473 v8::Persistent<v8::String> p_AAA(isolate, v8_str("AAA")); | 1444 v8::Persistent<v8::String> p_AAA(isolate, v8_str("AAA")); |
1474 p_AAA.SetWrapperClassId(1); | 1445 p_AAA.SetWrapperClassId(1); |
1475 v8::Persistent<v8::String> p_BBB(isolate, v8_str("BBB")); | 1446 v8::Persistent<v8::String> p_BBB(isolate, v8_str("BBB")); |
1476 p_BBB.SetWrapperClassId(1); | 1447 p_BBB.SetWrapperClassId(1); |
1477 v8::Persistent<v8::String> p_CCC(isolate, v8_str("CCC")); | 1448 v8::Persistent<v8::String> p_CCC(isolate, v8_str("CCC")); |
1478 p_CCC.SetWrapperClassId(2); | 1449 p_CCC.SetWrapperClassId(2); |
1479 CHECK_EQ(0, TestRetainedObjectInfo::instances.length()); | 1450 CHECK_EQ(0, TestRetainedObjectInfo::instances.length()); |
1480 const v8::HeapSnapshot* snapshot = | 1451 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1481 heap_profiler->TakeHeapSnapshot(v8_str("retained")); | |
1482 CHECK(ValidateSnapshot(snapshot)); | 1452 CHECK(ValidateSnapshot(snapshot)); |
1483 | 1453 |
1484 CHECK_EQ(3, TestRetainedObjectInfo::instances.length()); | 1454 CHECK_EQ(3, TestRetainedObjectInfo::instances.length()); |
1485 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) { | 1455 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) { |
1486 CHECK(TestRetainedObjectInfo::instances[i]->disposed()); | 1456 CHECK(TestRetainedObjectInfo::instances[i]->disposed()); |
1487 delete TestRetainedObjectInfo::instances[i]; | 1457 delete TestRetainedObjectInfo::instances[i]; |
1488 } | 1458 } |
1489 | 1459 |
1490 const v8::HeapGraphNode* native_group_aaa = GetNode( | 1460 const v8::HeapGraphNode* native_group_aaa = GetNode( |
1491 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "aaa-group"); | 1461 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "aaa-group"); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 | 1533 |
1564 | 1534 |
1565 TEST(HeapSnapshotImplicitReferences) { | 1535 TEST(HeapSnapshotImplicitReferences) { |
1566 LocalContext env; | 1536 LocalContext env; |
1567 v8::HandleScope scope(env->GetIsolate()); | 1537 v8::HandleScope scope(env->GetIsolate()); |
1568 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1538 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1569 | 1539 |
1570 GraphWithImplicitRefs graph(&env); | 1540 GraphWithImplicitRefs graph(&env); |
1571 v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); | 1541 v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); |
1572 | 1542 |
1573 const v8::HeapSnapshot* snapshot = | 1543 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1574 heap_profiler->TakeHeapSnapshot(v8_str("implicit_refs")); | |
1575 CHECK(ValidateSnapshot(snapshot)); | 1544 CHECK(ValidateSnapshot(snapshot)); |
1576 | 1545 |
1577 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); | 1546 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); |
1578 const v8::HeapGraphNode* obj0 = GetProperty( | 1547 const v8::HeapGraphNode* obj0 = GetProperty( |
1579 global_object, v8::HeapGraphEdge::kProperty, "root_object"); | 1548 global_object, v8::HeapGraphEdge::kProperty, "root_object"); |
1580 CHECK(obj0); | 1549 CHECK(obj0); |
1581 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType()); | 1550 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType()); |
1582 const v8::HeapGraphNode* obj1 = GetProperty( | 1551 const v8::HeapGraphNode* obj1 = GetProperty( |
1583 obj0, v8::HeapGraphEdge::kInternal, "native"); | 1552 obj0, v8::HeapGraphEdge::kInternal, "native"); |
1584 CHECK(obj1); | 1553 CHECK(obj1); |
(...skipping 12 matching lines...) Expand all Loading... |
1597 | 1566 |
1598 | 1567 |
1599 TEST(DeleteAllHeapSnapshots) { | 1568 TEST(DeleteAllHeapSnapshots) { |
1600 LocalContext env; | 1569 LocalContext env; |
1601 v8::HandleScope scope(env->GetIsolate()); | 1570 v8::HandleScope scope(env->GetIsolate()); |
1602 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1571 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1603 | 1572 |
1604 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); | 1573 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); |
1605 heap_profiler->DeleteAllHeapSnapshots(); | 1574 heap_profiler->DeleteAllHeapSnapshots(); |
1606 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); | 1575 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); |
1607 CHECK(heap_profiler->TakeHeapSnapshot(v8_str("1"))); | 1576 CHECK(heap_profiler->TakeHeapSnapshot()); |
1608 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); | 1577 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); |
1609 heap_profiler->DeleteAllHeapSnapshots(); | 1578 heap_profiler->DeleteAllHeapSnapshots(); |
1610 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); | 1579 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); |
1611 CHECK(heap_profiler->TakeHeapSnapshot(v8_str("1"))); | 1580 CHECK(heap_profiler->TakeHeapSnapshot()); |
1612 CHECK(heap_profiler->TakeHeapSnapshot(v8_str("2"))); | 1581 CHECK(heap_profiler->TakeHeapSnapshot()); |
1613 CHECK_EQ(2, heap_profiler->GetSnapshotCount()); | 1582 CHECK_EQ(2, heap_profiler->GetSnapshotCount()); |
1614 heap_profiler->DeleteAllHeapSnapshots(); | 1583 heap_profiler->DeleteAllHeapSnapshots(); |
1615 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); | 1584 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); |
1616 } | 1585 } |
1617 | 1586 |
1618 | 1587 |
1619 static const v8::HeapSnapshot* FindHeapSnapshot(v8::HeapProfiler* profiler, | 1588 static bool FindHeapSnapshot(v8::HeapProfiler* profiler, |
1620 unsigned uid) { | 1589 const v8::HeapSnapshot* snapshot) { |
1621 int length = profiler->GetSnapshotCount(); | 1590 int length = profiler->GetSnapshotCount(); |
1622 for (int i = 0; i < length; i++) { | 1591 for (int i = 0; i < length; i++) { |
1623 const v8::HeapSnapshot* snapshot = profiler->GetHeapSnapshot(i); | 1592 if (snapshot == profiler->GetHeapSnapshot(i)) return true; |
1624 if (snapshot->GetUid() == uid) { | |
1625 return snapshot; | |
1626 } | |
1627 } | 1593 } |
1628 return NULL; | 1594 return false; |
1629 } | 1595 } |
1630 | 1596 |
1631 | 1597 |
1632 TEST(DeleteHeapSnapshot) { | 1598 TEST(DeleteHeapSnapshot) { |
1633 LocalContext env; | 1599 LocalContext env; |
1634 v8::HandleScope scope(env->GetIsolate()); | 1600 v8::HandleScope scope(env->GetIsolate()); |
1635 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1601 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1636 | 1602 |
1637 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); | 1603 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); |
1638 const v8::HeapSnapshot* s1 = | 1604 const v8::HeapSnapshot* s1 = heap_profiler->TakeHeapSnapshot(); |
1639 heap_profiler->TakeHeapSnapshot(v8_str("1")); | |
1640 | 1605 |
1641 CHECK(s1); | 1606 CHECK(s1); |
1642 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); | 1607 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); |
1643 unsigned uid1 = s1->GetUid(); | 1608 CHECK(FindHeapSnapshot(heap_profiler, s1)); |
1644 CHECK_EQ(s1, FindHeapSnapshot(heap_profiler, uid1)); | |
1645 const_cast<v8::HeapSnapshot*>(s1)->Delete(); | 1609 const_cast<v8::HeapSnapshot*>(s1)->Delete(); |
1646 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); | 1610 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); |
1647 CHECK(!FindHeapSnapshot(heap_profiler, uid1)); | 1611 CHECK(!FindHeapSnapshot(heap_profiler, s1)); |
1648 | 1612 |
1649 const v8::HeapSnapshot* s2 = | 1613 const v8::HeapSnapshot* s2 = heap_profiler->TakeHeapSnapshot(); |
1650 heap_profiler->TakeHeapSnapshot(v8_str("2")); | |
1651 CHECK(s2); | 1614 CHECK(s2); |
1652 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); | 1615 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); |
1653 unsigned uid2 = s2->GetUid(); | 1616 CHECK(FindHeapSnapshot(heap_profiler, s2)); |
1654 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); | 1617 const v8::HeapSnapshot* s3 = heap_profiler->TakeHeapSnapshot(); |
1655 CHECK_EQ(s2, FindHeapSnapshot(heap_profiler, uid2)); | |
1656 const v8::HeapSnapshot* s3 = | |
1657 heap_profiler->TakeHeapSnapshot(v8_str("3")); | |
1658 CHECK(s3); | 1618 CHECK(s3); |
1659 CHECK_EQ(2, heap_profiler->GetSnapshotCount()); | 1619 CHECK_EQ(2, heap_profiler->GetSnapshotCount()); |
1660 unsigned uid3 = s3->GetUid(); | 1620 CHECK_NE(s2, s3); |
1661 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); | 1621 CHECK(FindHeapSnapshot(heap_profiler, s3)); |
1662 CHECK_EQ(s3, FindHeapSnapshot(heap_profiler, uid3)); | |
1663 const_cast<v8::HeapSnapshot*>(s2)->Delete(); | 1622 const_cast<v8::HeapSnapshot*>(s2)->Delete(); |
1664 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); | 1623 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); |
1665 CHECK(!FindHeapSnapshot(heap_profiler, uid2)); | 1624 CHECK(!FindHeapSnapshot(heap_profiler, s2)); |
1666 CHECK_EQ(s3, FindHeapSnapshot(heap_profiler, uid3)); | 1625 CHECK(FindHeapSnapshot(heap_profiler, s3)); |
1667 const_cast<v8::HeapSnapshot*>(s3)->Delete(); | 1626 const_cast<v8::HeapSnapshot*>(s3)->Delete(); |
1668 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); | 1627 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); |
1669 CHECK(!FindHeapSnapshot(heap_profiler, uid3)); | 1628 CHECK(!FindHeapSnapshot(heap_profiler, s3)); |
1670 } | 1629 } |
1671 | 1630 |
1672 | 1631 |
1673 class NameResolver : public v8::HeapProfiler::ObjectNameResolver { | 1632 class NameResolver : public v8::HeapProfiler::ObjectNameResolver { |
1674 public: | 1633 public: |
1675 virtual const char* GetName(v8::Handle<v8::Object> object) { | 1634 virtual const char* GetName(v8::Handle<v8::Object> object) { |
1676 return "Global object name"; | 1635 return "Global object name"; |
1677 } | 1636 } |
1678 }; | 1637 }; |
1679 | 1638 |
1680 | 1639 |
1681 TEST(GlobalObjectName) { | 1640 TEST(GlobalObjectName) { |
1682 LocalContext env; | 1641 LocalContext env; |
1683 v8::HandleScope scope(env->GetIsolate()); | 1642 v8::HandleScope scope(env->GetIsolate()); |
1684 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1643 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1685 | 1644 |
1686 CompileRun("document = { URL:\"abcdefgh\" };"); | 1645 CompileRun("document = { URL:\"abcdefgh\" };"); |
1687 | 1646 |
1688 NameResolver name_resolver; | 1647 NameResolver name_resolver; |
1689 const v8::HeapSnapshot* snapshot = | 1648 const v8::HeapSnapshot* snapshot = |
1690 heap_profiler->TakeHeapSnapshot(v8_str("document"), | 1649 heap_profiler->TakeHeapSnapshot(NULL, &name_resolver); |
1691 NULL, | |
1692 &name_resolver); | |
1693 CHECK(ValidateSnapshot(snapshot)); | 1650 CHECK(ValidateSnapshot(snapshot)); |
1694 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1651 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1695 CHECK(global); | 1652 CHECK(global); |
1696 CHECK_EQ(0, | 1653 CHECK_EQ(0, |
1697 strcmp("Object / Global object name", | 1654 strcmp("Object / Global object name", |
1698 const_cast<i::HeapEntry*>( | 1655 const_cast<i::HeapEntry*>( |
1699 reinterpret_cast<const i::HeapEntry*>(global))->name())); | 1656 reinterpret_cast<const i::HeapEntry*>(global))->name())); |
1700 } | 1657 } |
1701 | 1658 |
1702 | 1659 |
1703 TEST(GlobalObjectFields) { | 1660 TEST(GlobalObjectFields) { |
1704 LocalContext env; | 1661 LocalContext env; |
1705 v8::HandleScope scope(env->GetIsolate()); | 1662 v8::HandleScope scope(env->GetIsolate()); |
1706 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1663 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1707 CompileRun("obj = {};"); | 1664 CompileRun("obj = {};"); |
1708 const v8::HeapSnapshot* snapshot = | 1665 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1709 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
1710 CHECK(ValidateSnapshot(snapshot)); | 1666 CHECK(ValidateSnapshot(snapshot)); |
1711 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1667 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1712 const v8::HeapGraphNode* builtins = | 1668 const v8::HeapGraphNode* builtins = |
1713 GetProperty(global, v8::HeapGraphEdge::kInternal, "builtins"); | 1669 GetProperty(global, v8::HeapGraphEdge::kInternal, "builtins"); |
1714 CHECK(builtins); | 1670 CHECK(builtins); |
1715 const v8::HeapGraphNode* native_context = | 1671 const v8::HeapGraphNode* native_context = |
1716 GetProperty(global, v8::HeapGraphEdge::kInternal, "native_context"); | 1672 GetProperty(global, v8::HeapGraphEdge::kInternal, "native_context"); |
1717 CHECK(native_context); | 1673 CHECK(native_context); |
1718 const v8::HeapGraphNode* global_proxy = | 1674 const v8::HeapGraphNode* global_proxy = |
1719 GetProperty(global, v8::HeapGraphEdge::kInternal, "global_proxy"); | 1675 GetProperty(global, v8::HeapGraphEdge::kInternal, "global_proxy"); |
1720 CHECK(global_proxy); | 1676 CHECK(global_proxy); |
1721 } | 1677 } |
1722 | 1678 |
1723 | 1679 |
1724 TEST(NoHandleLeaks) { | 1680 TEST(NoHandleLeaks) { |
1725 LocalContext env; | 1681 LocalContext env; |
1726 v8::HandleScope scope(env->GetIsolate()); | 1682 v8::HandleScope scope(env->GetIsolate()); |
1727 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1683 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1728 | 1684 |
1729 CompileRun("document = { URL:\"abcdefgh\" };"); | 1685 CompileRun("document = { URL:\"abcdefgh\" };"); |
1730 | 1686 |
1731 v8::Handle<v8::String> name(v8_str("leakz")); | |
1732 i::Isolate* isolate = CcTest::i_isolate(); | 1687 i::Isolate* isolate = CcTest::i_isolate(); |
1733 int count_before = i::HandleScope::NumberOfHandles(isolate); | 1688 int count_before = i::HandleScope::NumberOfHandles(isolate); |
1734 heap_profiler->TakeHeapSnapshot(name); | 1689 heap_profiler->TakeHeapSnapshot(); |
1735 int count_after = i::HandleScope::NumberOfHandles(isolate); | 1690 int count_after = i::HandleScope::NumberOfHandles(isolate); |
1736 CHECK_EQ(count_before, count_after); | 1691 CHECK_EQ(count_before, count_after); |
1737 } | 1692 } |
1738 | 1693 |
1739 | 1694 |
1740 TEST(NodesIteration) { | 1695 TEST(NodesIteration) { |
1741 LocalContext env; | 1696 LocalContext env; |
1742 v8::HandleScope scope(env->GetIsolate()); | 1697 v8::HandleScope scope(env->GetIsolate()); |
1743 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1698 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1744 const v8::HeapSnapshot* snapshot = | 1699 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1745 heap_profiler->TakeHeapSnapshot(v8_str("iteration")); | |
1746 CHECK(ValidateSnapshot(snapshot)); | 1700 CHECK(ValidateSnapshot(snapshot)); |
1747 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1701 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1748 CHECK(global); | 1702 CHECK(global); |
1749 // Verify that we can find this object by iteration. | 1703 // Verify that we can find this object by iteration. |
1750 const int nodes_count = snapshot->GetNodesCount(); | 1704 const int nodes_count = snapshot->GetNodesCount(); |
1751 int count = 0; | 1705 int count = 0; |
1752 for (int i = 0; i < nodes_count; ++i) { | 1706 for (int i = 0; i < nodes_count; ++i) { |
1753 if (snapshot->GetNode(i) == global) | 1707 if (snapshot->GetNode(i) == global) |
1754 ++count; | 1708 ++count; |
1755 } | 1709 } |
1756 CHECK_EQ(1, count); | 1710 CHECK_EQ(1, count); |
1757 } | 1711 } |
1758 | 1712 |
1759 | 1713 |
1760 TEST(GetHeapValueForNode) { | 1714 TEST(GetHeapValueForNode) { |
1761 LocalContext env; | 1715 LocalContext env; |
1762 v8::HandleScope scope(env->GetIsolate()); | 1716 v8::HandleScope scope(env->GetIsolate()); |
1763 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1717 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1764 | 1718 |
1765 CompileRun("a = { s_prop: \'value\', n_prop: \'value2\' };"); | 1719 CompileRun("a = { s_prop: \'value\', n_prop: \'value2\' };"); |
1766 const v8::HeapSnapshot* snapshot = | 1720 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1767 heap_profiler->TakeHeapSnapshot(v8_str("value")); | |
1768 CHECK(ValidateSnapshot(snapshot)); | 1721 CHECK(ValidateSnapshot(snapshot)); |
1769 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1722 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1770 CHECK(heap_profiler->FindObjectById(global->GetId())->IsObject()); | 1723 CHECK(heap_profiler->FindObjectById(global->GetId())->IsObject()); |
1771 v8::Local<v8::Object> js_global = | 1724 v8::Local<v8::Object> js_global = |
1772 env->Global()->GetPrototype().As<v8::Object>(); | 1725 env->Global()->GetPrototype().As<v8::Object>(); |
1773 CHECK(js_global == heap_profiler->FindObjectById(global->GetId())); | 1726 CHECK(js_global == heap_profiler->FindObjectById(global->GetId())); |
1774 const v8::HeapGraphNode* obj = GetProperty( | 1727 const v8::HeapGraphNode* obj = GetProperty( |
1775 global, v8::HeapGraphEdge::kProperty, "a"); | 1728 global, v8::HeapGraphEdge::kProperty, "a"); |
1776 CHECK(heap_profiler->FindObjectById(obj->GetId())->IsObject()); | 1729 CHECK(heap_profiler->FindObjectById(obj->GetId())->IsObject()); |
1777 v8::Local<v8::Object> js_obj = js_global->Get(v8_str("a")).As<v8::Object>(); | 1730 v8::Local<v8::Object> js_obj = js_global->Get(v8_str("a")).As<v8::Object>(); |
(...skipping 13 matching lines...) Expand all Loading... |
1791 | 1744 |
1792 TEST(GetHeapValueForDeletedObject) { | 1745 TEST(GetHeapValueForDeletedObject) { |
1793 LocalContext env; | 1746 LocalContext env; |
1794 v8::HandleScope scope(env->GetIsolate()); | 1747 v8::HandleScope scope(env->GetIsolate()); |
1795 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1748 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1796 | 1749 |
1797 // It is impossible to delete a global property, so we are about to delete a | 1750 // It is impossible to delete a global property, so we are about to delete a |
1798 // property of the "a" object. Also, the "p" object can't be an empty one | 1751 // property of the "a" object. Also, the "p" object can't be an empty one |
1799 // because the empty object is static and isn't actually deleted. | 1752 // because the empty object is static and isn't actually deleted. |
1800 CompileRun("a = { p: { r: {} } };"); | 1753 CompileRun("a = { p: { r: {} } };"); |
1801 const v8::HeapSnapshot* snapshot = | 1754 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1802 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
1803 CHECK(ValidateSnapshot(snapshot)); | 1755 CHECK(ValidateSnapshot(snapshot)); |
1804 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1756 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1805 const v8::HeapGraphNode* obj = GetProperty( | 1757 const v8::HeapGraphNode* obj = GetProperty( |
1806 global, v8::HeapGraphEdge::kProperty, "a"); | 1758 global, v8::HeapGraphEdge::kProperty, "a"); |
1807 const v8::HeapGraphNode* prop = GetProperty( | 1759 const v8::HeapGraphNode* prop = GetProperty( |
1808 obj, v8::HeapGraphEdge::kProperty, "p"); | 1760 obj, v8::HeapGraphEdge::kProperty, "p"); |
1809 { | 1761 { |
1810 // Perform the check inside a nested local scope to avoid creating a | 1762 // Perform the check inside a nested local scope to avoid creating a |
1811 // reference to the object we are deleting. | 1763 // reference to the object we are deleting. |
1812 v8::HandleScope scope(env->GetIsolate()); | 1764 v8::HandleScope scope(env->GetIsolate()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1882 v8::HandleScope scope(env->GetIsolate()); | 1834 v8::HandleScope scope(env->GetIsolate()); |
1883 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1835 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1884 | 1836 |
1885 CompileRun("var obj1 = {};\n" | 1837 CompileRun("var obj1 = {};\n" |
1886 "obj1.__defineGetter__('propWithGetter', function Y() {\n" | 1838 "obj1.__defineGetter__('propWithGetter', function Y() {\n" |
1887 " return 42;\n" | 1839 " return 42;\n" |
1888 "});\n" | 1840 "});\n" |
1889 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" | 1841 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" |
1890 " return this.value_ = value;\n" | 1842 " return this.value_ = value;\n" |
1891 "});\n"); | 1843 "});\n"); |
1892 const v8::HeapSnapshot* snapshot = | 1844 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1893 heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors")); | |
1894 CHECK(ValidateSnapshot(snapshot)); | 1845 CHECK(ValidateSnapshot(snapshot)); |
1895 | 1846 |
1896 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1847 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1897 CHECK(global); | 1848 CHECK(global); |
1898 const v8::HeapGraphNode* obj1 = | 1849 const v8::HeapGraphNode* obj1 = |
1899 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); | 1850 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); |
1900 CHECK(obj1); | 1851 CHECK(obj1); |
1901 const v8::HeapGraphNode* func; | 1852 const v8::HeapGraphNode* func; |
1902 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); | 1853 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); |
1903 CHECK(func); | 1854 CHECK(func); |
(...skipping 24 matching lines...) Expand all Loading... |
1928 " set: function(value) { return this.prop_ = value; },\n" | 1879 " set: function(value) { return this.prop_ = value; },\n" |
1929 " configurable: true,\n" | 1880 " configurable: true,\n" |
1930 " enumerable: true,\n" | 1881 " enumerable: true,\n" |
1931 "});\n"); | 1882 "});\n"); |
1932 v8::Local<v8::Object> js_global = | 1883 v8::Local<v8::Object> js_global = |
1933 env->Global()->GetPrototype().As<v8::Object>(); | 1884 env->Global()->GetPrototype().As<v8::Object>(); |
1934 i::Handle<i::JSObject> js_obj1 = | 1885 i::Handle<i::JSObject> js_obj1 = |
1935 v8::Utils::OpenHandle(*js_global->Get(v8_str("obj1")).As<v8::Object>()); | 1886 v8::Utils::OpenHandle(*js_global->Get(v8_str("obj1")).As<v8::Object>()); |
1936 USE(js_obj1); | 1887 USE(js_obj1); |
1937 | 1888 |
1938 const v8::HeapSnapshot* snapshot = | 1889 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1939 heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors")); | |
1940 CHECK(ValidateSnapshot(snapshot)); | 1890 CHECK(ValidateSnapshot(snapshot)); |
1941 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1891 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1942 CHECK(global); | 1892 CHECK(global); |
1943 const v8::HeapGraphNode* obj1 = | 1893 const v8::HeapGraphNode* obj1 = |
1944 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); | 1894 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); |
1945 CHECK(obj1); | 1895 CHECK(obj1); |
1946 const v8::HeapGraphNode* func; | 1896 const v8::HeapGraphNode* func; |
1947 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get prop"); | 1897 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get prop"); |
1948 CHECK(func); | 1898 CHECK(func); |
1949 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set prop"); | 1899 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set prop"); |
1950 CHECK(func); | 1900 CHECK(func); |
1951 } | 1901 } |
1952 | 1902 |
1953 | 1903 |
1954 TEST(SlowCaseAccessors) { | 1904 TEST(SlowCaseAccessors) { |
1955 LocalContext env; | 1905 LocalContext env; |
1956 v8::HandleScope scope(env->GetIsolate()); | 1906 v8::HandleScope scope(env->GetIsolate()); |
1957 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1907 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1958 | 1908 |
1959 CompileRun("var obj1 = {};\n" | 1909 CompileRun("var obj1 = {};\n" |
1960 "for (var i = 0; i < 100; ++i) obj1['z' + i] = {};" | 1910 "for (var i = 0; i < 100; ++i) obj1['z' + i] = {};" |
1961 "obj1.__defineGetter__('propWithGetter', function Y() {\n" | 1911 "obj1.__defineGetter__('propWithGetter', function Y() {\n" |
1962 " return 42;\n" | 1912 " return 42;\n" |
1963 "});\n" | 1913 "});\n" |
1964 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" | 1914 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" |
1965 " return this.value_ = value;\n" | 1915 " return this.value_ = value;\n" |
1966 "});\n"); | 1916 "});\n"); |
1967 const v8::HeapSnapshot* snapshot = | 1917 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1968 heap_profiler->TakeHeapSnapshot(v8_str("slowCaseAccessors")); | |
1969 CHECK(ValidateSnapshot(snapshot)); | 1918 CHECK(ValidateSnapshot(snapshot)); |
1970 | 1919 |
1971 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1920 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1972 CHECK(global); | 1921 CHECK(global); |
1973 const v8::HeapGraphNode* obj1 = | 1922 const v8::HeapGraphNode* obj1 = |
1974 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); | 1923 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); |
1975 CHECK(obj1); | 1924 CHECK(obj1); |
1976 const v8::HeapGraphNode* func; | 1925 const v8::HeapGraphNode* func; |
1977 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); | 1926 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); |
1978 CHECK(func); | 1927 CHECK(func); |
1979 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); | 1928 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); |
1980 CHECK(!func); | 1929 CHECK(!func); |
1981 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter"); | 1930 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter"); |
1982 CHECK(func); | 1931 CHECK(func); |
1983 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter"); | 1932 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter"); |
1984 CHECK(!func); | 1933 CHECK(!func); |
1985 } | 1934 } |
1986 | 1935 |
1987 | 1936 |
1988 TEST(HiddenPropertiesFastCase) { | 1937 TEST(HiddenPropertiesFastCase) { |
1989 v8::Isolate* isolate = CcTest::isolate(); | 1938 v8::Isolate* isolate = CcTest::isolate(); |
1990 LocalContext env; | 1939 LocalContext env; |
1991 v8::HandleScope scope(isolate); | 1940 v8::HandleScope scope(isolate); |
1992 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 1941 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
1993 | 1942 |
1994 CompileRun( | 1943 CompileRun( |
1995 "function C(x) { this.a = this; this.b = x; }\n" | 1944 "function C(x) { this.a = this; this.b = x; }\n" |
1996 "c = new C(2012);\n"); | 1945 "c = new C(2012);\n"); |
1997 const v8::HeapSnapshot* snapshot = | 1946 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
1998 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1")); | |
1999 CHECK(ValidateSnapshot(snapshot)); | 1947 CHECK(ValidateSnapshot(snapshot)); |
2000 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1948 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2001 const v8::HeapGraphNode* c = | 1949 const v8::HeapGraphNode* c = |
2002 GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); | 1950 GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); |
2003 CHECK(c); | 1951 CHECK(c); |
2004 const v8::HeapGraphNode* hidden_props = | 1952 const v8::HeapGraphNode* hidden_props = |
2005 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties"); | 1953 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties"); |
2006 CHECK(!hidden_props); | 1954 CHECK(!hidden_props); |
2007 | 1955 |
2008 v8::Handle<v8::Value> cHandle = | 1956 v8::Handle<v8::Value> cHandle = |
2009 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "c")); | 1957 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "c")); |
2010 CHECK(!cHandle.IsEmpty() && cHandle->IsObject()); | 1958 CHECK(!cHandle.IsEmpty() && cHandle->IsObject()); |
2011 cHandle->ToObject(isolate)->SetHiddenValue(v8_str("key"), v8_str("val")); | 1959 cHandle->ToObject(isolate)->SetHiddenValue(v8_str("key"), v8_str("val")); |
2012 | 1960 |
2013 snapshot = heap_profiler->TakeHeapSnapshot( | 1961 snapshot = heap_profiler->TakeHeapSnapshot(); |
2014 v8_str("HiddenPropertiesFastCase2")); | |
2015 CHECK(ValidateSnapshot(snapshot)); | 1962 CHECK(ValidateSnapshot(snapshot)); |
2016 global = GetGlobalObject(snapshot); | 1963 global = GetGlobalObject(snapshot); |
2017 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); | 1964 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); |
2018 CHECK(c); | 1965 CHECK(c); |
2019 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal, | 1966 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal, |
2020 "hidden_properties"); | 1967 "hidden_properties"); |
2021 CHECK(hidden_props); | 1968 CHECK(hidden_props); |
2022 } | 1969 } |
2023 | 1970 |
2024 | 1971 |
2025 TEST(AccessorInfo) { | 1972 TEST(AccessorInfo) { |
2026 LocalContext env; | 1973 LocalContext env; |
2027 v8::HandleScope scope(env->GetIsolate()); | 1974 v8::HandleScope scope(env->GetIsolate()); |
2028 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1975 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2029 | 1976 |
2030 CompileRun("function foo(x) { }\n"); | 1977 CompileRun("function foo(x) { }\n"); |
2031 const v8::HeapSnapshot* snapshot = | 1978 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2032 heap_profiler->TakeHeapSnapshot(v8_str("AccessorInfoTest")); | |
2033 CHECK(ValidateSnapshot(snapshot)); | 1979 CHECK(ValidateSnapshot(snapshot)); |
2034 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1980 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2035 const v8::HeapGraphNode* foo = | 1981 const v8::HeapGraphNode* foo = |
2036 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); | 1982 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); |
2037 CHECK(foo); | 1983 CHECK(foo); |
2038 const v8::HeapGraphNode* map = | 1984 const v8::HeapGraphNode* map = |
2039 GetProperty(foo, v8::HeapGraphEdge::kInternal, "map"); | 1985 GetProperty(foo, v8::HeapGraphEdge::kInternal, "map"); |
2040 CHECK(map); | 1986 CHECK(map); |
2041 const v8::HeapGraphNode* descriptors = | 1987 const v8::HeapGraphNode* descriptors = |
2042 GetProperty(map, v8::HeapGraphEdge::kInternal, "descriptors"); | 1988 GetProperty(map, v8::HeapGraphEdge::kInternal, "descriptors"); |
(...skipping 24 matching lines...) Expand all Loading... |
2067 const v8::HeapGraphEdge* handle_edge = node->GetChild(i); | 2013 const v8::HeapGraphEdge* handle_edge = node->GetChild(i); |
2068 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true; | 2014 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true; |
2069 } | 2015 } |
2070 return false; | 2016 return false; |
2071 } | 2017 } |
2072 | 2018 |
2073 | 2019 |
2074 bool HasWeakGlobalHandle() { | 2020 bool HasWeakGlobalHandle() { |
2075 v8::Isolate* isolate = CcTest::isolate(); | 2021 v8::Isolate* isolate = CcTest::isolate(); |
2076 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 2022 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
2077 const v8::HeapSnapshot* snapshot = | 2023 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2078 heap_profiler->TakeHeapSnapshot(v8_str("weaks")); | |
2079 CHECK(ValidateSnapshot(snapshot)); | 2024 CHECK(ValidateSnapshot(snapshot)); |
2080 const v8::HeapGraphNode* gc_roots = GetNode( | 2025 const v8::HeapGraphNode* gc_roots = GetNode( |
2081 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); | 2026 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); |
2082 CHECK(gc_roots); | 2027 CHECK(gc_roots); |
2083 const v8::HeapGraphNode* global_handles = GetNode( | 2028 const v8::HeapGraphNode* global_handles = GetNode( |
2084 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); | 2029 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); |
2085 CHECK(global_handles); | 2030 CHECK(global_handles); |
2086 return HasWeakEdge(global_handles); | 2031 return HasWeakEdge(global_handles); |
2087 } | 2032 } |
2088 | 2033 |
(...skipping 19 matching lines...) Expand all Loading... |
2108 } | 2053 } |
2109 | 2054 |
2110 | 2055 |
2111 TEST(SfiAndJsFunctionWeakRefs) { | 2056 TEST(SfiAndJsFunctionWeakRefs) { |
2112 LocalContext env; | 2057 LocalContext env; |
2113 v8::HandleScope scope(env->GetIsolate()); | 2058 v8::HandleScope scope(env->GetIsolate()); |
2114 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2059 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2115 | 2060 |
2116 CompileRun( | 2061 CompileRun( |
2117 "fun = (function (x) { return function () { return x + 1; } })(1);"); | 2062 "fun = (function (x) { return function () { return x + 1; } })(1);"); |
2118 const v8::HeapSnapshot* snapshot = | 2063 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2119 heap_profiler->TakeHeapSnapshot(v8_str("fun")); | |
2120 CHECK(ValidateSnapshot(snapshot)); | 2064 CHECK(ValidateSnapshot(snapshot)); |
2121 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2065 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2122 CHECK(global); | 2066 CHECK(global); |
2123 const v8::HeapGraphNode* fun = | 2067 const v8::HeapGraphNode* fun = |
2124 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); | 2068 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); |
2125 CHECK(!HasWeakEdge(fun)); | 2069 CHECK(!HasWeakEdge(fun)); |
2126 const v8::HeapGraphNode* shared = | 2070 const v8::HeapGraphNode* shared = |
2127 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); | 2071 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); |
2128 CHECK(!HasWeakEdge(shared)); | 2072 CHECK(!HasWeakEdge(shared)); |
2129 } | 2073 } |
2130 | 2074 |
2131 | 2075 |
2132 TEST(NoDebugObjectInSnapshot) { | 2076 TEST(NoDebugObjectInSnapshot) { |
2133 LocalContext env; | 2077 LocalContext env; |
2134 v8::HandleScope scope(env->GetIsolate()); | 2078 v8::HandleScope scope(env->GetIsolate()); |
2135 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2079 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2136 | 2080 |
2137 CHECK(CcTest::i_isolate()->debug()->Load()); | 2081 CHECK(CcTest::i_isolate()->debug()->Load()); |
2138 CompileRun("foo = {};"); | 2082 CompileRun("foo = {};"); |
2139 const v8::HeapSnapshot* snapshot = | 2083 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2140 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2141 CHECK(ValidateSnapshot(snapshot)); | 2084 CHECK(ValidateSnapshot(snapshot)); |
2142 const v8::HeapGraphNode* root = snapshot->GetRoot(); | 2085 const v8::HeapGraphNode* root = snapshot->GetRoot(); |
2143 int globals_count = 0; | 2086 int globals_count = 0; |
2144 for (int i = 0; i < root->GetChildrenCount(); ++i) { | 2087 for (int i = 0; i < root->GetChildrenCount(); ++i) { |
2145 const v8::HeapGraphEdge* edge = root->GetChild(i); | 2088 const v8::HeapGraphEdge* edge = root->GetChild(i); |
2146 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { | 2089 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { |
2147 ++globals_count; | 2090 ++globals_count; |
2148 const v8::HeapGraphNode* global = edge->GetToNode(); | 2091 const v8::HeapGraphNode* global = edge->GetToNode(); |
2149 const v8::HeapGraphNode* foo = | 2092 const v8::HeapGraphNode* foo = |
2150 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); | 2093 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); |
2151 CHECK(foo); | 2094 CHECK(foo); |
2152 } | 2095 } |
2153 } | 2096 } |
2154 CHECK_EQ(1, globals_count); | 2097 CHECK_EQ(1, globals_count); |
2155 } | 2098 } |
2156 | 2099 |
2157 | 2100 |
2158 TEST(AllStrongGcRootsHaveNames) { | 2101 TEST(AllStrongGcRootsHaveNames) { |
2159 LocalContext env; | 2102 LocalContext env; |
2160 v8::HandleScope scope(env->GetIsolate()); | 2103 v8::HandleScope scope(env->GetIsolate()); |
2161 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2104 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2162 | 2105 |
2163 CompileRun("foo = {};"); | 2106 CompileRun("foo = {};"); |
2164 const v8::HeapSnapshot* snapshot = | 2107 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2165 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2166 CHECK(ValidateSnapshot(snapshot)); | 2108 CHECK(ValidateSnapshot(snapshot)); |
2167 const v8::HeapGraphNode* gc_roots = GetNode( | 2109 const v8::HeapGraphNode* gc_roots = GetNode( |
2168 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); | 2110 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); |
2169 CHECK(gc_roots); | 2111 CHECK(gc_roots); |
2170 const v8::HeapGraphNode* strong_roots = GetNode( | 2112 const v8::HeapGraphNode* strong_roots = GetNode( |
2171 gc_roots, v8::HeapGraphNode::kSynthetic, "(Strong roots)"); | 2113 gc_roots, v8::HeapGraphNode::kSynthetic, "(Strong roots)"); |
2172 CHECK(strong_roots); | 2114 CHECK(strong_roots); |
2173 for (int i = 0; i < strong_roots->GetChildrenCount(); ++i) { | 2115 for (int i = 0; i < strong_roots->GetChildrenCount(); ++i) { |
2174 const v8::HeapGraphEdge* edge = strong_roots->GetChild(i); | 2116 const v8::HeapGraphEdge* edge = strong_roots->GetChild(i); |
2175 CHECK_EQ(v8::HeapGraphEdge::kInternal, edge->GetType()); | 2117 CHECK_EQ(v8::HeapGraphEdge::kInternal, edge->GetType()); |
2176 v8::String::Utf8Value name(edge->GetName()); | 2118 v8::String::Utf8Value name(edge->GetName()); |
2177 CHECK(isalpha(**name)); | 2119 CHECK(isalpha(**name)); |
2178 } | 2120 } |
2179 } | 2121 } |
2180 | 2122 |
2181 | 2123 |
2182 TEST(NoRefsToNonEssentialEntries) { | 2124 TEST(NoRefsToNonEssentialEntries) { |
2183 LocalContext env; | 2125 LocalContext env; |
2184 v8::HandleScope scope(env->GetIsolate()); | 2126 v8::HandleScope scope(env->GetIsolate()); |
2185 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2127 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2186 CompileRun("global_object = {};\n"); | 2128 CompileRun("global_object = {};\n"); |
2187 const v8::HeapSnapshot* snapshot = | 2129 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2188 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2189 CHECK(ValidateSnapshot(snapshot)); | 2130 CHECK(ValidateSnapshot(snapshot)); |
2190 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2131 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2191 const v8::HeapGraphNode* global_object = | 2132 const v8::HeapGraphNode* global_object = |
2192 GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object"); | 2133 GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object"); |
2193 CHECK(global_object); | 2134 CHECK(global_object); |
2194 const v8::HeapGraphNode* properties = | 2135 const v8::HeapGraphNode* properties = |
2195 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "properties"); | 2136 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "properties"); |
2196 CHECK(!properties); | 2137 CHECK(!properties); |
2197 const v8::HeapGraphNode* elements = | 2138 const v8::HeapGraphNode* elements = |
2198 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "elements"); | 2139 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "elements"); |
2199 CHECK(!elements); | 2140 CHECK(!elements); |
2200 } | 2141 } |
2201 | 2142 |
2202 | 2143 |
2203 TEST(MapHasDescriptorsAndTransitions) { | 2144 TEST(MapHasDescriptorsAndTransitions) { |
2204 LocalContext env; | 2145 LocalContext env; |
2205 v8::HandleScope scope(env->GetIsolate()); | 2146 v8::HandleScope scope(env->GetIsolate()); |
2206 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2147 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2207 CompileRun("obj = { a: 10 };\n"); | 2148 CompileRun("obj = { a: 10 };\n"); |
2208 const v8::HeapSnapshot* snapshot = | 2149 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2209 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2210 CHECK(ValidateSnapshot(snapshot)); | 2150 CHECK(ValidateSnapshot(snapshot)); |
2211 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2151 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2212 const v8::HeapGraphNode* global_object = | 2152 const v8::HeapGraphNode* global_object = |
2213 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); | 2153 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); |
2214 CHECK(global_object); | 2154 CHECK(global_object); |
2215 | 2155 |
2216 const v8::HeapGraphNode* map = | 2156 const v8::HeapGraphNode* map = |
2217 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); | 2157 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); |
2218 CHECK(map); | 2158 CHECK(map); |
2219 const v8::HeapGraphNode* own_descriptors = GetProperty( | 2159 const v8::HeapGraphNode* own_descriptors = GetProperty( |
(...skipping 17 matching lines...) Expand all Loading... |
2237 "for (var i = 0; i < n; i++) {" | 2177 "for (var i = 0; i < n; i++) {" |
2238 " var f = 'function f_' + i + '() { ';" | 2178 " var f = 'function f_' + i + '() { ';" |
2239 " if (i > 0)" | 2179 " if (i > 0)" |
2240 " f += 'f_' + (i - 1) + '();';" | 2180 " f += 'f_' + (i - 1) + '();';" |
2241 " f += ' }';" | 2181 " f += ' }';" |
2242 " result.push(f);" | 2182 " result.push(f);" |
2243 "}" | 2183 "}" |
2244 "result.push('return f_' + (n - 1) + ';');" | 2184 "result.push('return f_' + (n - 1) + ';');" |
2245 "result.push('})()');" | 2185 "result.push('})()');" |
2246 "var ok = eval(result.join('\\n'));"); | 2186 "var ok = eval(result.join('\\n'));"); |
2247 const v8::HeapSnapshot* snapshot = | 2187 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2248 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2249 CHECK(ValidateSnapshot(snapshot)); | 2188 CHECK(ValidateSnapshot(snapshot)); |
2250 | 2189 |
2251 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2190 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2252 CHECK(global); | 2191 CHECK(global); |
2253 const v8::HeapGraphNode* ok_object = | 2192 const v8::HeapGraphNode* ok_object = |
2254 GetProperty(global, v8::HeapGraphEdge::kProperty, "ok"); | 2193 GetProperty(global, v8::HeapGraphEdge::kProperty, "ok"); |
2255 CHECK(ok_object); | 2194 CHECK(ok_object); |
2256 const v8::HeapGraphNode* context_object = | 2195 const v8::HeapGraphNode* context_object = |
2257 GetProperty(ok_object, v8::HeapGraphEdge::kInternal, "context"); | 2196 GetProperty(ok_object, v8::HeapGraphEdge::kInternal, "context"); |
2258 CHECK(context_object); | 2197 CHECK(context_object); |
(...skipping 13 matching lines...) Expand all Loading... |
2272 | 2211 |
2273 | 2212 |
2274 TEST(AllocationSitesAreVisible) { | 2213 TEST(AllocationSitesAreVisible) { |
2275 LocalContext env; | 2214 LocalContext env; |
2276 v8::Isolate* isolate = env->GetIsolate(); | 2215 v8::Isolate* isolate = env->GetIsolate(); |
2277 v8::HandleScope scope(isolate); | 2216 v8::HandleScope scope(isolate); |
2278 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 2217 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
2279 CompileRun( | 2218 CompileRun( |
2280 "fun = function () { var a = [3, 2, 1]; return a; }\n" | 2219 "fun = function () { var a = [3, 2, 1]; return a; }\n" |
2281 "fun();"); | 2220 "fun();"); |
2282 const v8::HeapSnapshot* snapshot = | 2221 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2283 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2284 CHECK(ValidateSnapshot(snapshot)); | 2222 CHECK(ValidateSnapshot(snapshot)); |
2285 | 2223 |
2286 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2224 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2287 CHECK(global); | 2225 CHECK(global); |
2288 const v8::HeapGraphNode* fun_code = | 2226 const v8::HeapGraphNode* fun_code = |
2289 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); | 2227 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); |
2290 CHECK(fun_code); | 2228 CHECK(fun_code); |
2291 const v8::HeapGraphNode* literals = | 2229 const v8::HeapGraphNode* literals = |
2292 GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals"); | 2230 GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals"); |
2293 CHECK(literals); | 2231 CHECK(literals); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2326 CHECK(v8::Integer::New(isolate, 1) | 2264 CHECK(v8::Integer::New(isolate, 1) |
2327 ->Equals(array->Get(v8::Integer::New(isolate, 2)))); | 2265 ->Equals(array->Get(v8::Integer::New(isolate, 2)))); |
2328 } | 2266 } |
2329 | 2267 |
2330 | 2268 |
2331 TEST(JSFunctionHasCodeLink) { | 2269 TEST(JSFunctionHasCodeLink) { |
2332 LocalContext env; | 2270 LocalContext env; |
2333 v8::HandleScope scope(env->GetIsolate()); | 2271 v8::HandleScope scope(env->GetIsolate()); |
2334 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2272 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2335 CompileRun("function foo(x, y) { return x + y; }\n"); | 2273 CompileRun("function foo(x, y) { return x + y; }\n"); |
2336 const v8::HeapSnapshot* snapshot = | 2274 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2337 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2338 CHECK(ValidateSnapshot(snapshot)); | 2275 CHECK(ValidateSnapshot(snapshot)); |
2339 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2276 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2340 const v8::HeapGraphNode* foo_func = | 2277 const v8::HeapGraphNode* foo_func = |
2341 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); | 2278 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); |
2342 CHECK(foo_func); | 2279 CHECK(foo_func); |
2343 const v8::HeapGraphNode* code = | 2280 const v8::HeapGraphNode* code = |
2344 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); | 2281 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); |
2345 CHECK(code); | 2282 CHECK(code); |
2346 } | 2283 } |
2347 | 2284 |
(...skipping 20 matching lines...) Expand all Loading... |
2368 } | 2305 } |
2369 return node; | 2306 return node; |
2370 } | 2307 } |
2371 | 2308 |
2372 | 2309 |
2373 TEST(CheckCodeNames) { | 2310 TEST(CheckCodeNames) { |
2374 LocalContext env; | 2311 LocalContext env; |
2375 v8::HandleScope scope(env->GetIsolate()); | 2312 v8::HandleScope scope(env->GetIsolate()); |
2376 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2313 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2377 CompileRun("var a = 1.1;"); | 2314 CompileRun("var a = 1.1;"); |
2378 const v8::HeapSnapshot* snapshot = | 2315 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2379 heap_profiler->TakeHeapSnapshot(v8_str("CheckCodeNames")); | |
2380 CHECK(ValidateSnapshot(snapshot)); | 2316 CHECK(ValidateSnapshot(snapshot)); |
2381 | 2317 |
2382 const char* stub_path[] = { | 2318 const char* stub_path[] = { |
2383 "::(GC roots)", | 2319 "::(GC roots)", |
2384 "::(Strong roots)", | 2320 "::(Strong roots)", |
2385 "code_stubs::", | 2321 "code_stubs::", |
2386 "::(ArraySingleArgumentConstructorStub code)" | 2322 "::(ArraySingleArgumentConstructorStub code)" |
2387 }; | 2323 }; |
2388 const v8::HeapGraphNode* node = GetNodeByPath(snapshot, | 2324 const v8::HeapGraphNode* node = GetNodeByPath(snapshot, |
2389 stub_path, arraysize(stub_path)); | 2325 stub_path, arraysize(stub_path)); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2627 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); | 2563 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); |
2628 heap_profiler->StopTrackingHeapObjects(); | 2564 heap_profiler->StopTrackingHeapObjects(); |
2629 } | 2565 } |
2630 | 2566 |
2631 | 2567 |
2632 TEST(ArrayBufferAndArrayBufferView) { | 2568 TEST(ArrayBufferAndArrayBufferView) { |
2633 LocalContext env; | 2569 LocalContext env; |
2634 v8::HandleScope scope(env->GetIsolate()); | 2570 v8::HandleScope scope(env->GetIsolate()); |
2635 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2571 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2636 CompileRun("arr1 = new Uint32Array(100);\n"); | 2572 CompileRun("arr1 = new Uint32Array(100);\n"); |
2637 const v8::HeapSnapshot* snapshot = | 2573 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2638 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2639 CHECK(ValidateSnapshot(snapshot)); | 2574 CHECK(ValidateSnapshot(snapshot)); |
2640 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2575 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2641 const v8::HeapGraphNode* arr1_obj = | 2576 const v8::HeapGraphNode* arr1_obj = |
2642 GetProperty(global, v8::HeapGraphEdge::kProperty, "arr1"); | 2577 GetProperty(global, v8::HeapGraphEdge::kProperty, "arr1"); |
2643 CHECK(arr1_obj); | 2578 CHECK(arr1_obj); |
2644 const v8::HeapGraphNode* arr1_buffer = | 2579 const v8::HeapGraphNode* arr1_buffer = |
2645 GetProperty(arr1_obj, v8::HeapGraphEdge::kInternal, "buffer"); | 2580 GetProperty(arr1_obj, v8::HeapGraphEdge::kInternal, "buffer"); |
2646 CHECK(arr1_buffer); | 2581 CHECK(arr1_buffer); |
2647 const v8::HeapGraphNode* first_view = | 2582 const v8::HeapGraphNode* first_view = |
2648 GetProperty(arr1_buffer, v8::HeapGraphEdge::kWeak, "weak_first_view"); | 2583 GetProperty(arr1_buffer, v8::HeapGraphEdge::kWeak, "weak_first_view"); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2686 DCHECK(data != NULL); | 2621 DCHECK(data != NULL); |
2687 v8::Local<v8::ArrayBuffer> ab2 = | 2622 v8::Local<v8::ArrayBuffer> ab2 = |
2688 v8::ArrayBuffer::New(isolate, data, ab_contents.ByteLength()); | 2623 v8::ArrayBuffer::New(isolate, data, ab_contents.ByteLength()); |
2689 CHECK(ab2->IsExternal()); | 2624 CHECK(ab2->IsExternal()); |
2690 env->Global()->Set(v8_str("ab1"), ab); | 2625 env->Global()->Set(v8_str("ab1"), ab); |
2691 env->Global()->Set(v8_str("ab2"), ab2); | 2626 env->Global()->Set(v8_str("ab2"), ab2); |
2692 | 2627 |
2693 v8::Handle<v8::Value> result = CompileRun("ab2.byteLength"); | 2628 v8::Handle<v8::Value> result = CompileRun("ab2.byteLength"); |
2694 CHECK_EQ(1024, result->Int32Value()); | 2629 CHECK_EQ(1024, result->Int32Value()); |
2695 | 2630 |
2696 const v8::HeapSnapshot* snapshot = | 2631 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2697 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2698 CHECK(ValidateSnapshot(snapshot)); | 2632 CHECK(ValidateSnapshot(snapshot)); |
2699 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2633 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2700 const v8::HeapGraphNode* ab1_node = | 2634 const v8::HeapGraphNode* ab1_node = |
2701 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab1"); | 2635 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab1"); |
2702 CHECK(ab1_node); | 2636 CHECK(ab1_node); |
2703 const v8::HeapGraphNode* ab1_data = | 2637 const v8::HeapGraphNode* ab1_data = |
2704 GetProperty(ab1_node, v8::HeapGraphEdge::kInternal, "backing_store"); | 2638 GetProperty(ab1_node, v8::HeapGraphEdge::kInternal, "backing_store"); |
2705 CHECK(ab1_data); | 2639 CHECK(ab1_data); |
2706 const v8::HeapGraphNode* ab2_node = | 2640 const v8::HeapGraphNode* ab2_node = |
2707 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab2"); | 2641 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab2"); |
(...skipping 13 matching lines...) Expand all Loading... |
2721 LocalContext env; | 2655 LocalContext env; |
2722 v8::Handle<v8::Object> global_proxy = env->Global(); | 2656 v8::Handle<v8::Object> global_proxy = env->Global(); |
2723 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 2657 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
2724 | 2658 |
2725 i::Factory* factory = CcTest::i_isolate()->factory(); | 2659 i::Factory* factory = CcTest::i_isolate()->factory(); |
2726 i::Handle<i::String> string = factory->NewStringFromStaticChars("string"); | 2660 i::Handle<i::String> string = factory->NewStringFromStaticChars("string"); |
2727 i::Handle<i::Object> box = factory->NewBox(string); | 2661 i::Handle<i::Object> box = factory->NewBox(string); |
2728 global->Set(0, v8::ToApiHandle<v8::Object>(box)); | 2662 global->Set(0, v8::ToApiHandle<v8::Object>(box)); |
2729 | 2663 |
2730 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 2664 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
2731 const v8::HeapSnapshot* snapshot = | 2665 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2732 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2733 CHECK(ValidateSnapshot(snapshot)); | 2666 CHECK(ValidateSnapshot(snapshot)); |
2734 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); | 2667 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); |
2735 const v8::HeapGraphNode* box_node = | 2668 const v8::HeapGraphNode* box_node = |
2736 GetProperty(global_node, v8::HeapGraphEdge::kElement, "0"); | 2669 GetProperty(global_node, v8::HeapGraphEdge::kElement, "0"); |
2737 CHECK(box_node); | 2670 CHECK(box_node); |
2738 v8::String::Utf8Value box_node_name(box_node->GetName()); | 2671 v8::String::Utf8Value box_node_name(box_node->GetName()); |
2739 CHECK_EQ(0, strcmp("system / Box", *box_node_name)); | 2672 CHECK_EQ(0, strcmp("system / Box", *box_node_name)); |
2740 const v8::HeapGraphNode* box_value = | 2673 const v8::HeapGraphNode* box_value = |
2741 GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value"); | 2674 GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value"); |
2742 CHECK(box_value); | 2675 CHECK(box_value); |
2743 } | 2676 } |
2744 | 2677 |
2745 | 2678 |
2746 TEST(WeakContainers) { | 2679 TEST(WeakContainers) { |
2747 i::FLAG_allow_natives_syntax = true; | 2680 i::FLAG_allow_natives_syntax = true; |
2748 LocalContext env; | 2681 LocalContext env; |
2749 v8::HandleScope scope(env->GetIsolate()); | 2682 v8::HandleScope scope(env->GetIsolate()); |
2750 if (!CcTest::i_isolate()->use_crankshaft()) return; | 2683 if (!CcTest::i_isolate()->use_crankshaft()) return; |
2751 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2684 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2752 CompileRun( | 2685 CompileRun( |
2753 "function foo(a) { return a.x; }\n" | 2686 "function foo(a) { return a.x; }\n" |
2754 "obj = {x : 123};\n" | 2687 "obj = {x : 123};\n" |
2755 "foo(obj);\n" | 2688 "foo(obj);\n" |
2756 "foo(obj);\n" | 2689 "foo(obj);\n" |
2757 "%OptimizeFunctionOnNextCall(foo);\n" | 2690 "%OptimizeFunctionOnNextCall(foo);\n" |
2758 "foo(obj);\n"); | 2691 "foo(obj);\n"); |
2759 const v8::HeapSnapshot* snapshot = | 2692 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2760 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | |
2761 CHECK(ValidateSnapshot(snapshot)); | 2693 CHECK(ValidateSnapshot(snapshot)); |
2762 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2694 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2763 const v8::HeapGraphNode* obj = | 2695 const v8::HeapGraphNode* obj = |
2764 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); | 2696 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); |
2765 CHECK(obj); | 2697 CHECK(obj); |
2766 const v8::HeapGraphNode* map = | 2698 const v8::HeapGraphNode* map = |
2767 GetProperty(obj, v8::HeapGraphEdge::kInternal, "map"); | 2699 GetProperty(obj, v8::HeapGraphEdge::kInternal, "map"); |
2768 CHECK(map); | 2700 CHECK(map); |
2769 const v8::HeapGraphNode* dependent_code = | 2701 const v8::HeapGraphNode* dependent_code = |
2770 GetProperty(map, v8::HeapGraphEdge::kInternal, "dependent_code"); | 2702 GetProperty(map, v8::HeapGraphEdge::kInternal, "dependent_code"); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2829 map.AddRange(ToAddress(0x180), 0x80, 6U); | 2761 map.AddRange(ToAddress(0x180), 0x80, 6U); |
2830 map.AddRange(ToAddress(0x180), 0x80, 7U); | 2762 map.AddRange(ToAddress(0x180), 0x80, 7U); |
2831 CHECK_EQ(7u, map.GetTraceNodeId(ToAddress(0x180))); | 2763 CHECK_EQ(7u, map.GetTraceNodeId(ToAddress(0x180))); |
2832 CHECK_EQ(5u, map.GetTraceNodeId(ToAddress(0x200))); | 2764 CHECK_EQ(5u, map.GetTraceNodeId(ToAddress(0x200))); |
2833 CHECK_EQ(3u, map.size()); | 2765 CHECK_EQ(3u, map.size()); |
2834 | 2766 |
2835 map.Clear(); | 2767 map.Clear(); |
2836 CHECK_EQ(0u, map.size()); | 2768 CHECK_EQ(0u, map.size()); |
2837 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x400))); | 2769 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x400))); |
2838 } | 2770 } |
OLD | NEW |