OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // | 2 // |
3 // Tests for heap profiler | 3 // Tests for heap profiler |
4 | 4 |
5 #ifdef ENABLE_LOGGING_AND_PROFILING | 5 #ifdef ENABLE_LOGGING_AND_PROFILING |
6 | 6 |
7 #include "v8.h" | 7 #include "v8.h" |
8 #include "heap-profiler.h" | 8 #include "heap-profiler.h" |
| 9 #include "snapshot.h" |
9 #include "string-stream.h" | 10 #include "string-stream.h" |
10 #include "cctest.h" | 11 #include "cctest.h" |
11 #include "zone-inl.h" | 12 #include "zone-inl.h" |
12 #include "../include/v8-profiler.h" | 13 #include "../include/v8-profiler.h" |
13 | 14 |
14 namespace i = v8::internal; | 15 namespace i = v8::internal; |
15 using i::ClustersCoarser; | 16 using i::ClustersCoarser; |
16 using i::JSObjectsCluster; | 17 using i::JSObjectsCluster; |
17 using i::JSObjectsRetainerTree; | 18 using i::JSObjectsRetainerTree; |
18 using i::JSObjectsClusterTree; | 19 using i::JSObjectsClusterTree; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 | 451 |
451 CompileAndRunScript( | 452 CompileAndRunScript( |
452 "function A2() {}\n" | 453 "function A2() {}\n" |
453 "function B2(x) { return function() { return typeof x; }; }\n" | 454 "function B2(x) { return function() { return typeof x; }; }\n" |
454 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" | 455 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" |
455 "var a2 = new A2();\n" | 456 "var a2 = new A2();\n" |
456 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" | 457 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" |
457 "var c2 = new C2(a2);"); | 458 "var c2 = new C2(a2);"); |
458 const v8::HeapSnapshot* snapshot_env2 = | 459 const v8::HeapSnapshot* snapshot_env2 = |
459 v8::HeapProfiler::TakeSnapshot(v8::String::New("env2")); | 460 v8::HeapProfiler::TakeSnapshot(v8::String::New("env2")); |
460 CHECK_EQ(1, snapshot_env2->GetHead()->GetChildrenCount()); | 461 const v8::HeapGraphNode* global_env2; |
461 const v8::HeapGraphNode* global_env2 = | 462 if (i::Snapshot::IsEnabled()) { |
462 snapshot_env2->GetHead()->GetChild(0)->GetToNode(); | 463 // In case if snapshots are enabled, there will present a |
| 464 // vanilla deserealized global object, without properties |
| 465 // added by the test code. |
| 466 CHECK_EQ(2, snapshot_env2->GetHead()->GetChildrenCount()); |
| 467 // Choose the global object of a bigger size. |
| 468 const v8::HeapGraphNode* node0 = |
| 469 snapshot_env2->GetHead()->GetChild(0)->GetToNode(); |
| 470 const v8::HeapGraphNode* node1 = |
| 471 snapshot_env2->GetHead()->GetChild(1)->GetToNode(); |
| 472 global_env2 = node0->GetTotalSize() > node1->GetTotalSize() ? |
| 473 node0 : node1; |
| 474 } else { |
| 475 CHECK_EQ(1, snapshot_env2->GetHead()->GetChildrenCount()); |
| 476 global_env2 = snapshot_env2->GetHead()->GetChild(0)->GetToNode(); |
| 477 } |
463 | 478 |
464 // Verify, that JS global object of env2 doesn't have '..1' | 479 // Verify, that JS global object of env2 doesn't have '..1' |
465 // properties, but has '..2' properties. | 480 // properties, but has '..2' properties. |
466 bool has_a1 = false, has_b1_1 = false, has_b1_2 = false, has_c1 = false; | 481 bool has_a1 = false, has_b1_1 = false, has_b1_2 = false, has_c1 = false; |
467 bool has_a2 = false, has_b2_1 = false, has_b2_2 = false, has_c2 = false; | 482 bool has_a2 = false, has_b2_1 = false, has_b2_2 = false, has_c2 = false; |
468 // This will be needed further. | 483 // This will be needed further. |
469 const v8::HeapGraphNode* a2_node = NULL; | 484 const v8::HeapGraphNode* a2_node = NULL; |
470 for (int i = 0, count = global_env2->GetChildrenCount(); i < count; ++i) { | 485 for (int i = 0, count = global_env2->GetChildrenCount(); i < count; ++i) { |
471 const v8::HeapGraphEdge* prop = global_env2->GetChild(i); | 486 const v8::HeapGraphEdge* prop = global_env2->GetChild(i); |
472 v8::String::AsciiValue prop_name(prop->GetName()); | 487 v8::String::AsciiValue prop_name(prop->GetName()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } | 559 } |
545 CHECK(has_global_obj_a2_ref); | 560 CHECK(has_global_obj_a2_ref); |
546 CHECK(has_c2_x1_ref); | 561 CHECK(has_c2_x1_ref); |
547 CHECK(has_c2_x2_ref); | 562 CHECK(has_c2_x2_ref); |
548 CHECK(has_c2_1_ref); | 563 CHECK(has_c2_1_ref); |
549 CHECK(has_b2_1_x_ref); | 564 CHECK(has_b2_1_x_ref); |
550 CHECK(has_b2_2_x_ref); | 565 CHECK(has_b2_2_x_ref); |
551 } | 566 } |
552 | 567 |
553 #endif // ENABLE_LOGGING_AND_PROFILING | 568 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |