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 18996004: HeapProfiler: check that heap snapshot has no unretained entries except root. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: ValidateSnapshot call added everywhere Created 7 years, 5 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 | « no previous file | 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 // 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 const v8::HeapGraphNode* node = prop->GetToNode(); 120 const v8::HeapGraphNode* node = prop->GetToNode();
121 if (node->GetType() == v8::HeapGraphNode::kString) { 121 if (node->GetType() == v8::HeapGraphNode::kString) {
122 v8::String::Utf8Value node_name(node->GetName()); 122 v8::String::Utf8Value node_name(node->GetName());
123 if (strcmp(contents, *node_name) == 0) return true; 123 if (strcmp(contents, *node_name) == 0) return true;
124 } 124 }
125 } 125 }
126 return false; 126 return false;
127 } 127 }
128 128
129 129
130 static bool AddressesMatch(void* key1, void* key2) {
131 return key1 == key2;
132 }
133
134
135 // Check that snapshot has no unretained entries except root.
136 static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth) {
137 i::HeapSnapshot* heap_snapshot = const_cast<i::HeapSnapshot*>(
138 reinterpret_cast<const i::HeapSnapshot*>(snapshot));
139
140 i::HashMap visited(AddressesMatch);
141 i::List<i::HeapGraphEdge>& edges = heap_snapshot->edges();
142 for (int i = 0; i < edges.length(); ++i) {
143 i::HashMap::Entry* entry = visited.Lookup(
144 reinterpret_cast<void*>(edges[i].to()),
145 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(edges[i].to())),
146 true);
147 uint32_t ref_count = static_cast<uint32_t>(
148 reinterpret_cast<uintptr_t>(entry->value));
149 entry->value = reinterpret_cast<void*>(ref_count + 1);
150 }
151 uint32_t unretained_entries_count = 0;
152 i::List<i::HeapEntry>& entries = heap_snapshot->entries();
153 for (int i = 0; i < entries.length(); ++i) {
154 i::HashMap::Entry* entry = visited.Lookup(
155 reinterpret_cast<void*>(&entries[i]),
156 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&entries[i])),
157 false);
158 if (!entry && entries[i].id() != 1) {
159 entries[i].Print("entry with no retainer", "", depth, 0);
160 ++unretained_entries_count;
161 }
162 }
163 return unretained_entries_count > 1 ? false : true;
164 }
165
166
130 TEST(HeapSnapshot) { 167 TEST(HeapSnapshot) {
131 LocalContext env2; 168 LocalContext env2;
132 v8::HandleScope scope(env2->GetIsolate()); 169 v8::HandleScope scope(env2->GetIsolate());
133 v8::HeapProfiler* heap_profiler = env2->GetIsolate()->GetHeapProfiler(); 170 v8::HeapProfiler* heap_profiler = env2->GetIsolate()->GetHeapProfiler();
134 171
135 CompileRun( 172 CompileRun(
136 "function A2() {}\n" 173 "function A2() {}\n"
137 "function B2(x) { return function() { return typeof x; }; }\n" 174 "function B2(x) { return function() { return typeof x; }; }\n"
138 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" 175 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n"
139 "var a2 = new A2();\n" 176 "var a2 = new A2();\n"
140 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" 177 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n"
141 "var c2 = new C2(a2);"); 178 "var c2 = new C2(a2);");
142 const v8::HeapSnapshot* snapshot_env2 = 179 const v8::HeapSnapshot* snapshot_env2 =
143 heap_profiler->TakeHeapSnapshot(v8_str("env2")); 180 heap_profiler->TakeHeapSnapshot(v8_str("env2"));
181 CHECK(ValidateSnapshot(snapshot_env2, 3));
144 const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2); 182 const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2);
145 183
146 // Verify, that JS global object of env2 has '..2' properties. 184 // Verify, that JS global object of env2 has '..2' properties.
147 const v8::HeapGraphNode* a2_node = 185 const v8::HeapGraphNode* a2_node =
148 GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "a2"); 186 GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "a2");
149 CHECK_NE(NULL, a2_node); 187 CHECK_NE(NULL, a2_node);
150 CHECK_NE( 188 CHECK_NE(
151 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_1")); 189 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_1"));
152 CHECK_NE( 190 CHECK_NE(
153 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_2")); 191 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_2"));
(...skipping 15 matching lines...) Expand all
169 207
170 // -a-> X1 --a 208 // -a-> X1 --a
171 // x -b-> X2 <-| 209 // x -b-> X2 <-|
172 CompileRun( 210 CompileRun(
173 "function X(a, b) { this.a = a; this.b = b; }\n" 211 "function X(a, b) { this.a = a; this.b = b; }\n"
174 "x = new X(new X(), new X());\n" 212 "x = new X(new X(), new X());\n"
175 "dummy = new X();\n" 213 "dummy = new X();\n"
176 "(function() { x.a.a = x.b; })();"); 214 "(function() { x.a.a = x.b; })();");
177 const v8::HeapSnapshot* snapshot = 215 const v8::HeapSnapshot* snapshot =
178 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); 216 heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
217 CHECK(ValidateSnapshot(snapshot, 3));
179 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 218 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
180 const v8::HeapGraphNode* x = 219 const v8::HeapGraphNode* x =
181 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); 220 GetProperty(global, v8::HeapGraphEdge::kProperty, "x");
182 CHECK_NE(NULL, x); 221 CHECK_NE(NULL, x);
183 const v8::HeapGraphNode* x1 = 222 const v8::HeapGraphNode* x1 =
184 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); 223 GetProperty(x, v8::HeapGraphEdge::kProperty, "a");
185 CHECK_NE(NULL, x1); 224 CHECK_NE(NULL, x1);
186 const v8::HeapGraphNode* x2 = 225 const v8::HeapGraphNode* x2 =
187 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); 226 GetProperty(x, v8::HeapGraphEdge::kProperty, "b");
188 CHECK_NE(NULL, x2); 227 CHECK_NE(NULL, x2);
189 228
190 // Test sizes. 229 // Test sizes.
191 CHECK_NE(0, x->GetSelfSize()); 230 CHECK_NE(0, x->GetSelfSize());
192 CHECK_NE(0, x1->GetSelfSize()); 231 CHECK_NE(0, x1->GetSelfSize());
193 CHECK_NE(0, x2->GetSelfSize()); 232 CHECK_NE(0, x2->GetSelfSize());
194 } 233 }
195 234
196 235
197 TEST(BoundFunctionInSnapshot) { 236 TEST(BoundFunctionInSnapshot) {
198 LocalContext env; 237 LocalContext env;
199 v8::HandleScope scope(env->GetIsolate()); 238 v8::HandleScope scope(env->GetIsolate());
200 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 239 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
201 CompileRun( 240 CompileRun(
202 "function myFunction(a, b) { this.a = a; this.b = b; }\n" 241 "function myFunction(a, b) { this.a = a; this.b = b; }\n"
203 "function AAAAA() {}\n" 242 "function AAAAA() {}\n"
204 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); 243 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n");
205 const v8::HeapSnapshot* snapshot = 244 const v8::HeapSnapshot* snapshot =
206 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); 245 heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
246 CHECK(ValidateSnapshot(snapshot, 3));
207 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 247 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
208 const v8::HeapGraphNode* f = 248 const v8::HeapGraphNode* f =
209 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction"); 249 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction");
210 CHECK(f); 250 CHECK(f);
211 CHECK_EQ(v8::String::New("native_bind"), f->GetName()); 251 CHECK_EQ(v8::String::New("native_bind"), f->GetName());
212 const v8::HeapGraphNode* bindings = 252 const v8::HeapGraphNode* bindings =
213 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings"); 253 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings");
214 CHECK_NE(NULL, bindings); 254 CHECK_NE(NULL, bindings);
215 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType()); 255 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType());
216 CHECK_EQ(4, bindings->GetChildrenCount()); 256 CHECK_EQ(4, bindings->GetChildrenCount());
(...skipping 18 matching lines...) Expand all
235 TEST(HeapSnapshotEntryChildren) { 275 TEST(HeapSnapshotEntryChildren) {
236 LocalContext env; 276 LocalContext env;
237 v8::HandleScope scope(env->GetIsolate()); 277 v8::HandleScope scope(env->GetIsolate());
238 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 278 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
239 279
240 CompileRun( 280 CompileRun(
241 "function A() { }\n" 281 "function A() { }\n"
242 "a = new A;"); 282 "a = new A;");
243 const v8::HeapSnapshot* snapshot = 283 const v8::HeapSnapshot* snapshot =
244 heap_profiler->TakeHeapSnapshot(v8_str("children")); 284 heap_profiler->TakeHeapSnapshot(v8_str("children"));
285 CHECK(ValidateSnapshot(snapshot, 3));
245 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 286 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
246 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { 287 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) {
247 const v8::HeapGraphEdge* prop = global->GetChild(i); 288 const v8::HeapGraphEdge* prop = global->GetChild(i);
248 CHECK_EQ(global, prop->GetFromNode()); 289 CHECK_EQ(global, prop->GetFromNode());
249 } 290 }
250 const v8::HeapGraphNode* a = 291 const v8::HeapGraphNode* a =
251 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); 292 GetProperty(global, v8::HeapGraphEdge::kProperty, "a");
252 CHECK_NE(NULL, a); 293 CHECK_NE(NULL, a);
253 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) { 294 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) {
254 const v8::HeapGraphEdge* prop = a->GetChild(i); 295 const v8::HeapGraphEdge* prop = a->GetChild(i);
255 CHECK_EQ(a, prop->GetFromNode()); 296 CHECK_EQ(a, prop->GetFromNode());
256 } 297 }
257 } 298 }
258 299
259 300
260 TEST(HeapSnapshotCodeObjects) { 301 TEST(HeapSnapshotCodeObjects) {
261 LocalContext env; 302 LocalContext env;
262 v8::HandleScope scope(env->GetIsolate()); 303 v8::HandleScope scope(env->GetIsolate());
263 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 304 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
264 305
265 CompileRun( 306 CompileRun(
266 "function lazy(x) { return x - 1; }\n" 307 "function lazy(x) { return x - 1; }\n"
267 "function compiled(x) { return x + 1; }\n" 308 "function compiled(x) { return x + 1; }\n"
268 "var anonymous = (function() { return function() { return 0; } })();\n" 309 "var anonymous = (function() { return function() { return 0; } })();\n"
269 "compiled(1)"); 310 "compiled(1)");
270 const v8::HeapSnapshot* snapshot = 311 const v8::HeapSnapshot* snapshot =
271 heap_profiler->TakeHeapSnapshot(v8_str("code")); 312 heap_profiler->TakeHeapSnapshot(v8_str("code"));
313 CHECK(ValidateSnapshot(snapshot, 3));
272 314
273 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 315 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
274 const v8::HeapGraphNode* compiled = 316 const v8::HeapGraphNode* compiled =
275 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled"); 317 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled");
276 CHECK_NE(NULL, compiled); 318 CHECK_NE(NULL, compiled);
277 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType()); 319 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType());
278 const v8::HeapGraphNode* lazy = 320 const v8::HeapGraphNode* lazy =
279 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy"); 321 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy");
280 CHECK_NE(NULL, lazy); 322 CHECK_NE(NULL, lazy);
281 CHECK_EQ(v8::HeapGraphNode::kClosure, lazy->GetType()); 323 CHECK_EQ(v8::HeapGraphNode::kClosure, lazy->GetType());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 367
326 TEST(HeapSnapshotHeapNumbers) { 368 TEST(HeapSnapshotHeapNumbers) {
327 LocalContext env; 369 LocalContext env;
328 v8::HandleScope scope(env->GetIsolate()); 370 v8::HandleScope scope(env->GetIsolate());
329 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 371 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
330 CompileRun( 372 CompileRun(
331 "a = 1; // a is Smi\n" 373 "a = 1; // a is Smi\n"
332 "b = 2.5; // b is HeapNumber"); 374 "b = 2.5; // b is HeapNumber");
333 const v8::HeapSnapshot* snapshot = 375 const v8::HeapSnapshot* snapshot =
334 heap_profiler->TakeHeapSnapshot(v8_str("numbers")); 376 heap_profiler->TakeHeapSnapshot(v8_str("numbers"));
377 CHECK(ValidateSnapshot(snapshot, 3));
335 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 378 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
336 CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a")); 379 CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a"));
337 const v8::HeapGraphNode* b = 380 const v8::HeapGraphNode* b =
338 GetProperty(global, v8::HeapGraphEdge::kProperty, "b"); 381 GetProperty(global, v8::HeapGraphEdge::kProperty, "b");
339 CHECK_NE(NULL, b); 382 CHECK_NE(NULL, b);
340 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType()); 383 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType());
341 } 384 }
342 385
343 386
344 TEST(HeapSnapshotSlicedString) { 387 TEST(HeapSnapshotSlicedString) {
345 LocalContext env; 388 LocalContext env;
346 v8::HandleScope scope(env->GetIsolate()); 389 v8::HandleScope scope(env->GetIsolate());
347 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 390 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
348 CompileRun( 391 CompileRun(
349 "parent_string = \"123456789.123456789.123456789.123456789.123456789." 392 "parent_string = \"123456789.123456789.123456789.123456789.123456789."
350 "123456789.123456789.123456789.123456789.123456789." 393 "123456789.123456789.123456789.123456789.123456789."
351 "123456789.123456789.123456789.123456789.123456789." 394 "123456789.123456789.123456789.123456789.123456789."
352 "123456789.123456789.123456789.123456789.123456789.\";" 395 "123456789.123456789.123456789.123456789.123456789.\";"
353 "child_string = parent_string.slice(100);"); 396 "child_string = parent_string.slice(100);");
354 const v8::HeapSnapshot* snapshot = 397 const v8::HeapSnapshot* snapshot =
355 heap_profiler->TakeHeapSnapshot(v8_str("strings")); 398 heap_profiler->TakeHeapSnapshot(v8_str("strings"));
399 CHECK(ValidateSnapshot(snapshot, 3));
356 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 400 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
357 const v8::HeapGraphNode* parent_string = 401 const v8::HeapGraphNode* parent_string =
358 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string"); 402 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string");
359 CHECK_NE(NULL, parent_string); 403 CHECK_NE(NULL, parent_string);
360 const v8::HeapGraphNode* child_string = 404 const v8::HeapGraphNode* child_string =
361 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string"); 405 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string");
362 CHECK_NE(NULL, child_string); 406 CHECK_NE(NULL, child_string);
363 const v8::HeapGraphNode* parent = 407 const v8::HeapGraphNode* parent =
364 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); 408 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent");
365 CHECK_EQ(parent_string, parent); 409 CHECK_EQ(parent_string, parent);
366 } 410 }
367 411
368 412
369 TEST(HeapSnapshotInternalReferences) { 413 TEST(HeapSnapshotInternalReferences) {
370 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 414 v8::Isolate* isolate = v8::Isolate::GetCurrent();
371 v8::HandleScope scope(isolate); 415 v8::HandleScope scope(isolate);
372 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 416 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
373 global_template->SetInternalFieldCount(2); 417 global_template->SetInternalFieldCount(2);
374 LocalContext env(NULL, global_template); 418 LocalContext env(NULL, global_template);
375 v8::Handle<v8::Object> global_proxy = env->Global(); 419 v8::Handle<v8::Object> global_proxy = env->Global();
376 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 420 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
377 CHECK_EQ(2, global->InternalFieldCount()); 421 CHECK_EQ(2, global->InternalFieldCount());
378 v8::Local<v8::Object> obj = v8::Object::New(); 422 v8::Local<v8::Object> obj = v8::Object::New();
379 global->SetInternalField(0, v8_num(17)); 423 global->SetInternalField(0, v8_num(17));
380 global->SetInternalField(1, obj); 424 global->SetInternalField(1, obj);
381 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 425 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
382 const v8::HeapSnapshot* snapshot = 426 const v8::HeapSnapshot* snapshot =
383 heap_profiler->TakeHeapSnapshot(v8_str("internals")); 427 heap_profiler->TakeHeapSnapshot(v8_str("internals"));
428 CHECK(ValidateSnapshot(snapshot, 3));
384 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); 429 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
385 // The first reference will not present, because it's a Smi. 430 // The first reference will not present, because it's a Smi.
386 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); 431 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0"));
387 // The second reference is to an object. 432 // The second reference is to an object.
388 CHECK_NE(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1")); 433 CHECK_NE(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1"));
389 } 434 }
390 435
391 436
392 // Trying to introduce a check helper for uint32_t causes many 437 // Trying to introduce a check helper for uint32_t causes many
393 // overloading ambiguities, so it seems easier just to cast 438 // overloading ambiguities, so it seems easier just to cast
394 // them to a signed type. 439 // them to a signed type.
395 #define CHECK_EQ_SNAPSHOT_OBJECT_ID(a, b) \ 440 #define CHECK_EQ_SNAPSHOT_OBJECT_ID(a, b) \
396 CHECK_EQ(static_cast<int32_t>(a), static_cast<int32_t>(b)) 441 CHECK_EQ(static_cast<int32_t>(a), static_cast<int32_t>(b))
397 #define CHECK_NE_SNAPSHOT_OBJECT_ID(a, b) \ 442 #define CHECK_NE_SNAPSHOT_OBJECT_ID(a, b) \
398 CHECK((a) != (b)) // NOLINT 443 CHECK((a) != (b)) // NOLINT
399 444
400 TEST(HeapSnapshotAddressReuse) { 445 TEST(HeapSnapshotAddressReuse) {
401 LocalContext env; 446 LocalContext env;
402 v8::HandleScope scope(env->GetIsolate()); 447 v8::HandleScope scope(env->GetIsolate());
403 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 448 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
404 449
405 CompileRun( 450 CompileRun(
406 "function A() {}\n" 451 "function A() {}\n"
407 "var a = [];\n" 452 "var a = [];\n"
408 "for (var i = 0; i < 10000; ++i)\n" 453 "for (var i = 0; i < 10000; ++i)\n"
409 " a[i] = new A();\n"); 454 " a[i] = new A();\n");
410 const v8::HeapSnapshot* snapshot1 = 455 const v8::HeapSnapshot* snapshot1 =
411 heap_profiler->TakeHeapSnapshot(v8_str("snapshot1")); 456 heap_profiler->TakeHeapSnapshot(v8_str("snapshot1"));
457 CHECK(ValidateSnapshot(snapshot1, 3));
412 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); 458 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId();
413 459
414 CompileRun( 460 CompileRun(
415 "for (var i = 0; i < 10000; ++i)\n" 461 "for (var i = 0; i < 10000; ++i)\n"
416 " a[i] = new A();\n"); 462 " a[i] = new A();\n");
417 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 463 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
418 464
419 const v8::HeapSnapshot* snapshot2 = 465 const v8::HeapSnapshot* snapshot2 =
420 heap_profiler->TakeHeapSnapshot(v8_str("snapshot2")); 466 heap_profiler->TakeHeapSnapshot(v8_str("snapshot2"));
467 CHECK(ValidateSnapshot(snapshot2, 3));
421 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); 468 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
422 469
423 const v8::HeapGraphNode* array_node = 470 const v8::HeapGraphNode* array_node =
424 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); 471 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a");
425 CHECK_NE(NULL, array_node); 472 CHECK_NE(NULL, array_node);
426 int wrong_count = 0; 473 int wrong_count = 0;
427 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) { 474 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) {
428 const v8::HeapGraphEdge* prop = array_node->GetChild(i); 475 const v8::HeapGraphEdge* prop = array_node->GetChild(i);
429 if (prop->GetType() != v8::HeapGraphEdge::kElement) 476 if (prop->GetType() != v8::HeapGraphEdge::kElement)
430 continue; 477 continue;
(...skipping 13 matching lines...) Expand all
444 CompileRun( 491 CompileRun(
445 "function AnObject() {\n" 492 "function AnObject() {\n"
446 " this.first = 'first';\n" 493 " this.first = 'first';\n"
447 " this.second = 'second';\n" 494 " this.second = 'second';\n"
448 "}\n" 495 "}\n"
449 "var a = new Array();\n" 496 "var a = new Array();\n"
450 "for (var i = 0; i < 10; ++i)\n" 497 "for (var i = 0; i < 10; ++i)\n"
451 " a.push(new AnObject());\n"); 498 " a.push(new AnObject());\n");
452 const v8::HeapSnapshot* snapshot1 = 499 const v8::HeapSnapshot* snapshot1 =
453 heap_profiler->TakeHeapSnapshot(v8_str("s1")); 500 heap_profiler->TakeHeapSnapshot(v8_str("s1"));
501 CHECK(ValidateSnapshot(snapshot1, 3));
454 502
455 CompileRun( 503 CompileRun(
456 "for (var i = 0; i < 1; ++i)\n" 504 "for (var i = 0; i < 1; ++i)\n"
457 " a.shift();\n"); 505 " a.shift();\n");
458 506
459 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 507 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
460 508
461 const v8::HeapSnapshot* snapshot2 = 509 const v8::HeapSnapshot* snapshot2 =
462 heap_profiler->TakeHeapSnapshot(v8_str("s2")); 510 heap_profiler->TakeHeapSnapshot(v8_str("s2"));
511 CHECK(ValidateSnapshot(snapshot2, 3));
463 512
464 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); 513 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
465 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); 514 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
466 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId()); 515 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId());
467 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId()); 516 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId());
468 517
469 const v8::HeapGraphNode* a1 = 518 const v8::HeapGraphNode* a1 =
470 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a"); 519 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a");
471 CHECK_NE(NULL, a1); 520 CHECK_NE(NULL, a1);
472 const v8::HeapGraphNode* k1 = 521 const v8::HeapGraphNode* k1 =
(...skipping 18 matching lines...) Expand all
491 540
492 CompileRun( 541 CompileRun(
493 "function A() {}\n" 542 "function A() {}\n"
494 "function B(x) { this.x = x; }\n" 543 "function B(x) { this.x = x; }\n"
495 "var a = new A();\n" 544 "var a = new A();\n"
496 "var b = new B(a);"); 545 "var b = new B(a);");
497 v8::Local<v8::String> s1_str = v8_str("s1"); 546 v8::Local<v8::String> s1_str = v8_str("s1");
498 v8::Local<v8::String> s2_str = v8_str("s2"); 547 v8::Local<v8::String> s2_str = v8_str("s2");
499 const v8::HeapSnapshot* snapshot1 = 548 const v8::HeapSnapshot* snapshot1 =
500 heap_profiler->TakeHeapSnapshot(s1_str); 549 heap_profiler->TakeHeapSnapshot(s1_str);
550 CHECK(ValidateSnapshot(snapshot1, 3));
501 551
502 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 552 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
503 553
504 const v8::HeapSnapshot* snapshot2 = 554 const v8::HeapSnapshot* snapshot2 =
505 heap_profiler->TakeHeapSnapshot(s2_str); 555 heap_profiler->TakeHeapSnapshot(s2_str);
556 CHECK(ValidateSnapshot(snapshot2, 3));
506 557
507 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000); 558 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000);
508 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= 559 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <=
509 snapshot2->GetMaxSnapshotJSObjectId()); 560 snapshot2->GetMaxSnapshotJSObjectId());
510 561
511 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); 562 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
512 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); 563 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
513 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId()); 564 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId());
514 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId()); 565 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId());
515 const v8::HeapGraphNode* A1 = 566 const v8::HeapGraphNode* A1 =
(...skipping 30 matching lines...) Expand all
546 CHECK_EQ_SNAPSHOT_OBJECT_ID(b1->GetId(), b2->GetId()); 597 CHECK_EQ_SNAPSHOT_OBJECT_ID(b1->GetId(), b2->GetId());
547 } 598 }
548 599
549 600
550 TEST(HeapSnapshotRootPreservedAfterSorting) { 601 TEST(HeapSnapshotRootPreservedAfterSorting) {
551 LocalContext env; 602 LocalContext env;
552 v8::HandleScope scope(env->GetIsolate()); 603 v8::HandleScope scope(env->GetIsolate());
553 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 604 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
554 const v8::HeapSnapshot* snapshot = 605 const v8::HeapSnapshot* snapshot =
555 heap_profiler->TakeHeapSnapshot(v8_str("s")); 606 heap_profiler->TakeHeapSnapshot(v8_str("s"));
607 CHECK(ValidateSnapshot(snapshot, 3));
556 const v8::HeapGraphNode* root1 = snapshot->GetRoot(); 608 const v8::HeapGraphNode* root1 = snapshot->GetRoot();
557 const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>( 609 const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>(
558 snapshot))->GetSortedEntriesList(); 610 snapshot))->GetSortedEntriesList();
559 const v8::HeapGraphNode* root2 = snapshot->GetRoot(); 611 const v8::HeapGraphNode* root2 = snapshot->GetRoot();
560 CHECK_EQ(root1, root2); 612 CHECK_EQ(root1, root2);
561 } 613 }
562 614
563 615
564 namespace { 616 namespace {
565 617
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 665
614 #define STRING_LITERAL_FOR_TEST \ 666 #define STRING_LITERAL_FOR_TEST \
615 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" 667 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\""
616 CompileRun( 668 CompileRun(
617 "function A(s) { this.s = s; }\n" 669 "function A(s) { this.s = s; }\n"
618 "function B(x) { this.x = x; }\n" 670 "function B(x) { this.x = x; }\n"
619 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n" 671 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n"
620 "var b = new B(a);"); 672 "var b = new B(a);");
621 const v8::HeapSnapshot* snapshot = 673 const v8::HeapSnapshot* snapshot =
622 heap_profiler->TakeHeapSnapshot(v8_str("json")); 674 heap_profiler->TakeHeapSnapshot(v8_str("json"));
675 CHECK(ValidateSnapshot(snapshot, 3));
676
623 TestJSONStream stream; 677 TestJSONStream stream;
624 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); 678 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
625 CHECK_GT(stream.size(), 0); 679 CHECK_GT(stream.size(), 0);
626 CHECK_EQ(1, stream.eos_signaled()); 680 CHECK_EQ(1, stream.eos_signaled());
627 i::ScopedVector<char> json(stream.size()); 681 i::ScopedVector<char> json(stream.size());
628 stream.WriteTo(json); 682 stream.WriteTo(json);
629 683
630 // Verify that snapshot string is valid JSON. 684 // Verify that snapshot string is valid JSON.
631 AsciiResource json_res(json); 685 AsciiResource json_res(json);
632 v8::Local<v8::String> json_string = v8::String::NewExternal(&json_res); 686 v8::Local<v8::String> json_string = v8::String::NewExternal(&json_res);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 *v8::String::Utf8Value(string)); 763 *v8::String::Utf8Value(string));
710 } 764 }
711 765
712 766
713 TEST(HeapSnapshotJSONSerializationAborting) { 767 TEST(HeapSnapshotJSONSerializationAborting) {
714 LocalContext env; 768 LocalContext env;
715 v8::HandleScope scope(env->GetIsolate()); 769 v8::HandleScope scope(env->GetIsolate());
716 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 770 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
717 const v8::HeapSnapshot* snapshot = 771 const v8::HeapSnapshot* snapshot =
718 heap_profiler->TakeHeapSnapshot(v8_str("abort")); 772 heap_profiler->TakeHeapSnapshot(v8_str("abort"));
773 CHECK(ValidateSnapshot(snapshot, 3));
719 TestJSONStream stream(5); 774 TestJSONStream stream(5);
720 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); 775 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
721 CHECK_GT(stream.size(), 0); 776 CHECK_GT(stream.size(), 0);
722 CHECK_EQ(0, stream.eos_signaled()); 777 CHECK_EQ(0, stream.eos_signaled());
723 } 778 }
724 779
725 namespace { 780 namespace {
726 781
727 class TestStatsStream : public v8::OutputStream { 782 class TestStatsStream : public v8::OutputStream {
728 public: 783 public:
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 } 1003 }
949 1004
950 1005
951 TEST(HeapSnapshotGetNodeById) { 1006 TEST(HeapSnapshotGetNodeById) {
952 LocalContext env; 1007 LocalContext env;
953 v8::HandleScope scope(env->GetIsolate()); 1008 v8::HandleScope scope(env->GetIsolate());
954 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1009 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
955 1010
956 const v8::HeapSnapshot* snapshot = 1011 const v8::HeapSnapshot* snapshot =
957 heap_profiler->TakeHeapSnapshot(v8_str("id")); 1012 heap_profiler->TakeHeapSnapshot(v8_str("id"));
1013 CHECK(ValidateSnapshot(snapshot, 3));
958 const v8::HeapGraphNode* root = snapshot->GetRoot(); 1014 const v8::HeapGraphNode* root = snapshot->GetRoot();
959 CheckChildrenIds(snapshot, root, 0, 3); 1015 CheckChildrenIds(snapshot, root, 0, 3);
960 // Check a big id, which should not exist yet. 1016 // Check a big id, which should not exist yet.
961 CHECK_EQ(NULL, snapshot->GetNodeById(0x1000000UL)); 1017 CHECK_EQ(NULL, snapshot->GetNodeById(0x1000000UL));
962 } 1018 }
963 1019
964 1020
965 TEST(HeapSnapshotGetSnapshotObjectId) { 1021 TEST(HeapSnapshotGetSnapshotObjectId) {
966 LocalContext env; 1022 LocalContext env;
967 v8::HandleScope scope(env->GetIsolate()); 1023 v8::HandleScope scope(env->GetIsolate());
968 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1024 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
969 CompileRun("globalObject = {};\n"); 1025 CompileRun("globalObject = {};\n");
970 const v8::HeapSnapshot* snapshot = 1026 const v8::HeapSnapshot* snapshot =
971 heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id")); 1027 heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id"));
1028 CHECK(ValidateSnapshot(snapshot, 3));
972 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1029 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
973 const v8::HeapGraphNode* global_object = 1030 const v8::HeapGraphNode* global_object =
974 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject"); 1031 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject");
975 CHECK(global_object); 1032 CHECK(global_object);
976 1033
977 v8::Local<v8::Value> globalObjectHandle = 1034 v8::Local<v8::Value> globalObjectHandle =
978 env->Global()->Get(v8::String::New("globalObject")); 1035 env->Global()->Get(v8::String::New("globalObject"));
979 CHECK(!globalObjectHandle.IsEmpty()); 1036 CHECK(!globalObjectHandle.IsEmpty());
980 CHECK(globalObjectHandle->IsObject()); 1037 CHECK(globalObjectHandle->IsObject());
981 1038
982 v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle); 1039 v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle);
983 CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId), 1040 CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId),
984 id); 1041 id);
985 CHECK_EQ(static_cast<int>(id), global_object->GetId()); 1042 CHECK_EQ(static_cast<int>(id), global_object->GetId());
986 } 1043 }
987 1044
988 1045
989 TEST(HeapSnapshotUnknownSnapshotObjectId) { 1046 TEST(HeapSnapshotUnknownSnapshotObjectId) {
990 LocalContext env; 1047 LocalContext env;
991 v8::HandleScope scope(env->GetIsolate()); 1048 v8::HandleScope scope(env->GetIsolate());
992 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1049 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
993 CompileRun("globalObject = {};\n"); 1050 CompileRun("globalObject = {};\n");
994 const v8::HeapSnapshot* snapshot = 1051 const v8::HeapSnapshot* snapshot =
995 heap_profiler->TakeHeapSnapshot(v8_str("unknown_object_id")); 1052 heap_profiler->TakeHeapSnapshot(v8_str("unknown_object_id"));
1053 CHECK(ValidateSnapshot(snapshot, 3));
996 const v8::HeapGraphNode* node = 1054 const v8::HeapGraphNode* node =
997 snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId); 1055 snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId);
998 CHECK_EQ(NULL, node); 1056 CHECK_EQ(NULL, node);
999 } 1057 }
1000 1058
1001 1059
1002 namespace { 1060 namespace {
1003 1061
1004 class TestActivityControl : public v8::ActivityControl { 1062 class TestActivityControl : public v8::ActivityControl {
1005 public: 1063 public:
(...skipping 26 matching lines...) Expand all
1032 heap_profiler->TakeHeapSnapshot(v8_str("abort"), 1090 heap_profiler->TakeHeapSnapshot(v8_str("abort"),
1033 &aborting_control); 1091 &aborting_control);
1034 CHECK_EQ(NULL, no_snapshot); 1092 CHECK_EQ(NULL, no_snapshot);
1035 CHECK_EQ(snapshots_count, heap_profiler->GetSnapshotCount()); 1093 CHECK_EQ(snapshots_count, heap_profiler->GetSnapshotCount());
1036 CHECK_GT(aborting_control.total(), aborting_control.done()); 1094 CHECK_GT(aborting_control.total(), aborting_control.done());
1037 1095
1038 TestActivityControl control(-1); // Don't abort. 1096 TestActivityControl control(-1); // Don't abort.
1039 const v8::HeapSnapshot* snapshot = 1097 const v8::HeapSnapshot* snapshot =
1040 heap_profiler->TakeHeapSnapshot(v8_str("full"), 1098 heap_profiler->TakeHeapSnapshot(v8_str("full"),
1041 &control); 1099 &control);
1100 CHECK(ValidateSnapshot(snapshot, 3));
1101
1042 CHECK_NE(NULL, snapshot); 1102 CHECK_NE(NULL, snapshot);
1043 CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount()); 1103 CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount());
1044 CHECK_EQ(control.total(), control.done()); 1104 CHECK_EQ(control.total(), control.done());
1045 CHECK_GT(control.total(), 0); 1105 CHECK_GT(control.total(), 0);
1046 } 1106 }
1047 1107
1048 1108
1049 namespace { 1109 namespace {
1050 1110
1051 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { 1111 class TestRetainedObjectInfo : public v8::RetainedObjectInfo {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 2, TestRetainedObjectInfo::WrapperInfoCallback); 1202 2, TestRetainedObjectInfo::WrapperInfoCallback);
1143 v8::Persistent<v8::String> p_AAA(isolate, v8_str("AAA")); 1203 v8::Persistent<v8::String> p_AAA(isolate, v8_str("AAA"));
1144 p_AAA.SetWrapperClassId(isolate, 1); 1204 p_AAA.SetWrapperClassId(isolate, 1);
1145 v8::Persistent<v8::String> p_BBB(isolate, v8_str("BBB")); 1205 v8::Persistent<v8::String> p_BBB(isolate, v8_str("BBB"));
1146 p_BBB.SetWrapperClassId(isolate, 1); 1206 p_BBB.SetWrapperClassId(isolate, 1);
1147 v8::Persistent<v8::String> p_CCC(isolate, v8_str("CCC")); 1207 v8::Persistent<v8::String> p_CCC(isolate, v8_str("CCC"));
1148 p_CCC.SetWrapperClassId(isolate, 2); 1208 p_CCC.SetWrapperClassId(isolate, 2);
1149 CHECK_EQ(0, TestRetainedObjectInfo::instances.length()); 1209 CHECK_EQ(0, TestRetainedObjectInfo::instances.length());
1150 const v8::HeapSnapshot* snapshot = 1210 const v8::HeapSnapshot* snapshot =
1151 heap_profiler->TakeHeapSnapshot(v8_str("retained")); 1211 heap_profiler->TakeHeapSnapshot(v8_str("retained"));
1212 CHECK(ValidateSnapshot(snapshot, 3));
1152 1213
1153 CHECK_EQ(3, TestRetainedObjectInfo::instances.length()); 1214 CHECK_EQ(3, TestRetainedObjectInfo::instances.length());
1154 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) { 1215 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) {
1155 CHECK(TestRetainedObjectInfo::instances[i]->disposed()); 1216 CHECK(TestRetainedObjectInfo::instances[i]->disposed());
1156 delete TestRetainedObjectInfo::instances[i]; 1217 delete TestRetainedObjectInfo::instances[i];
1157 } 1218 }
1158 1219
1159 const v8::HeapGraphNode* native_group_aaa = GetNode( 1220 const v8::HeapGraphNode* native_group_aaa = GetNode(
1160 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "aaa-group"); 1221 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "aaa-group");
1161 CHECK_NE(NULL, native_group_aaa); 1222 CHECK_NE(NULL, native_group_aaa);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 TEST(HeapSnapshotImplicitReferences) { 1295 TEST(HeapSnapshotImplicitReferences) {
1235 LocalContext env; 1296 LocalContext env;
1236 v8::HandleScope scope(env->GetIsolate()); 1297 v8::HandleScope scope(env->GetIsolate());
1237 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1298 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1238 1299
1239 GraphWithImplicitRefs graph(&env); 1300 GraphWithImplicitRefs graph(&env);
1240 v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue); 1301 v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue);
1241 1302
1242 const v8::HeapSnapshot* snapshot = 1303 const v8::HeapSnapshot* snapshot =
1243 heap_profiler->TakeHeapSnapshot(v8_str("implicit_refs")); 1304 heap_profiler->TakeHeapSnapshot(v8_str("implicit_refs"));
1305 CHECK(ValidateSnapshot(snapshot, 3));
1244 1306
1245 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot); 1307 const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot);
1246 const v8::HeapGraphNode* obj0 = GetProperty( 1308 const v8::HeapGraphNode* obj0 = GetProperty(
1247 global_object, v8::HeapGraphEdge::kProperty, "root_object"); 1309 global_object, v8::HeapGraphEdge::kProperty, "root_object");
1248 CHECK(obj0); 1310 CHECK(obj0);
1249 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType()); 1311 CHECK_EQ(v8::HeapGraphNode::kObject, obj0->GetType());
1250 const v8::HeapGraphNode* obj1 = GetProperty( 1312 const v8::HeapGraphNode* obj1 = GetProperty(
1251 obj0, v8::HeapGraphEdge::kInternal, "native"); 1313 obj0, v8::HeapGraphEdge::kInternal, "native");
1252 CHECK(obj1); 1314 CHECK(obj1);
1253 int implicit_targets_count = 0; 1315 int implicit_targets_count = 0;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 1360
1299 1361
1300 TEST(DeleteHeapSnapshot) { 1362 TEST(DeleteHeapSnapshot) {
1301 LocalContext env; 1363 LocalContext env;
1302 v8::HandleScope scope(env->GetIsolate()); 1364 v8::HandleScope scope(env->GetIsolate());
1303 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1365 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1304 1366
1305 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); 1367 CHECK_EQ(0, heap_profiler->GetSnapshotCount());
1306 const v8::HeapSnapshot* s1 = 1368 const v8::HeapSnapshot* s1 =
1307 heap_profiler->TakeHeapSnapshot(v8_str("1")); 1369 heap_profiler->TakeHeapSnapshot(v8_str("1"));
1370
1308 CHECK_NE(NULL, s1); 1371 CHECK_NE(NULL, s1);
1309 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); 1372 CHECK_EQ(1, heap_profiler->GetSnapshotCount());
1310 unsigned uid1 = s1->GetUid(); 1373 unsigned uid1 = s1->GetUid();
1311 CHECK_EQ(s1, FindHeapSnapshot(heap_profiler, uid1)); 1374 CHECK_EQ(s1, FindHeapSnapshot(heap_profiler, uid1));
1312 const_cast<v8::HeapSnapshot*>(s1)->Delete(); 1375 const_cast<v8::HeapSnapshot*>(s1)->Delete();
1313 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); 1376 CHECK_EQ(0, heap_profiler->GetSnapshotCount());
1314 CHECK_EQ(NULL, FindHeapSnapshot(heap_profiler, uid1)); 1377 CHECK_EQ(NULL, FindHeapSnapshot(heap_profiler, uid1));
1315 1378
1316 const v8::HeapSnapshot* s2 = 1379 const v8::HeapSnapshot* s2 =
1317 heap_profiler->TakeHeapSnapshot(v8_str("2")); 1380 heap_profiler->TakeHeapSnapshot(v8_str("2"));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 v8::HandleScope scope(env->GetIsolate()); 1413 v8::HandleScope scope(env->GetIsolate());
1351 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1414 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1352 1415
1353 CompileRun("document = { URL:\"abcdefgh\" };"); 1416 CompileRun("document = { URL:\"abcdefgh\" };");
1354 1417
1355 NameResolver name_resolver; 1418 NameResolver name_resolver;
1356 const v8::HeapSnapshot* snapshot = 1419 const v8::HeapSnapshot* snapshot =
1357 heap_profiler->TakeHeapSnapshot(v8_str("document"), 1420 heap_profiler->TakeHeapSnapshot(v8_str("document"),
1358 NULL, 1421 NULL,
1359 &name_resolver); 1422 &name_resolver);
1423 CHECK(ValidateSnapshot(snapshot, 3));
1360 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1424 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1361 CHECK_NE(NULL, global); 1425 CHECK_NE(NULL, global);
1362 CHECK_EQ("Object / Global object name" , 1426 CHECK_EQ("Object / Global object name" ,
1363 const_cast<i::HeapEntry*>( 1427 const_cast<i::HeapEntry*>(
1364 reinterpret_cast<const i::HeapEntry*>(global))->name()); 1428 reinterpret_cast<const i::HeapEntry*>(global))->name());
1365 } 1429 }
1366 1430
1367 1431
1368 TEST(NoHandleLeaks) { 1432 TEST(NoHandleLeaks) {
1369 LocalContext env; 1433 LocalContext env;
(...skipping 10 matching lines...) Expand all
1380 CHECK_EQ(count_before, count_after); 1444 CHECK_EQ(count_before, count_after);
1381 } 1445 }
1382 1446
1383 1447
1384 TEST(NodesIteration) { 1448 TEST(NodesIteration) {
1385 LocalContext env; 1449 LocalContext env;
1386 v8::HandleScope scope(env->GetIsolate()); 1450 v8::HandleScope scope(env->GetIsolate());
1387 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1451 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1388 const v8::HeapSnapshot* snapshot = 1452 const v8::HeapSnapshot* snapshot =
1389 heap_profiler->TakeHeapSnapshot(v8_str("iteration")); 1453 heap_profiler->TakeHeapSnapshot(v8_str("iteration"));
1454 CHECK(ValidateSnapshot(snapshot, 3));
1390 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1455 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1391 CHECK_NE(NULL, global); 1456 CHECK_NE(NULL, global);
1392 // Verify that we can find this object by iteration. 1457 // Verify that we can find this object by iteration.
1393 const int nodes_count = snapshot->GetNodesCount(); 1458 const int nodes_count = snapshot->GetNodesCount();
1394 int count = 0; 1459 int count = 0;
1395 for (int i = 0; i < nodes_count; ++i) { 1460 for (int i = 0; i < nodes_count; ++i) {
1396 if (snapshot->GetNode(i) == global) 1461 if (snapshot->GetNode(i) == global)
1397 ++count; 1462 ++count;
1398 } 1463 }
1399 CHECK_EQ(1, count); 1464 CHECK_EQ(1, count);
1400 } 1465 }
1401 1466
1402 1467
1403 TEST(GetHeapValue) { 1468 TEST(GetHeapValue) {
1404 LocalContext env; 1469 LocalContext env;
1405 v8::HandleScope scope(env->GetIsolate()); 1470 v8::HandleScope scope(env->GetIsolate());
1406 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1471 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1407 1472
1408 CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };"); 1473 CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };");
1409 const v8::HeapSnapshot* snapshot = 1474 const v8::HeapSnapshot* snapshot =
1410 heap_profiler->TakeHeapSnapshot(v8_str("value")); 1475 heap_profiler->TakeHeapSnapshot(v8_str("value"));
1476 CHECK(ValidateSnapshot(snapshot, 3));
1411 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1477 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1412 CHECK(global->GetHeapValue()->IsObject()); 1478 CHECK(global->GetHeapValue()->IsObject());
1413 v8::Local<v8::Object> js_global = 1479 v8::Local<v8::Object> js_global =
1414 env->Global()->GetPrototype().As<v8::Object>(); 1480 env->Global()->GetPrototype().As<v8::Object>();
1415 CHECK(js_global == global->GetHeapValue()); 1481 CHECK(js_global == global->GetHeapValue());
1416 const v8::HeapGraphNode* obj = GetProperty( 1482 const v8::HeapGraphNode* obj = GetProperty(
1417 global, v8::HeapGraphEdge::kProperty, "a"); 1483 global, v8::HeapGraphEdge::kProperty, "a");
1418 CHECK(obj->GetHeapValue()->IsObject()); 1484 CHECK(obj->GetHeapValue()->IsObject());
1419 v8::Local<v8::Object> js_obj = js_global->Get(v8_str("a")).As<v8::Object>(); 1485 v8::Local<v8::Object> js_obj = js_global->Get(v8_str("a")).As<v8::Object>();
1420 CHECK(js_obj == obj->GetHeapValue()); 1486 CHECK(js_obj == obj->GetHeapValue());
(...skipping 14 matching lines...) Expand all
1435 LocalContext env; 1501 LocalContext env;
1436 v8::HandleScope scope(env->GetIsolate()); 1502 v8::HandleScope scope(env->GetIsolate());
1437 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1503 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1438 1504
1439 // It is impossible to delete a global property, so we are about to delete a 1505 // It is impossible to delete a global property, so we are about to delete a
1440 // property of the "a" object. Also, the "p" object can't be an empty one 1506 // property of the "a" object. Also, the "p" object can't be an empty one
1441 // because the empty object is static and isn't actually deleted. 1507 // because the empty object is static and isn't actually deleted.
1442 CompileRun("a = { p: { r: {} } };"); 1508 CompileRun("a = { p: { r: {} } };");
1443 const v8::HeapSnapshot* snapshot = 1509 const v8::HeapSnapshot* snapshot =
1444 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 1510 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
1511 CHECK(ValidateSnapshot(snapshot, 3));
1445 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1512 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1446 const v8::HeapGraphNode* obj = GetProperty( 1513 const v8::HeapGraphNode* obj = GetProperty(
1447 global, v8::HeapGraphEdge::kProperty, "a"); 1514 global, v8::HeapGraphEdge::kProperty, "a");
1448 const v8::HeapGraphNode* prop = GetProperty( 1515 const v8::HeapGraphNode* prop = GetProperty(
1449 obj, v8::HeapGraphEdge::kProperty, "p"); 1516 obj, v8::HeapGraphEdge::kProperty, "p");
1450 { 1517 {
1451 // Perform the check inside a nested local scope to avoid creating a 1518 // Perform the check inside a nested local scope to avoid creating a
1452 // reference to the object we are deleting. 1519 // reference to the object we are deleting.
1453 v8::HandleScope scope(env->GetIsolate()); 1520 v8::HandleScope scope(env->GetIsolate());
1454 CHECK(prop->GetHeapValue()->IsObject()); 1521 CHECK(prop->GetHeapValue()->IsObject());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 1588
1522 CompileRun("var obj1 = {};\n" 1589 CompileRun("var obj1 = {};\n"
1523 "obj1.__defineGetter__('propWithGetter', function Y() {\n" 1590 "obj1.__defineGetter__('propWithGetter', function Y() {\n"
1524 " return 42;\n" 1591 " return 42;\n"
1525 "});\n" 1592 "});\n"
1526 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" 1593 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n"
1527 " return this.value_ = value;\n" 1594 " return this.value_ = value;\n"
1528 "});\n"); 1595 "});\n");
1529 const v8::HeapSnapshot* snapshot = 1596 const v8::HeapSnapshot* snapshot =
1530 heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors")); 1597 heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors"));
1598 CHECK(ValidateSnapshot(snapshot, 3));
1531 1599
1532 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1600 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1533 CHECK_NE(NULL, global); 1601 CHECK_NE(NULL, global);
1534 const v8::HeapGraphNode* obj1 = 1602 const v8::HeapGraphNode* obj1 =
1535 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); 1603 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1");
1536 CHECK_NE(NULL, obj1); 1604 CHECK_NE(NULL, obj1);
1537 const v8::HeapGraphNode* func; 1605 const v8::HeapGraphNode* func;
1538 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); 1606 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter");
1539 CHECK_NE(NULL, func); 1607 CHECK_NE(NULL, func);
1540 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); 1608 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter");
(...skipping 13 matching lines...) Expand all
1554 CompileRun("var obj1 = {};\n" 1622 CompileRun("var obj1 = {};\n"
1555 "for (var i = 0; i < 100; ++i) obj1['z' + i] = {};" 1623 "for (var i = 0; i < 100; ++i) obj1['z' + i] = {};"
1556 "obj1.__defineGetter__('propWithGetter', function Y() {\n" 1624 "obj1.__defineGetter__('propWithGetter', function Y() {\n"
1557 " return 42;\n" 1625 " return 42;\n"
1558 "});\n" 1626 "});\n"
1559 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" 1627 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n"
1560 " return this.value_ = value;\n" 1628 " return this.value_ = value;\n"
1561 "});\n"); 1629 "});\n");
1562 const v8::HeapSnapshot* snapshot = 1630 const v8::HeapSnapshot* snapshot =
1563 heap_profiler->TakeHeapSnapshot(v8_str("slowCaseAccessors")); 1631 heap_profiler->TakeHeapSnapshot(v8_str("slowCaseAccessors"));
1632 CHECK(ValidateSnapshot(snapshot, 3));
1564 1633
1565 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1634 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1566 CHECK_NE(NULL, global); 1635 CHECK_NE(NULL, global);
1567 const v8::HeapGraphNode* obj1 = 1636 const v8::HeapGraphNode* obj1 =
1568 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); 1637 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1");
1569 CHECK_NE(NULL, obj1); 1638 CHECK_NE(NULL, obj1);
1570 const v8::HeapGraphNode* func; 1639 const v8::HeapGraphNode* func;
1571 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); 1640 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter");
1572 CHECK_NE(NULL, func); 1641 CHECK_NE(NULL, func);
1573 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); 1642 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter");
1574 CHECK_EQ(NULL, func); 1643 CHECK_EQ(NULL, func);
1575 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter"); 1644 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter");
1576 CHECK_NE(NULL, func); 1645 CHECK_NE(NULL, func);
1577 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter"); 1646 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter");
1578 CHECK_EQ(NULL, func); 1647 CHECK_EQ(NULL, func);
1579 } 1648 }
1580 1649
1581 1650
1582 TEST(HiddenPropertiesFastCase) { 1651 TEST(HiddenPropertiesFastCase) {
1583 LocalContext env; 1652 LocalContext env;
1584 v8::HandleScope scope(env->GetIsolate()); 1653 v8::HandleScope scope(env->GetIsolate());
1585 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1654 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1586 1655
1587 CompileRun( 1656 CompileRun(
1588 "function C(x) { this.a = this; this.b = x; }\n" 1657 "function C(x) { this.a = this; this.b = x; }\n"
1589 "c = new C(2012);\n"); 1658 "c = new C(2012);\n");
1590 const v8::HeapSnapshot* snapshot = 1659 const v8::HeapSnapshot* snapshot =
1591 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1")); 1660 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1"));
1661 CHECK(ValidateSnapshot(snapshot, 3));
1592 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1662 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1593 const v8::HeapGraphNode* c = 1663 const v8::HeapGraphNode* c =
1594 GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); 1664 GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
1595 CHECK_NE(NULL, c); 1665 CHECK_NE(NULL, c);
1596 const v8::HeapGraphNode* hidden_props = 1666 const v8::HeapGraphNode* hidden_props =
1597 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties"); 1667 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties");
1598 CHECK_EQ(NULL, hidden_props); 1668 CHECK_EQ(NULL, hidden_props);
1599 1669
1600 v8::Handle<v8::Value> cHandle = env->Global()->Get(v8::String::New("c")); 1670 v8::Handle<v8::Value> cHandle = env->Global()->Get(v8::String::New("c"));
1601 CHECK(!cHandle.IsEmpty() && cHandle->IsObject()); 1671 CHECK(!cHandle.IsEmpty() && cHandle->IsObject());
1602 cHandle->ToObject()->SetHiddenValue(v8_str("key"), v8_str("val")); 1672 cHandle->ToObject()->SetHiddenValue(v8_str("key"), v8_str("val"));
1603 1673
1604 snapshot = heap_profiler->TakeHeapSnapshot( 1674 snapshot = heap_profiler->TakeHeapSnapshot(
1605 v8_str("HiddenPropertiesFastCase2")); 1675 v8_str("HiddenPropertiesFastCase2"));
1676 CHECK(ValidateSnapshot(snapshot, 3));
1606 global = GetGlobalObject(snapshot); 1677 global = GetGlobalObject(snapshot);
1607 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); 1678 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
1608 CHECK_NE(NULL, c); 1679 CHECK_NE(NULL, c);
1609 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal, 1680 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal,
1610 "hidden_properties"); 1681 "hidden_properties");
1611 CHECK_NE(NULL, hidden_props); 1682 CHECK_NE(NULL, hidden_props);
1612 } 1683 }
1613 1684
1614 1685
1615 bool HasWeakEdge(const v8::HeapGraphNode* node) { 1686 bool HasWeakEdge(const v8::HeapGraphNode* node) {
1616 for (int i = 0; i < node->GetChildrenCount(); ++i) { 1687 for (int i = 0; i < node->GetChildrenCount(); ++i) {
1617 const v8::HeapGraphEdge* handle_edge = node->GetChild(i); 1688 const v8::HeapGraphEdge* handle_edge = node->GetChild(i);
1618 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true; 1689 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true;
1619 } 1690 }
1620 return false; 1691 return false;
1621 } 1692 }
1622 1693
1623 1694
1624 bool HasWeakGlobalHandle() { 1695 bool HasWeakGlobalHandle() {
1625 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1696 v8::Isolate* isolate = v8::Isolate::GetCurrent();
1626 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 1697 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
1627 const v8::HeapSnapshot* snapshot = 1698 const v8::HeapSnapshot* snapshot =
1628 heap_profiler->TakeHeapSnapshot(v8_str("weaks")); 1699 heap_profiler->TakeHeapSnapshot(v8_str("weaks"));
1700 CHECK(ValidateSnapshot(snapshot, 3));
1629 const v8::HeapGraphNode* gc_roots = GetNode( 1701 const v8::HeapGraphNode* gc_roots = GetNode(
1630 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); 1702 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)");
1631 CHECK_NE(NULL, gc_roots); 1703 CHECK_NE(NULL, gc_roots);
1632 const v8::HeapGraphNode* global_handles = GetNode( 1704 const v8::HeapGraphNode* global_handles = GetNode(
1633 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); 1705 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)");
1634 CHECK_NE(NULL, global_handles); 1706 CHECK_NE(NULL, global_handles);
1635 return HasWeakEdge(global_handles); 1707 return HasWeakEdge(global_handles);
1636 } 1708 }
1637 1709
1638 1710
(...skipping 17 matching lines...) Expand all
1656 } 1728 }
1657 1729
1658 1730
1659 TEST(WeakNativeContextRefs) { 1731 TEST(WeakNativeContextRefs) {
1660 LocalContext env; 1732 LocalContext env;
1661 v8::HandleScope scope(env->GetIsolate()); 1733 v8::HandleScope scope(env->GetIsolate());
1662 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1734 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1663 1735
1664 const v8::HeapSnapshot* snapshot = 1736 const v8::HeapSnapshot* snapshot =
1665 heap_profiler->TakeHeapSnapshot(v8_str("weaks")); 1737 heap_profiler->TakeHeapSnapshot(v8_str("weaks"));
1738 CHECK(ValidateSnapshot(snapshot, 3));
1666 const v8::HeapGraphNode* gc_roots = GetNode( 1739 const v8::HeapGraphNode* gc_roots = GetNode(
1667 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); 1740 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)");
1668 CHECK_NE(NULL, gc_roots); 1741 CHECK_NE(NULL, gc_roots);
1669 const v8::HeapGraphNode* global_handles = GetNode( 1742 const v8::HeapGraphNode* global_handles = GetNode(
1670 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); 1743 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)");
1671 CHECK_NE(NULL, global_handles); 1744 CHECK_NE(NULL, global_handles);
1672 const v8::HeapGraphNode* native_context = GetNode( 1745 const v8::HeapGraphNode* native_context = GetNode(
1673 global_handles, v8::HeapGraphNode::kHidden, "system / NativeContext"); 1746 global_handles, v8::HeapGraphNode::kHidden, "system / NativeContext");
1674 CHECK_NE(NULL, native_context); 1747 CHECK_NE(NULL, native_context);
1675 CHECK(HasWeakEdge(native_context)); 1748 CHECK(HasWeakEdge(native_context));
1676 } 1749 }
1677 1750
1678 1751
1679 TEST(SfiAndJsFunctionWeakRefs) { 1752 TEST(SfiAndJsFunctionWeakRefs) {
1680 LocalContext env; 1753 LocalContext env;
1681 v8::HandleScope scope(env->GetIsolate()); 1754 v8::HandleScope scope(env->GetIsolate());
1682 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1755 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1683 1756
1684 CompileRun( 1757 CompileRun(
1685 "fun = (function (x) { return function () { return x + 1; } })(1);"); 1758 "fun = (function (x) { return function () { return x + 1; } })(1);");
1686 const v8::HeapSnapshot* snapshot = 1759 const v8::HeapSnapshot* snapshot =
1687 heap_profiler->TakeHeapSnapshot(v8_str("fun")); 1760 heap_profiler->TakeHeapSnapshot(v8_str("fun"));
1761 CHECK(ValidateSnapshot(snapshot, 3));
1688 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1762 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1689 CHECK_NE(NULL, global); 1763 CHECK_NE(NULL, global);
1690 const v8::HeapGraphNode* fun = 1764 const v8::HeapGraphNode* fun =
1691 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); 1765 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun");
1692 CHECK(HasWeakEdge(fun)); 1766 CHECK(HasWeakEdge(fun));
1693 const v8::HeapGraphNode* shared = 1767 const v8::HeapGraphNode* shared =
1694 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); 1768 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared");
1695 CHECK(HasWeakEdge(shared)); 1769 CHECK(HasWeakEdge(shared));
1696 } 1770 }
1697 1771
1698 1772
1699 #ifdef ENABLE_DEBUGGER_SUPPORT 1773 #ifdef ENABLE_DEBUGGER_SUPPORT
1700 TEST(NoDebugObjectInSnapshot) { 1774 TEST(NoDebugObjectInSnapshot) {
1701 LocalContext env; 1775 LocalContext env;
1702 v8::HandleScope scope(env->GetIsolate()); 1776 v8::HandleScope scope(env->GetIsolate());
1703 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1777 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1704 1778
1705 v8::internal::Isolate::Current()->debug()->Load(); 1779 v8::internal::Isolate::Current()->debug()->Load();
1706 CompileRun("foo = {};"); 1780 CompileRun("foo = {};");
1707 const v8::HeapSnapshot* snapshot = 1781 const v8::HeapSnapshot* snapshot =
1708 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 1782 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
1783 CHECK(ValidateSnapshot(snapshot, 3));
1709 const v8::HeapGraphNode* root = snapshot->GetRoot(); 1784 const v8::HeapGraphNode* root = snapshot->GetRoot();
1710 int globals_count = 0; 1785 int globals_count = 0;
1711 for (int i = 0; i < root->GetChildrenCount(); ++i) { 1786 for (int i = 0; i < root->GetChildrenCount(); ++i) {
1712 const v8::HeapGraphEdge* edge = root->GetChild(i); 1787 const v8::HeapGraphEdge* edge = root->GetChild(i);
1713 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { 1788 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) {
1714 ++globals_count; 1789 ++globals_count;
1715 const v8::HeapGraphNode* global = edge->GetToNode(); 1790 const v8::HeapGraphNode* global = edge->GetToNode();
1716 const v8::HeapGraphNode* foo = 1791 const v8::HeapGraphNode* foo =
1717 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); 1792 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo");
1718 CHECK_NE(NULL, foo); 1793 CHECK_NE(NULL, foo);
1719 } 1794 }
1720 } 1795 }
1721 CHECK_EQ(1, globals_count); 1796 CHECK_EQ(1, globals_count);
1722 } 1797 }
1723 #endif // ENABLE_DEBUGGER_SUPPORT 1798 #endif // ENABLE_DEBUGGER_SUPPORT
1724 1799
1725 1800
1726 TEST(AllStrongGcRootsHaveNames) { 1801 TEST(AllStrongGcRootsHaveNames) {
1727 LocalContext env; 1802 LocalContext env;
1728 v8::HandleScope scope(env->GetIsolate()); 1803 v8::HandleScope scope(env->GetIsolate());
1729 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1804 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1730 1805
1731 CompileRun("foo = {};"); 1806 CompileRun("foo = {};");
1732 const v8::HeapSnapshot* snapshot = 1807 const v8::HeapSnapshot* snapshot =
1733 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 1808 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
1809 CHECK(ValidateSnapshot(snapshot, 3));
1734 const v8::HeapGraphNode* gc_roots = GetNode( 1810 const v8::HeapGraphNode* gc_roots = GetNode(
1735 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); 1811 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)");
1736 CHECK_NE(NULL, gc_roots); 1812 CHECK_NE(NULL, gc_roots);
1737 const v8::HeapGraphNode* strong_roots = GetNode( 1813 const v8::HeapGraphNode* strong_roots = GetNode(
1738 gc_roots, v8::HeapGraphNode::kSynthetic, "(Strong roots)"); 1814 gc_roots, v8::HeapGraphNode::kSynthetic, "(Strong roots)");
1739 CHECK_NE(NULL, strong_roots); 1815 CHECK_NE(NULL, strong_roots);
1740 for (int i = 0; i < strong_roots->GetChildrenCount(); ++i) { 1816 for (int i = 0; i < strong_roots->GetChildrenCount(); ++i) {
1741 const v8::HeapGraphEdge* edge = strong_roots->GetChild(i); 1817 const v8::HeapGraphEdge* edge = strong_roots->GetChild(i);
1742 CHECK_EQ(v8::HeapGraphEdge::kInternal, edge->GetType()); 1818 CHECK_EQ(v8::HeapGraphEdge::kInternal, edge->GetType());
1743 v8::String::Utf8Value name(edge->GetName()); 1819 v8::String::Utf8Value name(edge->GetName());
1744 CHECK(isalpha(**name)); 1820 CHECK(isalpha(**name));
1745 } 1821 }
1746 } 1822 }
1747 1823
1748 1824
1749 TEST(NoRefsToNonEssentialEntries) { 1825 TEST(NoRefsToNonEssentialEntries) {
1750 LocalContext env; 1826 LocalContext env;
1751 v8::HandleScope scope(env->GetIsolate()); 1827 v8::HandleScope scope(env->GetIsolate());
1752 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1828 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1753 CompileRun("global_object = {};\n"); 1829 CompileRun("global_object = {};\n");
1754 const v8::HeapSnapshot* snapshot = 1830 const v8::HeapSnapshot* snapshot =
1755 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 1831 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
1832 CHECK(ValidateSnapshot(snapshot, 3));
1756 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1833 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1757 const v8::HeapGraphNode* global_object = 1834 const v8::HeapGraphNode* global_object =
1758 GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object"); 1835 GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object");
1759 CHECK_NE(NULL, global_object); 1836 CHECK_NE(NULL, global_object);
1760 const v8::HeapGraphNode* properties = 1837 const v8::HeapGraphNode* properties =
1761 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "properties"); 1838 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "properties");
1762 CHECK_EQ(NULL, properties); 1839 CHECK_EQ(NULL, properties);
1763 const v8::HeapGraphNode* elements = 1840 const v8::HeapGraphNode* elements =
1764 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "elements"); 1841 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "elements");
1765 CHECK_EQ(NULL, elements); 1842 CHECK_EQ(NULL, elements);
1766 } 1843 }
1767 1844
1768 1845
1769 TEST(MapHasDescriptorsAndTransitions) { 1846 TEST(MapHasDescriptorsAndTransitions) {
1770 LocalContext env; 1847 LocalContext env;
1771 v8::HandleScope scope(env->GetIsolate()); 1848 v8::HandleScope scope(env->GetIsolate());
1772 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1849 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1773 CompileRun("obj = { a: 10 };\n"); 1850 CompileRun("obj = { a: 10 };\n");
1774 const v8::HeapSnapshot* snapshot = 1851 const v8::HeapSnapshot* snapshot =
1775 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 1852 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
1853 CHECK(ValidateSnapshot(snapshot, 3));
1776 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1854 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1777 const v8::HeapGraphNode* global_object = 1855 const v8::HeapGraphNode* global_object =
1778 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); 1856 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj");
1779 CHECK_NE(NULL, global_object); 1857 CHECK_NE(NULL, global_object);
1780 1858
1781 const v8::HeapGraphNode* map = 1859 const v8::HeapGraphNode* map =
1782 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); 1860 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map");
1783 CHECK_NE(NULL, map); 1861 CHECK_NE(NULL, map);
1784 const v8::HeapGraphNode* own_descriptors = GetProperty( 1862 const v8::HeapGraphNode* own_descriptors = GetProperty(
1785 map, v8::HeapGraphEdge::kInternal, "descriptors"); 1863 map, v8::HeapGraphEdge::kInternal, "descriptors");
(...skipping 18 matching lines...) Expand all
1804 " if (i > 0)" 1882 " if (i > 0)"
1805 " f += 'f_' + (i - 1) + '();';" 1883 " f += 'f_' + (i - 1) + '();';"
1806 " f += ' }';" 1884 " f += ' }';"
1807 " result.push(f);" 1885 " result.push(f);"
1808 "}" 1886 "}"
1809 "result.push('return f_' + (n - 1) + ';');" 1887 "result.push('return f_' + (n - 1) + ';');"
1810 "result.push('})()');" 1888 "result.push('})()');"
1811 "var ok = eval(result.join('\\n'));"); 1889 "var ok = eval(result.join('\\n'));");
1812 const v8::HeapSnapshot* snapshot = 1890 const v8::HeapSnapshot* snapshot =
1813 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 1891 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
1892 CHECK(ValidateSnapshot(snapshot, 3));
1893
1814 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1894 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1815 CHECK_NE(NULL, global); 1895 CHECK_NE(NULL, global);
1816 const v8::HeapGraphNode* ok_object = 1896 const v8::HeapGraphNode* ok_object =
1817 GetProperty(global, v8::HeapGraphEdge::kProperty, "ok"); 1897 GetProperty(global, v8::HeapGraphEdge::kProperty, "ok");
1818 CHECK_NE(NULL, ok_object); 1898 CHECK_NE(NULL, ok_object);
1819 const v8::HeapGraphNode* context_object = 1899 const v8::HeapGraphNode* context_object =
1820 GetProperty(ok_object, v8::HeapGraphEdge::kInternal, "context"); 1900 GetProperty(ok_object, v8::HeapGraphEdge::kInternal, "context");
1821 CHECK_NE(NULL, context_object); 1901 CHECK_NE(NULL, context_object);
1822 // Check the objects are not duplicated in the context. 1902 // Check the objects are not duplicated in the context.
1823 CHECK_EQ(v8::internal::Context::MIN_CONTEXT_SLOTS + num_objects - 1, 1903 CHECK_EQ(v8::internal::Context::MIN_CONTEXT_SLOTS + num_objects - 1,
(...skipping 12 matching lines...) Expand all
1836 1916
1837 TEST(AllocationSitesAreVisible) { 1917 TEST(AllocationSitesAreVisible) {
1838 LocalContext env; 1918 LocalContext env;
1839 v8::HandleScope scope(env->GetIsolate()); 1919 v8::HandleScope scope(env->GetIsolate());
1840 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1920 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1841 CompileRun( 1921 CompileRun(
1842 "fun = function () { var a = [3, 2, 1]; return a; }\n" 1922 "fun = function () { var a = [3, 2, 1]; return a; }\n"
1843 "fun();"); 1923 "fun();");
1844 const v8::HeapSnapshot* snapshot = 1924 const v8::HeapSnapshot* snapshot =
1845 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 1925 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
1926 CHECK(ValidateSnapshot(snapshot, 3));
1846 1927
1847 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1928 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1848 CHECK_NE(NULL, global); 1929 CHECK_NE(NULL, global);
1849 const v8::HeapGraphNode* fun_code = 1930 const v8::HeapGraphNode* fun_code =
1850 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); 1931 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun");
1851 CHECK_NE(NULL, fun_code); 1932 CHECK_NE(NULL, fun_code);
1852 const v8::HeapGraphNode* literals = 1933 const v8::HeapGraphNode* literals =
1853 GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals"); 1934 GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals");
1854 CHECK_NE(NULL, literals); 1935 CHECK_NE(NULL, literals);
1855 CHECK_EQ(v8::HeapGraphNode::kArray, literals->GetType()); 1936 CHECK_EQ(v8::HeapGraphNode::kArray, literals->GetType());
(...skipping 19 matching lines...) Expand all
1875 1956
1876 CHECK(transition_info->GetHeapValue()->IsArray()); 1957 CHECK(transition_info->GetHeapValue()->IsArray());
1877 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast( 1958 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(
1878 transition_info->GetHeapValue()); 1959 transition_info->GetHeapValue());
1879 // Verify the array is "a" in the code above. 1960 // Verify the array is "a" in the code above.
1880 CHECK_EQ(3, array->Length()); 1961 CHECK_EQ(3, array->Length());
1881 CHECK_EQ(v8::Integer::New(3), array->Get(v8::Integer::New(0))); 1962 CHECK_EQ(v8::Integer::New(3), array->Get(v8::Integer::New(0)));
1882 CHECK_EQ(v8::Integer::New(2), array->Get(v8::Integer::New(1))); 1963 CHECK_EQ(v8::Integer::New(2), array->Get(v8::Integer::New(1)));
1883 CHECK_EQ(v8::Integer::New(1), array->Get(v8::Integer::New(2))); 1964 CHECK_EQ(v8::Integer::New(1), array->Get(v8::Integer::New(2)));
1884 } 1965 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698