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

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

Issue 146213004: A64: Synchronize with r16849. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-liveedit.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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 CHECK_NE(NULL, child_string); 406 CHECK_NE(NULL, child_string);
407 CHECK_EQ(v8::HeapGraphNode::kSlicedString, child_string->GetType()); 407 CHECK_EQ(v8::HeapGraphNode::kSlicedString, child_string->GetType());
408 const v8::HeapGraphNode* parent = 408 const v8::HeapGraphNode* parent =
409 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); 409 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent");
410 CHECK_EQ(parent_string, parent); 410 CHECK_EQ(parent_string, parent);
411 heap_profiler->DeleteAllHeapSnapshots(); 411 heap_profiler->DeleteAllHeapSnapshots();
412 } 412 }
413 413
414 414
415 TEST(HeapSnapshotConsString) { 415 TEST(HeapSnapshotConsString) {
416 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 416 v8::Isolate* isolate = CcTest::isolate();
417 v8::HandleScope scope(isolate); 417 v8::HandleScope scope(isolate);
418 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 418 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
419 global_template->SetInternalFieldCount(1); 419 global_template->SetInternalFieldCount(1);
420 LocalContext env(NULL, global_template); 420 LocalContext env(NULL, global_template);
421 v8::Handle<v8::Object> global_proxy = env->Global(); 421 v8::Handle<v8::Object> global_proxy = env->Global();
422 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 422 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
423 CHECK_EQ(1, global->InternalFieldCount()); 423 CHECK_EQ(1, global->InternalFieldCount());
424 424
425 i::Factory* factory = i::Isolate::Current()->factory(); 425 i::Factory* factory = CcTest::i_isolate()->factory();
426 i::Handle<i::String> first = 426 i::Handle<i::String> first =
427 factory->NewStringFromAscii(i::CStrVector("0123456789")); 427 factory->NewStringFromAscii(i::CStrVector("0123456789"));
428 i::Handle<i::String> second = 428 i::Handle<i::String> second =
429 factory->NewStringFromAscii(i::CStrVector("0123456789")); 429 factory->NewStringFromAscii(i::CStrVector("0123456789"));
430 i::Handle<i::String> cons_string = factory->NewConsString(first, second); 430 i::Handle<i::String> cons_string = factory->NewConsString(first, second);
431 431
432 global->SetInternalField(0, v8::ToApiHandle<v8::String>(cons_string)); 432 global->SetInternalField(0, v8::ToApiHandle<v8::String>(cons_string));
433 433
434 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 434 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
435 const v8::HeapSnapshot* snapshot = 435 const v8::HeapSnapshot* snapshot =
(...skipping 13 matching lines...) Expand all
449 const v8::HeapGraphNode* second_node = 449 const v8::HeapGraphNode* second_node =
450 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "second"); 450 GetProperty(string_node, v8::HeapGraphEdge::kInternal, "second");
451 CHECK_EQ(v8::HeapGraphNode::kString, second_node->GetType()); 451 CHECK_EQ(v8::HeapGraphNode::kString, second_node->GetType());
452 452
453 heap_profiler->DeleteAllHeapSnapshots(); 453 heap_profiler->DeleteAllHeapSnapshots();
454 } 454 }
455 455
456 456
457 457
458 TEST(HeapSnapshotInternalReferences) { 458 TEST(HeapSnapshotInternalReferences) {
459 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 459 v8::Isolate* isolate = CcTest::isolate();
460 v8::HandleScope scope(isolate); 460 v8::HandleScope scope(isolate);
461 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 461 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
462 global_template->SetInternalFieldCount(2); 462 global_template->SetInternalFieldCount(2);
463 LocalContext env(NULL, global_template); 463 LocalContext env(NULL, global_template);
464 v8::Handle<v8::Object> global_proxy = env->Global(); 464 v8::Handle<v8::Object> global_proxy = env->Global();
465 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 465 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
466 CHECK_EQ(2, global->InternalFieldCount()); 466 CHECK_EQ(2, global->InternalFieldCount());
467 v8::Local<v8::Object> obj = v8::Object::New(); 467 v8::Local<v8::Object> obj = v8::Object::New();
468 global->SetInternalField(0, v8_num(17)); 468 global->SetInternalField(0, v8_num(17));
469 global->SetInternalField(1, obj); 469 global->SetInternalField(1, obj);
(...skipping 28 matching lines...) Expand all
498 "for (var i = 0; i < 10000; ++i)\n" 498 "for (var i = 0; i < 10000; ++i)\n"
499 " a[i] = new A();\n"); 499 " a[i] = new A();\n");
500 const v8::HeapSnapshot* snapshot1 = 500 const v8::HeapSnapshot* snapshot1 =
501 heap_profiler->TakeHeapSnapshot(v8_str("snapshot1")); 501 heap_profiler->TakeHeapSnapshot(v8_str("snapshot1"));
502 CHECK(ValidateSnapshot(snapshot1)); 502 CHECK(ValidateSnapshot(snapshot1));
503 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); 503 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId();
504 504
505 CompileRun( 505 CompileRun(
506 "for (var i = 0; i < 10000; ++i)\n" 506 "for (var i = 0; i < 10000; ++i)\n"
507 " a[i] = new A();\n"); 507 " a[i] = new A();\n");
508 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 508 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
509 509
510 const v8::HeapSnapshot* snapshot2 = 510 const v8::HeapSnapshot* snapshot2 =
511 heap_profiler->TakeHeapSnapshot(v8_str("snapshot2")); 511 heap_profiler->TakeHeapSnapshot(v8_str("snapshot2"));
512 CHECK(ValidateSnapshot(snapshot2)); 512 CHECK(ValidateSnapshot(snapshot2));
513 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); 513 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
514 514
515 const v8::HeapGraphNode* array_node = 515 const v8::HeapGraphNode* array_node =
516 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); 516 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a");
517 CHECK_NE(NULL, array_node); 517 CHECK_NE(NULL, array_node);
518 int wrong_count = 0; 518 int wrong_count = 0;
(...skipping 23 matching lines...) Expand all
542 "for (var i = 0; i < 10; ++i)\n" 542 "for (var i = 0; i < 10; ++i)\n"
543 " a.push(new AnObject());\n"); 543 " a.push(new AnObject());\n");
544 const v8::HeapSnapshot* snapshot1 = 544 const v8::HeapSnapshot* snapshot1 =
545 heap_profiler->TakeHeapSnapshot(v8_str("s1")); 545 heap_profiler->TakeHeapSnapshot(v8_str("s1"));
546 CHECK(ValidateSnapshot(snapshot1)); 546 CHECK(ValidateSnapshot(snapshot1));
547 547
548 CompileRun( 548 CompileRun(
549 "for (var i = 0; i < 1; ++i)\n" 549 "for (var i = 0; i < 1; ++i)\n"
550 " a.shift();\n"); 550 " a.shift();\n");
551 551
552 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 552 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
553 553
554 const v8::HeapSnapshot* snapshot2 = 554 const v8::HeapSnapshot* snapshot2 =
555 heap_profiler->TakeHeapSnapshot(v8_str("s2")); 555 heap_profiler->TakeHeapSnapshot(v8_str("s2"));
556 CHECK(ValidateSnapshot(snapshot2)); 556 CHECK(ValidateSnapshot(snapshot2));
557 557
558 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); 558 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
559 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); 559 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
560 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId()); 560 CHECK_NE_SNAPSHOT_OBJECT_ID(0, global1->GetId());
561 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId()); 561 CHECK_EQ_SNAPSHOT_OBJECT_ID(global1->GetId(), global2->GetId());
562 562
(...skipping 24 matching lines...) Expand all
587 "function A() {}\n" 587 "function A() {}\n"
588 "function B(x) { this.x = x; }\n" 588 "function B(x) { this.x = x; }\n"
589 "var a = new A();\n" 589 "var a = new A();\n"
590 "var b = new B(a);"); 590 "var b = new B(a);");
591 v8::Local<v8::String> s1_str = v8_str("s1"); 591 v8::Local<v8::String> s1_str = v8_str("s1");
592 v8::Local<v8::String> s2_str = v8_str("s2"); 592 v8::Local<v8::String> s2_str = v8_str("s2");
593 const v8::HeapSnapshot* snapshot1 = 593 const v8::HeapSnapshot* snapshot1 =
594 heap_profiler->TakeHeapSnapshot(s1_str); 594 heap_profiler->TakeHeapSnapshot(s1_str);
595 CHECK(ValidateSnapshot(snapshot1)); 595 CHECK(ValidateSnapshot(snapshot1));
596 596
597 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 597 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
598 598
599 const v8::HeapSnapshot* snapshot2 = 599 const v8::HeapSnapshot* snapshot2 =
600 heap_profiler->TakeHeapSnapshot(s2_str); 600 heap_profiler->TakeHeapSnapshot(s2_str);
601 CHECK(ValidateSnapshot(snapshot2)); 601 CHECK(ValidateSnapshot(snapshot2));
602 602
603 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000); 603 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000);
604 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= 604 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <=
605 snapshot2->GetMaxSnapshotJSObjectId()); 605 snapshot2->GetMaxSnapshotJSObjectId());
606 606
607 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); 607 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 894
895 TEST(HeapSnapshotObjectsStats) { 895 TEST(HeapSnapshotObjectsStats) {
896 LocalContext env; 896 LocalContext env;
897 v8::HandleScope scope(env->GetIsolate()); 897 v8::HandleScope scope(env->GetIsolate());
898 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 898 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
899 899
900 heap_profiler->StartTrackingHeapObjects(); 900 heap_profiler->StartTrackingHeapObjects();
901 // We have to call GC 6 times. In other case the garbage will be 901 // We have to call GC 6 times. In other case the garbage will be
902 // the reason of flakiness. 902 // the reason of flakiness.
903 for (int i = 0; i < 6; ++i) { 903 for (int i = 0; i < 6; ++i) {
904 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 904 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
905 } 905 }
906 906
907 v8::SnapshotObjectId initial_id; 907 v8::SnapshotObjectId initial_id;
908 { 908 {
909 // Single chunk of data expected in update. Initial data. 909 // Single chunk of data expected in update. Initial data.
910 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler, 910 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler,
911 &initial_id); 911 &initial_id);
912 CHECK_EQ(1, stats_update.intervals_count()); 912 CHECK_EQ(1, stats_update.intervals_count());
913 CHECK_EQ(1, stats_update.updates_written()); 913 CHECK_EQ(1, stats_update.updates_written());
914 CHECK_LT(0, stats_update.entries_size()); 914 CHECK_LT(0, stats_update.entries_size());
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 1475
1476 1476
1477 TEST(NoHandleLeaks) { 1477 TEST(NoHandleLeaks) {
1478 LocalContext env; 1478 LocalContext env;
1479 v8::HandleScope scope(env->GetIsolate()); 1479 v8::HandleScope scope(env->GetIsolate());
1480 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1480 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1481 1481
1482 CompileRun("document = { URL:\"abcdefgh\" };"); 1482 CompileRun("document = { URL:\"abcdefgh\" };");
1483 1483
1484 v8::Handle<v8::String> name(v8_str("leakz")); 1484 v8::Handle<v8::String> name(v8_str("leakz"));
1485 i::Isolate* isolate = i::Isolate::Current(); 1485 i::Isolate* isolate = CcTest::i_isolate();
1486 int count_before = i::HandleScope::NumberOfHandles(isolate); 1486 int count_before = i::HandleScope::NumberOfHandles(isolate);
1487 heap_profiler->TakeHeapSnapshot(name); 1487 heap_profiler->TakeHeapSnapshot(name);
1488 int count_after = i::HandleScope::NumberOfHandles(isolate); 1488 int count_after = i::HandleScope::NumberOfHandles(isolate);
1489 CHECK_EQ(count_before, count_after); 1489 CHECK_EQ(count_before, count_after);
1490 } 1490 }
1491 1491
1492 1492
1493 TEST(NodesIteration) { 1493 TEST(NodesIteration) {
1494 LocalContext env; 1494 LocalContext env;
1495 v8::HandleScope scope(env->GetIsolate()); 1495 v8::HandleScope scope(env->GetIsolate());
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 bool HasWeakEdge(const v8::HeapGraphNode* node) { 1731 bool HasWeakEdge(const v8::HeapGraphNode* node) {
1732 for (int i = 0; i < node->GetChildrenCount(); ++i) { 1732 for (int i = 0; i < node->GetChildrenCount(); ++i) {
1733 const v8::HeapGraphEdge* handle_edge = node->GetChild(i); 1733 const v8::HeapGraphEdge* handle_edge = node->GetChild(i);
1734 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true; 1734 if (handle_edge->GetType() == v8::HeapGraphEdge::kWeak) return true;
1735 } 1735 }
1736 return false; 1736 return false;
1737 } 1737 }
1738 1738
1739 1739
1740 bool HasWeakGlobalHandle() { 1740 bool HasWeakGlobalHandle() {
1741 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1741 v8::Isolate* isolate = CcTest::isolate();
1742 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 1742 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
1743 const v8::HeapSnapshot* snapshot = 1743 const v8::HeapSnapshot* snapshot =
1744 heap_profiler->TakeHeapSnapshot(v8_str("weaks")); 1744 heap_profiler->TakeHeapSnapshot(v8_str("weaks"));
1745 CHECK(ValidateSnapshot(snapshot)); 1745 CHECK(ValidateSnapshot(snapshot));
1746 const v8::HeapGraphNode* gc_roots = GetNode( 1746 const v8::HeapGraphNode* gc_roots = GetNode(
1747 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); 1747 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)");
1748 CHECK_NE(NULL, gc_roots); 1748 CHECK_NE(NULL, gc_roots);
1749 const v8::HeapGraphNode* global_handles = GetNode( 1749 const v8::HeapGraphNode* global_handles = GetNode(
1750 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); 1750 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)");
1751 CHECK_NE(NULL, global_handles); 1751 CHECK_NE(NULL, global_handles);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 CHECK(!HasWeakEdge(shared)); 1793 CHECK(!HasWeakEdge(shared));
1794 } 1794 }
1795 1795
1796 1796
1797 #ifdef ENABLE_DEBUGGER_SUPPORT 1797 #ifdef ENABLE_DEBUGGER_SUPPORT
1798 TEST(NoDebugObjectInSnapshot) { 1798 TEST(NoDebugObjectInSnapshot) {
1799 LocalContext env; 1799 LocalContext env;
1800 v8::HandleScope scope(env->GetIsolate()); 1800 v8::HandleScope scope(env->GetIsolate());
1801 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1801 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1802 1802
1803 v8::internal::Isolate::Current()->debug()->Load(); 1803 CcTest::i_isolate()->debug()->Load();
1804 CompileRun("foo = {};"); 1804 CompileRun("foo = {};");
1805 const v8::HeapSnapshot* snapshot = 1805 const v8::HeapSnapshot* snapshot =
1806 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 1806 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
1807 CHECK(ValidateSnapshot(snapshot)); 1807 CHECK(ValidateSnapshot(snapshot));
1808 const v8::HeapGraphNode* root = snapshot->GetRoot(); 1808 const v8::HeapGraphNode* root = snapshot->GetRoot();
1809 int globals_count = 0; 1809 int globals_count = 0;
1810 for (int i = 0; i < root->GetChildrenCount(); ++i) { 1810 for (int i = 0; i < root->GetChildrenCount(); ++i) {
1811 const v8::HeapGraphEdge* edge = root->GetChild(i); 1811 const v8::HeapGraphEdge* edge = root->GetChild(i);
1812 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { 1812 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) {
1813 ++globals_count; 1813 ++globals_count;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 1998 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
1999 CHECK(ValidateSnapshot(snapshot)); 1999 CHECK(ValidateSnapshot(snapshot));
2000 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2000 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2001 const v8::HeapGraphNode* foo_func = 2001 const v8::HeapGraphNode* foo_func =
2002 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); 2002 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo");
2003 CHECK_NE(NULL, foo_func); 2003 CHECK_NE(NULL, foo_func);
2004 const v8::HeapGraphNode* code = 2004 const v8::HeapGraphNode* code =
2005 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); 2005 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code");
2006 CHECK_NE(NULL, code); 2006 CHECK_NE(NULL, code);
2007 } 2007 }
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-liveedit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698