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

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

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