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

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

Issue 11953043: Implicit references are missing in heap profiles (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 11 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 <ctype.h> 5 #include <ctype.h>
6 6
7 #include "v8.h" 7 #include "v8.h"
8 8
9 #include "cctest.h" 9 #include "cctest.h"
10 #include "hashmap.h" 10 #include "hashmap.h"
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 instance_ = this; 1109 instance_ = this;
1110 for (int i = 0; i < kObjectsCount; i++) { 1110 for (int i = 0; i < kObjectsCount; i++) {
1111 objects_[i] = v8::Persistent<v8::Object>::New(v8::Object::New()); 1111 objects_[i] = v8::Persistent<v8::Object>::New(v8::Object::New());
1112 } 1112 }
1113 (*env)->Global()->Set(v8_str("root_object"), objects_[0]); 1113 (*env)->Global()->Set(v8_str("root_object"), objects_[0]);
1114 } 1114 }
1115 ~GraphWithImplicitRefs() { 1115 ~GraphWithImplicitRefs() {
1116 instance_ = NULL; 1116 instance_ = NULL;
1117 } 1117 }
1118 1118
1119 static void gcPrologue() { 1119 static void gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) {
1120 instance_->AddImplicitReferences(); 1120 instance_->AddImplicitReferences();
1121 } 1121 }
1122 1122
1123 private: 1123 private:
1124 void AddImplicitReferences() { 1124 void AddImplicitReferences() {
1125 // 0 -> 1 1125 // 0 -> 1
1126 v8::V8::AddImplicitReferences( 1126 v8::V8::AddImplicitReferences(
1127 v8::Persistent<v8::Object>::Cast(objects_[0]), &objects_[1], 1); 1127 v8::Persistent<v8::Object>::Cast(objects_[0]), &objects_[1], 1);
1128 // Adding two more references(note length=2 in params): 1 -> 2, 1 -> 3 1128 // Adding two more references(note length=2 in params): 1 -> 2, 1 -> 3
1129 v8::V8::AddImplicitReferences( 1129 v8::V8::AddImplicitReferences(
1130 v8::Persistent<v8::Object>::Cast(objects_[1]), &objects_[2], 2); 1130 v8::Persistent<v8::Object>::Cast(objects_[1]), &objects_[2], 2);
1131 } 1131 }
1132 1132
1133 v8::Persistent<v8::Value> objects_[kObjectsCount]; 1133 v8::Persistent<v8::Value> objects_[kObjectsCount];
1134 static GraphWithImplicitRefs* instance_; 1134 static GraphWithImplicitRefs* instance_;
1135 }; 1135 };
1136 1136
1137 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL; 1137 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL;
1138 1138
1139 1139
1140 TEST(HeapSnapshotImplicitReferences) { 1140 TEST(HeapSnapshotImplicitReferences) {
1141 v8::HandleScope scope; 1141 v8::HandleScope scope;
1142 LocalContext env; 1142 LocalContext env;
1143 1143
1144 GraphWithImplicitRefs graph(&env); 1144 GraphWithImplicitRefs graph(&env);
1145 v8::V8::SetGlobalGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); 1145 v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue);
1146 1146
1147 const v8::HeapSnapshot* snapshot = 1147 const v8::HeapSnapshot* snapshot =
1148 v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs")); 1148 v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs"));
1149 1149
1150 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); 1150 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot);
1151 const v8::HeapGraphNode* obj0 = GetProperty( 1151 const v8::HeapGraphNode* obj0 = GetProperty(
1152 global_object, v8::HeapGraphEdge::kProperty, "root_object"); 1152 global_object, v8::HeapGraphEdge::kProperty, "root_object");
1153 CHECK(obj0); 1153 CHECK(obj0);
1154 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType()); 1154 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType());
1155 const v8::HeapGraphNode* obj1 = GetProperty( 1155 const v8::HeapGraphNode* obj1 = GetProperty(
1156 obj0, v8::HeapGraphEdge::kInternal, "native"); 1156 obj0, v8::HeapGraphEdge::kInternal, "native");
1157 CHECK(obj1); 1157 CHECK(obj1);
1158 int implicit_targets_count = 0; 1158 int implicit_targets_count = 0;
1159 for (int i = 0, count = obj1->GetChildrenCount(); i < count; ++i) { 1159 for (int i = 0, count = obj1->GetChildrenCount(); i < count; ++i) {
1160 const v8::HeapGraphEdge* prop = obj1->GetChild(i); 1160 const v8::HeapGraphEdge* prop = obj1->GetChild(i);
1161 v8::String::AsciiValue prop_name(prop->GetName()); 1161 v8::String::AsciiValue prop_name(prop->GetName());
1162 if (prop->GetType() == v8::HeapGraphEdge::kInternal && 1162 if (prop->GetType() == v8::HeapGraphEdge::kInternal &&
1163 strcmp("native", *prop_name) == 0) { 1163 strcmp("native", *prop_name) == 0) {
1164 ++implicit_targets_count; 1164 ++implicit_targets_count;
1165 } 1165 }
1166 } 1166 }
1167 CHECK_EQ(2, implicit_targets_count); 1167 CHECK_EQ(2, implicit_targets_count);
1168 v8::V8::SetGlobalGCPrologueCallback(NULL); 1168 v8::V8::RemoveGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue);
1169 } 1169 }
1170 1170
1171 1171
1172 TEST(DeleteAllHeapSnapshots) { 1172 TEST(DeleteAllHeapSnapshots) {
1173 v8::HandleScope scope; 1173 v8::HandleScope scope;
1174 LocalContext env; 1174 LocalContext env;
1175 1175
1176 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); 1176 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
1177 v8::HeapProfiler::DeleteAllSnapshots(); 1177 v8::HeapProfiler::DeleteAllSnapshots();
1178 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount()); 1178 CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 const v8::HeapGraphNode* map = 1650 const v8::HeapGraphNode* map =
1651 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); 1651 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map");
1652 CHECK_NE(NULL, map); 1652 CHECK_NE(NULL, map);
1653 const v8::HeapGraphNode* own_descriptors = GetProperty( 1653 const v8::HeapGraphNode* own_descriptors = GetProperty(
1654 map, v8::HeapGraphEdge::kInternal, "descriptors"); 1654 map, v8::HeapGraphEdge::kInternal, "descriptors");
1655 CHECK_NE(NULL, own_descriptors); 1655 CHECK_NE(NULL, own_descriptors);
1656 const v8::HeapGraphNode* own_transitions = GetProperty( 1656 const v8::HeapGraphNode* own_transitions = GetProperty(
1657 map, v8::HeapGraphEdge::kInternal, "transitions"); 1657 map, v8::HeapGraphEdge::kInternal, "transitions");
1658 CHECK_EQ(NULL, own_transitions); 1658 CHECK_EQ(NULL, own_transitions);
1659 } 1659 }
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