OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // | 2 // |
3 // Tests for heap profiler | 3 // Tests for heap profiler |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "cctest.h" | 7 #include "cctest.h" |
8 #include "heap-profiler.h" | 8 #include "heap-profiler.h" |
9 #include "snapshot.h" | 9 #include "snapshot.h" |
10 #include "utils-inl.h" | 10 #include "utils-inl.h" |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
798 const v8::HeapGraphNode* n_CCC = GetNode( | 798 const v8::HeapGraphNode* n_CCC = GetNode( |
799 ccc, v8::HeapGraphNode::kString, "CCC"); | 799 ccc, v8::HeapGraphNode::kString, "CCC"); |
800 CHECK_NE(NULL, n_CCC); | 800 CHECK_NE(NULL, n_CCC); |
801 | 801 |
802 CHECK_EQ(aaa, GetProperty(n_AAA, v8::HeapGraphEdge::kInternal, "native")); | 802 CHECK_EQ(aaa, GetProperty(n_AAA, v8::HeapGraphEdge::kInternal, "native")); |
803 CHECK_EQ(aaa, GetProperty(n_BBB, v8::HeapGraphEdge::kInternal, "native")); | 803 CHECK_EQ(aaa, GetProperty(n_BBB, v8::HeapGraphEdge::kInternal, "native")); |
804 CHECK_EQ(ccc, GetProperty(n_CCC, v8::HeapGraphEdge::kInternal, "native")); | 804 CHECK_EQ(ccc, GetProperty(n_CCC, v8::HeapGraphEdge::kInternal, "native")); |
805 } | 805 } |
806 | 806 |
807 | 807 |
808 class GraphWithImplicitRefs { | |
809 public: | |
810 explicit GraphWithImplicitRefs(LocalContext* env) { | |
811 CHECK_EQ(NULL, instance_); | |
812 instance_ = this; | |
813 for (int i = 0; i < 4; i++) { | |
814 objects_[i] = v8::Persistent<v8::Object>::New(v8::Object::New()); | |
815 } | |
816 (*env)->Global()->Set(v8_str("root_object"), objects_[0]); | |
817 } | |
818 ~GraphWithImplicitRefs() { | |
819 instance_ = NULL; | |
820 } | |
821 | |
822 static void gcPrologue() { | |
823 instance_->AddImplicitReferences(); | |
824 } | |
825 | |
826 private: | |
827 void AddImplicitReferences() { | |
828 // 0 -> 1 | |
829 v8::V8::AddImplicitReferences( | |
830 v8::Persistent<v8::Object>::Cast(objects_[0]), &objects_[1], 1); | |
831 // 1 -> 2, 1 -> 3 | |
mnaganov (inactive)
2012/02/03 14:23:41
Then please add "(note length = 2)" for clarity.
yurys
2012/02/03 14:50:57
Done.
| |
832 v8::V8::AddImplicitReferences( | |
833 v8::Persistent<v8::Object>::Cast(objects_[1]), &objects_[2], 2); | |
834 } | |
835 | |
836 v8::Persistent<v8::Value> objects_[4]; | |
mnaganov (inactive)
2012/02/03 14:23:41
OK, at least, please introduce a constant for the
yurys
2012/02/03 14:50:57
Done.
| |
837 static GraphWithImplicitRefs* instance_; | |
838 }; | |
839 | |
840 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL; | |
841 | |
842 | |
843 TEST(HeapSnapshotImplicitReferences) { | |
844 v8::HandleScope scope; | |
845 LocalContext env; | |
846 | |
847 GraphWithImplicitRefs graph(&env); | |
848 v8::V8::SetGlobalGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); | |
849 | |
850 const v8::HeapSnapshot* snapshot = | |
851 v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs")); | |
852 | |
853 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); | |
854 // Use kShortcut type to skip intermediate JSGlobalPropertyCell | |
855 const v8::HeapGraphNode* obj0 = GetProperty( | |
856 global_object, v8::HeapGraphEdge::kShortcut, "root_object"); | |
857 CHECK(obj0); | |
858 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType()); | |
859 const v8::HeapGraphNode* obj1 = GetProperty( | |
860 obj0, v8::HeapGraphEdge::kInternal, "native"); | |
861 CHECK(obj1); | |
862 int implicit_targets_count = 0; | |
863 for (int i = 0, count = obj1->GetChildrenCount(); i < count; ++i) { | |
864 const v8::HeapGraphEdge* prop = obj1->GetChild(i); | |
865 v8::String::AsciiValue prop_name(prop->GetName()); | |
866 if (prop->GetType() == v8::HeapGraphEdge::kInternal && | |
867 strcmp("native", *prop_name) == 0) { | |
868 ++implicit_targets_count; | |
869 } | |
870 } | |
871 CHECK_EQ(2, implicit_targets_count); | |
872 v8::V8::SetGlobalGCPrologueCallback(NULL); | |
873 } | |
874 | |
875 | |
808 TEST(DeleteAllHeapSnapshots) { | 876 TEST(DeleteAllHeapSnapshots) { |
809 v8::HandleScope scope; | 877 v8::HandleScope scope; |
810 LocalContext env; | 878 LocalContext env; |
811 | 879 |
812 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); | 880 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); |
813 v8::HeapProfiler::DeleteAllSnapshots(); | 881 v8::HeapProfiler::DeleteAllSnapshots(); |
814 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); | 882 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); |
815 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1"))); | 883 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1"))); |
816 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); | 884 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); |
817 v8::HeapProfiler::DeleteAllSnapshots(); | 885 v8::HeapProfiler::DeleteAllSnapshots(); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); | 1223 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); |
1156 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 1224 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
1157 CHECK_NE(NULL, global); | 1225 CHECK_NE(NULL, global); |
1158 const v8::HeapGraphNode* fun = | 1226 const v8::HeapGraphNode* fun = |
1159 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); | 1227 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); |
1160 CHECK(HasWeakEdge(fun)); | 1228 CHECK(HasWeakEdge(fun)); |
1161 const v8::HeapGraphNode* shared = | 1229 const v8::HeapGraphNode* shared = |
1162 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); | 1230 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); |
1163 CHECK(HasWeakEdge(shared)); | 1231 CHECK(HasWeakEdge(shared)); |
1164 } | 1232 } |
OLD | NEW |