OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 CHECK_EQ(ccc, GetProperty(n_CCC, v8::HeapGraphEdge::kInternal, "native")); | 1184 CHECK_EQ(ccc, GetProperty(n_CCC, v8::HeapGraphEdge::kInternal, "native")); |
1185 } | 1185 } |
1186 | 1186 |
1187 | 1187 |
1188 class GraphWithImplicitRefs { | 1188 class GraphWithImplicitRefs { |
1189 public: | 1189 public: |
1190 static const int kObjectsCount = 4; | 1190 static const int kObjectsCount = 4; |
1191 explicit GraphWithImplicitRefs(LocalContext* env) { | 1191 explicit GraphWithImplicitRefs(LocalContext* env) { |
1192 CHECK_EQ(NULL, instance_); | 1192 CHECK_EQ(NULL, instance_); |
1193 instance_ = this; | 1193 instance_ = this; |
1194 v8::Isolate* isolate = (*env)->GetIsolate(); | 1194 isolate_ = (*env)->GetIsolate(); |
1195 for (int i = 0; i < kObjectsCount; i++) { | 1195 for (int i = 0; i < kObjectsCount; i++) { |
1196 objects_[i] = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); | 1196 objects_[i] = |
| 1197 v8::Persistent<v8::Object>::New(isolate_, v8::Object::New()); |
1197 } | 1198 } |
1198 (*env)->Global()->Set(v8_str("root_object"), objects_[0]); | 1199 (*env)->Global()->Set(v8_str("root_object"), objects_[0]); |
1199 } | 1200 } |
1200 ~GraphWithImplicitRefs() { | 1201 ~GraphWithImplicitRefs() { |
1201 instance_ = NULL; | 1202 instance_ = NULL; |
1202 } | 1203 } |
1203 | 1204 |
1204 static void gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) { | 1205 static void gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) { |
1205 instance_->AddImplicitReferences(); | 1206 instance_->AddImplicitReferences(); |
1206 } | 1207 } |
1207 | 1208 |
1208 private: | 1209 private: |
1209 void AddImplicitReferences() { | 1210 void AddImplicitReferences() { |
1210 // 0 -> 1 | 1211 // 0 -> 1 |
1211 v8::V8::AddImplicitReferences( | 1212 v8::V8::SetObjectGroupId(isolate_, |
1212 v8::Persistent<v8::Object>::Cast(objects_[0]), &objects_[1], 1); | 1213 v8::Persistent<v8::Object>::Cast(objects_[0]), |
| 1214 v8::UniqueId(1)); |
| 1215 v8::V8::SetObjectGroupRepresentative( |
| 1216 isolate_, |
| 1217 v8::UniqueId(1), |
| 1218 v8::Persistent<v8::Object>::Cast(objects_[0])); |
| 1219 v8::V8::AddImplicitReference(isolate_, |
| 1220 v8::UniqueId(1), |
| 1221 v8::Persistent<v8::Object>::Cast(objects_[1])); |
1213 // Adding two more references(note length=2 in params): 1 -> 2, 1 -> 3 | 1222 // Adding two more references(note length=2 in params): 1 -> 2, 1 -> 3 |
1214 v8::V8::AddImplicitReferences( | 1223 v8::V8::SetObjectGroupId(isolate_, |
1215 v8::Persistent<v8::Object>::Cast(objects_[1]), &objects_[2], 2); | 1224 v8::Persistent<v8::Object>::Cast(objects_[1]), |
| 1225 v8::UniqueId(2)); |
| 1226 v8::V8::SetObjectGroupRepresentative( |
| 1227 isolate_, |
| 1228 v8::UniqueId(2), |
| 1229 v8::Persistent<v8::Object>::Cast(objects_[1])); |
| 1230 v8::V8::AddImplicitReference(isolate_, |
| 1231 v8::UniqueId(2), |
| 1232 v8::Persistent<v8::Object>::Cast(objects_[2])); |
| 1233 v8::V8::AddImplicitReference(isolate_, |
| 1234 v8::UniqueId(2), |
| 1235 v8::Persistent<v8::Object>::Cast(objects_[3])); |
1216 } | 1236 } |
1217 | 1237 |
1218 v8::Persistent<v8::Value> objects_[kObjectsCount]; | 1238 v8::Persistent<v8::Value> objects_[kObjectsCount]; |
1219 static GraphWithImplicitRefs* instance_; | 1239 static GraphWithImplicitRefs* instance_; |
| 1240 v8::Isolate* isolate_; |
1220 }; | 1241 }; |
1221 | 1242 |
1222 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL; | 1243 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL; |
1223 | 1244 |
1224 | 1245 |
1225 TEST(HeapSnapshotImplicitReferences) { | 1246 TEST(HeapSnapshotImplicitReferences) { |
1226 LocalContext env; | 1247 LocalContext env; |
1227 v8::HandleScope scope(env->GetIsolate()); | 1248 v8::HandleScope scope(env->GetIsolate()); |
1228 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1249 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1229 | 1250 |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1765 // Check all the objects have got their names. | 1786 // Check all the objects have got their names. |
1766 // ... well check just every 8th because otherwise it's too slow in debug. | 1787 // ... well check just every 8th because otherwise it's too slow in debug. |
1767 for (int i = 0; i < num_objects - 1; i += 8) { | 1788 for (int i = 0; i < num_objects - 1; i += 8) { |
1768 i::EmbeddedVector<char, 100> var_name; | 1789 i::EmbeddedVector<char, 100> var_name; |
1769 i::OS::SNPrintF(var_name, "f_%d", i); | 1790 i::OS::SNPrintF(var_name, "f_%d", i); |
1770 const v8::HeapGraphNode* f_object = GetProperty( | 1791 const v8::HeapGraphNode* f_object = GetProperty( |
1771 context_object, v8::HeapGraphEdge::kContextVariable, var_name.start()); | 1792 context_object, v8::HeapGraphEdge::kContextVariable, var_name.start()); |
1772 CHECK_NE(NULL, f_object); | 1793 CHECK_NE(NULL, f_object); |
1773 } | 1794 } |
1774 } | 1795 } |
OLD | NEW |