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

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

Issue 14007008: New GC APIs, try 2. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: code review (yurys) Created 7 years, 8 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
« no previous file with comments | « test/cctest/test-global-handles.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | 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 // 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
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 isolate_->SetObjectGroupId(v8::Persistent<v8::Object>::Cast(objects_[0]),
1212 v8::Persistent<v8::Object>::Cast(objects_[0]), &objects_[1], 1); 1213 v8::UniqueId(1));
1213 // Adding two more references(note length=2 in params): 1 -> 2, 1 -> 3 1214 isolate_->SetReferenceFromGroup(
1214 v8::V8::AddImplicitReferences( 1215 v8::UniqueId(1), v8::Persistent<v8::Object>::Cast(objects_[1]));
1215 v8::Persistent<v8::Object>::Cast(objects_[1]), &objects_[2], 2); 1216 // Adding two more references: 1 -> 2, 1 -> 3
1217 isolate_->SetReference(v8::Persistent<v8::Object>::Cast(objects_[1]),
1218 v8::Persistent<v8::Object>::Cast(objects_[2]));
1219 isolate_->SetReference(v8::Persistent<v8::Object>::Cast(objects_[1]),
1220 v8::Persistent<v8::Object>::Cast(objects_[3]));
1216 } 1221 }
1217 1222
1218 v8::Persistent<v8::Value> objects_[kObjectsCount]; 1223 v8::Persistent<v8::Value> objects_[kObjectsCount];
1219 static GraphWithImplicitRefs* instance_; 1224 static GraphWithImplicitRefs* instance_;
1225 v8::Isolate* isolate_;
1220 }; 1226 };
1221 1227
1222 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL; 1228 GraphWithImplicitRefs* GraphWithImplicitRefs::instance_ = NULL;
1223 1229
1224 1230
1225 TEST(HeapSnapshotImplicitReferences) { 1231 TEST(HeapSnapshotImplicitReferences) {
1226 LocalContext env; 1232 LocalContext env;
1227 v8::HandleScope scope(env->GetIsolate()); 1233 v8::HandleScope scope(env->GetIsolate());
1228 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1234 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1229 1235
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 // Check all the objects have got their names. 1771 // Check all the objects have got their names.
1766 // ... well check just every 8th because otherwise it's too slow in debug. 1772 // ... well check just every 8th because otherwise it's too slow in debug.
1767 for (int i = 0; i < num_objects - 1; i += 8) { 1773 for (int i = 0; i < num_objects - 1; i += 8) {
1768 i::EmbeddedVector<char, 100> var_name; 1774 i::EmbeddedVector<char, 100> var_name;
1769 i::OS::SNPrintF(var_name, "f_%d", i); 1775 i::OS::SNPrintF(var_name, "f_%d", i);
1770 const v8::HeapGraphNode* f_object = GetProperty( 1776 const v8::HeapGraphNode* f_object = GetProperty(
1771 context_object, v8::HeapGraphEdge::kContextVariable, var_name.start()); 1777 context_object, v8::HeapGraphEdge::kContextVariable, var_name.start());
1772 CHECK_NE(NULL, f_object); 1778 CHECK_NE(NULL, f_object);
1773 } 1779 }
1774 } 1780 }
OLDNEW
« no previous file with comments | « test/cctest/test-global-handles.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698