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

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
« no previous file with comments | « 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 static const int kObjectsCount = 4;
811 explicit GraphWithImplicitRefs(LocalContext* env) {
812 CHECK_EQ(NULL, instance_);
813 instance_ = this;
814 for (int i = 0; i < kObjectsCount; i++) {
815 objects_[i] = v8::Persistent<v8::Object>::New(v8::Object::New());
816 }
817 (*env)->Global()->Set(v8_str("root_object"), objects_[0]);
818 }
819 ~GraphWithImplicitRefs() {
820 instance_ = NULL;
821 }
822
823 static void gcPrologue() {
824 instance_->AddImplicitReferences();
825 }
826
827 private:
828 void AddImplicitReferences() {
829 // 0 -> 1
830 v8::V8::AddImplicitReferences(
831 v8::Persistent<v8::Object>::Cast(objects_[0]), &objects_[1], 1);
832 // Adding two more references(note length=2 in params): 1 -> 2, 1 -> 3
833 v8::V8::AddImplicitReferences(
834 v8::Persistent<v8::Object>::Cast(objects_[1]), &objects_[2], 2);
835 }
836
837 v8::Persistent<v8::Value> objects_[kObjectsCount];
838 static GraphWithImplicitRefs* instance_;
839 };
840
841 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL;
842
843
844 TEST(HeapSnapshotImplicitReferences) {
845 v8::HandleScope scope;
846 LocalContext env;
847
848 GraphWithImplicitRefs graph(&env);
849 v8::V8::SetGlobalGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue);
850
851 const v8::HeapSnapshot* snapshot =
852 v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs"));
853
854 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot);
855 // Use kShortcut type to skip intermediate JSGlobalPropertyCell
856 const v8::HeapGraphNode* obj0 = GetProperty(
857 global_object, v8::HeapGraphEdge::kShortcut, "root_object");
858 CHECK(obj0);
859 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType());
860 const v8::HeapGraphNode* obj1 = GetProperty(
861 obj0, v8::HeapGraphEdge::kInternal, "native");
862 CHECK(obj1);
863 int implicit_targets_count = 0;
864 for (int i = 0, count = obj1->GetChildrenCount(); i < count; ++i) {
865 const v8::HeapGraphEdge* prop = obj1->GetChild(i);
866 v8::String::AsciiValue prop_name(prop->GetName());
867 if (prop->GetType() == v8::HeapGraphEdge::kInternal &&
868 strcmp("native", *prop_name) == 0) {
869 ++implicit_targets_count;
870 }
871 }
872 CHECK_EQ(2, implicit_targets_count);
873 v8::V8::SetGlobalGCPrologueCallback(NULL);
874 }
875
876
808 TEST(DeleteAllHeapSnapshots) { 877 TEST(DeleteAllHeapSnapshots) {
809 v8::HandleScope scope; 878 v8::HandleScope scope;
810 LocalContext env; 879 LocalContext env;
811 880
812 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); 881 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
813 v8::HeapProfiler::DeleteAllSnapshots(); 882 v8::HeapProfiler::DeleteAllSnapshots();
814 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); 883 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
815 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1"))); 884 CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1")));
816 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount()); 885 CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount());
817 v8::HeapProfiler::DeleteAllSnapshots(); 886 v8::HeapProfiler::DeleteAllSnapshots();
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 v8::HeapProfiler::TakeSnapshot(v8_str("fun")); 1224 v8::HeapProfiler::TakeSnapshot(v8_str("fun"));
1156 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1225 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1157 CHECK_NE(NULL, global); 1226 CHECK_NE(NULL, global);
1158 const v8::HeapGraphNode* fun = 1227 const v8::HeapGraphNode* fun =
1159 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun"); 1228 GetProperty(global, v8::HeapGraphEdge::kShortcut, "fun");
1160 CHECK(HasWeakEdge(fun)); 1229 CHECK(HasWeakEdge(fun));
1161 const v8::HeapGraphNode* shared = 1230 const v8::HeapGraphNode* shared =
1162 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); 1231 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared");
1163 CHECK(HasWeakEdge(shared)); 1232 CHECK(HasWeakEdge(shared));
1164 } 1233 }
OLDNEW
« no previous file with comments | « src/profile-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698