| OLD | NEW |
| 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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 494 |
| 495 CompileRun(program); | 495 CompileRun(program); |
| 496 // The TakeHeapSnapshot function does not do enough GCs to ensure | 496 // The TakeHeapSnapshot function does not do enough GCs to ensure |
| 497 // that all garbage is collected. We perform addition GC here | 497 // that all garbage is collected. We perform addition GC here |
| 498 // to reclaim a floating AllocationSite and to fix the following failure: | 498 // to reclaim a floating AllocationSite and to fix the following failure: |
| 499 // # Check failed: ValidateSnapshot(snapshot). | 499 // # Check failed: ValidateSnapshot(snapshot). |
| 500 // Stdout: | 500 // Stdout: |
| 501 // 28 @ 13523 entry with no retainer: /hidden/ system / AllocationSite | 501 // 28 @ 13523 entry with no retainer: /hidden/ system / AllocationSite |
| 502 // 44 @ 767 $map: /hidden/ system / Map | 502 // 44 @ 767 $map: /hidden/ system / Map |
| 503 // 44 @ 59 $map: /hidden/ system / Map | 503 // 44 @ 59 $map: /hidden/ system / Map |
| 504 CcTest::heap()->CollectAllGarbage(); | 504 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); |
| 505 | 505 |
| 506 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); | 506 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
| 507 CHECK(ValidateSnapshot(snapshot)); | 507 CHECK(ValidateSnapshot(snapshot)); |
| 508 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 508 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 509 const v8::HeapGraphNode* var = | 509 const v8::HeapGraphNode* var = |
| 510 GetProperty(global, v8::HeapGraphEdge::kProperty, var_name); | 510 GetProperty(global, v8::HeapGraphEdge::kProperty, var_name); |
| 511 CHECK(var); | 511 CHECK(var); |
| 512 CHECK_EQ(var->GetType(), v8::HeapGraphNode::kSimdValue); | 512 CHECK_EQ(var->GetType(), v8::HeapGraphNode::kSimdValue); |
| 513 } | 513 } |
| 514 | 514 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 "var a = [];\n" | 731 "var a = [];\n" |
| 732 "for (var i = 0; i < 10000; ++i)\n" | 732 "for (var i = 0; i < 10000; ++i)\n" |
| 733 " a[i] = new A();\n"); | 733 " a[i] = new A();\n"); |
| 734 const v8::HeapSnapshot* snapshot1 = heap_profiler->TakeHeapSnapshot(); | 734 const v8::HeapSnapshot* snapshot1 = heap_profiler->TakeHeapSnapshot(); |
| 735 CHECK(ValidateSnapshot(snapshot1)); | 735 CHECK(ValidateSnapshot(snapshot1)); |
| 736 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); | 736 v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); |
| 737 | 737 |
| 738 CompileRun( | 738 CompileRun( |
| 739 "for (var i = 0; i < 10000; ++i)\n" | 739 "for (var i = 0; i < 10000; ++i)\n" |
| 740 " a[i] = new A();\n"); | 740 " a[i] = new A();\n"); |
| 741 CcTest::heap()->CollectAllGarbage(); | 741 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); |
| 742 | 742 |
| 743 const v8::HeapSnapshot* snapshot2 = heap_profiler->TakeHeapSnapshot(); | 743 const v8::HeapSnapshot* snapshot2 = heap_profiler->TakeHeapSnapshot(); |
| 744 CHECK(ValidateSnapshot(snapshot2)); | 744 CHECK(ValidateSnapshot(snapshot2)); |
| 745 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); | 745 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
| 746 | 746 |
| 747 const v8::HeapGraphNode* array_node = | 747 const v8::HeapGraphNode* array_node = |
| 748 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); | 748 GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); |
| 749 CHECK(array_node); | 749 CHECK(array_node); |
| 750 int wrong_count = 0; | 750 int wrong_count = 0; |
| 751 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) { | 751 for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 773 "var a = new Array();\n" | 773 "var a = new Array();\n" |
| 774 "for (var i = 0; i < 10; ++i)\n" | 774 "for (var i = 0; i < 10; ++i)\n" |
| 775 " a.push(new AnObject());\n"); | 775 " a.push(new AnObject());\n"); |
| 776 const v8::HeapSnapshot* snapshot1 = heap_profiler->TakeHeapSnapshot(); | 776 const v8::HeapSnapshot* snapshot1 = heap_profiler->TakeHeapSnapshot(); |
| 777 CHECK(ValidateSnapshot(snapshot1)); | 777 CHECK(ValidateSnapshot(snapshot1)); |
| 778 | 778 |
| 779 CompileRun( | 779 CompileRun( |
| 780 "for (var i = 0; i < 1; ++i)\n" | 780 "for (var i = 0; i < 1; ++i)\n" |
| 781 " a.shift();\n"); | 781 " a.shift();\n"); |
| 782 | 782 |
| 783 CcTest::heap()->CollectAllGarbage(); | 783 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); |
| 784 | 784 |
| 785 const v8::HeapSnapshot* snapshot2 = heap_profiler->TakeHeapSnapshot(); | 785 const v8::HeapSnapshot* snapshot2 = heap_profiler->TakeHeapSnapshot(); |
| 786 CHECK(ValidateSnapshot(snapshot2)); | 786 CHECK(ValidateSnapshot(snapshot2)); |
| 787 | 787 |
| 788 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); | 788 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); |
| 789 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); | 789 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
| 790 CHECK_NE(0u, global1->GetId()); | 790 CHECK_NE(0u, global1->GetId()); |
| 791 CHECK_EQ(global1->GetId(), global2->GetId()); | 791 CHECK_EQ(global1->GetId(), global2->GetId()); |
| 792 | 792 |
| 793 const v8::HeapGraphNode* a1 = | 793 const v8::HeapGraphNode* a1 = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 814 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 814 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 815 | 815 |
| 816 CompileRun( | 816 CompileRun( |
| 817 "function A() {}\n" | 817 "function A() {}\n" |
| 818 "function B(x) { this.x = x; }\n" | 818 "function B(x) { this.x = x; }\n" |
| 819 "var a = new A();\n" | 819 "var a = new A();\n" |
| 820 "var b = new B(a);"); | 820 "var b = new B(a);"); |
| 821 const v8::HeapSnapshot* snapshot1 = heap_profiler->TakeHeapSnapshot(); | 821 const v8::HeapSnapshot* snapshot1 = heap_profiler->TakeHeapSnapshot(); |
| 822 CHECK(ValidateSnapshot(snapshot1)); | 822 CHECK(ValidateSnapshot(snapshot1)); |
| 823 | 823 |
| 824 CcTest::heap()->CollectAllGarbage(); | 824 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); |
| 825 | 825 |
| 826 const v8::HeapSnapshot* snapshot2 = heap_profiler->TakeHeapSnapshot(); | 826 const v8::HeapSnapshot* snapshot2 = heap_profiler->TakeHeapSnapshot(); |
| 827 CHECK(ValidateSnapshot(snapshot2)); | 827 CHECK(ValidateSnapshot(snapshot2)); |
| 828 | 828 |
| 829 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000u); | 829 CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000u); |
| 830 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= | 830 CHECK(snapshot1->GetMaxSnapshotJSObjectId() <= |
| 831 snapshot2->GetMaxSnapshotJSObjectId()); | 831 snapshot2->GetMaxSnapshotJSObjectId()); |
| 832 | 832 |
| 833 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); | 833 const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1); |
| 834 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); | 834 const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 | 1143 |
| 1144 TEST(HeapSnapshotObjectsStats) { | 1144 TEST(HeapSnapshotObjectsStats) { |
| 1145 LocalContext env; | 1145 LocalContext env; |
| 1146 v8::HandleScope scope(env->GetIsolate()); | 1146 v8::HandleScope scope(env->GetIsolate()); |
| 1147 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1147 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 1148 | 1148 |
| 1149 heap_profiler->StartTrackingHeapObjects(); | 1149 heap_profiler->StartTrackingHeapObjects(); |
| 1150 // We have to call GC 6 times. In other case the garbage will be | 1150 // We have to call GC 6 times. In other case the garbage will be |
| 1151 // the reason of flakiness. | 1151 // the reason of flakiness. |
| 1152 for (int i = 0; i < 6; ++i) { | 1152 for (int i = 0; i < 6; ++i) { |
| 1153 CcTest::heap()->CollectAllGarbage(); | 1153 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); |
| 1154 } | 1154 } |
| 1155 | 1155 |
| 1156 v8::SnapshotObjectId initial_id; | 1156 v8::SnapshotObjectId initial_id; |
| 1157 { | 1157 { |
| 1158 // Single chunk of data expected in update. Initial data. | 1158 // Single chunk of data expected in update. Initial data. |
| 1159 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler, | 1159 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler, |
| 1160 &initial_id); | 1160 &initial_id); |
| 1161 CHECK_EQ(1, stats_update.intervals_count()); | 1161 CHECK_EQ(1, stats_update.intervals_count()); |
| 1162 CHECK_EQ(1, stats_update.updates_written()); | 1162 CHECK_EQ(1, stats_update.updates_written()); |
| 1163 CHECK_LT(0u, stats_update.entries_size()); | 1163 CHECK_LT(0u, stats_update.entries_size()); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 } | 1298 } |
| 1299 GetHeapStatsUpdate(heap_profiler); | 1299 GetHeapStatsUpdate(heap_profiler); |
| 1300 | 1300 |
| 1301 for (int i = 0; i < kLength; i++) { | 1301 for (int i = 0; i < kLength; i++) { |
| 1302 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]); | 1302 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]); |
| 1303 CHECK_NE(v8::HeapProfiler::kUnknownObjectId, id); | 1303 CHECK_NE(v8::HeapProfiler::kUnknownObjectId, id); |
| 1304 ids[i] = id; | 1304 ids[i] = id; |
| 1305 } | 1305 } |
| 1306 | 1306 |
| 1307 heap_profiler->StopTrackingHeapObjects(); | 1307 heap_profiler->StopTrackingHeapObjects(); |
| 1308 CcTest::heap()->CollectAllAvailableGarbage(); | 1308 CcTest::CollectAllAvailableGarbage(); |
| 1309 | 1309 |
| 1310 for (int i = 0; i < kLength; i++) { | 1310 for (int i = 0; i < kLength; i++) { |
| 1311 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]); | 1311 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]); |
| 1312 CHECK_EQ(ids[i], id); | 1312 CHECK_EQ(ids[i], id); |
| 1313 v8::Local<v8::Value> obj = heap_profiler->FindObjectById(ids[i]); | 1313 v8::Local<v8::Value> obj = heap_profiler->FindObjectById(ids[i]); |
| 1314 CHECK(objects[i]->Equals(env.local(), obj).FromJust()); | 1314 CHECK(objects[i]->Equals(env.local(), obj).FromJust()); |
| 1315 } | 1315 } |
| 1316 | 1316 |
| 1317 heap_profiler->ClearObjectIds(); | 1317 heap_profiler->ClearObjectIds(); |
| 1318 for (int i = 0; i < kLength; i++) { | 1318 for (int i = 0; i < kLength; i++) { |
| (...skipping 1732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3051 } | 3051 } |
| 3052 | 3052 |
| 3053 // A test case with scripts unloaded before profile gathered | 3053 // A test case with scripts unloaded before profile gathered |
| 3054 { | 3054 { |
| 3055 heap_profiler->StartSamplingHeapProfiler(64); | 3055 heap_profiler->StartSamplingHeapProfiler(64); |
| 3056 CompileRun( | 3056 CompileRun( |
| 3057 "for (var i = 0; i < 1024; i++) {\n" | 3057 "for (var i = 0; i < 1024; i++) {\n" |
| 3058 " eval(\"new Array(100)\");\n" | 3058 " eval(\"new Array(100)\");\n" |
| 3059 "}\n"); | 3059 "}\n"); |
| 3060 | 3060 |
| 3061 CcTest::heap()->CollectAllGarbage(); | 3061 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); |
| 3062 | 3062 |
| 3063 std::unique_ptr<v8::AllocationProfile> profile( | 3063 std::unique_ptr<v8::AllocationProfile> profile( |
| 3064 heap_profiler->GetAllocationProfile()); | 3064 heap_profiler->GetAllocationProfile()); |
| 3065 CHECK(profile); | 3065 CHECK(profile); |
| 3066 | 3066 |
| 3067 CheckNoZeroCountNodes(profile->GetRootNode()); | 3067 CheckNoZeroCountNodes(profile->GetRootNode()); |
| 3068 | 3068 |
| 3069 heap_profiler->StopSamplingHeapProfiler(); | 3069 heap_profiler->StopSamplingHeapProfiler(); |
| 3070 } | 3070 } |
| 3071 } | 3071 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3105 | 3105 |
| 3106 CompileRun( | 3106 CompileRun( |
| 3107 "for (var j = 0; j < 500; ++j) {\n" | 3107 "for (var j = 0; j < 500; ++j) {\n" |
| 3108 " var a = [];\n" | 3108 " var a = [];\n" |
| 3109 " for (var i = 0; i < 5; ++i)\n" | 3109 " for (var i = 0; i < 5; ++i)\n" |
| 3110 " a[i] = i;\n" | 3110 " a[i] = i;\n" |
| 3111 " for (var i = 0; i < 3; ++i)\n" | 3111 " for (var i = 0; i < 3; ++i)\n" |
| 3112 " a.shift();\n" | 3112 " a.shift();\n" |
| 3113 "}\n"); | 3113 "}\n"); |
| 3114 | 3114 |
| 3115 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE); | 3115 CcTest::CollectGarbage(v8::internal::NEW_SPACE); |
| 3116 // Should not crash. | 3116 // Should not crash. |
| 3117 | 3117 |
| 3118 heap_profiler->StopSamplingHeapProfiler(); | 3118 heap_profiler->StopSamplingHeapProfiler(); |
| 3119 } | 3119 } |
| OLD | NEW |