Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 9316092: Heap profiler should report implicit references (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/profile-generator.cc ('K') | « src/profile-generator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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++)
mnaganov (inactive) 2012/02/03 13:57:19 nit: brackets
yurys 2012/02/03 14:09:26 Done. Are they required by V8 coding style?
mnaganov (inactive) 2012/02/03 14:23:41 Google C++ coding style says "conditional or loop
814 objects_[i] = v8::Persistent<v8::Object>::New(v8::Object::New());
815 (*env)->Global()->Set(v8_str("root_object"), objects_[0]);
816 }
817 ~GraphWithImplicitRefs() {
818 instance_ = NULL;
819 }
820
821 static void gcPrologue() {
822 instance_->AddImplicitReferences();
823 }
824
825 private:
826 void AddImplicitReferences() {
827 // 0 -> 1
828 v8::V8::AddImplicitReferences(
829 v8::Persistent<v8::Object>::Cast(objects_[0]), &objects_[1], 1);
830 // 1 -> 2, 1 -> 3
831 v8::V8::AddImplicitReferences(
832 v8::Persistent<v8::Object>::Cast(objects_[1]), &objects_[2], 2);
mnaganov (inactive) 2012/02/03 13:57:19 Have you forgot to add 1->3 reference, or what doe
yurys 2012/02/03 14:09:26 No, the comment is perfectly fine, although Ilya a
833 }
834
835 v8::Persistent<v8::Value> objects_[4];
mnaganov (inactive) 2012/02/03 13:57:19 I think, using an enum for test objects and their
yurys 2012/02/03 14:09:26 Well, I started with storing each object in its ow
836 static GraphWithImplicitRefs* instance_;
837 };
838
839 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL;
840
841
842 TEST(HeapSnapshotImplicitReferences) {
843 v8::HandleScope scope;
844 LocalContext env;
845
846 GraphWithImplicitRefs graph(&env);
847 v8::V8::SetGlobalGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue);
848
849 const v8::HeapSnapshot* snapshot =
850 v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs"));
851
852 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot);
853 // Use kShortcut type to skip intermediate JSGlobalPropertyCell
854 const v8::HeapGraphNode* o0 = GetProperty(
mnaganov (inactive) 2012/02/03 13:57:19 This name looks weird. In other tests names like "
yurys 2012/02/03 14:09:26 Done.
855 global_object, v8::HeapGraphEdge::kShortcut, "root_object");
856 CHECK(o0);
857 CHECK_EQ(v8::HeapGraphNode::kObject, o0->GetType());
858 const v8::HeapGraphNode* o1 = GetProperty(
859 o0, v8::HeapGraphEdge::kInternal, "native");
860 CHECK(o1);
861 int implicit_targets_count = 0;
862 for (int i = 0, count = o1->GetChildrenCount(); i < count; ++i) {
863 const v8::HeapGraphEdge* prop = o1->GetChild(i);
864 v8::String::AsciiValue prop_name(prop->GetName());
865 if (prop->GetType() == v8::HeapGraphEdge::kInternal &&
866 strcmp("native", *prop_name) == 0) {
867 ++implicit_targets_count;
868 }
869 }
870 CHECK_EQ(2, implicit_targets_count);
871 v8::V8::SetGlobalGCPrologueCallback(NULL);
872 }
873
874
808 TEST(DeleteAllHeapSnapshots) { 875 TEST(DeleteAllHeapSnapshots) {
809 v8::HandleScope scope; 876 v8::HandleScope scope;
810 LocalContext env; 877 LocalContext env;
811 878
812 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); 879 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
813 v8::HeapProfiler::DeleteAllSnapshots(); 880 v8::HeapProfiler::DeleteAllSnapshots();
814 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); 881 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
815 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1"))); 882 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1")));
816 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); 883 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount());
817 v8::HeapProfiler::DeleteAllSnapshots(); 884 v8::HeapProfiler::DeleteAllSnapshots();
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); 1222 v8::HeapProfiler::TakeSnapshot(v8_str("fun"));
1156 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1223 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1157 CHECK_NE(NULL, global); 1224 CHECK_NE(NULL, global);
1158 const v8::HeapGraphNode* fun = 1225 const v8::HeapGraphNode* fun =
1159 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); 1226 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun");
1160 CHECK(HasWeakEdge(fun)); 1227 CHECK(HasWeakEdge(fun));
1161 const v8::HeapGraphNode* shared = 1228 const v8::HeapGraphNode* shared =
1162 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); 1229 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared");
1163 CHECK(HasWeakEdge(shared)); 1230 CHECK(HasWeakEdge(shared));
1164 } 1231 }
OLDNEW
« src/profile-generator.cc ('K') | « src/profile-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698