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

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

Issue 893533003: Revert "Make GCC happy again." and "Initial switch to Chromium-style CHECK_* and DCHECK_* macros.". (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-hashmap.cc ('k') | test/cctest/test-lockers.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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" 184 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n"
185 "var c2 = new C2(a2);"); 185 "var c2 = new C2(a2);");
186 const v8::HeapSnapshot* snapshot_env2 = 186 const v8::HeapSnapshot* snapshot_env2 =
187 heap_profiler->TakeHeapSnapshot(v8_str("env2")); 187 heap_profiler->TakeHeapSnapshot(v8_str("env2"));
188 CHECK(ValidateSnapshot(snapshot_env2)); 188 CHECK(ValidateSnapshot(snapshot_env2));
189 const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2); 189 const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2);
190 190
191 // Verify, that JS global object of env2 has '..2' properties. 191 // Verify, that JS global object of env2 has '..2' properties.
192 const v8::HeapGraphNode* a2_node = 192 const v8::HeapGraphNode* a2_node =
193 GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "a2"); 193 GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "a2");
194 CHECK(a2_node); 194 CHECK_NE(NULL, a2_node);
195 CHECK(GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_1")); 195 CHECK_NE(
196 CHECK(GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_2")); 196 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_1"));
197 CHECK(GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "c2")); 197 CHECK_NE(
198 NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "b2_2"));
199 CHECK_NE(NULL, GetProperty(global_env2, v8::HeapGraphEdge::kProperty, "c2"));
198 200
199 NamedEntriesDetector det; 201 NamedEntriesDetector det;
200 det.CheckAllReachables(const_cast<i::HeapEntry*>( 202 det.CheckAllReachables(const_cast<i::HeapEntry*>(
201 reinterpret_cast<const i::HeapEntry*>(global_env2))); 203 reinterpret_cast<const i::HeapEntry*>(global_env2)));
202 CHECK(det.has_A2); 204 CHECK(det.has_A2);
203 CHECK(det.has_B2); 205 CHECK(det.has_B2);
204 CHECK(det.has_C2); 206 CHECK(det.has_C2);
205 } 207 }
206 208
207 209
208 TEST(HeapSnapshotObjectSizes) { 210 TEST(HeapSnapshotObjectSizes) {
209 LocalContext env; 211 LocalContext env;
210 v8::HandleScope scope(env->GetIsolate()); 212 v8::HandleScope scope(env->GetIsolate());
211 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 213 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
212 214
213 // -a-> X1 --a 215 // -a-> X1 --a
214 // x -b-> X2 <-| 216 // x -b-> X2 <-|
215 CompileRun( 217 CompileRun(
216 "function X(a, b) { this.a = a; this.b = b; }\n" 218 "function X(a, b) { this.a = a; this.b = b; }\n"
217 "x = new X(new X(), new X());\n" 219 "x = new X(new X(), new X());\n"
218 "dummy = new X();\n" 220 "dummy = new X();\n"
219 "(function() { x.a.a = x.b; })();"); 221 "(function() { x.a.a = x.b; })();");
220 const v8::HeapSnapshot* snapshot = 222 const v8::HeapSnapshot* snapshot =
221 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); 223 heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
222 CHECK(ValidateSnapshot(snapshot)); 224 CHECK(ValidateSnapshot(snapshot));
223 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 225 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
224 const v8::HeapGraphNode* x = 226 const v8::HeapGraphNode* x =
225 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); 227 GetProperty(global, v8::HeapGraphEdge::kProperty, "x");
226 CHECK(x); 228 CHECK_NE(NULL, x);
227 const v8::HeapGraphNode* x1 = 229 const v8::HeapGraphNode* x1 =
228 GetProperty(x, v8::HeapGraphEdge::kProperty, "a"); 230 GetProperty(x, v8::HeapGraphEdge::kProperty, "a");
229 CHECK(x1); 231 CHECK_NE(NULL, x1);
230 const v8::HeapGraphNode* x2 = 232 const v8::HeapGraphNode* x2 =
231 GetProperty(x, v8::HeapGraphEdge::kProperty, "b"); 233 GetProperty(x, v8::HeapGraphEdge::kProperty, "b");
232 CHECK(x2); 234 CHECK_NE(NULL, x2);
233 235
234 // Test sizes. 236 // Test sizes.
235 CHECK_NE(0, static_cast<int>(x->GetShallowSize())); 237 CHECK_NE(0, static_cast<int>(x->GetShallowSize()));
236 CHECK_NE(0, static_cast<int>(x1->GetShallowSize())); 238 CHECK_NE(0, static_cast<int>(x1->GetShallowSize()));
237 CHECK_NE(0, static_cast<int>(x2->GetShallowSize())); 239 CHECK_NE(0, static_cast<int>(x2->GetShallowSize()));
238 } 240 }
239 241
240 242
241 TEST(BoundFunctionInSnapshot) { 243 TEST(BoundFunctionInSnapshot) {
242 LocalContext env; 244 LocalContext env;
243 v8::HandleScope scope(env->GetIsolate()); 245 v8::HandleScope scope(env->GetIsolate());
244 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 246 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
245 CompileRun( 247 CompileRun(
246 "function myFunction(a, b) { this.a = a; this.b = b; }\n" 248 "function myFunction(a, b) { this.a = a; this.b = b; }\n"
247 "function AAAAA() {}\n" 249 "function AAAAA() {}\n"
248 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); 250 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n");
249 const v8::HeapSnapshot* snapshot = 251 const v8::HeapSnapshot* snapshot =
250 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); 252 heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
251 CHECK(ValidateSnapshot(snapshot)); 253 CHECK(ValidateSnapshot(snapshot));
252 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 254 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
253 const v8::HeapGraphNode* f = 255 const v8::HeapGraphNode* f =
254 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction"); 256 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction");
255 CHECK(f); 257 CHECK(f);
256 CHECK(v8::String::NewFromUtf8(env->GetIsolate(), "native_bind") 258 CHECK_EQ(v8::String::NewFromUtf8(env->GetIsolate(), "native_bind"),
257 ->Equals(f->GetName())); 259 f->GetName());
258 const v8::HeapGraphNode* bindings = 260 const v8::HeapGraphNode* bindings =
259 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings"); 261 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings");
260 CHECK(bindings); 262 CHECK_NE(NULL, bindings);
261 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType()); 263 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType());
262 CHECK_EQ(3, bindings->GetChildrenCount()); 264 CHECK_EQ(3, bindings->GetChildrenCount());
263 265
264 const v8::HeapGraphNode* bound_this = GetProperty( 266 const v8::HeapGraphNode* bound_this = GetProperty(
265 f, v8::HeapGraphEdge::kShortcut, "bound_this"); 267 f, v8::HeapGraphEdge::kShortcut, "bound_this");
266 CHECK(bound_this); 268 CHECK(bound_this);
267 CHECK_EQ(v8::HeapGraphNode::kObject, bound_this->GetType()); 269 CHECK_EQ(v8::HeapGraphNode::kObject, bound_this->GetType());
268 270
269 const v8::HeapGraphNode* bound_function = GetProperty( 271 const v8::HeapGraphNode* bound_function = GetProperty(
270 f, v8::HeapGraphEdge::kShortcut, "bound_function"); 272 f, v8::HeapGraphEdge::kShortcut, "bound_function");
(...skipping 18 matching lines...) Expand all
289 const v8::HeapSnapshot* snapshot = 291 const v8::HeapSnapshot* snapshot =
290 heap_profiler->TakeHeapSnapshot(v8_str("children")); 292 heap_profiler->TakeHeapSnapshot(v8_str("children"));
291 CHECK(ValidateSnapshot(snapshot)); 293 CHECK(ValidateSnapshot(snapshot));
292 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 294 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
293 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { 295 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) {
294 const v8::HeapGraphEdge* prop = global->GetChild(i); 296 const v8::HeapGraphEdge* prop = global->GetChild(i);
295 CHECK_EQ(global, prop->GetFromNode()); 297 CHECK_EQ(global, prop->GetFromNode());
296 } 298 }
297 const v8::HeapGraphNode* a = 299 const v8::HeapGraphNode* a =
298 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); 300 GetProperty(global, v8::HeapGraphEdge::kProperty, "a");
299 CHECK(a); 301 CHECK_NE(NULL, a);
300 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) { 302 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) {
301 const v8::HeapGraphEdge* prop = a->GetChild(i); 303 const v8::HeapGraphEdge* prop = a->GetChild(i);
302 CHECK_EQ(a, prop->GetFromNode()); 304 CHECK_EQ(a, prop->GetFromNode());
303 } 305 }
304 } 306 }
305 307
306 308
307 TEST(HeapSnapshotCodeObjects) { 309 TEST(HeapSnapshotCodeObjects) {
308 LocalContext env; 310 LocalContext env;
309 v8::HandleScope scope(env->GetIsolate()); 311 v8::HandleScope scope(env->GetIsolate());
310 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 312 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
311 313
312 CompileRun( 314 CompileRun(
313 "function lazy(x) { return x - 1; }\n" 315 "function lazy(x) { return x - 1; }\n"
314 "function compiled(x) { return x + 1; }\n" 316 "function compiled(x) { return x + 1; }\n"
315 "var anonymous = (function() { return function() { return 0; } })();\n" 317 "var anonymous = (function() { return function() { return 0; } })();\n"
316 "compiled(1)"); 318 "compiled(1)");
317 const v8::HeapSnapshot* snapshot = 319 const v8::HeapSnapshot* snapshot =
318 heap_profiler->TakeHeapSnapshot(v8_str("code")); 320 heap_profiler->TakeHeapSnapshot(v8_str("code"));
319 CHECK(ValidateSnapshot(snapshot)); 321 CHECK(ValidateSnapshot(snapshot));
320 322
321 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 323 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
322 const v8::HeapGraphNode* compiled = 324 const v8::HeapGraphNode* compiled =
323 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled"); 325 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled");
324 CHECK(compiled); 326 CHECK_NE(NULL, compiled);
325 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType()); 327 CHECK_EQ(v8::HeapGraphNode::kClosure, compiled->GetType());
326 const v8::HeapGraphNode* lazy = 328 const v8::HeapGraphNode* lazy =
327 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy"); 329 GetProperty(global, v8::HeapGraphEdge::kProperty, "lazy");
328 CHECK(lazy); 330 CHECK_NE(NULL, lazy);
329 CHECK_EQ(v8::HeapGraphNode::kClosure, lazy->GetType()); 331 CHECK_EQ(v8::HeapGraphNode::kClosure, lazy->GetType());
330 const v8::HeapGraphNode* anonymous = 332 const v8::HeapGraphNode* anonymous =
331 GetProperty(global, v8::HeapGraphEdge::kProperty, "anonymous"); 333 GetProperty(global, v8::HeapGraphEdge::kProperty, "anonymous");
332 CHECK(anonymous); 334 CHECK_NE(NULL, anonymous);
333 CHECK_EQ(v8::HeapGraphNode::kClosure, anonymous->GetType()); 335 CHECK_EQ(v8::HeapGraphNode::kClosure, anonymous->GetType());
334 v8::String::Utf8Value anonymous_name(anonymous->GetName()); 336 v8::String::Utf8Value anonymous_name(anonymous->GetName());
335 CHECK_EQ(0, strcmp("", *anonymous_name)); 337 CHECK_EQ("", *anonymous_name);
336 338
337 // Find references to code. 339 // Find references to code.
338 const v8::HeapGraphNode* compiled_code = 340 const v8::HeapGraphNode* compiled_code =
339 GetProperty(compiled, v8::HeapGraphEdge::kInternal, "shared"); 341 GetProperty(compiled, v8::HeapGraphEdge::kInternal, "shared");
340 CHECK(compiled_code); 342 CHECK_NE(NULL, compiled_code);
341 const v8::HeapGraphNode* lazy_code = 343 const v8::HeapGraphNode* lazy_code =
342 GetProperty(lazy, v8::HeapGraphEdge::kInternal, "shared"); 344 GetProperty(lazy, v8::HeapGraphEdge::kInternal, "shared");
343 CHECK(lazy_code); 345 CHECK_NE(NULL, lazy_code);
344 346
345 // Check that there's no strong next_code_link. There might be a weak one 347 // Check that there's no strong next_code_link. There might be a weak one
346 // but might be not, so we can't check that fact. 348 // but might be not, so we can't check that fact.
347 const v8::HeapGraphNode* code = 349 const v8::HeapGraphNode* code =
348 GetProperty(compiled_code, v8::HeapGraphEdge::kInternal, "code"); 350 GetProperty(compiled_code, v8::HeapGraphEdge::kInternal, "code");
349 CHECK(code); 351 CHECK_NE(NULL, code);
350 const v8::HeapGraphNode* next_code_link = 352 const v8::HeapGraphNode* next_code_link =
351 GetProperty(code, v8::HeapGraphEdge::kInternal, "code"); 353 GetProperty(code, v8::HeapGraphEdge::kInternal, "code");
352 CHECK(!next_code_link); 354 CHECK_EQ(NULL, next_code_link);
353 355
354 // Verify that non-compiled code doesn't contain references to "x" 356 // Verify that non-compiled code doesn't contain references to "x"
355 // literal, while compiled code does. The scope info is stored in FixedArray 357 // literal, while compiled code does. The scope info is stored in FixedArray
356 // objects attached to the SharedFunctionInfo. 358 // objects attached to the SharedFunctionInfo.
357 bool compiled_references_x = false, lazy_references_x = false; 359 bool compiled_references_x = false, lazy_references_x = false;
358 for (int i = 0, count = compiled_code->GetChildrenCount(); i < count; ++i) { 360 for (int i = 0, count = compiled_code->GetChildrenCount(); i < count; ++i) {
359 const v8::HeapGraphEdge* prop = compiled_code->GetChild(i); 361 const v8::HeapGraphEdge* prop = compiled_code->GetChild(i);
360 const v8::HeapGraphNode* node = prop->GetToNode(); 362 const v8::HeapGraphNode* node = prop->GetToNode();
361 if (node->GetType() == v8::HeapGraphNode::kArray) { 363 if (node->GetType() == v8::HeapGraphNode::kArray) {
362 if (HasString(node, "x")) { 364 if (HasString(node, "x")) {
(...skipping 21 matching lines...) Expand all
384 LocalContext env; 386 LocalContext env;
385 v8::HandleScope scope(env->GetIsolate()); 387 v8::HandleScope scope(env->GetIsolate());
386 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 388 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
387 CompileRun( 389 CompileRun(
388 "a = 1; // a is Smi\n" 390 "a = 1; // a is Smi\n"
389 "b = 2.5; // b is HeapNumber"); 391 "b = 2.5; // b is HeapNumber");
390 const v8::HeapSnapshot* snapshot = 392 const v8::HeapSnapshot* snapshot =
391 heap_profiler->TakeHeapSnapshot(v8_str("numbers")); 393 heap_profiler->TakeHeapSnapshot(v8_str("numbers"));
392 CHECK(ValidateSnapshot(snapshot)); 394 CHECK(ValidateSnapshot(snapshot));
393 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 395 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
394 CHECK(!GetProperty(global, v8::HeapGraphEdge::kProperty, "a")); 396 CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a"));
395 const v8::HeapGraphNode* b = 397 const v8::HeapGraphNode* b =
396 GetProperty(global, v8::HeapGraphEdge::kProperty, "b"); 398 GetProperty(global, v8::HeapGraphEdge::kProperty, "b");
397 CHECK(b); 399 CHECK_NE(NULL, b);
398 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType()); 400 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType());
399 } 401 }
400 402
401 403
402 TEST(HeapSnapshotSlicedString) { 404 TEST(HeapSnapshotSlicedString) {
403 LocalContext env; 405 LocalContext env;
404 v8::HandleScope scope(env->GetIsolate()); 406 v8::HandleScope scope(env->GetIsolate());
405 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 407 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
406 CompileRun( 408 CompileRun(
407 "parent_string = \"123456789.123456789.123456789.123456789.123456789." 409 "parent_string = \"123456789.123456789.123456789.123456789.123456789."
408 "123456789.123456789.123456789.123456789.123456789." 410 "123456789.123456789.123456789.123456789.123456789."
409 "123456789.123456789.123456789.123456789.123456789." 411 "123456789.123456789.123456789.123456789.123456789."
410 "123456789.123456789.123456789.123456789.123456789.\";" 412 "123456789.123456789.123456789.123456789.123456789.\";"
411 "child_string = parent_string.slice(100);"); 413 "child_string = parent_string.slice(100);");
412 const v8::HeapSnapshot* snapshot = 414 const v8::HeapSnapshot* snapshot =
413 heap_profiler->TakeHeapSnapshot(v8_str("strings")); 415 heap_profiler->TakeHeapSnapshot(v8_str("strings"));
414 CHECK(ValidateSnapshot(snapshot)); 416 CHECK(ValidateSnapshot(snapshot));
415 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 417 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
416 const v8::HeapGraphNode* parent_string = 418 const v8::HeapGraphNode* parent_string =
417 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string"); 419 GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string");
418 CHECK(parent_string); 420 CHECK_NE(NULL, parent_string);
419 const v8::HeapGraphNode* child_string = 421 const v8::HeapGraphNode* child_string =
420 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string"); 422 GetProperty(global, v8::HeapGraphEdge::kProperty, "child_string");
421 CHECK(child_string); 423 CHECK_NE(NULL, child_string);
422 CHECK_EQ(v8::HeapGraphNode::kSlicedString, child_string->GetType()); 424 CHECK_EQ(v8::HeapGraphNode::kSlicedString, child_string->GetType());
423 const v8::HeapGraphNode* parent = 425 const v8::HeapGraphNode* parent =
424 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); 426 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent");
425 CHECK_EQ(parent_string, parent); 427 CHECK_EQ(parent_string, parent);
426 heap_profiler->DeleteAllHeapSnapshots(); 428 heap_profiler->DeleteAllHeapSnapshots();
427 } 429 }
428 430
429 431
430 TEST(HeapSnapshotConsString) { 432 TEST(HeapSnapshotConsString) {
431 v8::Isolate* isolate = CcTest::isolate(); 433 v8::Isolate* isolate = CcTest::isolate();
(...skipping 15 matching lines...) Expand all
447 global->SetInternalField(0, v8::ToApiHandle<v8::String>(cons_string)); 449 global->SetInternalField(0, v8::ToApiHandle<v8::String>(cons_string));
448 450
449 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 451 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
450 const v8::HeapSnapshot* snapshot = 452 const v8::HeapSnapshot* snapshot =
451 heap_profiler->TakeHeapSnapshot(v8_str("cons_strings")); 453 heap_profiler->TakeHeapSnapshot(v8_str("cons_strings"));
452 CHECK(ValidateSnapshot(snapshot)); 454 CHECK(ValidateSnapshot(snapshot));
453 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); 455 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
454 456
455 const v8::HeapGraphNode* string_node = 457 const v8::HeapGraphNode* string_node =
456 GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0"); 458 GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0");
457 CHECK(string_node); 459 CHECK_NE(NULL, string_node);
458 CHECK_EQ(v8::HeapGraphNode::kConsString, string_node->GetType()); 460 CHECK_EQ(v8::HeapGraphNode::kConsString, string_node->GetType());
459 461
460 const v8::HeapGraphNode* first_node = 462 const v8::HeapGraphNode* first_node =
461 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "first"); 463 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "first");
462 CHECK_EQ(v8::HeapGraphNode::kString, first_node->GetType()); 464 CHECK_EQ(v8::HeapGraphNode::kString, first_node->GetType());
463 465
464 const v8::HeapGraphNode* second_node = 466 const v8::HeapGraphNode* second_node =
465 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "second"); 467 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "second");
466 CHECK_EQ(v8::HeapGraphNode::kString, second_node->GetType()); 468 CHECK_EQ(v8::HeapGraphNode::kString, second_node->GetType());
467 469
468 heap_profiler->DeleteAllHeapSnapshots(); 470 heap_profiler->DeleteAllHeapSnapshots();
469 } 471 }
470 472
471 473
472 TEST(HeapSnapshotSymbol) { 474 TEST(HeapSnapshotSymbol) {
473 LocalContext env; 475 LocalContext env;
474 v8::HandleScope scope(env->GetIsolate()); 476 v8::HandleScope scope(env->GetIsolate());
475 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 477 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
476 478
477 CompileRun("a = Symbol('mySymbol');\n"); 479 CompileRun("a = Symbol('mySymbol');\n");
478 const v8::HeapSnapshot* snapshot = 480 const v8::HeapSnapshot* snapshot =
479 heap_profiler->TakeHeapSnapshot(v8_str("Symbol")); 481 heap_profiler->TakeHeapSnapshot(v8_str("Symbol"));
480 CHECK(ValidateSnapshot(snapshot)); 482 CHECK(ValidateSnapshot(snapshot));
481 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 483 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
482 const v8::HeapGraphNode* a = 484 const v8::HeapGraphNode* a =
483 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); 485 GetProperty(global, v8::HeapGraphEdge::kProperty, "a");
484 CHECK(a); 486 CHECK_NE(NULL, a);
485 CHECK_EQ(a->GetType(), v8::HeapGraphNode::kSymbol); 487 CHECK_EQ(a->GetType(), v8::HeapGraphNode::kSymbol);
486 CHECK(v8_str("symbol")->Equals(a->GetName())); 488 CHECK_EQ(v8_str("symbol"), a->GetName());
487 const v8::HeapGraphNode* name = 489 const v8::HeapGraphNode* name =
488 GetProperty(a, v8::HeapGraphEdge::kInternal, "name"); 490 GetProperty(a, v8::HeapGraphEdge::kInternal, "name");
489 CHECK(name); 491 CHECK_NE(NULL, name);
490 CHECK(v8_str("mySymbol")->Equals(name->GetName())); 492 CHECK_EQ(v8_str("mySymbol"), name->GetName());
491 } 493 }
492 494
493 495
494 TEST(HeapSnapshotWeakCollection) { 496 TEST(HeapSnapshotWeakCollection) {
495 LocalContext env; 497 LocalContext env;
496 v8::HandleScope scope(env->GetIsolate()); 498 v8::HandleScope scope(env->GetIsolate());
497 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 499 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
498 500
499 CompileRun( 501 CompileRun(
500 "k = {}; v = {}; s = 'str';\n" 502 "k = {}; v = {}; s = 'str';\n"
501 "ws = new WeakSet(); ws.add(k); ws.add(v); ws[s] = s;\n" 503 "ws = new WeakSet(); ws.add(k); ws.add(v); ws[s] = s;\n"
502 "wm = new WeakMap(); wm.set(k, v); wm[s] = s;\n"); 504 "wm = new WeakMap(); wm.set(k, v); wm[s] = s;\n");
503 const v8::HeapSnapshot* snapshot = 505 const v8::HeapSnapshot* snapshot =
504 heap_profiler->TakeHeapSnapshot(v8_str("WeakCollections")); 506 heap_profiler->TakeHeapSnapshot(v8_str("WeakCollections"));
505 CHECK(ValidateSnapshot(snapshot)); 507 CHECK(ValidateSnapshot(snapshot));
506 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 508 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
507 const v8::HeapGraphNode* k = 509 const v8::HeapGraphNode* k =
508 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); 510 GetProperty(global, v8::HeapGraphEdge::kProperty, "k");
509 CHECK(k); 511 CHECK_NE(NULL, k);
510 const v8::HeapGraphNode* v = 512 const v8::HeapGraphNode* v =
511 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); 513 GetProperty(global, v8::HeapGraphEdge::kProperty, "v");
512 CHECK(v); 514 CHECK_NE(NULL, v);
513 const v8::HeapGraphNode* s = 515 const v8::HeapGraphNode* s =
514 GetProperty(global, v8::HeapGraphEdge::kProperty, "s"); 516 GetProperty(global, v8::HeapGraphEdge::kProperty, "s");
515 CHECK(s); 517 CHECK_NE(NULL, s);
516 518
517 const v8::HeapGraphNode* ws = 519 const v8::HeapGraphNode* ws =
518 GetProperty(global, v8::HeapGraphEdge::kProperty, "ws"); 520 GetProperty(global, v8::HeapGraphEdge::kProperty, "ws");
519 CHECK(ws); 521 CHECK_NE(NULL, ws);
520 CHECK_EQ(v8::HeapGraphNode::kObject, ws->GetType()); 522 CHECK_EQ(v8::HeapGraphNode::kObject, ws->GetType());
521 CHECK(v8_str("WeakSet")->Equals(ws->GetName())); 523 CHECK_EQ(v8_str("WeakSet"), ws->GetName());
522 524
523 const v8::HeapGraphNode* ws_table = 525 const v8::HeapGraphNode* ws_table =
524 GetProperty(ws, v8::HeapGraphEdge::kInternal, "table"); 526 GetProperty(ws, v8::HeapGraphEdge::kInternal, "table");
525 CHECK_EQ(v8::HeapGraphNode::kArray, ws_table->GetType()); 527 CHECK_EQ(v8::HeapGraphNode::kArray, ws_table->GetType());
526 CHECK_GT(ws_table->GetChildrenCount(), 0); 528 CHECK_GT(ws_table->GetChildrenCount(), 0);
527 int weak_entries = 0; 529 int weak_entries = 0;
528 for (int i = 0, count = ws_table->GetChildrenCount(); i < count; ++i) { 530 for (int i = 0, count = ws_table->GetChildrenCount(); i < count; ++i) {
529 const v8::HeapGraphEdge* prop = ws_table->GetChild(i); 531 const v8::HeapGraphEdge* prop = ws_table->GetChild(i);
530 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue; 532 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue;
531 if (k->GetId() == prop->GetToNode()->GetId()) { 533 if (k->GetId() == prop->GetToNode()->GetId()) {
532 ++weak_entries; 534 ++weak_entries;
533 } 535 }
534 } 536 }
535 CHECK_EQ(1, weak_entries); 537 CHECK_EQ(1, weak_entries);
536 const v8::HeapGraphNode* ws_s = 538 const v8::HeapGraphNode* ws_s =
537 GetProperty(ws, v8::HeapGraphEdge::kProperty, "str"); 539 GetProperty(ws, v8::HeapGraphEdge::kProperty, "str");
538 CHECK(ws_s); 540 CHECK_NE(NULL, ws_s);
539 CHECK_EQ(s->GetId(), ws_s->GetId()); 541 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(ws_s->GetId()));
540 542
541 const v8::HeapGraphNode* wm = 543 const v8::HeapGraphNode* wm =
542 GetProperty(global, v8::HeapGraphEdge::kProperty, "wm"); 544 GetProperty(global, v8::HeapGraphEdge::kProperty, "wm");
543 CHECK(wm); 545 CHECK_NE(NULL, wm);
544 CHECK_EQ(v8::HeapGraphNode::kObject, wm->GetType()); 546 CHECK_EQ(v8::HeapGraphNode::kObject, wm->GetType());
545 CHECK(v8_str("WeakMap")->Equals(wm->GetName())); 547 CHECK_EQ(v8_str("WeakMap"), wm->GetName());
546 548
547 const v8::HeapGraphNode* wm_table = 549 const v8::HeapGraphNode* wm_table =
548 GetProperty(wm, v8::HeapGraphEdge::kInternal, "table"); 550 GetProperty(wm, v8::HeapGraphEdge::kInternal, "table");
549 CHECK_EQ(v8::HeapGraphNode::kArray, wm_table->GetType()); 551 CHECK_EQ(v8::HeapGraphNode::kArray, wm_table->GetType());
550 CHECK_GT(wm_table->GetChildrenCount(), 0); 552 CHECK_GT(wm_table->GetChildrenCount(), 0);
551 weak_entries = 0; 553 weak_entries = 0;
552 for (int i = 0, count = wm_table->GetChildrenCount(); i < count; ++i) { 554 for (int i = 0, count = wm_table->GetChildrenCount(); i < count; ++i) {
553 const v8::HeapGraphEdge* prop = wm_table->GetChild(i); 555 const v8::HeapGraphEdge* prop = wm_table->GetChild(i);
554 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue; 556 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue;
555 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); 557 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId();
556 if (to_node_id == k->GetId() || to_node_id == v->GetId()) { 558 if (to_node_id == k->GetId() || to_node_id == v->GetId()) {
557 ++weak_entries; 559 ++weak_entries;
558 } 560 }
559 } 561 }
560 CHECK_EQ(2, weak_entries); 562 CHECK_EQ(2, weak_entries);
561 const v8::HeapGraphNode* wm_s = 563 const v8::HeapGraphNode* wm_s =
562 GetProperty(wm, v8::HeapGraphEdge::kProperty, "str"); 564 GetProperty(wm, v8::HeapGraphEdge::kProperty, "str");
563 CHECK(wm_s); 565 CHECK_NE(NULL, wm_s);
564 CHECK_EQ(s->GetId(), wm_s->GetId()); 566 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(wm_s->GetId()));
565 } 567 }
566 568
567 569
568 TEST(HeapSnapshotCollection) { 570 TEST(HeapSnapshotCollection) {
569 LocalContext env; 571 LocalContext env;
570 v8::HandleScope scope(env->GetIsolate()); 572 v8::HandleScope scope(env->GetIsolate());
571 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 573 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
572 574
573 CompileRun( 575 CompileRun(
574 "k = {}; v = {}; s = 'str';\n" 576 "k = {}; v = {}; s = 'str';\n"
575 "set = new Set(); set.add(k); set.add(v); set[s] = s;\n" 577 "set = new Set(); set.add(k); set.add(v); set[s] = s;\n"
576 "map = new Map(); map.set(k, v); map[s] = s;\n"); 578 "map = new Map(); map.set(k, v); map[s] = s;\n");
577 const v8::HeapSnapshot* snapshot = 579 const v8::HeapSnapshot* snapshot =
578 heap_profiler->TakeHeapSnapshot(v8_str("Collections")); 580 heap_profiler->TakeHeapSnapshot(v8_str("Collections"));
579 CHECK(ValidateSnapshot(snapshot)); 581 CHECK(ValidateSnapshot(snapshot));
580 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 582 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
581 const v8::HeapGraphNode* k = 583 const v8::HeapGraphNode* k =
582 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); 584 GetProperty(global, v8::HeapGraphEdge::kProperty, "k");
583 CHECK(k); 585 CHECK_NE(NULL, k);
584 const v8::HeapGraphNode* v = 586 const v8::HeapGraphNode* v =
585 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); 587 GetProperty(global, v8::HeapGraphEdge::kProperty, "v");
586 CHECK(v); 588 CHECK_NE(NULL, v);
587 const v8::HeapGraphNode* s = 589 const v8::HeapGraphNode* s =
588 GetProperty(global, v8::HeapGraphEdge::kProperty, "s"); 590 GetProperty(global, v8::HeapGraphEdge::kProperty, "s");
589 CHECK(s); 591 CHECK_NE(NULL, s);
590 592
591 const v8::HeapGraphNode* set = 593 const v8::HeapGraphNode* set =
592 GetProperty(global, v8::HeapGraphEdge::kProperty, "set"); 594 GetProperty(global, v8::HeapGraphEdge::kProperty, "set");
593 CHECK(set); 595 CHECK_NE(NULL, set);
594 CHECK_EQ(v8::HeapGraphNode::kObject, set->GetType()); 596 CHECK_EQ(v8::HeapGraphNode::kObject, set->GetType());
595 CHECK(v8_str("Set")->Equals(set->GetName())); 597 CHECK_EQ(v8_str("Set"), set->GetName());
596 598
597 const v8::HeapGraphNode* set_table = 599 const v8::HeapGraphNode* set_table =
598 GetProperty(set, v8::HeapGraphEdge::kInternal, "table"); 600 GetProperty(set, v8::HeapGraphEdge::kInternal, "table");
599 CHECK_EQ(v8::HeapGraphNode::kArray, set_table->GetType()); 601 CHECK_EQ(v8::HeapGraphNode::kArray, set_table->GetType());
600 CHECK_GT(set_table->GetChildrenCount(), 0); 602 CHECK_GT(set_table->GetChildrenCount(), 0);
601 int entries = 0; 603 int entries = 0;
602 for (int i = 0, count = set_table->GetChildrenCount(); i < count; ++i) { 604 for (int i = 0, count = set_table->GetChildrenCount(); i < count; ++i) {
603 const v8::HeapGraphEdge* prop = set_table->GetChild(i); 605 const v8::HeapGraphEdge* prop = set_table->GetChild(i);
604 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); 606 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId();
605 if (to_node_id == k->GetId() || to_node_id == v->GetId()) { 607 if (to_node_id == k->GetId() || to_node_id == v->GetId()) {
606 ++entries; 608 ++entries;
607 } 609 }
608 } 610 }
609 CHECK_EQ(2, entries); 611 CHECK_EQ(2, entries);
610 const v8::HeapGraphNode* set_s = 612 const v8::HeapGraphNode* set_s =
611 GetProperty(set, v8::HeapGraphEdge::kProperty, "str"); 613 GetProperty(set, v8::HeapGraphEdge::kProperty, "str");
612 CHECK(set_s); 614 CHECK_NE(NULL, set_s);
613 CHECK_EQ(s->GetId(), set_s->GetId()); 615 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(set_s->GetId()));
614 616
615 const v8::HeapGraphNode* map = 617 const v8::HeapGraphNode* map =
616 GetProperty(global, v8::HeapGraphEdge::kProperty, "map"); 618 GetProperty(global, v8::HeapGraphEdge::kProperty, "map");
617 CHECK(map); 619 CHECK_NE(NULL, map);
618 CHECK_EQ(v8::HeapGraphNode::kObject, map->GetType()); 620 CHECK_EQ(v8::HeapGraphNode::kObject, map->GetType());
619 CHECK(v8_str("Map")->Equals(map->GetName())); 621 CHECK_EQ(v8_str("Map"), map->GetName());
620 622
621 const v8::HeapGraphNode* map_table = 623 const v8::HeapGraphNode* map_table =
622 GetProperty(map, v8::HeapGraphEdge::kInternal, "table"); 624 GetProperty(map, v8::HeapGraphEdge::kInternal, "table");
623 CHECK_EQ(v8::HeapGraphNode::kArray, map_table->GetType()); 625 CHECK_EQ(v8::HeapGraphNode::kArray, map_table->GetType());
624 CHECK_GT(map_table->GetChildrenCount(), 0); 626 CHECK_GT(map_table->GetChildrenCount(), 0);
625 entries = 0; 627 entries = 0;
626 for (int i = 0, count = map_table->GetChildrenCount(); i < count; ++i) { 628 for (int i = 0, count = map_table->GetChildrenCount(); i < count; ++i) {
627 const v8::HeapGraphEdge* prop = map_table->GetChild(i); 629 const v8::HeapGraphEdge* prop = map_table->GetChild(i);
628 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); 630 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId();
629 if (to_node_id == k->GetId() || to_node_id == v->GetId()) { 631 if (to_node_id == k->GetId() || to_node_id == v->GetId()) {
630 ++entries; 632 ++entries;
631 } 633 }
632 } 634 }
633 CHECK_EQ(2, entries); 635 CHECK_EQ(2, entries);
634 const v8::HeapGraphNode* map_s = 636 const v8::HeapGraphNode* map_s =
635 GetProperty(map, v8::HeapGraphEdge::kProperty, "str"); 637 GetProperty(map, v8::HeapGraphEdge::kProperty, "str");
636 CHECK(map_s); 638 CHECK_NE(NULL, map_s);
637 CHECK_EQ(s->GetId(), map_s->GetId()); 639 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(map_s->GetId()));
638 } 640 }
639 641
640 642
641 TEST(HeapSnapshotInternalReferences) { 643 TEST(HeapSnapshotInternalReferences) {
642 v8::Isolate* isolate = CcTest::isolate(); 644 v8::Isolate* isolate = CcTest::isolate();
643 v8::HandleScope scope(isolate); 645 v8::HandleScope scope(isolate);
644 v8::Local<v8::ObjectTemplate> global_template = 646 v8::Local<v8::ObjectTemplate> global_template =
645 v8::ObjectTemplate::New(isolate); 647 v8::ObjectTemplate::New(isolate);
646 global_template->SetInternalFieldCount(2); 648 global_template->SetInternalFieldCount(2);
647 LocalContext env(NULL, global_template); 649 LocalContext env(NULL, global_template);
648 v8::Handle<v8::Object> global_proxy = env->Global(); 650 v8::Handle<v8::Object> global_proxy = env->Global();
649 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 651 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
650 CHECK_EQ(2, global->InternalFieldCount()); 652 CHECK_EQ(2, global->InternalFieldCount());
651 v8::Local<v8::Object> obj = v8::Object::New(isolate); 653 v8::Local<v8::Object> obj = v8::Object::New(isolate);
652 global->SetInternalField(0, v8_num(17)); 654 global->SetInternalField(0, v8_num(17));
653 global->SetInternalField(1, obj); 655 global->SetInternalField(1, obj);
654 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 656 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
655 const v8::HeapSnapshot* snapshot = 657 const v8::HeapSnapshot* snapshot =
656 heap_profiler->TakeHeapSnapshot(v8_str("internals")); 658 heap_profiler->TakeHeapSnapshot(v8_str("internals"));
657 CHECK(ValidateSnapshot(snapshot)); 659 CHECK(ValidateSnapshot(snapshot));
658 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); 660 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
659 // The first reference will not present, because it's a Smi. 661 // The first reference will not present, because it's a Smi.
660 CHECK(!GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); 662 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0"));
661 // The second reference is to an object. 663 // The second reference is to an object.
662 CHECK(GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1")); 664 CHECK_NE(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1"));
663 } 665 }
664 666
665 667
668 // Trying to introduce a check helper for uint32_t causes many
669 // overloading ambiguities, so it seems easier just to cast
670 // them to a signed type.
671 #define CHECK_EQ_SNAPSHOT_OBJECT_ID(a, b) \
672 CHECK_EQ(static_cast<int32_t>(a), static_cast<int32_t>(b))
673 #define CHECK_NE_SNAPSHOT_OBJECT_ID(a, b) \
674 CHECK((a) != (b)) // NOLINT
675
666 TEST(HeapSnapshotAddressReuse) { 676 TEST(HeapSnapshotAddressReuse) {
667 LocalContext env; 677 LocalContext env;
668 v8::HandleScope scope(env->GetIsolate()); 678 v8::HandleScope scope(env->GetIsolate());
669 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 679 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
670 680
671 CompileRun( 681 CompileRun(
672 "function A() {}\n" 682 "function A() {}\n"
673 "var a = [];\n" 683 "var a = [];\n"
674 "for (var i = 0; i < 10000; ++i)\n" 684 "for (var i = 0; i < 10000; ++i)\n"
675 " a[i] = new A();\n"); 685 " a[i] = new A();\n");
676 const v8::HeapSnapshot* snapshot1 = 686 const v8::HeapSnapshot* snapshot1 =
677 heap_profiler->TakeHeapSnapshot(v8_str("snapshot1")); 687 heap_profiler->TakeHeapSnapshot(v8_str("snapshot1"));
678 CHECK(ValidateSnapshot(snapshot1)); 688 CHECK(ValidateSnapshot(snapshot1));
679 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); 689 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId();
680 690
681 CompileRun( 691 CompileRun(
682 "for (var i = 0; i < 10000; ++i)\n" 692 "for (var i = 0; i < 10000; ++i)\n"
683 " a[i] = new A();\n"); 693 " a[i] = new A();\n");
684 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 694 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
685 695
686 const v8::HeapSnapshot* snapshot2 = 696 const v8::HeapSnapshot* snapshot2 =
687 heap_profiler->TakeHeapSnapshot(v8_str("snapshot2")); 697 heap_profiler->TakeHeapSnapshot(v8_str("snapshot2"));
688 CHECK(ValidateSnapshot(snapshot2)); 698 CHECK(ValidateSnapshot(snapshot2));
689 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); 699 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
690 700
691 const v8::HeapGraphNode* array_node = 701 const v8::HeapGraphNode* array_node =
692 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); 702 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a");
693 CHECK(array_node); 703 CHECK_NE(NULL, array_node);
694 int wrong_count = 0; 704 int wrong_count = 0;
695 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) { 705 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) {
696 const v8::HeapGraphEdge* prop = array_node->GetChild(i); 706 const v8::HeapGraphEdge* prop = array_node->GetChild(i);
697 if (prop->GetType() != v8::HeapGraphEdge::kElement) 707 if (prop->GetType() != v8::HeapGraphEdge::kElement)
698 continue; 708 continue;
699 v8::SnapshotObjectId id = prop->GetToNode()->GetId(); 709 v8::SnapshotObjectId id = prop->GetToNode()->GetId();
700 if (id < maxId1) 710 if (id < maxId1)
701 ++wrong_count; 711 ++wrong_count;
702 } 712 }
703 CHECK_EQ(0, wrong_count); 713 CHECK_EQ(0, wrong_count);
(...skipping 22 matching lines...) Expand all
726 " a.shift();\n"); 736 " a.shift();\n");
727 737
728 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 738 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
729 739
730 const v8::HeapSnapshot* snapshot2 = 740 const v8::HeapSnapshot* snapshot2 =
731 heap_profiler->TakeHeapSnapshot(v8_str("s2")); 741 heap_profiler->TakeHeapSnapshot(v8_str("s2"));
732 CHECK(ValidateSnapshot(snapshot2)); 742 CHECK(ValidateSnapshot(snapshot2));
733 743
734 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); 744 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
735 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); 745 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
736 CHECK_NE(0u, global1->GetId()); 746 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId());
737 CHECK_EQ(global1->GetId(), global2->GetId()); 747 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId());
738 748
739 const v8::HeapGraphNode* a1 = 749 const v8::HeapGraphNode* a1 =
740 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a"); 750 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a");
741 CHECK(a1); 751 CHECK_NE(NULL, a1);
742 const v8::HeapGraphNode* k1 = 752 const v8::HeapGraphNode* k1 =
743 GetProperty(a1, v8::HeapGraphEdge::kInternal, "elements"); 753 GetProperty(a1, v8::HeapGraphEdge::kInternal, "elements");
744 CHECK(k1); 754 CHECK_NE(NULL, k1);
745 const v8::HeapGraphNode* a2 = 755 const v8::HeapGraphNode* a2 =
746 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); 756 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a");
747 CHECK(a2); 757 CHECK_NE(NULL, a2);
748 const v8::HeapGraphNode* k2 = 758 const v8::HeapGraphNode* k2 =
749 GetProperty(a2, v8::HeapGraphEdge::kInternal, "elements"); 759 GetProperty(a2, v8::HeapGraphEdge::kInternal, "elements");
750 CHECK(k2); 760 CHECK_NE(NULL, k2);
751 761
752 CHECK_EQ(a1->GetId(), a2->GetId()); 762 CHECK_EQ_SNAPSHOT_OBJECT_ID(a1->GetId(), a2->GetId());
753 CHECK_EQ(k1->GetId(), k2->GetId()); 763 CHECK_EQ_SNAPSHOT_OBJECT_ID(k1->GetId(), k2->GetId());
754 } 764 }
755 765
756 766
757 TEST(HeapEntryIdsAndGC) { 767 TEST(HeapEntryIdsAndGC) {
758 LocalContext env; 768 LocalContext env;
759 v8::HandleScope scope(env->GetIsolate()); 769 v8::HandleScope scope(env->GetIsolate());
760 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 770 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
761 771
762 CompileRun( 772 CompileRun(
763 "function A() {}\n" 773 "function A() {}\n"
764 "function B(x) { this.x = x; }\n" 774 "function B(x) { this.x = x; }\n"
765 "var a = new A();\n" 775 "var a = new A();\n"
766 "var b = new B(a);"); 776 "var b = new B(a);");
767 v8::Local<v8::String> s1_str = v8_str("s1"); 777 v8::Local<v8::String> s1_str = v8_str("s1");
768 v8::Local<v8::String> s2_str = v8_str("s2"); 778 v8::Local<v8::String> s2_str = v8_str("s2");
769 const v8::HeapSnapshot* snapshot1 = 779 const v8::HeapSnapshot* snapshot1 =
770 heap_profiler->TakeHeapSnapshot(s1_str); 780 heap_profiler->TakeHeapSnapshot(s1_str);
771 CHECK(ValidateSnapshot(snapshot1)); 781 CHECK(ValidateSnapshot(snapshot1));
772 782
773 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 783 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
774 784
775 const v8::HeapSnapshot* snapshot2 = 785 const v8::HeapSnapshot* snapshot2 =
776 heap_profiler->TakeHeapSnapshot(s2_str); 786 heap_profiler->TakeHeapSnapshot(s2_str);
777 CHECK(ValidateSnapshot(snapshot2)); 787 CHECK(ValidateSnapshot(snapshot2));
778 788
779 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000u); 789 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000);
780 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= 790 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <=
781 snapshot2->GetMaxSnapshotJSObjectId()); 791 snapshot2->GetMaxSnapshotJSObjectId());
782 792
783 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); 793 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
784 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); 794 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
785 CHECK_NE(0u, global1->GetId()); 795 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId());
786 CHECK_EQ(global1->GetId(), global2->GetId()); 796 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId());
787 const v8::HeapGraphNode* A1 = 797 const v8::HeapGraphNode* A1 =
788 GetProperty(global1, v8::HeapGraphEdge::kProperty, "A"); 798 GetProperty(global1, v8::HeapGraphEdge::kProperty, "A");
789 CHECK(A1); 799 CHECK_NE(NULL, A1);
790 const v8::HeapGraphNode* A2 = 800 const v8::HeapGraphNode* A2 =
791 GetProperty(global2, v8::HeapGraphEdge::kProperty, "A"); 801 GetProperty(global2, v8::HeapGraphEdge::kProperty, "A");
792 CHECK(A2); 802 CHECK_NE(NULL, A2);
793 CHECK_NE(0u, A1->GetId()); 803 CHECK_NE_SNAPSHOT_OBJECT_ID(0, A1->GetId());
794 CHECK_EQ(A1->GetId(), A2->GetId()); 804 CHECK_EQ_SNAPSHOT_OBJECT_ID(A1->GetId(), A2->GetId());
795 const v8::HeapGraphNode* B1 = 805 const v8::HeapGraphNode* B1 =
796 GetProperty(global1, v8::HeapGraphEdge::kProperty, "B"); 806 GetProperty(global1, v8::HeapGraphEdge::kProperty, "B");
797 CHECK(B1); 807 CHECK_NE(NULL, B1);
798 const v8::HeapGraphNode* B2 = 808 const v8::HeapGraphNode* B2 =
799 GetProperty(global2, v8::HeapGraphEdge::kProperty, "B"); 809 GetProperty(global2, v8::HeapGraphEdge::kProperty, "B");
800 CHECK(B2); 810 CHECK_NE(NULL, B2);
801 CHECK_NE(0u, B1->GetId()); 811 CHECK_NE_SNAPSHOT_OBJECT_ID(0, B1->GetId());
802 CHECK_EQ(B1->GetId(), B2->GetId()); 812 CHECK_EQ_SNAPSHOT_OBJECT_ID(B1->GetId(), B2->GetId());
803 const v8::HeapGraphNode* a1 = 813 const v8::HeapGraphNode* a1 =
804 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a"); 814 GetProperty(global1, v8::HeapGraphEdge::kProperty, "a");
805 CHECK(a1); 815 CHECK_NE(NULL, a1);
806 const v8::HeapGraphNode* a2 = 816 const v8::HeapGraphNode* a2 =
807 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); 817 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a");
808 CHECK(a2); 818 CHECK_NE(NULL, a2);
809 CHECK_NE(0u, a1->GetId()); 819 CHECK_NE_SNAPSHOT_OBJECT_ID(0, a1->GetId());
810 CHECK_EQ(a1->GetId(), a2->GetId()); 820 CHECK_EQ_SNAPSHOT_OBJECT_ID(a1->GetId(), a2->GetId());
811 const v8::HeapGraphNode* b1 = 821 const v8::HeapGraphNode* b1 =
812 GetProperty(global1, v8::HeapGraphEdge::kProperty, "b"); 822 GetProperty(global1, v8::HeapGraphEdge::kProperty, "b");
813 CHECK(b1); 823 CHECK_NE(NULL, b1);
814 const v8::HeapGraphNode* b2 = 824 const v8::HeapGraphNode* b2 =
815 GetProperty(global2, v8::HeapGraphEdge::kProperty, "b"); 825 GetProperty(global2, v8::HeapGraphEdge::kProperty, "b");
816 CHECK(b2); 826 CHECK_NE(NULL, b2);
817 CHECK_NE(0u, b1->GetId()); 827 CHECK_NE_SNAPSHOT_OBJECT_ID(0, b1->GetId());
818 CHECK_EQ(b1->GetId(), b2->GetId()); 828 CHECK_EQ_SNAPSHOT_OBJECT_ID(b1->GetId(), b2->GetId());
819 } 829 }
820 830
821 831
822 TEST(HeapSnapshotRootPreservedAfterSorting) { 832 TEST(HeapSnapshotRootPreservedAfterSorting) {
823 LocalContext env; 833 LocalContext env;
824 v8::HandleScope scope(env->GetIsolate()); 834 v8::HandleScope scope(env->GetIsolate());
825 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 835 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
826 const v8::HeapSnapshot* snapshot = 836 const v8::HeapSnapshot* snapshot =
827 heap_profiler->TakeHeapSnapshot(v8_str("s")); 837 heap_profiler->TakeHeapSnapshot(v8_str("s"));
828 CHECK(ValidateSnapshot(snapshot)); 838 CHECK(ValidateSnapshot(snapshot));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 int string_index = static_cast<int>( 986 int string_index = static_cast<int>(
977 nodes_array->Get(string_obj_pos + 1)->ToNumber(isolate)->Value()); 987 nodes_array->Get(string_obj_pos + 1)->ToNumber(isolate)->Value());
978 CHECK_GT(string_index, 0); 988 CHECK_GT(string_index, 0);
979 v8::Local<v8::Object> strings_array = 989 v8::Local<v8::Object> strings_array =
980 parsed_snapshot->Get(v8_str("strings"))->ToObject(isolate); 990 parsed_snapshot->Get(v8_str("strings"))->ToObject(isolate);
981 v8::Local<v8::String> string = 991 v8::Local<v8::String> string =
982 strings_array->Get(string_index)->ToString(isolate); 992 strings_array->Get(string_index)->ToString(isolate);
983 v8::Local<v8::String> ref_string = 993 v8::Local<v8::String> ref_string =
984 CompileRun(STRING_LITERAL_FOR_TEST)->ToString(isolate); 994 CompileRun(STRING_LITERAL_FOR_TEST)->ToString(isolate);
985 #undef STRING_LITERAL_FOR_TEST 995 #undef STRING_LITERAL_FOR_TEST
986 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(ref_string), 996 CHECK_EQ(*v8::String::Utf8Value(ref_string),
987 *v8::String::Utf8Value(string))); 997 *v8::String::Utf8Value(string));
988 } 998 }
989 999
990 1000
991 TEST(HeapSnapshotJSONSerializationAborting) { 1001 TEST(HeapSnapshotJSONSerializationAborting) {
992 LocalContext env; 1002 LocalContext env;
993 v8::HandleScope scope(env->GetIsolate()); 1003 v8::HandleScope scope(env->GetIsolate());
994 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1004 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
995 const v8::HeapSnapshot* snapshot = 1005 const v8::HeapSnapshot* snapshot =
996 heap_profiler->TakeHeapSnapshot(v8_str("abort")); 1006 heap_profiler->TakeHeapSnapshot(v8_str("abort"));
997 CHECK(ValidateSnapshot(snapshot)); 1007 CHECK(ValidateSnapshot(snapshot));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 1093 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
1084 } 1094 }
1085 1095
1086 v8::SnapshotObjectId initial_id; 1096 v8::SnapshotObjectId initial_id;
1087 { 1097 {
1088 // Single chunk of data expected in update. Initial data. 1098 // Single chunk of data expected in update. Initial data.
1089 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler, 1099 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler,
1090 &initial_id); 1100 &initial_id);
1091 CHECK_EQ(1, stats_update.intervals_count()); 1101 CHECK_EQ(1, stats_update.intervals_count());
1092 CHECK_EQ(1, stats_update.updates_written()); 1102 CHECK_EQ(1, stats_update.updates_written());
1093 CHECK_LT(0u, stats_update.entries_size()); 1103 CHECK_LT(0, stats_update.entries_size());
1094 CHECK_EQ(0, stats_update.first_interval_index()); 1104 CHECK_EQ(0, stats_update.first_interval_index());
1095 } 1105 }
1096 1106
1097 // No data expected in update because nothing has happened. 1107 // No data expected in update because nothing has happened.
1098 v8::SnapshotObjectId same_id; 1108 v8::SnapshotObjectId same_id;
1099 CHECK_EQ(0, GetHeapStatsUpdate(heap_profiler, &same_id).updates_written()); 1109 CHECK_EQ(0, GetHeapStatsUpdate(heap_profiler, &same_id).updates_written());
1100 CHECK_EQ(initial_id, same_id); 1110 CHECK_EQ_SNAPSHOT_OBJECT_ID(initial_id, same_id);
1101 1111
1102 { 1112 {
1103 v8::SnapshotObjectId additional_string_id; 1113 v8::SnapshotObjectId additional_string_id;
1104 v8::HandleScope inner_scope_1(env->GetIsolate()); 1114 v8::HandleScope inner_scope_1(env->GetIsolate());
1105 v8_str("string1"); 1115 v8_str("string1");
1106 { 1116 {
1107 // Single chunk of data with one new entry expected in update. 1117 // Single chunk of data with one new entry expected in update.
1108 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler, 1118 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler,
1109 &additional_string_id); 1119 &additional_string_id);
1110 CHECK_LT(same_id, additional_string_id); 1120 CHECK_LT(same_id, additional_string_id);
1111 CHECK_EQ(1, stats_update.intervals_count()); 1121 CHECK_EQ(1, stats_update.intervals_count());
1112 CHECK_EQ(1, stats_update.updates_written()); 1122 CHECK_EQ(1, stats_update.updates_written());
1113 CHECK_LT(0u, stats_update.entries_size()); 1123 CHECK_LT(0, stats_update.entries_size());
1114 CHECK_EQ(1u, stats_update.entries_count()); 1124 CHECK_EQ(1, stats_update.entries_count());
1115 CHECK_EQ(2, stats_update.first_interval_index()); 1125 CHECK_EQ(2, stats_update.first_interval_index());
1116 } 1126 }
1117 1127
1118 // No data expected in update because nothing happened. 1128 // No data expected in update because nothing happened.
1119 v8::SnapshotObjectId last_id; 1129 v8::SnapshotObjectId last_id;
1120 CHECK_EQ(0, GetHeapStatsUpdate(heap_profiler, &last_id).updates_written()); 1130 CHECK_EQ(0, GetHeapStatsUpdate(heap_profiler, &last_id).updates_written());
1121 CHECK_EQ(additional_string_id, last_id); 1131 CHECK_EQ_SNAPSHOT_OBJECT_ID(additional_string_id, last_id);
1122 1132
1123 { 1133 {
1124 v8::HandleScope inner_scope_2(env->GetIsolate()); 1134 v8::HandleScope inner_scope_2(env->GetIsolate());
1125 v8_str("string2"); 1135 v8_str("string2");
1126 1136
1127 uint32_t entries_size; 1137 uint32_t entries_size;
1128 { 1138 {
1129 v8::HandleScope inner_scope_3(env->GetIsolate()); 1139 v8::HandleScope inner_scope_3(env->GetIsolate());
1130 v8_str("string3"); 1140 v8_str("string3");
1131 v8_str("string4"); 1141 v8_str("string4");
1132 1142
1133 { 1143 {
1134 // Single chunk of data with three new entries expected in update. 1144 // Single chunk of data with three new entries expected in update.
1135 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler); 1145 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
1136 CHECK_EQ(1, stats_update.intervals_count()); 1146 CHECK_EQ(1, stats_update.intervals_count());
1137 CHECK_EQ(1, stats_update.updates_written()); 1147 CHECK_EQ(1, stats_update.updates_written());
1138 CHECK_LT(0u, entries_size = stats_update.entries_size()); 1148 CHECK_LT(0, entries_size = stats_update.entries_size());
1139 CHECK_EQ(3u, stats_update.entries_count()); 1149 CHECK_EQ(3, stats_update.entries_count());
1140 CHECK_EQ(4, stats_update.first_interval_index()); 1150 CHECK_EQ(4, stats_update.first_interval_index());
1141 } 1151 }
1142 } 1152 }
1143 1153
1144 { 1154 {
1145 // Single chunk of data with two left entries expected in update. 1155 // Single chunk of data with two left entries expected in update.
1146 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler); 1156 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
1147 CHECK_EQ(1, stats_update.intervals_count()); 1157 CHECK_EQ(1, stats_update.intervals_count());
1148 CHECK_EQ(1, stats_update.updates_written()); 1158 CHECK_EQ(1, stats_update.updates_written());
1149 CHECK_GT(entries_size, stats_update.entries_size()); 1159 CHECK_GT(entries_size, stats_update.entries_size());
1150 CHECK_EQ(1u, stats_update.entries_count()); 1160 CHECK_EQ(1, stats_update.entries_count());
1151 // Two strings from forth interval were released. 1161 // Two strings from forth interval were released.
1152 CHECK_EQ(4, stats_update.first_interval_index()); 1162 CHECK_EQ(4, stats_update.first_interval_index());
1153 } 1163 }
1154 } 1164 }
1155 1165
1156 { 1166 {
1157 // Single chunk of data with 0 left entries expected in update. 1167 // Single chunk of data with 0 left entries expected in update.
1158 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler); 1168 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
1159 CHECK_EQ(1, stats_update.intervals_count()); 1169 CHECK_EQ(1, stats_update.intervals_count());
1160 CHECK_EQ(1, stats_update.updates_written()); 1170 CHECK_EQ(1, stats_update.updates_written());
1161 CHECK_EQ(0u, stats_update.entries_size()); 1171 CHECK_EQ(0, stats_update.entries_size());
1162 CHECK_EQ(0u, stats_update.entries_count()); 1172 CHECK_EQ(0, stats_update.entries_count());
1163 // The last string from forth interval was released. 1173 // The last string from forth interval was released.
1164 CHECK_EQ(4, stats_update.first_interval_index()); 1174 CHECK_EQ(4, stats_update.first_interval_index());
1165 } 1175 }
1166 } 1176 }
1167 { 1177 {
1168 // Single chunk of data with 0 left entries expected in update. 1178 // Single chunk of data with 0 left entries expected in update.
1169 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler); 1179 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
1170 CHECK_EQ(1, stats_update.intervals_count()); 1180 CHECK_EQ(1, stats_update.intervals_count());
1171 CHECK_EQ(1, stats_update.updates_written()); 1181 CHECK_EQ(1, stats_update.updates_written());
1172 CHECK_EQ(0u, stats_update.entries_size()); 1182 CHECK_EQ(0, stats_update.entries_size());
1173 CHECK_EQ(0u, stats_update.entries_count()); 1183 CHECK_EQ(0, stats_update.entries_count());
1174 // The only string from the second interval was released. 1184 // The only string from the second interval was released.
1175 CHECK_EQ(2, stats_update.first_interval_index()); 1185 CHECK_EQ(2, stats_update.first_interval_index());
1176 } 1186 }
1177 1187
1178 v8::Local<v8::Array> array = v8::Array::New(env->GetIsolate()); 1188 v8::Local<v8::Array> array = v8::Array::New(env->GetIsolate());
1179 CHECK_EQ(0u, array->Length()); 1189 CHECK_EQ(0, array->Length());
1180 // Force array's buffer allocation. 1190 // Force array's buffer allocation.
1181 array->Set(2, v8_num(7)); 1191 array->Set(2, v8_num(7));
1182 1192
1183 uint32_t entries_size; 1193 uint32_t entries_size;
1184 { 1194 {
1185 // Single chunk of data with 2 entries expected in update. 1195 // Single chunk of data with 2 entries expected in update.
1186 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler); 1196 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
1187 CHECK_EQ(1, stats_update.intervals_count()); 1197 CHECK_EQ(1, stats_update.intervals_count());
1188 CHECK_EQ(1, stats_update.updates_written()); 1198 CHECK_EQ(1, stats_update.updates_written());
1189 CHECK_LT(0u, entries_size = stats_update.entries_size()); 1199 CHECK_LT(0, entries_size = stats_update.entries_size());
1190 // They are the array and its buffer. 1200 // They are the array and its buffer.
1191 CHECK_EQ(2u, stats_update.entries_count()); 1201 CHECK_EQ(2, stats_update.entries_count());
1192 CHECK_EQ(8, stats_update.first_interval_index()); 1202 CHECK_EQ(8, stats_update.first_interval_index());
1193 } 1203 }
1194 1204
1195 for (int i = 0; i < 100; ++i) 1205 for (int i = 0; i < 100; ++i)
1196 array->Set(i, v8_num(i)); 1206 array->Set(i, v8_num(i));
1197 1207
1198 { 1208 {
1199 // Single chunk of data with 1 entry expected in update. 1209 // Single chunk of data with 1 entry expected in update.
1200 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler); 1210 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
1201 CHECK_EQ(1, stats_update.intervals_count()); 1211 CHECK_EQ(1, stats_update.intervals_count());
1202 // The first interval was changed because old buffer was collected. 1212 // The first interval was changed because old buffer was collected.
1203 // The second interval was changed because new buffer was allocated. 1213 // The second interval was changed because new buffer was allocated.
1204 CHECK_EQ(2, stats_update.updates_written()); 1214 CHECK_EQ(2, stats_update.updates_written());
1205 CHECK_LT(entries_size, stats_update.entries_size()); 1215 CHECK_LT(entries_size, stats_update.entries_size());
1206 CHECK_EQ(2u, stats_update.entries_count()); 1216 CHECK_EQ(2, stats_update.entries_count());
1207 CHECK_EQ(8, stats_update.first_interval_index()); 1217 CHECK_EQ(8, stats_update.first_interval_index());
1208 } 1218 }
1209 1219
1210 heap_profiler->StopTrackingHeapObjects(); 1220 heap_profiler->StopTrackingHeapObjects();
1211 } 1221 }
1212 1222
1213 1223
1214 TEST(HeapObjectIds) { 1224 TEST(HeapObjectIds) {
1215 LocalContext env; 1225 LocalContext env;
1216 v8::Isolate* isolate = env->GetIsolate(); 1226 v8::Isolate* isolate = env->GetIsolate();
1217 v8::HandleScope scope(isolate); 1227 v8::HandleScope scope(isolate);
1218 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1228 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1219 1229
1220 const int kLength = 10; 1230 const int kLength = 10;
1221 v8::Handle<v8::Object> objects[kLength]; 1231 v8::Handle<v8::Object> objects[kLength];
1222 v8::SnapshotObjectId ids[kLength]; 1232 v8::SnapshotObjectId ids[kLength];
1223 1233
1224 heap_profiler->StartTrackingHeapObjects(false); 1234 heap_profiler->StartTrackingHeapObjects(false);
1225 1235
1226 for (int i = 0; i < kLength; i++) { 1236 for (int i = 0; i < kLength; i++) {
1227 objects[i] = v8::Object::New(isolate); 1237 objects[i] = v8::Object::New(isolate);
1228 } 1238 }
1229 GetHeapStatsUpdate(heap_profiler); 1239 GetHeapStatsUpdate(heap_profiler);
1230 1240
1231 for (int i = 0; i < kLength; i++) { 1241 for (int i = 0; i < kLength; i++) {
1232 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]); 1242 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]);
1233 CHECK_NE(v8::HeapProfiler::kUnknownObjectId, id); 1243 CHECK_NE(v8::HeapProfiler::kUnknownObjectId, static_cast<int>(id));
1234 ids[i] = id; 1244 ids[i] = id;
1235 } 1245 }
1236 1246
1237 heap_profiler->StopTrackingHeapObjects(); 1247 heap_profiler->StopTrackingHeapObjects();
1238 CcTest::heap()->CollectAllAvailableGarbage(); 1248 CcTest::heap()->CollectAllAvailableGarbage();
1239 1249
1240 for (int i = 0; i < kLength; i++) { 1250 for (int i = 0; i < kLength; i++) {
1241 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]); 1251 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]);
1242 CHECK_EQ(ids[i], id); 1252 CHECK_EQ(static_cast<int>(ids[i]), static_cast<int>(id));
1243 v8::Handle<v8::Value> obj = heap_profiler->FindObjectById(ids[i]); 1253 v8::Handle<v8::Value> obj = heap_profiler->FindObjectById(ids[i]);
1244 CHECK(objects[i]->Equals(obj)); 1254 CHECK_EQ(objects[i], obj);
1245 } 1255 }
1246 1256
1247 heap_profiler->ClearObjectIds(); 1257 heap_profiler->ClearObjectIds();
1248 for (int i = 0; i < kLength; i++) { 1258 for (int i = 0; i < kLength; i++) {
1249 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]); 1259 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]);
1250 CHECK_EQ(v8::HeapProfiler::kUnknownObjectId, id); 1260 CHECK_EQ(v8::HeapProfiler::kUnknownObjectId, static_cast<int>(id));
1251 v8::Handle<v8::Value> obj = heap_profiler->FindObjectById(ids[i]); 1261 v8::Handle<v8::Value> obj = heap_profiler->FindObjectById(ids[i]);
1252 CHECK(obj.IsEmpty()); 1262 CHECK(obj.IsEmpty());
1253 } 1263 }
1254 } 1264 }
1255 1265
1256 1266
1257 static void CheckChildrenIds(const v8::HeapSnapshot* snapshot, 1267 static void CheckChildrenIds(const v8::HeapSnapshot* snapshot,
1258 const v8::HeapGraphNode* node, 1268 const v8::HeapGraphNode* node,
1259 int level, int max_level) { 1269 int level, int max_level) {
1260 if (level > max_level) return; 1270 if (level > max_level) return;
1261 CHECK_EQ(node, snapshot->GetNodeById(node->GetId())); 1271 CHECK_EQ(node, snapshot->GetNodeById(node->GetId()));
1262 for (int i = 0, count = node->GetChildrenCount(); i < count; ++i) { 1272 for (int i = 0, count = node->GetChildrenCount(); i < count; ++i) {
1263 const v8::HeapGraphEdge* prop = node->GetChild(i); 1273 const v8::HeapGraphEdge* prop = node->GetChild(i);
1264 const v8::HeapGraphNode* child = 1274 const v8::HeapGraphNode* child =
1265 snapshot->GetNodeById(prop->GetToNode()->GetId()); 1275 snapshot->GetNodeById(prop->GetToNode()->GetId());
1266 CHECK_EQ(prop->GetToNode()->GetId(), child->GetId()); 1276 CHECK_EQ_SNAPSHOT_OBJECT_ID(prop->GetToNode()->GetId(), child->GetId());
1267 CHECK_EQ(prop->GetToNode(), child); 1277 CHECK_EQ(prop->GetToNode(), child);
1268 CheckChildrenIds(snapshot, child, level + 1, max_level); 1278 CheckChildrenIds(snapshot, child, level + 1, max_level);
1269 } 1279 }
1270 } 1280 }
1271 1281
1272 1282
1273 TEST(HeapSnapshotGetNodeById) { 1283 TEST(HeapSnapshotGetNodeById) {
1274 LocalContext env; 1284 LocalContext env;
1275 v8::HandleScope scope(env->GetIsolate()); 1285 v8::HandleScope scope(env->GetIsolate());
1276 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1286 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1277 1287
1278 const v8::HeapSnapshot* snapshot = 1288 const v8::HeapSnapshot* snapshot =
1279 heap_profiler->TakeHeapSnapshot(v8_str("id")); 1289 heap_profiler->TakeHeapSnapshot(v8_str("id"));
1280 CHECK(ValidateSnapshot(snapshot)); 1290 CHECK(ValidateSnapshot(snapshot));
1281 const v8::HeapGraphNode* root = snapshot->GetRoot(); 1291 const v8::HeapGraphNode* root = snapshot->GetRoot();
1282 CheckChildrenIds(snapshot, root, 0, 3); 1292 CheckChildrenIds(snapshot, root, 0, 3);
1283 // Check a big id, which should not exist yet. 1293 // Check a big id, which should not exist yet.
1284 CHECK(!snapshot->GetNodeById(0x1000000UL)); 1294 CHECK_EQ(NULL, snapshot->GetNodeById(0x1000000UL));
1285 } 1295 }
1286 1296
1287 1297
1288 TEST(HeapSnapshotGetSnapshotObjectId) { 1298 TEST(HeapSnapshotGetSnapshotObjectId) {
1289 LocalContext env; 1299 LocalContext env;
1290 v8::HandleScope scope(env->GetIsolate()); 1300 v8::HandleScope scope(env->GetIsolate());
1291 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1301 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1292 CompileRun("globalObject = {};\n"); 1302 CompileRun("globalObject = {};\n");
1293 const v8::HeapSnapshot* snapshot = 1303 const v8::HeapSnapshot* snapshot =
1294 heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id")); 1304 heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id"));
1295 CHECK(ValidateSnapshot(snapshot)); 1305 CHECK(ValidateSnapshot(snapshot));
1296 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1306 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1297 const v8::HeapGraphNode* global_object = 1307 const v8::HeapGraphNode* global_object =
1298 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject"); 1308 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject");
1299 CHECK(global_object); 1309 CHECK(global_object);
1300 1310
1301 v8::Local<v8::Value> globalObjectHandle = env->Global()->Get( 1311 v8::Local<v8::Value> globalObjectHandle = env->Global()->Get(
1302 v8::String::NewFromUtf8(env->GetIsolate(), "globalObject")); 1312 v8::String::NewFromUtf8(env->GetIsolate(), "globalObject"));
1303 CHECK(!globalObjectHandle.IsEmpty()); 1313 CHECK(!globalObjectHandle.IsEmpty());
1304 CHECK(globalObjectHandle->IsObject()); 1314 CHECK(globalObjectHandle->IsObject());
1305 1315
1306 v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle); 1316 v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle);
1307 CHECK_NE(v8::HeapProfiler::kUnknownObjectId, id); 1317 CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId),
1308 CHECK_EQ(id, global_object->GetId()); 1318 id);
1319 CHECK_EQ(static_cast<int>(id), global_object->GetId());
1309 } 1320 }
1310 1321
1311 1322
1312 TEST(HeapSnapshotUnknownSnapshotObjectId) { 1323 TEST(HeapSnapshotUnknownSnapshotObjectId) {
1313 LocalContext env; 1324 LocalContext env;
1314 v8::HandleScope scope(env->GetIsolate()); 1325 v8::HandleScope scope(env->GetIsolate());
1315 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1326 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1316 CompileRun("globalObject = {};\n"); 1327 CompileRun("globalObject = {};\n");
1317 const v8::HeapSnapshot* snapshot = 1328 const v8::HeapSnapshot* snapshot =
1318 heap_profiler->TakeHeapSnapshot(v8_str("unknown_object_id")); 1329 heap_profiler->TakeHeapSnapshot(v8_str("unknown_object_id"));
1319 CHECK(ValidateSnapshot(snapshot)); 1330 CHECK(ValidateSnapshot(snapshot));
1320 const v8::HeapGraphNode* node = 1331 const v8::HeapGraphNode* node =
1321 snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId); 1332 snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId);
1322 CHECK(!node); 1333 CHECK_EQ(NULL, node);
1323 } 1334 }
1324 1335
1325 1336
1326 namespace { 1337 namespace {
1327 1338
1328 class TestActivityControl : public v8::ActivityControl { 1339 class TestActivityControl : public v8::ActivityControl {
1329 public: 1340 public:
1330 explicit TestActivityControl(int abort_count) 1341 explicit TestActivityControl(int abort_count)
1331 : done_(0), total_(0), abort_count_(abort_count) {} 1342 : done_(0), total_(0), abort_count_(abort_count) {}
1332 ControlOption ReportProgressValue(int done, int total) { 1343 ControlOption ReportProgressValue(int done, int total) {
(...skipping 15 matching lines...) Expand all
1348 TEST(TakeHeapSnapshotAborting) { 1359 TEST(TakeHeapSnapshotAborting) {
1349 LocalContext env; 1360 LocalContext env;
1350 v8::HandleScope scope(env->GetIsolate()); 1361 v8::HandleScope scope(env->GetIsolate());
1351 1362
1352 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1363 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1353 const int snapshots_count = heap_profiler->GetSnapshotCount(); 1364 const int snapshots_count = heap_profiler->GetSnapshotCount();
1354 TestActivityControl aborting_control(1); 1365 TestActivityControl aborting_control(1);
1355 const v8::HeapSnapshot* no_snapshot = 1366 const v8::HeapSnapshot* no_snapshot =
1356 heap_profiler->TakeHeapSnapshot(v8_str("abort"), 1367 heap_profiler->TakeHeapSnapshot(v8_str("abort"),
1357 &aborting_control); 1368 &aborting_control);
1358 CHECK(!no_snapshot); 1369 CHECK_EQ(NULL, no_snapshot);
1359 CHECK_EQ(snapshots_count, heap_profiler->GetSnapshotCount()); 1370 CHECK_EQ(snapshots_count, heap_profiler->GetSnapshotCount());
1360 CHECK_GT(aborting_control.total(), aborting_control.done()); 1371 CHECK_GT(aborting_control.total(), aborting_control.done());
1361 1372
1362 TestActivityControl control(-1); // Don't abort. 1373 TestActivityControl control(-1); // Don't abort.
1363 const v8::HeapSnapshot* snapshot = 1374 const v8::HeapSnapshot* snapshot =
1364 heap_profiler->TakeHeapSnapshot(v8_str("full"), 1375 heap_profiler->TakeHeapSnapshot(v8_str("full"),
1365 &control); 1376 &control);
1366 CHECK(ValidateSnapshot(snapshot)); 1377 CHECK(ValidateSnapshot(snapshot));
1367 1378
1368 CHECK(snapshot); 1379 CHECK_NE(NULL, snapshot);
1369 CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount()); 1380 CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount());
1370 CHECK_EQ(control.total(), control.done()); 1381 CHECK_EQ(control.total(), control.done());
1371 CHECK_GT(control.total(), 0); 1382 CHECK_GT(control.total(), 0);
1372 } 1383 }
1373 1384
1374 1385
1375 namespace { 1386 namespace {
1376 1387
1377 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { 1388 class TestRetainedObjectInfo : public v8::RetainedObjectInfo {
1378 public: 1389 public:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 CHECK(ValidateSnapshot(snapshot)); 1489 CHECK(ValidateSnapshot(snapshot));
1479 1490
1480 CHECK_EQ(3, TestRetainedObjectInfo::instances.length()); 1491 CHECK_EQ(3, TestRetainedObjectInfo::instances.length());
1481 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) { 1492 for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) {
1482 CHECK(TestRetainedObjectInfo::instances[i]->disposed()); 1493 CHECK(TestRetainedObjectInfo::instances[i]->disposed());
1483 delete TestRetainedObjectInfo::instances[i]; 1494 delete TestRetainedObjectInfo::instances[i];
1484 } 1495 }
1485 1496
1486 const v8::HeapGraphNode* native_group_aaa = GetNode( 1497 const v8::HeapGraphNode* native_group_aaa = GetNode(
1487 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "aaa-group"); 1498 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "aaa-group");
1488 CHECK(native_group_aaa); 1499 CHECK_NE(NULL, native_group_aaa);
1489 CHECK_EQ(1, native_group_aaa->GetChildrenCount()); 1500 CHECK_EQ(1, native_group_aaa->GetChildrenCount());
1490 const v8::HeapGraphNode* aaa = GetNode( 1501 const v8::HeapGraphNode* aaa = GetNode(
1491 native_group_aaa, v8::HeapGraphNode::kNative, "aaa / 100 entries"); 1502 native_group_aaa, v8::HeapGraphNode::kNative, "aaa / 100 entries");
1492 CHECK(aaa); 1503 CHECK_NE(NULL, aaa);
1493 CHECK_EQ(2, aaa->GetChildrenCount()); 1504 CHECK_EQ(2, aaa->GetChildrenCount());
1494 1505
1495 const v8::HeapGraphNode* native_group_ccc = GetNode( 1506 const v8::HeapGraphNode* native_group_ccc = GetNode(
1496 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "ccc-group"); 1507 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "ccc-group");
1497 const v8::HeapGraphNode* ccc = GetNode( 1508 const v8::HeapGraphNode* ccc = GetNode(
1498 native_group_ccc, v8::HeapGraphNode::kNative, "ccc"); 1509 native_group_ccc, v8::HeapGraphNode::kNative, "ccc");
1499 CHECK(ccc); 1510 CHECK_NE(NULL, ccc);
1500 1511
1501 const v8::HeapGraphNode* n_AAA = GetNode( 1512 const v8::HeapGraphNode* n_AAA = GetNode(
1502 aaa, v8::HeapGraphNode::kString, "AAA"); 1513 aaa, v8::HeapGraphNode::kString, "AAA");
1503 CHECK(n_AAA); 1514 CHECK_NE(NULL, n_AAA);
1504 const v8::HeapGraphNode* n_BBB = GetNode( 1515 const v8::HeapGraphNode* n_BBB = GetNode(
1505 aaa, v8::HeapGraphNode::kString, "BBB"); 1516 aaa, v8::HeapGraphNode::kString, "BBB");
1506 CHECK(n_BBB); 1517 CHECK_NE(NULL, n_BBB);
1507 CHECK_EQ(1, ccc->GetChildrenCount()); 1518 CHECK_EQ(1, ccc->GetChildrenCount());
1508 const v8::HeapGraphNode* n_CCC = GetNode( 1519 const v8::HeapGraphNode* n_CCC = GetNode(
1509 ccc, v8::HeapGraphNode::kString, "CCC"); 1520 ccc, v8::HeapGraphNode::kString, "CCC");
1510 CHECK(n_CCC); 1521 CHECK_NE(NULL, n_CCC);
1511 1522
1512 CHECK_EQ(aaa, GetProperty(n_AAA, v8::HeapGraphEdge::kInternal, "native")); 1523 CHECK_EQ(aaa, GetProperty(n_AAA, v8::HeapGraphEdge::kInternal, "native"));
1513 CHECK_EQ(aaa, GetProperty(n_BBB, v8::HeapGraphEdge::kInternal, "native")); 1524 CHECK_EQ(aaa, GetProperty(n_BBB, v8::HeapGraphEdge::kInternal, "native"));
1514 CHECK_EQ(ccc, GetProperty(n_CCC, v8::HeapGraphEdge::kInternal, "native")); 1525 CHECK_EQ(ccc, GetProperty(n_CCC, v8::HeapGraphEdge::kInternal, "native"));
1515 } 1526 }
1516 1527
1517 1528
1518 class GraphWithImplicitRefs { 1529 class GraphWithImplicitRefs {
1519 public: 1530 public:
1520 static const int kObjectsCount = 4; 1531 static const int kObjectsCount = 4;
1521 explicit GraphWithImplicitRefs(LocalContext* env) { 1532 explicit GraphWithImplicitRefs(LocalContext* env) {
1522 CHECK(!instance_); 1533 CHECK_EQ(NULL, instance_);
1523 instance_ = this; 1534 instance_ = this;
1524 isolate_ = (*env)->GetIsolate(); 1535 isolate_ = (*env)->GetIsolate();
1525 for (int i = 0; i < kObjectsCount; i++) { 1536 for (int i = 0; i < kObjectsCount; i++) {
1526 objects_[i].Reset(isolate_, v8::Object::New(isolate_)); 1537 objects_[i].Reset(isolate_, v8::Object::New(isolate_));
1527 } 1538 }
1528 (*env)->Global()->Set(v8_str("root_object"), 1539 (*env)->Global()->Set(v8_str("root_object"),
1529 v8::Local<v8::Value>::New(isolate_, objects_[0])); 1540 v8::Local<v8::Value>::New(isolate_, objects_[0]));
1530 } 1541 }
1531 ~GraphWithImplicitRefs() { 1542 ~GraphWithImplicitRefs() {
1532 instance_ = NULL; 1543 instance_ = NULL;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 1604
1594 1605
1595 TEST(DeleteAllHeapSnapshots) { 1606 TEST(DeleteAllHeapSnapshots) {
1596 LocalContext env; 1607 LocalContext env;
1597 v8::HandleScope scope(env->GetIsolate()); 1608 v8::HandleScope scope(env->GetIsolate());
1598 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1609 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1599 1610
1600 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); 1611 CHECK_EQ(0, heap_profiler->GetSnapshotCount());
1601 heap_profiler->DeleteAllHeapSnapshots(); 1612 heap_profiler->DeleteAllHeapSnapshots();
1602 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); 1613 CHECK_EQ(0, heap_profiler->GetSnapshotCount());
1603 CHECK(heap_profiler->TakeHeapSnapshot(v8_str("1"))); 1614 CHECK_NE(NULL, heap_profiler->TakeHeapSnapshot(v8_str("1")));
1604 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); 1615 CHECK_EQ(1, heap_profiler->GetSnapshotCount());
1605 heap_profiler->DeleteAllHeapSnapshots(); 1616 heap_profiler->DeleteAllHeapSnapshots();
1606 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); 1617 CHECK_EQ(0, heap_profiler->GetSnapshotCount());
1607 CHECK(heap_profiler->TakeHeapSnapshot(v8_str("1"))); 1618 CHECK_NE(NULL, heap_profiler->TakeHeapSnapshot(v8_str("1")));
1608 CHECK(heap_profiler->TakeHeapSnapshot(v8_str("2"))); 1619 CHECK_NE(NULL, heap_profiler->TakeHeapSnapshot(v8_str("2")));
1609 CHECK_EQ(2, heap_profiler->GetSnapshotCount()); 1620 CHECK_EQ(2, heap_profiler->GetSnapshotCount());
1610 heap_profiler->DeleteAllHeapSnapshots(); 1621 heap_profiler->DeleteAllHeapSnapshots();
1611 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); 1622 CHECK_EQ(0, heap_profiler->GetSnapshotCount());
1612 } 1623 }
1613 1624
1614 1625
1615 static const v8::HeapSnapshot* FindHeapSnapshot(v8::HeapProfiler* profiler, 1626 static const v8::HeapSnapshot* FindHeapSnapshot(v8::HeapProfiler* profiler,
1616 unsigned uid) { 1627 unsigned uid) {
1617 int length = profiler->GetSnapshotCount(); 1628 int length = profiler->GetSnapshotCount();
1618 for (int i = 0; i < length; i++) { 1629 for (int i = 0; i < length; i++) {
1619 const v8::HeapSnapshot* snapshot = profiler->GetHeapSnapshot(i); 1630 const v8::HeapSnapshot* snapshot = profiler->GetHeapSnapshot(i);
1620 if (snapshot->GetUid() == uid) { 1631 if (snapshot->GetUid() == uid) {
1621 return snapshot; 1632 return snapshot;
1622 } 1633 }
1623 } 1634 }
1624 return NULL; 1635 return NULL;
1625 } 1636 }
1626 1637
1627 1638
1628 TEST(DeleteHeapSnapshot) { 1639 TEST(DeleteHeapSnapshot) {
1629 LocalContext env; 1640 LocalContext env;
1630 v8::HandleScope scope(env->GetIsolate()); 1641 v8::HandleScope scope(env->GetIsolate());
1631 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1642 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1632 1643
1633 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); 1644 CHECK_EQ(0, heap_profiler->GetSnapshotCount());
1634 const v8::HeapSnapshot* s1 = 1645 const v8::HeapSnapshot* s1 =
1635 heap_profiler->TakeHeapSnapshot(v8_str("1")); 1646 heap_profiler->TakeHeapSnapshot(v8_str("1"));
1636 1647
1637 CHECK(s1); 1648 CHECK_NE(NULL, s1);
1638 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); 1649 CHECK_EQ(1, heap_profiler->GetSnapshotCount());
1639 unsigned uid1 = s1->GetUid(); 1650 unsigned uid1 = s1->GetUid();
1640 CHECK_EQ(s1, FindHeapSnapshot(heap_profiler, uid1)); 1651 CHECK_EQ(s1, FindHeapSnapshot(heap_profiler, uid1));
1641 const_cast<v8::HeapSnapshot*>(s1)->Delete(); 1652 const_cast<v8::HeapSnapshot*>(s1)->Delete();
1642 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); 1653 CHECK_EQ(0, heap_profiler->GetSnapshotCount());
1643 CHECK(!FindHeapSnapshot(heap_profiler, uid1)); 1654 CHECK_EQ(NULL, FindHeapSnapshot(heap_profiler, uid1));
1644 1655
1645 const v8::HeapSnapshot* s2 = 1656 const v8::HeapSnapshot* s2 =
1646 heap_profiler->TakeHeapSnapshot(v8_str("2")); 1657 heap_profiler->TakeHeapSnapshot(v8_str("2"));
1647 CHECK(s2); 1658 CHECK_NE(NULL, s2);
1648 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); 1659 CHECK_EQ(1, heap_profiler->GetSnapshotCount());
1649 unsigned uid2 = s2->GetUid(); 1660 unsigned uid2 = s2->GetUid();
1650 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); 1661 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
1651 CHECK_EQ(s2, FindHeapSnapshot(heap_profiler, uid2)); 1662 CHECK_EQ(s2, FindHeapSnapshot(heap_profiler, uid2));
1652 const v8::HeapSnapshot* s3 = 1663 const v8::HeapSnapshot* s3 =
1653 heap_profiler->TakeHeapSnapshot(v8_str("3")); 1664 heap_profiler->TakeHeapSnapshot(v8_str("3"));
1654 CHECK(s3); 1665 CHECK_NE(NULL, s3);
1655 CHECK_EQ(2, heap_profiler->GetSnapshotCount()); 1666 CHECK_EQ(2, heap_profiler->GetSnapshotCount());
1656 unsigned uid3 = s3->GetUid(); 1667 unsigned uid3 = s3->GetUid();
1657 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); 1668 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
1658 CHECK_EQ(s3, FindHeapSnapshot(heap_profiler, uid3)); 1669 CHECK_EQ(s3, FindHeapSnapshot(heap_profiler, uid3));
1659 const_cast<v8::HeapSnapshot*>(s2)->Delete(); 1670 const_cast<v8::HeapSnapshot*>(s2)->Delete();
1660 CHECK_EQ(1, heap_profiler->GetSnapshotCount()); 1671 CHECK_EQ(1, heap_profiler->GetSnapshotCount());
1661 CHECK(!FindHeapSnapshot(heap_profiler, uid2)); 1672 CHECK_EQ(NULL, FindHeapSnapshot(heap_profiler, uid2));
1662 CHECK_EQ(s3, FindHeapSnapshot(heap_profiler, uid3)); 1673 CHECK_EQ(s3, FindHeapSnapshot(heap_profiler, uid3));
1663 const_cast<v8::HeapSnapshot*>(s3)->Delete(); 1674 const_cast<v8::HeapSnapshot*>(s3)->Delete();
1664 CHECK_EQ(0, heap_profiler->GetSnapshotCount()); 1675 CHECK_EQ(0, heap_profiler->GetSnapshotCount());
1665 CHECK(!FindHeapSnapshot(heap_profiler, uid3)); 1676 CHECK_EQ(NULL, FindHeapSnapshot(heap_profiler, uid3));
1666 } 1677 }
1667 1678
1668 1679
1669 class NameResolver : public v8::HeapProfiler::ObjectNameResolver { 1680 class NameResolver : public v8::HeapProfiler::ObjectNameResolver {
1670 public: 1681 public:
1671 virtual const char* GetName(v8::Handle<v8::Object> object) { 1682 virtual const char* GetName(v8::Handle<v8::Object> object) {
1672 return "Global object name"; 1683 return "Global object name";
1673 } 1684 }
1674 }; 1685 };
1675 1686
1676 1687
1677 TEST(GlobalObjectName) { 1688 TEST(GlobalObjectName) {
1678 LocalContext env; 1689 LocalContext env;
1679 v8::HandleScope scope(env->GetIsolate()); 1690 v8::HandleScope scope(env->GetIsolate());
1680 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1691 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1681 1692
1682 CompileRun("document = { URL:\"abcdefgh\" };"); 1693 CompileRun("document = { URL:\"abcdefgh\" };");
1683 1694
1684 NameResolver name_resolver; 1695 NameResolver name_resolver;
1685 const v8::HeapSnapshot* snapshot = 1696 const v8::HeapSnapshot* snapshot =
1686 heap_profiler->TakeHeapSnapshot(v8_str("document"), 1697 heap_profiler->TakeHeapSnapshot(v8_str("document"),
1687 NULL, 1698 NULL,
1688 &name_resolver); 1699 &name_resolver);
1689 CHECK(ValidateSnapshot(snapshot)); 1700 CHECK(ValidateSnapshot(snapshot));
1690 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1701 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1691 CHECK(global); 1702 CHECK_NE(NULL, global);
1692 CHECK_EQ(0, 1703 CHECK_EQ("Object / Global object name" ,
1693 strcmp("Object / Global object name", 1704 const_cast<i::HeapEntry*>(
1694 const_cast<i::HeapEntry*>( 1705 reinterpret_cast<const i::HeapEntry*>(global))->name());
1695 reinterpret_cast<const i::HeapEntry*>(global))->name()));
1696 } 1706 }
1697 1707
1698 1708
1699 TEST(GlobalObjectFields) { 1709 TEST(GlobalObjectFields) {
1700 LocalContext env; 1710 LocalContext env;
1701 v8::HandleScope scope(env->GetIsolate()); 1711 v8::HandleScope scope(env->GetIsolate());
1702 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1712 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1703 CompileRun("obj = {};"); 1713 CompileRun("obj = {};");
1704 const v8::HeapSnapshot* snapshot = 1714 const v8::HeapSnapshot* snapshot =
1705 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 1715 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
1706 CHECK(ValidateSnapshot(snapshot)); 1716 CHECK(ValidateSnapshot(snapshot));
1707 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1717 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1708 const v8::HeapGraphNode* builtins = 1718 const v8::HeapGraphNode* builtins =
1709 GetProperty(global, v8::HeapGraphEdge::kInternal, "builtins"); 1719 GetProperty(global, v8::HeapGraphEdge::kInternal, "builtins");
1710 CHECK(builtins); 1720 CHECK_NE(NULL, builtins);
1711 const v8::HeapGraphNode* native_context = 1721 const v8::HeapGraphNode* native_context =
1712 GetProperty(global, v8::HeapGraphEdge::kInternal, "native_context"); 1722 GetProperty(global, v8::HeapGraphEdge::kInternal, "native_context");
1713 CHECK(native_context); 1723 CHECK_NE(NULL, native_context);
1714 const v8::HeapGraphNode* global_proxy = 1724 const v8::HeapGraphNode* global_proxy =
1715 GetProperty(global, v8::HeapGraphEdge::kInternal, "global_proxy"); 1725 GetProperty(global, v8::HeapGraphEdge::kInternal, "global_proxy");
1716 CHECK(global_proxy); 1726 CHECK_NE(NULL, global_proxy);
1717 } 1727 }
1718 1728
1719 1729
1720 TEST(NoHandleLeaks) { 1730 TEST(NoHandleLeaks) {
1721 LocalContext env; 1731 LocalContext env;
1722 v8::HandleScope scope(env->GetIsolate()); 1732 v8::HandleScope scope(env->GetIsolate());
1723 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1733 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1724 1734
1725 CompileRun("document = { URL:\"abcdefgh\" };"); 1735 CompileRun("document = { URL:\"abcdefgh\" };");
1726 1736
1727 v8::Handle<v8::String> name(v8_str("leakz")); 1737 v8::Handle<v8::String> name(v8_str("leakz"));
1728 i::Isolate* isolate = CcTest::i_isolate(); 1738 i::Isolate* isolate = CcTest::i_isolate();
1729 int count_before = i::HandleScope::NumberOfHandles(isolate); 1739 int count_before = i::HandleScope::NumberOfHandles(isolate);
1730 heap_profiler->TakeHeapSnapshot(name); 1740 heap_profiler->TakeHeapSnapshot(name);
1731 int count_after = i::HandleScope::NumberOfHandles(isolate); 1741 int count_after = i::HandleScope::NumberOfHandles(isolate);
1732 CHECK_EQ(count_before, count_after); 1742 CHECK_EQ(count_before, count_after);
1733 } 1743 }
1734 1744
1735 1745
1736 TEST(NodesIteration) { 1746 TEST(NodesIteration) {
1737 LocalContext env; 1747 LocalContext env;
1738 v8::HandleScope scope(env->GetIsolate()); 1748 v8::HandleScope scope(env->GetIsolate());
1739 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1749 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1740 const v8::HeapSnapshot* snapshot = 1750 const v8::HeapSnapshot* snapshot =
1741 heap_profiler->TakeHeapSnapshot(v8_str("iteration")); 1751 heap_profiler->TakeHeapSnapshot(v8_str("iteration"));
1742 CHECK(ValidateSnapshot(snapshot)); 1752 CHECK(ValidateSnapshot(snapshot));
1743 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1753 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1744 CHECK(global); 1754 CHECK_NE(NULL, global);
1745 // Verify that we can find this object by iteration. 1755 // Verify that we can find this object by iteration.
1746 const int nodes_count = snapshot->GetNodesCount(); 1756 const int nodes_count = snapshot->GetNodesCount();
1747 int count = 0; 1757 int count = 0;
1748 for (int i = 0; i < nodes_count; ++i) { 1758 for (int i = 0; i < nodes_count; ++i) {
1749 if (snapshot->GetNode(i) == global) 1759 if (snapshot->GetNode(i) == global)
1750 ++count; 1760 ++count;
1751 } 1761 }
1752 CHECK_EQ(1, count); 1762 CHECK_EQ(1, count);
1753 } 1763 }
1754 1764
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 " return 42;\n" 1893 " return 42;\n"
1884 "});\n" 1894 "});\n"
1885 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" 1895 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n"
1886 " return this.value_ = value;\n" 1896 " return this.value_ = value;\n"
1887 "});\n"); 1897 "});\n");
1888 const v8::HeapSnapshot* snapshot = 1898 const v8::HeapSnapshot* snapshot =
1889 heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors")); 1899 heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors"));
1890 CHECK(ValidateSnapshot(snapshot)); 1900 CHECK(ValidateSnapshot(snapshot));
1891 1901
1892 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1902 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1893 CHECK(global); 1903 CHECK_NE(NULL, global);
1894 const v8::HeapGraphNode* obj1 = 1904 const v8::HeapGraphNode* obj1 =
1895 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); 1905 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1");
1896 CHECK(obj1); 1906 CHECK_NE(NULL, obj1);
1897 const v8::HeapGraphNode* func; 1907 const v8::HeapGraphNode* func;
1898 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); 1908 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter");
1899 CHECK(func); 1909 CHECK_NE(NULL, func);
1900 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); 1910 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter");
1901 CHECK(!func); 1911 CHECK_EQ(NULL, func);
1902 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter"); 1912 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter");
1903 CHECK(func); 1913 CHECK_NE(NULL, func);
1904 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter"); 1914 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter");
1905 CHECK(!func); 1915 CHECK_EQ(NULL, func);
1906 } 1916 }
1907 1917
1908 1918
1909 TEST(FastCaseRedefinedAccessors) { 1919 TEST(FastCaseRedefinedAccessors) {
1910 LocalContext env; 1920 LocalContext env;
1911 v8::HandleScope scope(env->GetIsolate()); 1921 v8::HandleScope scope(env->GetIsolate());
1912 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1922 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1913 1923
1914 CompileRun( 1924 CompileRun(
1915 "var obj1 = {};\n" 1925 "var obj1 = {};\n"
(...skipping 12 matching lines...) Expand all
1928 v8::Local<v8::Object> js_global = 1938 v8::Local<v8::Object> js_global =
1929 env->Global()->GetPrototype().As<v8::Object>(); 1939 env->Global()->GetPrototype().As<v8::Object>();
1930 i::Handle<i::JSObject> js_obj1 = 1940 i::Handle<i::JSObject> js_obj1 =
1931 v8::Utils::OpenHandle(*js_global->Get(v8_str("obj1")).As<v8::Object>()); 1941 v8::Utils::OpenHandle(*js_global->Get(v8_str("obj1")).As<v8::Object>());
1932 USE(js_obj1); 1942 USE(js_obj1);
1933 1943
1934 const v8::HeapSnapshot* snapshot = 1944 const v8::HeapSnapshot* snapshot =
1935 heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors")); 1945 heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors"));
1936 CHECK(ValidateSnapshot(snapshot)); 1946 CHECK(ValidateSnapshot(snapshot));
1937 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1947 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1938 CHECK(global); 1948 CHECK_NE(NULL, global);
1939 const v8::HeapGraphNode* obj1 = 1949 const v8::HeapGraphNode* obj1 =
1940 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); 1950 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1");
1941 CHECK(obj1); 1951 CHECK_NE(NULL, obj1);
1942 const v8::HeapGraphNode* func; 1952 const v8::HeapGraphNode* func;
1943 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get prop"); 1953 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get prop");
1944 CHECK(func); 1954 CHECK_NE(NULL, func);
1945 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set prop"); 1955 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set prop");
1946 CHECK(func); 1956 CHECK_NE(NULL, func);
1947 } 1957 }
1948 1958
1949 1959
1950 TEST(SlowCaseAccessors) { 1960 TEST(SlowCaseAccessors) {
1951 LocalContext env; 1961 LocalContext env;
1952 v8::HandleScope scope(env->GetIsolate()); 1962 v8::HandleScope scope(env->GetIsolate());
1953 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1963 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1954 1964
1955 CompileRun("var obj1 = {};\n" 1965 CompileRun("var obj1 = {};\n"
1956 "for (var i = 0; i < 100; ++i) obj1['z' + i] = {};" 1966 "for (var i = 0; i < 100; ++i) obj1['z' + i] = {};"
1957 "obj1.__defineGetter__('propWithGetter', function Y() {\n" 1967 "obj1.__defineGetter__('propWithGetter', function Y() {\n"
1958 " return 42;\n" 1968 " return 42;\n"
1959 "});\n" 1969 "});\n"
1960 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n" 1970 "obj1.__defineSetter__('propWithSetter', function Z(value) {\n"
1961 " return this.value_ = value;\n" 1971 " return this.value_ = value;\n"
1962 "});\n"); 1972 "});\n");
1963 const v8::HeapSnapshot* snapshot = 1973 const v8::HeapSnapshot* snapshot =
1964 heap_profiler->TakeHeapSnapshot(v8_str("slowCaseAccessors")); 1974 heap_profiler->TakeHeapSnapshot(v8_str("slowCaseAccessors"));
1965 CHECK(ValidateSnapshot(snapshot)); 1975 CHECK(ValidateSnapshot(snapshot));
1966 1976
1967 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1977 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1968 CHECK(global); 1978 CHECK_NE(NULL, global);
1969 const v8::HeapGraphNode* obj1 = 1979 const v8::HeapGraphNode* obj1 =
1970 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1"); 1980 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj1");
1971 CHECK(obj1); 1981 CHECK_NE(NULL, obj1);
1972 const v8::HeapGraphNode* func; 1982 const v8::HeapGraphNode* func;
1973 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter"); 1983 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithGetter");
1974 CHECK(func); 1984 CHECK_NE(NULL, func);
1975 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter"); 1985 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithGetter");
1976 CHECK(!func); 1986 CHECK_EQ(NULL, func);
1977 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter"); 1987 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "set propWithSetter");
1978 CHECK(func); 1988 CHECK_NE(NULL, func);
1979 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter"); 1989 func = GetProperty(obj1, v8::HeapGraphEdge::kProperty, "get propWithSetter");
1980 CHECK(!func); 1990 CHECK_EQ(NULL, func);
1981 } 1991 }
1982 1992
1983 1993
1984 TEST(HiddenPropertiesFastCase) { 1994 TEST(HiddenPropertiesFastCase) {
1985 v8::Isolate* isolate = CcTest::isolate(); 1995 v8::Isolate* isolate = CcTest::isolate();
1986 LocalContext env; 1996 LocalContext env;
1987 v8::HandleScope scope(isolate); 1997 v8::HandleScope scope(isolate);
1988 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 1998 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
1989 1999
1990 CompileRun( 2000 CompileRun(
1991 "function C(x) { this.a = this; this.b = x; }\n" 2001 "function C(x) { this.a = this; this.b = x; }\n"
1992 "c = new C(2012);\n"); 2002 "c = new C(2012);\n");
1993 const v8::HeapSnapshot* snapshot = 2003 const v8::HeapSnapshot* snapshot =
1994 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1")); 2004 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1"));
1995 CHECK(ValidateSnapshot(snapshot)); 2005 CHECK(ValidateSnapshot(snapshot));
1996 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2006 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1997 const v8::HeapGraphNode* c = 2007 const v8::HeapGraphNode* c =
1998 GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); 2008 GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
1999 CHECK(c); 2009 CHECK_NE(NULL, c);
2000 const v8::HeapGraphNode* hidden_props = 2010 const v8::HeapGraphNode* hidden_props =
2001 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties"); 2011 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties");
2002 CHECK(!hidden_props); 2012 CHECK_EQ(NULL, hidden_props);
2003 2013
2004 v8::Handle<v8::Value> cHandle = 2014 v8::Handle<v8::Value> cHandle =
2005 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "c")); 2015 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "c"));
2006 CHECK(!cHandle.IsEmpty() && cHandle->IsObject()); 2016 CHECK(!cHandle.IsEmpty() && cHandle->IsObject());
2007 cHandle->ToObject(isolate)->SetHiddenValue(v8_str("key"), v8_str("val")); 2017 cHandle->ToObject(isolate)->SetHiddenValue(v8_str("key"), v8_str("val"));
2008 2018
2009 snapshot = heap_profiler->TakeHeapSnapshot( 2019 snapshot = heap_profiler->TakeHeapSnapshot(
2010 v8_str("HiddenPropertiesFastCase2")); 2020 v8_str("HiddenPropertiesFastCase2"));
2011 CHECK(ValidateSnapshot(snapshot)); 2021 CHECK(ValidateSnapshot(snapshot));
2012 global = GetGlobalObject(snapshot); 2022 global = GetGlobalObject(snapshot);
2013 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); 2023 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
2014 CHECK(c); 2024 CHECK_NE(NULL, c);
2015 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal, 2025 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal,
2016 "hidden_properties"); 2026 "hidden_properties");
2017 CHECK(hidden_props); 2027 CHECK_NE(NULL, hidden_props);
2018 } 2028 }
2019 2029
2020 2030
2021 TEST(AccessorInfo) { 2031 TEST(AccessorInfo) {
2022 LocalContext env; 2032 LocalContext env;
2023 v8::HandleScope scope(env->GetIsolate()); 2033 v8::HandleScope scope(env->GetIsolate());
2024 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2034 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2025 2035
2026 CompileRun("function foo(x) { }\n"); 2036 CompileRun("function foo(x) { }\n");
2027 const v8::HeapSnapshot* snapshot = 2037 const v8::HeapSnapshot* snapshot =
2028 heap_profiler->TakeHeapSnapshot(v8_str("AccessorInfoTest")); 2038 heap_profiler->TakeHeapSnapshot(v8_str("AccessorInfoTest"));
2029 CHECK(ValidateSnapshot(snapshot)); 2039 CHECK(ValidateSnapshot(snapshot));
2030 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2040 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2031 const v8::HeapGraphNode* foo = 2041 const v8::HeapGraphNode* foo =
2032 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); 2042 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo");
2033 CHECK(foo); 2043 CHECK_NE(NULL, foo);
2034 const v8::HeapGraphNode* map = 2044 const v8::HeapGraphNode* map =
2035 GetProperty(foo, v8::HeapGraphEdge::kInternal, "map"); 2045 GetProperty(foo, v8::HeapGraphEdge::kInternal, "map");
2036 CHECK(map); 2046 CHECK_NE(NULL, map);
2037 const v8::HeapGraphNode* descriptors = 2047 const v8::HeapGraphNode* descriptors =
2038 GetProperty(map, v8::HeapGraphEdge::kInternal, "descriptors"); 2048 GetProperty(map, v8::HeapGraphEdge::kInternal, "descriptors");
2039 CHECK(descriptors); 2049 CHECK_NE(NULL, descriptors);
2040 const v8::HeapGraphNode* length_name = 2050 const v8::HeapGraphNode* length_name =
2041 GetProperty(descriptors, v8::HeapGraphEdge::kInternal, "2"); 2051 GetProperty(descriptors, v8::HeapGraphEdge::kInternal, "2");
2042 CHECK(length_name); 2052 CHECK_NE(NULL, length_name);
2043 CHECK_EQ(0, strcmp("length", *v8::String::Utf8Value(length_name->GetName()))); 2053 CHECK_EQ("length", *v8::String::Utf8Value(length_name->GetName()));
2044 const v8::HeapGraphNode* length_accessor = 2054 const v8::HeapGraphNode* length_accessor =
2045 GetProperty(descriptors, v8::HeapGraphEdge::kInternal, "4"); 2055 GetProperty(descriptors, v8::HeapGraphEdge::kInternal, "4");
2046 CHECK(length_accessor); 2056 CHECK_NE(NULL, length_accessor);
2047 CHECK_EQ(0, strcmp("system / ExecutableAccessorInfo", 2057 CHECK_EQ("system / ExecutableAccessorInfo",
2048 *v8::String::Utf8Value(length_accessor->GetName()))); 2058 *v8::String::Utf8Value(length_accessor->GetName()));
2049 const v8::HeapGraphNode* name = 2059 const v8::HeapGraphNode* name =
2050 GetProperty(length_accessor, v8::HeapGraphEdge::kInternal, "name"); 2060 GetProperty(length_accessor, v8::HeapGraphEdge::kInternal, "name");
2051 CHECK(name); 2061 CHECK_NE(NULL, name);
2052 const v8::HeapGraphNode* getter = 2062 const v8::HeapGraphNode* getter =
2053 GetProperty(length_accessor, v8::HeapGraphEdge::kInternal, "getter"); 2063 GetProperty(length_accessor, v8::HeapGraphEdge::kInternal, "getter");
2054 CHECK(getter); 2064 CHECK_NE(NULL, getter);
2055 const v8::HeapGraphNode* setter = 2065 const v8::HeapGraphNode* setter =
2056 GetProperty(length_accessor, v8::HeapGraphEdge::kInternal, "setter"); 2066 GetProperty(length_accessor, v8::HeapGraphEdge::kInternal, "setter");
2057 CHECK(setter); 2067 CHECK_NE(NULL, setter);
2058 } 2068 }
2059 2069
2060 2070
2061 bool HasWeakEdge(const v8::HeapGraphNode* node) { 2071 bool HasWeakEdge(const v8::HeapGraphNode* node) {
2062 for (int i = 0; i < node->GetChildrenCount(); ++i) { 2072 for (int i = 0; i < node->GetChildrenCount(); ++i) {
2063 const v8::HeapGraphEdge* handle_edge = node->GetChild(i); 2073 const v8::HeapGraphEdge* handle_edge = node->GetChild(i);
2064 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true; 2074 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true;
2065 } 2075 }
2066 return false; 2076 return false;
2067 } 2077 }
2068 2078
2069 2079
2070 bool HasWeakGlobalHandle() { 2080 bool HasWeakGlobalHandle() {
2071 v8::Isolate* isolate = CcTest::isolate(); 2081 v8::Isolate* isolate = CcTest::isolate();
2072 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 2082 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
2073 const v8::HeapSnapshot* snapshot = 2083 const v8::HeapSnapshot* snapshot =
2074 heap_profiler->TakeHeapSnapshot(v8_str("weaks")); 2084 heap_profiler->TakeHeapSnapshot(v8_str("weaks"));
2075 CHECK(ValidateSnapshot(snapshot)); 2085 CHECK(ValidateSnapshot(snapshot));
2076 const v8::HeapGraphNode* gc_roots = GetNode( 2086 const v8::HeapGraphNode* gc_roots = GetNode(
2077 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); 2087 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)");
2078 CHECK(gc_roots); 2088 CHECK_NE(NULL, gc_roots);
2079 const v8::HeapGraphNode* global_handles = GetNode( 2089 const v8::HeapGraphNode* global_handles = GetNode(
2080 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); 2090 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)");
2081 CHECK(global_handles); 2091 CHECK_NE(NULL, global_handles);
2082 return HasWeakEdge(global_handles); 2092 return HasWeakEdge(global_handles);
2083 } 2093 }
2084 2094
2085 2095
2086 static void PersistentHandleCallback( 2096 static void PersistentHandleCallback(
2087 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { 2097 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
2088 data.GetParameter()->Reset(); 2098 data.GetParameter()->Reset();
2089 delete data.GetParameter(); 2099 delete data.GetParameter();
2090 } 2100 }
2091 2101
(...skipping 16 matching lines...) Expand all
2108 LocalContext env; 2118 LocalContext env;
2109 v8::HandleScope scope(env->GetIsolate()); 2119 v8::HandleScope scope(env->GetIsolate());
2110 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2120 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2111 2121
2112 CompileRun( 2122 CompileRun(
2113 "fun = (function (x) { return function () { return x + 1; } })(1);"); 2123 "fun = (function (x) { return function () { return x + 1; } })(1);");
2114 const v8::HeapSnapshot* snapshot = 2124 const v8::HeapSnapshot* snapshot =
2115 heap_profiler->TakeHeapSnapshot(v8_str("fun")); 2125 heap_profiler->TakeHeapSnapshot(v8_str("fun"));
2116 CHECK(ValidateSnapshot(snapshot)); 2126 CHECK(ValidateSnapshot(snapshot));
2117 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2127 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2118 CHECK(global); 2128 CHECK_NE(NULL, global);
2119 const v8::HeapGraphNode* fun = 2129 const v8::HeapGraphNode* fun =
2120 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); 2130 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun");
2121 CHECK(!HasWeakEdge(fun)); 2131 CHECK(!HasWeakEdge(fun));
2122 const v8::HeapGraphNode* shared = 2132 const v8::HeapGraphNode* shared =
2123 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared"); 2133 GetProperty(fun, v8::HeapGraphEdge::kInternal, "shared");
2124 CHECK(!HasWeakEdge(shared)); 2134 CHECK(!HasWeakEdge(shared));
2125 } 2135 }
2126 2136
2127 2137
2128 TEST(NoDebugObjectInSnapshot) { 2138 TEST(NoDebugObjectInSnapshot) {
2129 LocalContext env; 2139 LocalContext env;
2130 v8::HandleScope scope(env->GetIsolate()); 2140 v8::HandleScope scope(env->GetIsolate());
2131 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2141 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2132 2142
2133 CHECK(CcTest::i_isolate()->debug()->Load()); 2143 CHECK(CcTest::i_isolate()->debug()->Load());
2134 CompileRun("foo = {};"); 2144 CompileRun("foo = {};");
2135 const v8::HeapSnapshot* snapshot = 2145 const v8::HeapSnapshot* snapshot =
2136 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2146 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2137 CHECK(ValidateSnapshot(snapshot)); 2147 CHECK(ValidateSnapshot(snapshot));
2138 const v8::HeapGraphNode* root = snapshot->GetRoot(); 2148 const v8::HeapGraphNode* root = snapshot->GetRoot();
2139 int globals_count = 0; 2149 int globals_count = 0;
2140 for (int i = 0; i < root->GetChildrenCount(); ++i) { 2150 for (int i = 0; i < root->GetChildrenCount(); ++i) {
2141 const v8::HeapGraphEdge* edge = root->GetChild(i); 2151 const v8::HeapGraphEdge* edge = root->GetChild(i);
2142 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { 2152 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) {
2143 ++globals_count; 2153 ++globals_count;
2144 const v8::HeapGraphNode* global = edge->GetToNode(); 2154 const v8::HeapGraphNode* global = edge->GetToNode();
2145 const v8::HeapGraphNode* foo = 2155 const v8::HeapGraphNode* foo =
2146 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); 2156 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo");
2147 CHECK(foo); 2157 CHECK_NE(NULL, foo);
2148 } 2158 }
2149 } 2159 }
2150 CHECK_EQ(1, globals_count); 2160 CHECK_EQ(1, globals_count);
2151 } 2161 }
2152 2162
2153 2163
2154 TEST(AllStrongGcRootsHaveNames) { 2164 TEST(AllStrongGcRootsHaveNames) {
2155 LocalContext env; 2165 LocalContext env;
2156 v8::HandleScope scope(env->GetIsolate()); 2166 v8::HandleScope scope(env->GetIsolate());
2157 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2167 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2158 2168
2159 CompileRun("foo = {};"); 2169 CompileRun("foo = {};");
2160 const v8::HeapSnapshot* snapshot = 2170 const v8::HeapSnapshot* snapshot =
2161 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2171 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2162 CHECK(ValidateSnapshot(snapshot)); 2172 CHECK(ValidateSnapshot(snapshot));
2163 const v8::HeapGraphNode* gc_roots = GetNode( 2173 const v8::HeapGraphNode* gc_roots = GetNode(
2164 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); 2174 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)");
2165 CHECK(gc_roots); 2175 CHECK_NE(NULL, gc_roots);
2166 const v8::HeapGraphNode* strong_roots = GetNode( 2176 const v8::HeapGraphNode* strong_roots = GetNode(
2167 gc_roots, v8::HeapGraphNode::kSynthetic, "(Strong roots)"); 2177 gc_roots, v8::HeapGraphNode::kSynthetic, "(Strong roots)");
2168 CHECK(strong_roots); 2178 CHECK_NE(NULL, strong_roots);
2169 for (int i = 0; i < strong_roots->GetChildrenCount(); ++i) { 2179 for (int i = 0; i < strong_roots->GetChildrenCount(); ++i) {
2170 const v8::HeapGraphEdge* edge = strong_roots->GetChild(i); 2180 const v8::HeapGraphEdge* edge = strong_roots->GetChild(i);
2171 CHECK_EQ(v8::HeapGraphEdge::kInternal, edge->GetType()); 2181 CHECK_EQ(v8::HeapGraphEdge::kInternal, edge->GetType());
2172 v8::String::Utf8Value name(edge->GetName()); 2182 v8::String::Utf8Value name(edge->GetName());
2173 CHECK(isalpha(**name)); 2183 CHECK(isalpha(**name));
2174 } 2184 }
2175 } 2185 }
2176 2186
2177 2187
2178 TEST(NoRefsToNonEssentialEntries) { 2188 TEST(NoRefsToNonEssentialEntries) {
2179 LocalContext env; 2189 LocalContext env;
2180 v8::HandleScope scope(env->GetIsolate()); 2190 v8::HandleScope scope(env->GetIsolate());
2181 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2191 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2182 CompileRun("global_object = {};\n"); 2192 CompileRun("global_object = {};\n");
2183 const v8::HeapSnapshot* snapshot = 2193 const v8::HeapSnapshot* snapshot =
2184 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2194 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2185 CHECK(ValidateSnapshot(snapshot)); 2195 CHECK(ValidateSnapshot(snapshot));
2186 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2196 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2187 const v8::HeapGraphNode* global_object = 2197 const v8::HeapGraphNode* global_object =
2188 GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object"); 2198 GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object");
2189 CHECK(global_object); 2199 CHECK_NE(NULL, global_object);
2190 const v8::HeapGraphNode* properties = 2200 const v8::HeapGraphNode* properties =
2191 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "properties"); 2201 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "properties");
2192 CHECK(!properties); 2202 CHECK_EQ(NULL, properties);
2193 const v8::HeapGraphNode* elements = 2203 const v8::HeapGraphNode* elements =
2194 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "elements"); 2204 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "elements");
2195 CHECK(!elements); 2205 CHECK_EQ(NULL, elements);
2196 } 2206 }
2197 2207
2198 2208
2199 TEST(MapHasDescriptorsAndTransitions) { 2209 TEST(MapHasDescriptorsAndTransitions) {
2200 LocalContext env; 2210 LocalContext env;
2201 v8::HandleScope scope(env->GetIsolate()); 2211 v8::HandleScope scope(env->GetIsolate());
2202 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2212 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2203 CompileRun("obj = { a: 10 };\n"); 2213 CompileRun("obj = { a: 10 };\n");
2204 const v8::HeapSnapshot* snapshot = 2214 const v8::HeapSnapshot* snapshot =
2205 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2215 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2206 CHECK(ValidateSnapshot(snapshot)); 2216 CHECK(ValidateSnapshot(snapshot));
2207 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2217 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2208 const v8::HeapGraphNode* global_object = 2218 const v8::HeapGraphNode* global_object =
2209 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); 2219 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj");
2210 CHECK(global_object); 2220 CHECK_NE(NULL, global_object);
2211 2221
2212 const v8::HeapGraphNode* map = 2222 const v8::HeapGraphNode* map =
2213 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map"); 2223 GetProperty(global_object, v8::HeapGraphEdge::kInternal, "map");
2214 CHECK(map); 2224 CHECK_NE(NULL, map);
2215 const v8::HeapGraphNode* own_descriptors = GetProperty( 2225 const v8::HeapGraphNode* own_descriptors = GetProperty(
2216 map, v8::HeapGraphEdge::kInternal, "descriptors"); 2226 map, v8::HeapGraphEdge::kInternal, "descriptors");
2217 CHECK(own_descriptors); 2227 CHECK_NE(NULL, own_descriptors);
2218 const v8::HeapGraphNode* own_transitions = GetProperty( 2228 const v8::HeapGraphNode* own_transitions = GetProperty(
2219 map, v8::HeapGraphEdge::kInternal, "transitions"); 2229 map, v8::HeapGraphEdge::kInternal, "transitions");
2220 CHECK(!own_transitions); 2230 CHECK_EQ(NULL, own_transitions);
2221 } 2231 }
2222 2232
2223 2233
2224 TEST(ManyLocalsInSharedContext) { 2234 TEST(ManyLocalsInSharedContext) {
2225 LocalContext env; 2235 LocalContext env;
2226 v8::HandleScope scope(env->GetIsolate()); 2236 v8::HandleScope scope(env->GetIsolate());
2227 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2237 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2228 int num_objects = 6000; 2238 int num_objects = 6000;
2229 CompileRun( 2239 CompileRun(
2230 "var n = 6000;" 2240 "var n = 6000;"
2231 "var result = [];" 2241 "var result = [];"
2232 "result.push('(function outer() {');" 2242 "result.push('(function outer() {');"
2233 "for (var i = 0; i < n; i++) {" 2243 "for (var i = 0; i < n; i++) {"
2234 " var f = 'function f_' + i + '() { ';" 2244 " var f = 'function f_' + i + '() { ';"
2235 " if (i > 0)" 2245 " if (i > 0)"
2236 " f += 'f_' + (i - 1) + '();';" 2246 " f += 'f_' + (i - 1) + '();';"
2237 " f += ' }';" 2247 " f += ' }';"
2238 " result.push(f);" 2248 " result.push(f);"
2239 "}" 2249 "}"
2240 "result.push('return f_' + (n - 1) + ';');" 2250 "result.push('return f_' + (n - 1) + ';');"
2241 "result.push('})()');" 2251 "result.push('})()');"
2242 "var ok = eval(result.join('\\n'));"); 2252 "var ok = eval(result.join('\\n'));");
2243 const v8::HeapSnapshot* snapshot = 2253 const v8::HeapSnapshot* snapshot =
2244 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2254 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2245 CHECK(ValidateSnapshot(snapshot)); 2255 CHECK(ValidateSnapshot(snapshot));
2246 2256
2247 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2257 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2248 CHECK(global); 2258 CHECK_NE(NULL, global);
2249 const v8::HeapGraphNode* ok_object = 2259 const v8::HeapGraphNode* ok_object =
2250 GetProperty(global, v8::HeapGraphEdge::kProperty, "ok"); 2260 GetProperty(global, v8::HeapGraphEdge::kProperty, "ok");
2251 CHECK(ok_object); 2261 CHECK_NE(NULL, ok_object);
2252 const v8::HeapGraphNode* context_object = 2262 const v8::HeapGraphNode* context_object =
2253 GetProperty(ok_object, v8::HeapGraphEdge::kInternal, "context"); 2263 GetProperty(ok_object, v8::HeapGraphEdge::kInternal, "context");
2254 CHECK(context_object); 2264 CHECK_NE(NULL, context_object);
2255 // Check the objects are not duplicated in the context. 2265 // Check the objects are not duplicated in the context.
2256 CHECK_EQ(v8::internal::Context::MIN_CONTEXT_SLOTS + num_objects - 1, 2266 CHECK_EQ(v8::internal::Context::MIN_CONTEXT_SLOTS + num_objects - 1,
2257 context_object->GetChildrenCount()); 2267 context_object->GetChildrenCount());
2258 // Check all the objects have got their names. 2268 // Check all the objects have got their names.
2259 // ... well check just every 15th because otherwise it's too slow in debug. 2269 // ... well check just every 15th because otherwise it's too slow in debug.
2260 for (int i = 0; i < num_objects - 1; i += 15) { 2270 for (int i = 0; i < num_objects - 1; i += 15) {
2261 i::EmbeddedVector<char, 100> var_name; 2271 i::EmbeddedVector<char, 100> var_name;
2262 i::SNPrintF(var_name, "f_%d", i); 2272 i::SNPrintF(var_name, "f_%d", i);
2263 const v8::HeapGraphNode* f_object = GetProperty( 2273 const v8::HeapGraphNode* f_object = GetProperty(
2264 context_object, v8::HeapGraphEdge::kContextVariable, var_name.start()); 2274 context_object, v8::HeapGraphEdge::kContextVariable, var_name.start());
2265 CHECK(f_object); 2275 CHECK_NE(NULL, f_object);
2266 } 2276 }
2267 } 2277 }
2268 2278
2269 2279
2270 TEST(AllocationSitesAreVisible) { 2280 TEST(AllocationSitesAreVisible) {
2271 LocalContext env; 2281 LocalContext env;
2272 v8::Isolate* isolate = env->GetIsolate(); 2282 v8::Isolate* isolate = env->GetIsolate();
2273 v8::HandleScope scope(isolate); 2283 v8::HandleScope scope(isolate);
2274 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 2284 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
2275 CompileRun( 2285 CompileRun(
2276 "fun = function () { var a = [3, 2, 1]; return a; }\n" 2286 "fun = function () { var a = [3, 2, 1]; return a; }\n"
2277 "fun();"); 2287 "fun();");
2278 const v8::HeapSnapshot* snapshot = 2288 const v8::HeapSnapshot* snapshot =
2279 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2289 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2280 CHECK(ValidateSnapshot(snapshot)); 2290 CHECK(ValidateSnapshot(snapshot));
2281 2291
2282 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2292 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2283 CHECK(global); 2293 CHECK_NE(NULL, global);
2284 const v8::HeapGraphNode* fun_code = 2294 const v8::HeapGraphNode* fun_code =
2285 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun"); 2295 GetProperty(global, v8::HeapGraphEdge::kProperty, "fun");
2286 CHECK(fun_code); 2296 CHECK_NE(NULL, fun_code);
2287 const v8::HeapGraphNode* literals = 2297 const v8::HeapGraphNode* literals =
2288 GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals"); 2298 GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals");
2289 CHECK(literals); 2299 CHECK_NE(NULL, literals);
2290 CHECK_EQ(v8::HeapGraphNode::kArray, literals->GetType()); 2300 CHECK_EQ(v8::HeapGraphNode::kArray, literals->GetType());
2291 CHECK_EQ(2, literals->GetChildrenCount()); 2301 CHECK_EQ(2, literals->GetChildrenCount());
2292 2302
2293 // The second value in the literals array should be the boilerplate, 2303 // The second value in the literals array should be the boilerplate,
2294 // after an AllocationSite. 2304 // after an AllocationSite.
2295 const v8::HeapGraphEdge* prop = literals->GetChild(1); 2305 const v8::HeapGraphEdge* prop = literals->GetChild(1);
2296 const v8::HeapGraphNode* allocation_site = prop->GetToNode(); 2306 const v8::HeapGraphNode* allocation_site = prop->GetToNode();
2297 v8::String::Utf8Value name(allocation_site->GetName()); 2307 v8::String::Utf8Value name(allocation_site->GetName());
2298 CHECK_EQ(0, strcmp("system / AllocationSite", *name)); 2308 CHECK_EQ("system / AllocationSite", *name);
2299 const v8::HeapGraphNode* transition_info = 2309 const v8::HeapGraphNode* transition_info =
2300 GetProperty(allocation_site, v8::HeapGraphEdge::kInternal, 2310 GetProperty(allocation_site, v8::HeapGraphEdge::kInternal,
2301 "transition_info"); 2311 "transition_info");
2302 CHECK(transition_info); 2312 CHECK_NE(NULL, transition_info);
2303 2313
2304 const v8::HeapGraphNode* elements = 2314 const v8::HeapGraphNode* elements =
2305 GetProperty(transition_info, v8::HeapGraphEdge::kInternal, 2315 GetProperty(transition_info, v8::HeapGraphEdge::kInternal,
2306 "elements"); 2316 "elements");
2307 CHECK(elements); 2317 CHECK_NE(NULL, elements);
2308 CHECK_EQ(v8::HeapGraphNode::kArray, elements->GetType()); 2318 CHECK_EQ(v8::HeapGraphNode::kArray, elements->GetType());
2309 CHECK_EQ(v8::internal::FixedArray::SizeFor(3), 2319 CHECK_EQ(v8::internal::FixedArray::SizeFor(3),
2310 static_cast<int>(elements->GetShallowSize())); 2320 static_cast<int>(elements->GetShallowSize()));
2311 2321
2312 v8::Handle<v8::Value> array_val = 2322 v8::Handle<v8::Value> array_val =
2313 heap_profiler->FindObjectById(transition_info->GetId()); 2323 heap_profiler->FindObjectById(transition_info->GetId());
2314 CHECK(array_val->IsArray()); 2324 CHECK(array_val->IsArray());
2315 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(array_val); 2325 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(array_val);
2316 // Verify the array is "a" in the code above. 2326 // Verify the array is "a" in the code above.
2317 CHECK_EQ(3u, array->Length()); 2327 CHECK_EQ(3, array->Length());
2318 CHECK(v8::Integer::New(isolate, 3) 2328 CHECK_EQ(v8::Integer::New(isolate, 3),
2319 ->Equals(array->Get(v8::Integer::New(isolate, 0)))); 2329 array->Get(v8::Integer::New(isolate, 0)));
2320 CHECK(v8::Integer::New(isolate, 2) 2330 CHECK_EQ(v8::Integer::New(isolate, 2),
2321 ->Equals(array->Get(v8::Integer::New(isolate, 1)))); 2331 array->Get(v8::Integer::New(isolate, 1)));
2322 CHECK(v8::Integer::New(isolate, 1) 2332 CHECK_EQ(v8::Integer::New(isolate, 1),
2323 ->Equals(array->Get(v8::Integer::New(isolate, 2)))); 2333 array->Get(v8::Integer::New(isolate, 2)));
2324 } 2334 }
2325 2335
2326 2336
2327 TEST(JSFunctionHasCodeLink) { 2337 TEST(JSFunctionHasCodeLink) {
2328 LocalContext env; 2338 LocalContext env;
2329 v8::HandleScope scope(env->GetIsolate()); 2339 v8::HandleScope scope(env->GetIsolate());
2330 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2340 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2331 CompileRun("function foo(x, y) { return x + y; }\n"); 2341 CompileRun("function foo(x, y) { return x + y; }\n");
2332 const v8::HeapSnapshot* snapshot = 2342 const v8::HeapSnapshot* snapshot =
2333 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2343 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2334 CHECK(ValidateSnapshot(snapshot)); 2344 CHECK(ValidateSnapshot(snapshot));
2335 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2345 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2336 const v8::HeapGraphNode* foo_func = 2346 const v8::HeapGraphNode* foo_func =
2337 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); 2347 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo");
2338 CHECK(foo_func); 2348 CHECK_NE(NULL, foo_func);
2339 const v8::HeapGraphNode* code = 2349 const v8::HeapGraphNode* code =
2340 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); 2350 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code");
2341 CHECK(code); 2351 CHECK_NE(NULL, code);
2342 } 2352 }
2343 2353
2344 2354
2345 static const v8::HeapGraphNode* GetNodeByPath(const v8::HeapSnapshot* snapshot, 2355 static const v8::HeapGraphNode* GetNodeByPath(const v8::HeapSnapshot* snapshot,
2346 const char* path[], 2356 const char* path[],
2347 int depth) { 2357 int depth) {
2348 const v8::HeapGraphNode* node = snapshot->GetRoot(); 2358 const v8::HeapGraphNode* node = snapshot->GetRoot();
2349 for (int current_depth = 0; current_depth < depth; ++current_depth) { 2359 for (int current_depth = 0; current_depth < depth; ++current_depth) {
2350 int i, count = node->GetChildrenCount(); 2360 int i, count = node->GetChildrenCount();
2351 for (i = 0; i < count; ++i) { 2361 for (i = 0; i < count; ++i) {
(...skipping 24 matching lines...) Expand all
2376 CHECK(ValidateSnapshot(snapshot)); 2386 CHECK(ValidateSnapshot(snapshot));
2377 2387
2378 const char* stub_path[] = { 2388 const char* stub_path[] = {
2379 "::(GC roots)", 2389 "::(GC roots)",
2380 "::(Strong roots)", 2390 "::(Strong roots)",
2381 "code_stubs::", 2391 "code_stubs::",
2382 "::(ArraySingleArgumentConstructorStub code)" 2392 "::(ArraySingleArgumentConstructorStub code)"
2383 }; 2393 };
2384 const v8::HeapGraphNode* node = GetNodeByPath(snapshot, 2394 const v8::HeapGraphNode* node = GetNodeByPath(snapshot,
2385 stub_path, arraysize(stub_path)); 2395 stub_path, arraysize(stub_path));
2386 CHECK(node); 2396 CHECK_NE(NULL, node);
2387 2397
2388 const char* builtin_path1[] = { 2398 const char* builtin_path1[] = {
2389 "::(GC roots)", 2399 "::(GC roots)",
2390 "::(Builtins)", 2400 "::(Builtins)",
2391 "::(KeyedLoadIC_Generic builtin)" 2401 "::(KeyedLoadIC_Generic builtin)"
2392 }; 2402 };
2393 node = GetNodeByPath(snapshot, builtin_path1, arraysize(builtin_path1)); 2403 node = GetNodeByPath(snapshot, builtin_path1, arraysize(builtin_path1));
2394 CHECK(node); 2404 CHECK_NE(NULL, node);
2395 2405
2396 const char* builtin_path2[] = {"::(GC roots)", "::(Builtins)", 2406 const char* builtin_path2[] = {"::(GC roots)", "::(Builtins)",
2397 "::(CompileLazy builtin)"}; 2407 "::(CompileLazy builtin)"};
2398 node = GetNodeByPath(snapshot, builtin_path2, arraysize(builtin_path2)); 2408 node = GetNodeByPath(snapshot, builtin_path2, arraysize(builtin_path2));
2399 CHECK(node); 2409 CHECK_NE(NULL, node);
2400 v8::String::Utf8Value node_name(node->GetName()); 2410 v8::String::Utf8Value node_name(node->GetName());
2401 CHECK_EQ(0, strcmp("(CompileLazy builtin)", *node_name)); 2411 CHECK_EQ("(CompileLazy builtin)", *node_name);
2402 } 2412 }
2403 2413
2404 2414
2405 static const char* record_trace_tree_source = 2415 static const char* record_trace_tree_source =
2406 "var topFunctions = [];\n" 2416 "var topFunctions = [];\n"
2407 "var global = this;\n" 2417 "var global = this;\n"
2408 "function generateFunctions(width, depth) {\n" 2418 "function generateFunctions(width, depth) {\n"
2409 " var script = [];\n" 2419 " var script = [];\n"
2410 " for (var i = 0; i < width; i++) {\n" 2420 " for (var i = 0; i < width; i++) {\n"
2411 " for (var j = 0; j < depth; j++) {\n" 2421 " for (var j = 0; j < depth; j++) {\n"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 CompileRun( 2484 CompileRun(
2475 "var a = [];\n" 2485 "var a = [];\n"
2476 "for (var i = 0; i < 5; ++i)\n" 2486 "for (var i = 0; i < 5; ++i)\n"
2477 " a[i] = i;\n" 2487 " a[i] = i;\n"
2478 "for (var i = 0; i < 3; ++i)\n" 2488 "for (var i = 0; i < 3; ++i)\n"
2479 " a.shift();\n"); 2489 " a.shift();\n");
2480 2490
2481 const char* names[] = {""}; 2491 const char* names[] = {""};
2482 AllocationTracker* tracker = 2492 AllocationTracker* tracker =
2483 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); 2493 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2484 CHECK(tracker); 2494 CHECK_NE(NULL, tracker);
2485 // Resolve all function locations. 2495 // Resolve all function locations.
2486 tracker->PrepareForSerialization(); 2496 tracker->PrepareForSerialization();
2487 // Print for better diagnostics in case of failure. 2497 // Print for better diagnostics in case of failure.
2488 tracker->trace_tree()->Print(tracker); 2498 tracker->trace_tree()->Print(tracker);
2489 2499
2490 AllocationTraceNode* node = 2500 AllocationTraceNode* node =
2491 FindNode(tracker, Vector<const char*>(names, arraysize(names))); 2501 FindNode(tracker, Vector<const char*>(names, arraysize(names)));
2492 CHECK(node); 2502 CHECK_NE(NULL, node);
2493 CHECK_GE(node->allocation_count(), 2u); 2503 CHECK_GE(node->allocation_count(), 2);
2494 CHECK_GE(node->allocation_size(), 4u * 5u); 2504 CHECK_GE(node->allocation_size(), 4 * 5);
2495 heap_profiler->StopTrackingHeapObjects(); 2505 heap_profiler->StopTrackingHeapObjects();
2496 } 2506 }
2497 2507
2498 2508
2499 TEST(TrackHeapAllocations) { 2509 TEST(TrackHeapAllocations) {
2500 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2510 v8::HandleScope scope(v8::Isolate::GetCurrent());
2501 LocalContext env; 2511 LocalContext env;
2502 2512
2503 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2513 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2504 heap_profiler->StartTrackingHeapObjects(true); 2514 heap_profiler->StartTrackingHeapObjects(true);
2505 2515
2506 CompileRun(record_trace_tree_source); 2516 CompileRun(record_trace_tree_source);
2507 2517
2508 AllocationTracker* tracker = 2518 AllocationTracker* tracker =
2509 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); 2519 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2510 CHECK(tracker); 2520 CHECK_NE(NULL, tracker);
2511 // Resolve all function locations. 2521 // Resolve all function locations.
2512 tracker->PrepareForSerialization(); 2522 tracker->PrepareForSerialization();
2513 // Print for better diagnostics in case of failure. 2523 // Print for better diagnostics in case of failure.
2514 tracker->trace_tree()->Print(tracker); 2524 tracker->trace_tree()->Print(tracker);
2515 2525
2516 const char* names[] = {"", "start", "f_0_0", "f_0_1", "f_0_2"}; 2526 const char* names[] = {"", "start", "f_0_0", "f_0_1", "f_0_2"};
2517 AllocationTraceNode* node = 2527 AllocationTraceNode* node =
2518 FindNode(tracker, Vector<const char*>(names, arraysize(names))); 2528 FindNode(tracker, Vector<const char*>(names, arraysize(names)));
2519 CHECK(node); 2529 CHECK_NE(NULL, node);
2520 CHECK_GE(node->allocation_count(), 100u); 2530 CHECK_GE(node->allocation_count(), 100);
2521 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); 2531 CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
2522 heap_profiler->StopTrackingHeapObjects(); 2532 heap_profiler->StopTrackingHeapObjects();
2523 } 2533 }
2524 2534
2525 2535
2526 static const char* inline_heap_allocation_source = 2536 static const char* inline_heap_allocation_source =
2527 "function f_0(x) {\n" 2537 "function f_0(x) {\n"
2528 " return f_1(x+1);\n" 2538 " return f_1(x+1);\n"
2529 "}\n" 2539 "}\n"
2530 "%NeverOptimizeFunction(f_0);\n" 2540 "%NeverOptimizeFunction(f_0);\n"
(...skipping 19 matching lines...) Expand all
2550 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2560 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2551 const char* names[] = {"", "start", "f_0", "f_1"}; 2561 const char* names[] = {"", "start", "f_0", "f_1"};
2552 // First check that normally all allocations are recorded. 2562 // First check that normally all allocations are recorded.
2553 { 2563 {
2554 heap_profiler->StartTrackingHeapObjects(true); 2564 heap_profiler->StartTrackingHeapObjects(true);
2555 2565
2556 CompileRun(inline_heap_allocation_source); 2566 CompileRun(inline_heap_allocation_source);
2557 2567
2558 AllocationTracker* tracker = 2568 AllocationTracker* tracker =
2559 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); 2569 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2560 CHECK(tracker); 2570 CHECK_NE(NULL, tracker);
2561 // Resolve all function locations. 2571 // Resolve all function locations.
2562 tracker->PrepareForSerialization(); 2572 tracker->PrepareForSerialization();
2563 // Print for better diagnostics in case of failure. 2573 // Print for better diagnostics in case of failure.
2564 tracker->trace_tree()->Print(tracker); 2574 tracker->trace_tree()->Print(tracker);
2565 2575
2566 AllocationTraceNode* node = 2576 AllocationTraceNode* node =
2567 FindNode(tracker, Vector<const char*>(names, arraysize(names))); 2577 FindNode(tracker, Vector<const char*>(names, arraysize(names)));
2568 CHECK(node); 2578 CHECK_NE(NULL, node);
2569 CHECK_GE(node->allocation_count(), 100u); 2579 CHECK_GE(node->allocation_count(), 100);
2570 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); 2580 CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
2571 heap_profiler->StopTrackingHeapObjects(); 2581 heap_profiler->StopTrackingHeapObjects();
2572 } 2582 }
2573 2583
2574 { 2584 {
2575 heap_profiler->StartTrackingHeapObjects(true); 2585 heap_profiler->StartTrackingHeapObjects(true);
2576 2586
2577 // Now check that not all allocations are tracked if we manually reenable 2587 // Now check that not all allocations are tracked if we manually reenable
2578 // inline allocations. 2588 // inline allocations.
2579 CHECK(CcTest::heap()->inline_allocation_disabled()); 2589 CHECK(CcTest::heap()->inline_allocation_disabled());
2580 CcTest::heap()->EnableInlineAllocation(); 2590 CcTest::heap()->EnableInlineAllocation();
2581 2591
2582 CompileRun(inline_heap_allocation_source); 2592 CompileRun(inline_heap_allocation_source);
2583 2593
2584 AllocationTracker* tracker = 2594 AllocationTracker* tracker =
2585 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); 2595 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2586 CHECK(tracker); 2596 CHECK_NE(NULL, tracker);
2587 // Resolve all function locations. 2597 // Resolve all function locations.
2588 tracker->PrepareForSerialization(); 2598 tracker->PrepareForSerialization();
2589 // Print for better diagnostics in case of failure. 2599 // Print for better diagnostics in case of failure.
2590 tracker->trace_tree()->Print(tracker); 2600 tracker->trace_tree()->Print(tracker);
2591 2601
2592 AllocationTraceNode* node = 2602 AllocationTraceNode* node =
2593 FindNode(tracker, Vector<const char*>(names, arraysize(names))); 2603 FindNode(tracker, Vector<const char*>(names, arraysize(names)));
2594 CHECK(node); 2604 CHECK_NE(NULL, node);
2595 CHECK_LT(node->allocation_count(), 100u); 2605 CHECK_LT(node->allocation_count(), 100);
2596 2606
2597 CcTest::heap()->DisableInlineAllocation(); 2607 CcTest::heap()->DisableInlineAllocation();
2598 heap_profiler->StopTrackingHeapObjects(); 2608 heap_profiler->StopTrackingHeapObjects();
2599 } 2609 }
2600 } 2610 }
2601 2611
2602 2612
2603 TEST(TrackV8ApiAllocation) { 2613 TEST(TrackV8ApiAllocation) {
2604 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2614 v8::HandleScope scope(v8::Isolate::GetCurrent());
2605 LocalContext env; 2615 LocalContext env;
2606 2616
2607 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2617 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2608 const char* names[] = { "(V8 API)" }; 2618 const char* names[] = { "(V8 API)" };
2609 heap_profiler->StartTrackingHeapObjects(true); 2619 heap_profiler->StartTrackingHeapObjects(true);
2610 2620
2611 v8::Handle<v8::Object> o1 = v8::Object::New(env->GetIsolate()); 2621 v8::Handle<v8::Object> o1 = v8::Object::New(env->GetIsolate());
2612 o1->Clone(); 2622 o1->Clone();
2613 2623
2614 AllocationTracker* tracker = 2624 AllocationTracker* tracker =
2615 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); 2625 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2616 CHECK(tracker); 2626 CHECK_NE(NULL, tracker);
2617 // Resolve all function locations. 2627 // Resolve all function locations.
2618 tracker->PrepareForSerialization(); 2628 tracker->PrepareForSerialization();
2619 // Print for better diagnostics in case of failure. 2629 // Print for better diagnostics in case of failure.
2620 tracker->trace_tree()->Print(tracker); 2630 tracker->trace_tree()->Print(tracker);
2621 2631
2622 AllocationTraceNode* node = 2632 AllocationTraceNode* node =
2623 FindNode(tracker, Vector<const char*>(names, arraysize(names))); 2633 FindNode(tracker, Vector<const char*>(names, arraysize(names)));
2624 CHECK(node); 2634 CHECK_NE(NULL, node);
2625 CHECK_GE(node->allocation_count(), 2u); 2635 CHECK_GE(node->allocation_count(), 2);
2626 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); 2636 CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
2627 heap_profiler->StopTrackingHeapObjects(); 2637 heap_profiler->StopTrackingHeapObjects();
2628 } 2638 }
2629 2639
2630 2640
2631 TEST(ArrayBufferAndArrayBufferView) { 2641 TEST(ArrayBufferAndArrayBufferView) {
2632 LocalContext env; 2642 LocalContext env;
2633 v8::HandleScope scope(env->GetIsolate()); 2643 v8::HandleScope scope(env->GetIsolate());
2634 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2644 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2635 CompileRun("arr1 = new Uint32Array(100);\n"); 2645 CompileRun("arr1 = new Uint32Array(100);\n");
2636 const v8::HeapSnapshot* snapshot = 2646 const v8::HeapSnapshot* snapshot =
2637 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2647 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2638 CHECK(ValidateSnapshot(snapshot)); 2648 CHECK(ValidateSnapshot(snapshot));
2639 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2649 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2640 const v8::HeapGraphNode* arr1_obj = 2650 const v8::HeapGraphNode* arr1_obj =
2641 GetProperty(global, v8::HeapGraphEdge::kProperty, "arr1"); 2651 GetProperty(global, v8::HeapGraphEdge::kProperty, "arr1");
2642 CHECK(arr1_obj); 2652 CHECK_NE(NULL, arr1_obj);
2643 const v8::HeapGraphNode* arr1_buffer = 2653 const v8::HeapGraphNode* arr1_buffer =
2644 GetProperty(arr1_obj, v8::HeapGraphEdge::kInternal, "buffer"); 2654 GetProperty(arr1_obj, v8::HeapGraphEdge::kInternal, "buffer");
2645 CHECK(arr1_buffer); 2655 CHECK_NE(NULL, arr1_buffer);
2646 const v8::HeapGraphNode* first_view = 2656 const v8::HeapGraphNode* first_view =
2647 GetProperty(arr1_buffer, v8::HeapGraphEdge::kWeak, "weak_first_view"); 2657 GetProperty(arr1_buffer, v8::HeapGraphEdge::kWeak, "weak_first_view");
2648 CHECK(first_view); 2658 CHECK_NE(NULL, first_view);
2649 const v8::HeapGraphNode* backing_store = 2659 const v8::HeapGraphNode* backing_store =
2650 GetProperty(arr1_buffer, v8::HeapGraphEdge::kInternal, "backing_store"); 2660 GetProperty(arr1_buffer, v8::HeapGraphEdge::kInternal, "backing_store");
2651 CHECK(backing_store); 2661 CHECK_NE(NULL, backing_store);
2652 CHECK_EQ(400, static_cast<int>(backing_store->GetShallowSize())); 2662 CHECK_EQ(400, static_cast<int>(backing_store->GetShallowSize()));
2653 } 2663 }
2654 2664
2655 2665
2656 static int GetRetainersCount(const v8::HeapSnapshot* snapshot, 2666 static int GetRetainersCount(const v8::HeapSnapshot* snapshot,
2657 const v8::HeapGraphNode* node) { 2667 const v8::HeapGraphNode* node) {
2658 int count = 0; 2668 int count = 0;
2659 for (int i = 0, l = snapshot->GetNodesCount(); i < l; ++i) { 2669 for (int i = 0, l = snapshot->GetNodesCount(); i < l; ++i) {
2660 const v8::HeapGraphNode* parent = snapshot->GetNode(i); 2670 const v8::HeapGraphNode* parent = snapshot->GetNode(i);
2661 for (int j = 0, l2 = parent->GetChildrenCount(); j < l2; ++j) { 2671 for (int j = 0, l2 = parent->GetChildrenCount(); j < l2; ++j) {
(...skipping 29 matching lines...) Expand all
2691 2701
2692 v8::Handle<v8::Value> result = CompileRun("ab2.byteLength"); 2702 v8::Handle<v8::Value> result = CompileRun("ab2.byteLength");
2693 CHECK_EQ(1024, result->Int32Value()); 2703 CHECK_EQ(1024, result->Int32Value());
2694 2704
2695 const v8::HeapSnapshot* snapshot = 2705 const v8::HeapSnapshot* snapshot =
2696 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2706 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2697 CHECK(ValidateSnapshot(snapshot)); 2707 CHECK(ValidateSnapshot(snapshot));
2698 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2708 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2699 const v8::HeapGraphNode* ab1_node = 2709 const v8::HeapGraphNode* ab1_node =
2700 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab1"); 2710 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab1");
2701 CHECK(ab1_node); 2711 CHECK_NE(NULL, ab1_node);
2702 const v8::HeapGraphNode* ab1_data = 2712 const v8::HeapGraphNode* ab1_data =
2703 GetProperty(ab1_node, v8::HeapGraphEdge::kInternal, "backing_store"); 2713 GetProperty(ab1_node, v8::HeapGraphEdge::kInternal, "backing_store");
2704 CHECK(ab1_data); 2714 CHECK_NE(NULL, ab1_data);
2705 const v8::HeapGraphNode* ab2_node = 2715 const v8::HeapGraphNode* ab2_node =
2706 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab2"); 2716 GetProperty(global, v8::HeapGraphEdge::kProperty, "ab2");
2707 CHECK(ab2_node); 2717 CHECK_NE(NULL, ab2_node);
2708 const v8::HeapGraphNode* ab2_data = 2718 const v8::HeapGraphNode* ab2_data =
2709 GetProperty(ab2_node, v8::HeapGraphEdge::kInternal, "backing_store"); 2719 GetProperty(ab2_node, v8::HeapGraphEdge::kInternal, "backing_store");
2710 CHECK(ab2_data); 2720 CHECK_NE(NULL, ab2_data);
2711 CHECK_EQ(ab1_data, ab2_data); 2721 CHECK_EQ(ab1_data, ab2_data);
2712 CHECK_EQ(2, GetRetainersCount(snapshot, ab1_data)); 2722 CHECK_EQ(2, GetRetainersCount(snapshot, ab1_data));
2713 free(data); 2723 free(data);
2714 } 2724 }
2715 2725
2716 2726
2717 TEST(BoxObject) { 2727 TEST(BoxObject) {
2718 v8::Isolate* isolate = CcTest::isolate(); 2728 v8::Isolate* isolate = CcTest::isolate();
2719 v8::HandleScope scope(isolate); 2729 v8::HandleScope scope(isolate);
2720 LocalContext env; 2730 LocalContext env;
2721 v8::Handle<v8::Object> global_proxy = env->Global(); 2731 v8::Handle<v8::Object> global_proxy = env->Global();
2722 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 2732 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
2723 2733
2724 i::Factory* factory = CcTest::i_isolate()->factory(); 2734 i::Factory* factory = CcTest::i_isolate()->factory();
2725 i::Handle<i::String> string = factory->NewStringFromStaticChars("string"); 2735 i::Handle<i::String> string = factory->NewStringFromStaticChars("string");
2726 i::Handle<i::Object> box = factory->NewBox(string); 2736 i::Handle<i::Object> box = factory->NewBox(string);
2727 global->Set(0, v8::ToApiHandle<v8::Object>(box)); 2737 global->Set(0, v8::ToApiHandle<v8::Object>(box));
2728 2738
2729 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 2739 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
2730 const v8::HeapSnapshot* snapshot = 2740 const v8::HeapSnapshot* snapshot =
2731 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2741 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2732 CHECK(ValidateSnapshot(snapshot)); 2742 CHECK(ValidateSnapshot(snapshot));
2733 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); 2743 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
2734 const v8::HeapGraphNode* box_node = 2744 const v8::HeapGraphNode* box_node =
2735 GetProperty(global_node, v8::HeapGraphEdge::kElement, "0"); 2745 GetProperty(global_node, v8::HeapGraphEdge::kElement, "0");
2736 CHECK(box_node); 2746 CHECK_NE(NULL, box_node);
2737 v8::String::Utf8Value box_node_name(box_node->GetName()); 2747 v8::String::Utf8Value box_node_name(box_node->GetName());
2738 CHECK_EQ(0, strcmp("system / Box", *box_node_name)); 2748 CHECK_EQ("system / Box", *box_node_name);
2739 const v8::HeapGraphNode* box_value = 2749 const v8::HeapGraphNode* box_value =
2740 GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value"); 2750 GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value");
2741 CHECK(box_value); 2751 CHECK_NE(NULL, box_value);
2742 } 2752 }
2743 2753
2744 2754
2745 TEST(WeakContainers) { 2755 TEST(WeakContainers) {
2746 i::FLAG_allow_natives_syntax = true; 2756 i::FLAG_allow_natives_syntax = true;
2747 LocalContext env; 2757 LocalContext env;
2748 v8::HandleScope scope(env->GetIsolate()); 2758 v8::HandleScope scope(env->GetIsolate());
2749 if (!CcTest::i_isolate()->use_crankshaft()) return; 2759 if (!CcTest::i_isolate()->use_crankshaft()) return;
2750 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2760 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2751 CompileRun( 2761 CompileRun(
2752 "function foo(a) { return a.x; }\n" 2762 "function foo(a) { return a.x; }\n"
2753 "obj = {x : 123};\n" 2763 "obj = {x : 123};\n"
2754 "foo(obj);\n" 2764 "foo(obj);\n"
2755 "foo(obj);\n" 2765 "foo(obj);\n"
2756 "%OptimizeFunctionOnNextCall(foo);\n" 2766 "%OptimizeFunctionOnNextCall(foo);\n"
2757 "foo(obj);\n"); 2767 "foo(obj);\n");
2758 const v8::HeapSnapshot* snapshot = 2768 const v8::HeapSnapshot* snapshot =
2759 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2769 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2760 CHECK(ValidateSnapshot(snapshot)); 2770 CHECK(ValidateSnapshot(snapshot));
2761 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2771 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2762 const v8::HeapGraphNode* obj = 2772 const v8::HeapGraphNode* obj =
2763 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj"); 2773 GetProperty(global, v8::HeapGraphEdge::kProperty, "obj");
2764 CHECK(obj); 2774 CHECK_NE(NULL, obj);
2765 const v8::HeapGraphNode* map = 2775 const v8::HeapGraphNode* map =
2766 GetProperty(obj, v8::HeapGraphEdge::kInternal, "map"); 2776 GetProperty(obj, v8::HeapGraphEdge::kInternal, "map");
2767 CHECK(map); 2777 CHECK_NE(NULL, map);
2768 const v8::HeapGraphNode* dependent_code = 2778 const v8::HeapGraphNode* dependent_code =
2769 GetProperty(map, v8::HeapGraphEdge::kInternal, "dependent_code"); 2779 GetProperty(map, v8::HeapGraphEdge::kInternal, "dependent_code");
2770 if (!dependent_code) return; 2780 if (!dependent_code) return;
2771 int count = dependent_code->GetChildrenCount(); 2781 int count = dependent_code->GetChildrenCount();
2772 CHECK_NE(0, count); 2782 CHECK_NE(0, count);
2773 for (int i = 0; i < count; ++i) { 2783 for (int i = 0; i < count; ++i) {
2774 const v8::HeapGraphEdge* prop = dependent_code->GetChild(i); 2784 const v8::HeapGraphEdge* prop = dependent_code->GetChild(i);
2775 CHECK_EQ(v8::HeapGraphEdge::kWeak, prop->GetType()); 2785 CHECK_EQ(v8::HeapGraphEdge::kWeak, prop->GetType());
2776 } 2786 }
2777 } 2787 }
2778 2788
2779 2789
2780 static inline i::Address ToAddress(int n) { 2790 static inline i::Address ToAddress(int n) {
2781 return reinterpret_cast<i::Address>(n); 2791 return reinterpret_cast<i::Address>(n);
2782 } 2792 }
2783 2793
2784 2794
2785 TEST(AddressToTraceMap) { 2795 TEST(AddressToTraceMap) {
2786 i::AddressToTraceMap map; 2796 i::AddressToTraceMap map;
2787 2797
2788 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(150))); 2798 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(150)));
2789 2799
2790 // [0x100, 0x200) -> 1 2800 // [0x100, 0x200) -> 1
2791 map.AddRange(ToAddress(0x100), 0x100, 1U); 2801 map.AddRange(ToAddress(0x100), 0x100, 1U);
2792 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x50))); 2802 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x50)));
2793 CHECK_EQ(1u, map.GetTraceNodeId(ToAddress(0x100))); 2803 CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x100)));
2794 CHECK_EQ(1u, map.GetTraceNodeId(ToAddress(0x150))); 2804 CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x150)));
2795 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x100 + 0x100))); 2805 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x100 + 0x100)));
2796 CHECK_EQ(1u, map.size()); 2806 CHECK_EQ(1, static_cast<int>(map.size()));
2797 2807
2798 // [0x100, 0x200) -> 1, [0x200, 0x300) -> 2 2808 // [0x100, 0x200) -> 1, [0x200, 0x300) -> 2
2799 map.AddRange(ToAddress(0x200), 0x100, 2U); 2809 map.AddRange(ToAddress(0x200), 0x100, 2U);
2800 CHECK_EQ(2u, map.GetTraceNodeId(ToAddress(0x2a0))); 2810 CHECK_EQ(2, map.GetTraceNodeId(ToAddress(0x2a0)));
2801 CHECK_EQ(2u, map.size()); 2811 CHECK_EQ(2, static_cast<int>(map.size()));
2802 2812
2803 // [0x100, 0x180) -> 1, [0x180, 0x280) -> 3, [0x280, 0x300) -> 2 2813 // [0x100, 0x180) -> 1, [0x180, 0x280) -> 3, [0x280, 0x300) -> 2
2804 map.AddRange(ToAddress(0x180), 0x100, 3U); 2814 map.AddRange(ToAddress(0x180), 0x100, 3U);
2805 CHECK_EQ(1u, map.GetTraceNodeId(ToAddress(0x17F))); 2815 CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x17F)));
2806 CHECK_EQ(2u, map.GetTraceNodeId(ToAddress(0x280))); 2816 CHECK_EQ(2, map.GetTraceNodeId(ToAddress(0x280)));
2807 CHECK_EQ(3u, map.GetTraceNodeId(ToAddress(0x180))); 2817 CHECK_EQ(3, map.GetTraceNodeId(ToAddress(0x180)));
2808 CHECK_EQ(3u, map.size()); 2818 CHECK_EQ(3, static_cast<int>(map.size()));
2809 2819
2810 // [0x100, 0x180) -> 1, [0x180, 0x280) -> 3, [0x280, 0x300) -> 2, 2820 // [0x100, 0x180) -> 1, [0x180, 0x280) -> 3, [0x280, 0x300) -> 2,
2811 // [0x400, 0x500) -> 4 2821 // [0x400, 0x500) -> 4
2812 map.AddRange(ToAddress(0x400), 0x100, 4U); 2822 map.AddRange(ToAddress(0x400), 0x100, 4U);
2813 CHECK_EQ(1u, map.GetTraceNodeId(ToAddress(0x17F))); 2823 CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x17F)));
2814 CHECK_EQ(2u, map.GetTraceNodeId(ToAddress(0x280))); 2824 CHECK_EQ(2, map.GetTraceNodeId(ToAddress(0x280)));
2815 CHECK_EQ(3u, map.GetTraceNodeId(ToAddress(0x180))); 2825 CHECK_EQ(3, map.GetTraceNodeId(ToAddress(0x180)));
2816 CHECK_EQ(4u, map.GetTraceNodeId(ToAddress(0x450))); 2826 CHECK_EQ(4, map.GetTraceNodeId(ToAddress(0x450)));
2817 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x500))); 2827 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x500)));
2818 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x350))); 2828 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x350)));
2819 CHECK_EQ(4u, map.size()); 2829 CHECK_EQ(4, static_cast<int>(map.size()));
2820 2830
2821 // [0x100, 0x180) -> 1, [0x180, 0x200) -> 3, [0x200, 0x600) -> 5 2831 // [0x100, 0x180) -> 1, [0x180, 0x200) -> 3, [0x200, 0x600) -> 5
2822 map.AddRange(ToAddress(0x200), 0x400, 5U); 2832 map.AddRange(ToAddress(0x200), 0x400, 5U);
2823 CHECK_EQ(5u, map.GetTraceNodeId(ToAddress(0x200))); 2833 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200)));
2824 CHECK_EQ(5u, map.GetTraceNodeId(ToAddress(0x400))); 2834 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x400)));
2825 CHECK_EQ(3u, map.size()); 2835 CHECK_EQ(3, static_cast<int>(map.size()));
2826 2836
2827 // [0x100, 0x180) -> 1, [0x180, 0x200) -> 7, [0x200, 0x600) ->5 2837 // [0x100, 0x180) -> 1, [0x180, 0x200) -> 7, [0x200, 0x600) ->5
2828 map.AddRange(ToAddress(0x180), 0x80, 6U); 2838 map.AddRange(ToAddress(0x180), 0x80, 6U);
2829 map.AddRange(ToAddress(0x180), 0x80, 7U); 2839 map.AddRange(ToAddress(0x180), 0x80, 7U);
2830 CHECK_EQ(7u, map.GetTraceNodeId(ToAddress(0x180))); 2840 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180)));
2831 CHECK_EQ(5u, map.GetTraceNodeId(ToAddress(0x200))); 2841 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200)));
2832 CHECK_EQ(3u, map.size()); 2842 CHECK_EQ(3, static_cast<int>(map.size()));
2833 2843
2834 map.Clear(); 2844 map.Clear();
2835 CHECK_EQ(0u, map.size()); 2845 CHECK_EQ(0, static_cast<int>(map.size()));
2836 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x400))); 2846 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400)));
2837 } 2847 }
OLDNEW
« no previous file with comments | « test/cctest/test-hashmap.cc ('k') | test/cctest/test-lockers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698