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