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 "snapshot.h" |
10 #include "string-stream.h" | 10 #include "string-stream.h" |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 lazy_references_x = true; | 622 lazy_references_x = true; |
623 break; | 623 break; |
624 } | 624 } |
625 } | 625 } |
626 } | 626 } |
627 CHECK(compiled_references_x); | 627 CHECK(compiled_references_x); |
628 CHECK(!lazy_references_x); | 628 CHECK(!lazy_references_x); |
629 } | 629 } |
630 | 630 |
631 | 631 |
| 632 // Trying to introduce a check helper for uint64_t causes many |
| 633 // overloading ambiguities, so it seems easier just to cast |
| 634 // them to a signed type. |
| 635 #define CHECK_EQ_UINT64_T(a, b) \ |
| 636 CHECK_EQ(static_cast<int64_t>(a), static_cast<int64_t>(b)) |
| 637 |
632 TEST(HeapEntryIdsAndGC) { | 638 TEST(HeapEntryIdsAndGC) { |
633 v8::HandleScope scope; | 639 v8::HandleScope scope; |
634 LocalContext env; | 640 LocalContext env; |
635 | 641 |
636 CompileAndRunScript( | 642 CompileAndRunScript( |
637 "function A() {}\n" | 643 "function A() {}\n" |
638 "function B(x) { this.x = x; }\n" | 644 "function B(x) { this.x = x; }\n" |
639 "var a = new A();\n" | 645 "var a = new A();\n" |
640 "var b = new B(a);"); | 646 "var b = new B(a);"); |
641 const v8::HeapSnapshot* snapshot1 = | 647 const v8::HeapSnapshot* snapshot1 = |
642 v8::HeapProfiler::TakeSnapshot(v8::String::New("s1")); | 648 v8::HeapProfiler::TakeSnapshot(v8::String::New("s1")); |
643 | 649 |
644 i::Heap::CollectAllGarbage(true); // Enforce compaction. | 650 i::Heap::CollectAllGarbage(true); // Enforce compaction. |
645 | 651 |
646 const v8::HeapSnapshot* snapshot2 = | 652 const v8::HeapSnapshot* snapshot2 = |
647 v8::HeapProfiler::TakeSnapshot(v8::String::New("s2")); | 653 v8::HeapProfiler::TakeSnapshot(v8::String::New("s2")); |
648 | 654 |
649 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); | 655 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); |
650 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); | 656 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
651 CHECK_NE(0, global1->GetId()); | 657 CHECK(global1->GetId() != 0); |
652 CHECK_EQ(global1->GetId(), global2->GetId()); | 658 CHECK_EQ_UINT64_T(global1->GetId(), global2->GetId()); |
653 const v8::HeapGraphNode* A1 = | 659 const v8::HeapGraphNode* A1 = |
654 GetProperty(global1, v8::HeapGraphEdge::PROPERTY, "A"); | 660 GetProperty(global1, v8::HeapGraphEdge::PROPERTY, "A"); |
655 const v8::HeapGraphNode* A2 = | 661 const v8::HeapGraphNode* A2 = |
656 GetProperty(global2, v8::HeapGraphEdge::PROPERTY, "A"); | 662 GetProperty(global2, v8::HeapGraphEdge::PROPERTY, "A"); |
657 CHECK_NE(0, A1->GetId()); | 663 CHECK(A1->GetId() != 0); |
658 CHECK_EQ(A1->GetId(), A2->GetId()); | 664 CHECK_EQ_UINT64_T(A1->GetId(), A2->GetId()); |
659 const v8::HeapGraphNode* B1 = | 665 const v8::HeapGraphNode* B1 = |
660 GetProperty(global1, v8::HeapGraphEdge::PROPERTY, "B"); | 666 GetProperty(global1, v8::HeapGraphEdge::PROPERTY, "B"); |
661 const v8::HeapGraphNode* B2 = | 667 const v8::HeapGraphNode* B2 = |
662 GetProperty(global2, v8::HeapGraphEdge::PROPERTY, "B"); | 668 GetProperty(global2, v8::HeapGraphEdge::PROPERTY, "B"); |
663 CHECK_NE(0, B1->GetId()); | 669 CHECK(B1->GetId() != 0); |
664 CHECK_EQ(B1->GetId(), B2->GetId()); | 670 CHECK_EQ_UINT64_T(B1->GetId(), B2->GetId()); |
665 const v8::HeapGraphNode* a1 = | 671 const v8::HeapGraphNode* a1 = |
666 GetProperty(global1, v8::HeapGraphEdge::PROPERTY, "a"); | 672 GetProperty(global1, v8::HeapGraphEdge::PROPERTY, "a"); |
667 const v8::HeapGraphNode* a2 = | 673 const v8::HeapGraphNode* a2 = |
668 GetProperty(global2, v8::HeapGraphEdge::PROPERTY, "a"); | 674 GetProperty(global2, v8::HeapGraphEdge::PROPERTY, "a"); |
669 CHECK_NE(0, a1->GetId()); | 675 CHECK(a1->GetId() != 0); |
670 CHECK_EQ(a1->GetId(), a2->GetId()); | 676 CHECK_EQ_UINT64_T(a1->GetId(), a2->GetId()); |
671 const v8::HeapGraphNode* b1 = | 677 const v8::HeapGraphNode* b1 = |
672 GetProperty(global1, v8::HeapGraphEdge::PROPERTY, "b"); | 678 GetProperty(global1, v8::HeapGraphEdge::PROPERTY, "b"); |
673 const v8::HeapGraphNode* b2 = | 679 const v8::HeapGraphNode* b2 = |
674 GetProperty(global2, v8::HeapGraphEdge::PROPERTY, "b"); | 680 GetProperty(global2, v8::HeapGraphEdge::PROPERTY, "b"); |
675 CHECK_NE(0, b1->GetId()); | 681 CHECK(b1->GetId() != 0); |
676 CHECK_EQ(b1->GetId(), b2->GetId()); | 682 CHECK_EQ_UINT64_T(b1->GetId(), b2->GetId()); |
677 } | 683 } |
678 | 684 |
679 | 685 |
680 TEST(HeapSnapshotsDiff) { | 686 TEST(HeapSnapshotsDiff) { |
681 v8::HandleScope scope; | 687 v8::HandleScope scope; |
682 LocalContext env; | 688 LocalContext env; |
683 | 689 |
684 CompileAndRunScript( | 690 CompileAndRunScript( |
685 "function A() {}\n" | 691 "function A() {}\n" |
686 "function B(x) { this.x = x; }\n" | 692 "function B(x) { this.x = x; }\n" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 v8::String::AsciiValue node_name(node->GetName()); | 740 v8::String::AsciiValue node_name(node->GetName()); |
735 if (strcmp(*node_name, "A") == 0) { | 741 if (strcmp(*node_name, "A") == 0) { |
736 CHECK(IsNodeRetainedAs(node, v8::HeapGraphEdge::PROPERTY, "a")); | 742 CHECK(IsNodeRetainedAs(node, v8::HeapGraphEdge::PROPERTY, "a")); |
737 CHECK(!found_A_del); | 743 CHECK(!found_A_del); |
738 found_A_del = true; | 744 found_A_del = true; |
739 s2_A_id = node->GetId(); | 745 s2_A_id = node->GetId(); |
740 } | 746 } |
741 } | 747 } |
742 } | 748 } |
743 CHECK(found_A_del); | 749 CHECK(found_A_del); |
744 CHECK_NE(0, s1_A_id); | 750 CHECK(s1_A_id != 0); |
745 CHECK(s1_A_id != s2_A_id); | 751 CHECK(s1_A_id != s2_A_id); |
746 } | 752 } |
747 | 753 |
748 #endif // ENABLE_LOGGING_AND_PROFILING | 754 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |