| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Tests for heap profiler | 3 // Tests for heap profiler |
| 4 | 4 |
| 5 #ifdef ENABLE_LOGGING_AND_PROFILING | 5 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 6 | 6 |
| 7 #include "v8.h" | 7 #include "v8.h" |
| 8 #include "heap-profiler.h" | 8 #include "heap-profiler.h" |
| 9 #include "snapshot.h" | 9 #include "snapshot.h" |
| 10 #include "string-stream.h" | 10 #include "string-stream.h" |
| 11 #include "cctest.h" | 11 #include "cctest.h" |
| 12 #include "zone-inl.h" | 12 #include "zone-inl.h" |
| 13 #include "../include/v8-profiler.h" | 13 #include "../include/v8-profiler.h" |
| 14 | 14 |
| 15 namespace i = v8::internal; | 15 namespace i = v8::internal; |
| 16 using i::ClustersCoarser; | 16 using i::ClustersCoarser; |
| 17 using i::JSObjectsCluster; | 17 using i::JSObjectsCluster; |
| 18 using i::JSObjectsRetainerTree; | 18 using i::JSObjectsRetainerTree; |
| 19 using i::JSObjectsClusterTree; | 19 using i::JSObjectsClusterTree; |
| 20 using i::RetainerHeapProfile; | 20 using i::RetainerHeapProfile; |
| 21 | 21 |
| 22 | 22 |
| 23 static void CompileAndRunScript(const char *src) { | |
| 24 v8::Script::Compile(v8::String::New(src))->Run(); | |
| 25 } | |
| 26 | |
| 27 | |
| 28 namespace { | 23 namespace { |
| 29 | 24 |
| 30 class ConstructorHeapProfileTestHelper : public i::ConstructorHeapProfile { | 25 class ConstructorHeapProfileTestHelper : public i::ConstructorHeapProfile { |
| 31 public: | 26 public: |
| 32 ConstructorHeapProfileTestHelper() | 27 ConstructorHeapProfileTestHelper() |
| 33 : i::ConstructorHeapProfile(), | 28 : i::ConstructorHeapProfile(), |
| 34 f_name_(i::Factory::NewStringFromAscii(i::CStrVector("F"))), | 29 f_name_(i::Factory::NewStringFromAscii(i::CStrVector("F"))), |
| 35 f_count_(0) { | 30 f_count_(0) { |
| 36 } | 31 } |
| 37 | 32 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 51 int f_count_; | 46 int f_count_; |
| 52 }; | 47 }; |
| 53 | 48 |
| 54 } // namespace | 49 } // namespace |
| 55 | 50 |
| 56 | 51 |
| 57 TEST(ConstructorProfile) { | 52 TEST(ConstructorProfile) { |
| 58 v8::HandleScope scope; | 53 v8::HandleScope scope; |
| 59 LocalContext env; | 54 LocalContext env; |
| 60 | 55 |
| 61 CompileAndRunScript( | 56 CompileRun( |
| 62 "function F() {} // A constructor\n" | 57 "function F() {} // A constructor\n" |
| 63 "var f1 = new F();\n" | 58 "var f1 = new F();\n" |
| 64 "var f2 = new F();\n"); | 59 "var f2 = new F();\n"); |
| 65 | 60 |
| 66 ConstructorHeapProfileTestHelper cons_profile; | 61 ConstructorHeapProfileTestHelper cons_profile; |
| 67 i::AssertNoAllocation no_alloc; | 62 i::AssertNoAllocation no_alloc; |
| 68 i::HeapIterator iterator; | 63 i::HeapIterator iterator; |
| 69 for (i::HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) | 64 for (i::HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) |
| 70 cons_profile.CollectStats(obj); | 65 cons_profile.CollectStats(obj); |
| 71 CHECK_EQ(0, cons_profile.f_count()); | 66 CHECK_EQ(0, cons_profile.f_count()); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 i::List<const char*> lines_; | 347 i::List<const char*> lines_; |
| 353 }; | 348 }; |
| 354 | 349 |
| 355 } // namespace | 350 } // namespace |
| 356 | 351 |
| 357 | 352 |
| 358 TEST(RetainerProfile) { | 353 TEST(RetainerProfile) { |
| 359 v8::HandleScope scope; | 354 v8::HandleScope scope; |
| 360 LocalContext env; | 355 LocalContext env; |
| 361 | 356 |
| 362 CompileAndRunScript( | 357 CompileRun( |
| 363 "function A() {}\n" | 358 "function A() {}\n" |
| 364 "function B(x) { this.x = x; }\n" | 359 "function B(x) { this.x = x; }\n" |
| 365 "function C(x) { this.x1 = x; this.x2 = x; }\n" | 360 "function C(x) { this.x1 = x; this.x2 = x; }\n" |
| 366 "var a = new A();\n" | 361 "var a = new A();\n" |
| 367 "var b1 = new B(a), b2 = new B(a);\n" | 362 "var b1 = new B(a), b2 = new B(a);\n" |
| 368 "var c = new C(a);"); | 363 "var c = new C(a);"); |
| 369 | 364 |
| 370 RetainerHeapProfile ret_profile; | 365 RetainerHeapProfile ret_profile; |
| 371 i::AssertNoAllocation no_alloc; | 366 i::AssertNoAllocation no_alloc; |
| 372 i::HeapIterator iterator; | 367 i::HeapIterator iterator; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 return false; | 461 return false; |
| 467 } | 462 } |
| 468 | 463 |
| 469 | 464 |
| 470 TEST(HeapSnapshot) { | 465 TEST(HeapSnapshot) { |
| 471 v8::HandleScope scope; | 466 v8::HandleScope scope; |
| 472 v8::Handle<v8::String> token1 = v8::String::New("token1"); | 467 v8::Handle<v8::String> token1 = v8::String::New("token1"); |
| 473 LocalContext env1; | 468 LocalContext env1; |
| 474 env1->SetSecurityToken(token1); | 469 env1->SetSecurityToken(token1); |
| 475 | 470 |
| 476 CompileAndRunScript( | 471 CompileRun( |
| 477 "function A1() {}\n" | 472 "function A1() {}\n" |
| 478 "function B1(x) { this.x = x; }\n" | 473 "function B1(x) { this.x = x; }\n" |
| 479 "function C1(x) { this.x1 = x; this.x2 = x; }\n" | 474 "function C1(x) { this.x1 = x; this.x2 = x; }\n" |
| 480 "var a1 = new A1();\n" | 475 "var a1 = new A1();\n" |
| 481 "var b1_1 = new B1(a1), b1_2 = new B1(a1);\n" | 476 "var b1_1 = new B1(a1), b1_2 = new B1(a1);\n" |
| 482 "var c1 = new C1(a1);"); | 477 "var c1 = new C1(a1);"); |
| 483 | 478 |
| 484 v8::Handle<v8::String> token2 = v8::String::New("token2"); | 479 v8::Handle<v8::String> token2 = v8::String::New("token2"); |
| 485 LocalContext env2; | 480 LocalContext env2; |
| 486 env2->SetSecurityToken(token2); | 481 env2->SetSecurityToken(token2); |
| 487 | 482 |
| 488 CompileAndRunScript( | 483 CompileRun( |
| 489 "function A2() {}\n" | 484 "function A2() {}\n" |
| 490 "function B2(x) { return function() { return typeof x; }; }\n" | 485 "function B2(x) { return function() { return typeof x; }; }\n" |
| 491 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" | 486 "function C2(x) { this.x1 = x; this.x2 = x; this[1] = x; }\n" |
| 492 "var a2 = new A2();\n" | 487 "var a2 = new A2();\n" |
| 493 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" | 488 "var b2_1 = new B2(a2), b2_2 = new B2(a2);\n" |
| 494 "var c2 = new C2(a2);"); | 489 "var c2 = new C2(a2);"); |
| 495 const v8::HeapSnapshot* snapshot_env2 = | 490 const v8::HeapSnapshot* snapshot_env2 = |
| 496 v8::HeapProfiler::TakeSnapshot(v8::String::New("env2")); | 491 v8::HeapProfiler::TakeSnapshot(v8::String::New("env2")); |
| 497 i::HeapSnapshot* i_snapshot_env2 = | 492 i::HeapSnapshot* i_snapshot_env2 = |
| 498 const_cast<i::HeapSnapshot*>( | 493 const_cast<i::HeapSnapshot*>( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 CHECK(has_b2_2_x_ref); | 571 CHECK(has_b2_2_x_ref); |
| 577 } | 572 } |
| 578 | 573 |
| 579 | 574 |
| 580 TEST(HeapSnapshotObjectSizes) { | 575 TEST(HeapSnapshotObjectSizes) { |
| 581 v8::HandleScope scope; | 576 v8::HandleScope scope; |
| 582 LocalContext env; | 577 LocalContext env; |
| 583 | 578 |
| 584 // -a-> X1 --a | 579 // -a-> X1 --a |
| 585 // x -b-> X2 <-| | 580 // x -b-> X2 <-| |
| 586 CompileAndRunScript( | 581 CompileRun( |
| 587 "function X(a, b) { this.a = a; this.b = b; }\n" | 582 "function X(a, b) { this.a = a; this.b = b; }\n" |
| 588 "x = new X(new X(), new X());\n" | 583 "x = new X(new X(), new X());\n" |
| 589 "x.a.a = x.b;"); | 584 "x.a.a = x.b;"); |
| 590 const v8::HeapSnapshot* snapshot = | 585 const v8::HeapSnapshot* snapshot = |
| 591 v8::HeapProfiler::TakeSnapshot(v8::String::New("sizes")); | 586 v8::HeapProfiler::TakeSnapshot(v8::String::New("sizes")); |
| 592 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 587 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 593 const v8::HeapGraphNode* x = | 588 const v8::HeapGraphNode* x = |
| 594 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); | 589 GetProperty(global, v8::HeapGraphEdge::kProperty, "x"); |
| 595 CHECK_NE(NULL, x); | 590 CHECK_NE(NULL, x); |
| 596 const v8::HeapGraphNode* x_prototype = | 591 const v8::HeapGraphNode* x_prototype = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 617 x2->GetReachableSize() - x_prototype->GetReachableSize()); | 612 x2->GetReachableSize() - x_prototype->GetReachableSize()); |
| 618 CHECK_EQ( | 613 CHECK_EQ( |
| 619 x2->GetSelfSize(), x2->GetRetainedSize()); | 614 x2->GetSelfSize(), x2->GetRetainedSize()); |
| 620 } | 615 } |
| 621 | 616 |
| 622 | 617 |
| 623 TEST(HeapSnapshotEntryChildren) { | 618 TEST(HeapSnapshotEntryChildren) { |
| 624 v8::HandleScope scope; | 619 v8::HandleScope scope; |
| 625 LocalContext env; | 620 LocalContext env; |
| 626 | 621 |
| 627 CompileAndRunScript( | 622 CompileRun( |
| 628 "function A() { }\n" | 623 "function A() { }\n" |
| 629 "a = new A;"); | 624 "a = new A;"); |
| 630 const v8::HeapSnapshot* snapshot = | 625 const v8::HeapSnapshot* snapshot = |
| 631 v8::HeapProfiler::TakeSnapshot(v8::String::New("children")); | 626 v8::HeapProfiler::TakeSnapshot(v8::String::New("children")); |
| 632 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 627 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 633 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { | 628 for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) { |
| 634 const v8::HeapGraphEdge* prop = global->GetChild(i); | 629 const v8::HeapGraphEdge* prop = global->GetChild(i); |
| 635 CHECK_EQ(global, prop->GetFromNode()); | 630 CHECK_EQ(global, prop->GetFromNode()); |
| 636 } | 631 } |
| 637 const v8::HeapGraphNode* a = | 632 const v8::HeapGraphNode* a = |
| 638 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); | 633 GetProperty(global, v8::HeapGraphEdge::kProperty, "a"); |
| 639 CHECK_NE(NULL, a); | 634 CHECK_NE(NULL, a); |
| 640 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) { | 635 for (int i = 0, count = a->GetChildrenCount(); i < count; ++i) { |
| 641 const v8::HeapGraphEdge* prop = a->GetChild(i); | 636 const v8::HeapGraphEdge* prop = a->GetChild(i); |
| 642 CHECK_EQ(a, prop->GetFromNode()); | 637 CHECK_EQ(a, prop->GetFromNode()); |
| 643 } | 638 } |
| 644 } | 639 } |
| 645 | 640 |
| 646 | 641 |
| 647 TEST(HeapSnapshotCodeObjects) { | 642 TEST(HeapSnapshotCodeObjects) { |
| 648 v8::HandleScope scope; | 643 v8::HandleScope scope; |
| 649 LocalContext env; | 644 LocalContext env; |
| 650 | 645 |
| 651 CompileAndRunScript( | 646 CompileRun( |
| 652 "function lazy(x) { return x - 1; }\n" | 647 "function lazy(x) { return x - 1; }\n" |
| 653 "function compiled(x) { return x + 1; }\n" | 648 "function compiled(x) { return x + 1; }\n" |
| 654 "var anonymous = (function() { return function() { return 0; } })();\n" | 649 "var anonymous = (function() { return function() { return 0; } })();\n" |
| 655 "compiled(1)"); | 650 "compiled(1)"); |
| 656 const v8::HeapSnapshot* snapshot = | 651 const v8::HeapSnapshot* snapshot = |
| 657 v8::HeapProfiler::TakeSnapshot(v8::String::New("code")); | 652 v8::HeapProfiler::TakeSnapshot(v8::String::New("code")); |
| 658 | 653 |
| 659 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 654 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 660 const v8::HeapGraphNode* compiled = | 655 const v8::HeapGraphNode* compiled = |
| 661 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled"); | 656 GetProperty(global, v8::HeapGraphEdge::kProperty, "compiled"); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 lazy_references_x = true; | 697 lazy_references_x = true; |
| 703 break; | 698 break; |
| 704 } | 699 } |
| 705 } | 700 } |
| 706 } | 701 } |
| 707 CHECK(compiled_references_x); | 702 CHECK(compiled_references_x); |
| 708 CHECK(!lazy_references_x); | 703 CHECK(!lazy_references_x); |
| 709 } | 704 } |
| 710 | 705 |
| 711 | 706 |
| 707 TEST(HeapSnapshotHeapNumbers) { |
| 708 v8::HandleScope scope; |
| 709 LocalContext env; |
| 710 CompileRun( |
| 711 "a = 1; // a is Smi\n" |
| 712 "b = 2.5; // b is HeapNumber"); |
| 713 const v8::HeapSnapshot* snapshot = |
| 714 v8::HeapProfiler::TakeSnapshot(v8::String::New("numbers")); |
| 715 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 716 CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a")); |
| 717 const v8::HeapGraphNode* b = |
| 718 GetProperty(global, v8::HeapGraphEdge::kProperty, "b"); |
| 719 CHECK_NE(NULL, b); |
| 720 CHECK_EQ(v8::HeapGraphNode::kHeapNumber, b->GetType()); |
| 721 } |
| 722 |
| 723 |
| 724 TEST(HeapSnapshotInternalReferences) { |
| 725 v8::HandleScope scope; |
| 726 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 727 global_template->SetInternalFieldCount(2); |
| 728 LocalContext env(NULL, global_template); |
| 729 v8::Handle<v8::Object> global_proxy = env->Global(); |
| 730 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
| 731 CHECK_EQ(2, global->InternalFieldCount()); |
| 732 v8::Local<v8::Object> obj = v8::Object::New(); |
| 733 global->SetInternalField(0, v8_num(17)); |
| 734 global->SetInternalField(1, obj); |
| 735 const v8::HeapSnapshot* snapshot = |
| 736 v8::HeapProfiler::TakeSnapshot(v8::String::New("internals")); |
| 737 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); |
| 738 // The first reference will not present, because it's a Smi. |
| 739 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); |
| 740 // The second reference is to an object. |
| 741 CHECK_NE(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "1")); |
| 742 } |
| 743 |
| 744 |
| 712 // Trying to introduce a check helper for uint64_t causes many | 745 // Trying to introduce a check helper for uint64_t causes many |
| 713 // overloading ambiguities, so it seems easier just to cast | 746 // overloading ambiguities, so it seems easier just to cast |
| 714 // them to a signed type. | 747 // them to a signed type. |
| 715 #define CHECK_EQ_UINT64_T(a, b) \ | 748 #define CHECK_EQ_UINT64_T(a, b) \ |
| 716 CHECK_EQ(static_cast<int64_t>(a), static_cast<int64_t>(b)) | 749 CHECK_EQ(static_cast<int64_t>(a), static_cast<int64_t>(b)) |
| 717 #define CHECK_NE_UINT64_T(a, b) \ | 750 #define CHECK_NE_UINT64_T(a, b) \ |
| 718 CHECK((a) != (b)) // NOLINT | 751 CHECK((a) != (b)) // NOLINT |
| 719 | 752 |
| 720 TEST(HeapEntryIdsAndGC) { | 753 TEST(HeapEntryIdsAndGC) { |
| 721 v8::HandleScope scope; | 754 v8::HandleScope scope; |
| 722 LocalContext env; | 755 LocalContext env; |
| 723 | 756 |
| 724 CompileAndRunScript( | 757 CompileRun( |
| 725 "function A() {}\n" | 758 "function A() {}\n" |
| 726 "function B(x) { this.x = x; }\n" | 759 "function B(x) { this.x = x; }\n" |
| 727 "var a = new A();\n" | 760 "var a = new A();\n" |
| 728 "var b = new B(a);"); | 761 "var b = new B(a);"); |
| 729 const v8::HeapSnapshot* snapshot1 = | 762 const v8::HeapSnapshot* snapshot1 = |
| 730 v8::HeapProfiler::TakeSnapshot(v8::String::New("s1")); | 763 v8::HeapProfiler::TakeSnapshot(v8::String::New("s1")); |
| 731 | 764 |
| 732 i::Heap::CollectAllGarbage(true); // Enforce compaction. | 765 i::Heap::CollectAllGarbage(true); // Enforce compaction. |
| 733 | 766 |
| 734 const v8::HeapSnapshot* snapshot2 = | 767 const v8::HeapSnapshot* snapshot2 = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 CHECK_NE(NULL, b2); | 803 CHECK_NE(NULL, b2); |
| 771 CHECK_NE_UINT64_T(0, b1->GetId()); | 804 CHECK_NE_UINT64_T(0, b1->GetId()); |
| 772 CHECK_EQ_UINT64_T(b1->GetId(), b2->GetId()); | 805 CHECK_EQ_UINT64_T(b1->GetId(), b2->GetId()); |
| 773 } | 806 } |
| 774 | 807 |
| 775 | 808 |
| 776 TEST(HeapSnapshotsDiff) { | 809 TEST(HeapSnapshotsDiff) { |
| 777 v8::HandleScope scope; | 810 v8::HandleScope scope; |
| 778 LocalContext env; | 811 LocalContext env; |
| 779 | 812 |
| 780 CompileAndRunScript( | 813 CompileRun( |
| 781 "function A() {}\n" | 814 "function A() {}\n" |
| 782 "function B(x) { this.x = x; }\n" | 815 "function B(x) { this.x = x; }\n" |
| 783 "function A2(a) { for (var i = 0; i < a; ++i) this[i] = i; }\n" | 816 "function A2(a) { for (var i = 0; i < a; ++i) this[i] = i; }\n" |
| 784 "var a = new A();\n" | 817 "var a = new A();\n" |
| 785 "var b = new B(a);"); | 818 "var b = new B(a);"); |
| 786 const v8::HeapSnapshot* snapshot1 = | 819 const v8::HeapSnapshot* snapshot1 = |
| 787 v8::HeapProfiler::TakeSnapshot(v8::String::New("s1")); | 820 v8::HeapProfiler::TakeSnapshot(v8::String::New("s1")); |
| 788 | 821 |
| 789 CompileAndRunScript( | 822 CompileRun( |
| 790 "delete a;\n" | 823 "delete a;\n" |
| 791 "b.x = null;\n" | 824 "b.x = null;\n" |
| 792 "var a = new A2(20);\n" | 825 "var a = new A2(20);\n" |
| 793 "var b2 = new B(a);"); | 826 "var b2 = new B(a);"); |
| 794 const v8::HeapSnapshot* snapshot2 = | 827 const v8::HeapSnapshot* snapshot2 = |
| 795 v8::HeapProfiler::TakeSnapshot(v8::String::New("s2")); | 828 v8::HeapProfiler::TakeSnapshot(v8::String::New("s2")); |
| 796 | 829 |
| 797 const v8::HeapSnapshotsDiff* diff = snapshot1->CompareWith(snapshot2); | 830 const v8::HeapSnapshotsDiff* diff = snapshot1->CompareWith(snapshot2); |
| 798 | 831 |
| 799 // Verify additions: ensure that addition of A and B was detected. | 832 // Verify additions: ensure that addition of A and B was detected. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 && element == prop->GetName()->Int32Value()) | 947 && element == prop->GetName()->Int32Value()) |
| 915 return true; | 948 return true; |
| 916 } | 949 } |
| 917 return false; | 950 return false; |
| 918 } | 951 } |
| 919 | 952 |
| 920 TEST(AggregatedHeapSnapshot) { | 953 TEST(AggregatedHeapSnapshot) { |
| 921 v8::HandleScope scope; | 954 v8::HandleScope scope; |
| 922 LocalContext env; | 955 LocalContext env; |
| 923 | 956 |
| 924 CompileAndRunScript( | 957 CompileRun( |
| 925 "function A() {}\n" | 958 "function A() {}\n" |
| 926 "function B(x) { this.x = x; }\n" | 959 "function B(x) { this.x = x; }\n" |
| 927 "var a = new A();\n" | 960 "var a = new A();\n" |
| 928 "var b = new B(a);"); | 961 "var b = new B(a);"); |
| 929 const v8::HeapSnapshot* snapshot = | 962 const v8::HeapSnapshot* snapshot = |
| 930 v8::HeapProfiler::TakeSnapshot( | 963 v8::HeapProfiler::TakeSnapshot( |
| 931 v8::String::New("agg"), v8::HeapSnapshot::kAggregated); | 964 v8::String::New("agg"), v8::HeapSnapshot::kAggregated); |
| 932 const v8::HeapGraphNode* strings = GetChild(snapshot->GetRoot(), | 965 const v8::HeapGraphNode* strings = GetChild(snapshot->GetRoot(), |
| 933 v8::HeapGraphNode::kInternal, | 966 v8::HeapGraphNode::kInternal, |
| 934 "STRING_TYPE"); | 967 "STRING_TYPE"); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 }; | 1068 }; |
| 1036 | 1069 |
| 1037 } // namespace | 1070 } // namespace |
| 1038 | 1071 |
| 1039 TEST(HeapSnapshotJSONSerialization) { | 1072 TEST(HeapSnapshotJSONSerialization) { |
| 1040 v8::HandleScope scope; | 1073 v8::HandleScope scope; |
| 1041 LocalContext env; | 1074 LocalContext env; |
| 1042 | 1075 |
| 1043 #define STRING_LITERAL_FOR_TEST \ | 1076 #define STRING_LITERAL_FOR_TEST \ |
| 1044 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" | 1077 "\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\"" |
| 1045 CompileAndRunScript( | 1078 CompileRun( |
| 1046 "function A(s) { this.s = s; }\n" | 1079 "function A(s) { this.s = s; }\n" |
| 1047 "function B(x) { this.x = x; }\n" | 1080 "function B(x) { this.x = x; }\n" |
| 1048 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n" | 1081 "var a = new A(" STRING_LITERAL_FOR_TEST ");\n" |
| 1049 "var b = new B(a);"); | 1082 "var b = new B(a);"); |
| 1050 const v8::HeapSnapshot* snapshot = | 1083 const v8::HeapSnapshot* snapshot = |
| 1051 v8::HeapProfiler::TakeSnapshot(v8::String::New("json")); | 1084 v8::HeapProfiler::TakeSnapshot(v8::String::New("json")); |
| 1052 TestJSONStream stream; | 1085 TestJSONStream stream; |
| 1053 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); | 1086 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); |
| 1054 CHECK_GT(stream.size(), 0); | 1087 CHECK_GT(stream.size(), 0); |
| 1055 CHECK_EQ(1, stream.eos_signaled()); | 1088 CHECK_EQ(1, stream.eos_signaled()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 LocalContext env; | 1175 LocalContext env; |
| 1143 const v8::HeapSnapshot* snapshot = | 1176 const v8::HeapSnapshot* snapshot = |
| 1144 v8::HeapProfiler::TakeSnapshot(v8::String::New("abort")); | 1177 v8::HeapProfiler::TakeSnapshot(v8::String::New("abort")); |
| 1145 TestJSONStream stream(5); | 1178 TestJSONStream stream(5); |
| 1146 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); | 1179 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); |
| 1147 CHECK_GT(stream.size(), 0); | 1180 CHECK_GT(stream.size(), 0); |
| 1148 CHECK_EQ(0, stream.eos_signaled()); | 1181 CHECK_EQ(0, stream.eos_signaled()); |
| 1149 } | 1182 } |
| 1150 | 1183 |
| 1151 #endif // ENABLE_LOGGING_AND_PROFILING | 1184 #endif // ENABLE_LOGGING_AND_PROFILING |
| OLD | NEW |