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

Side by Side Diff: test/unittests/compiler/zone-pool-unittest.cc

Issue 2401173002: Version 5.6.1.1 (cherry-pick) (Closed)
Patch Set: Created 4 years, 2 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/unittests/BUILD.gn ('k') | test/unittests/compiler/zone-stats-unittest.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/zone-stats.h"
6 #include "src/base/utils/random-number-generator.h" 5 #include "src/base/utils/random-number-generator.h"
6 #include "src/compiler/zone-pool.h"
7 #include "test/unittests/test-utils.h" 7 #include "test/unittests/test-utils.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 namespace compiler { 11 namespace compiler {
12 12
13 class ZoneStatsTest : public TestWithIsolate { 13 class ZonePoolTest : public TestWithIsolate {
14 public: 14 public:
15 ZoneStatsTest() : zone_stats_(&allocator_) {} 15 ZonePoolTest() : zone_pool_(&allocator_) {}
16 16
17 protected: 17 protected:
18 ZoneStats* zone_stats() { return &zone_stats_; } 18 ZonePool* zone_pool() { return &zone_pool_; }
19 19
20 void ExpectForPool(size_t current, size_t max, size_t total) { 20 void ExpectForPool(size_t current, size_t max, size_t total) {
21 ASSERT_EQ(current, zone_stats()->GetCurrentAllocatedBytes()); 21 ASSERT_EQ(current, zone_pool()->GetCurrentAllocatedBytes());
22 ASSERT_EQ(max, zone_stats()->GetMaxAllocatedBytes()); 22 ASSERT_EQ(max, zone_pool()->GetMaxAllocatedBytes());
23 ASSERT_EQ(total, zone_stats()->GetTotalAllocatedBytes()); 23 ASSERT_EQ(total, zone_pool()->GetTotalAllocatedBytes());
24 } 24 }
25 25
26 void Expect(ZoneStats::StatsScope* stats, size_t current, size_t max, 26 void Expect(ZonePool::StatsScope* stats, size_t current, size_t max,
27 size_t total) { 27 size_t total) {
28 ASSERT_EQ(current, stats->GetCurrentAllocatedBytes()); 28 ASSERT_EQ(current, stats->GetCurrentAllocatedBytes());
29 ASSERT_EQ(max, stats->GetMaxAllocatedBytes()); 29 ASSERT_EQ(max, stats->GetMaxAllocatedBytes());
30 ASSERT_EQ(total, stats->GetTotalAllocatedBytes()); 30 ASSERT_EQ(total, stats->GetTotalAllocatedBytes());
31 } 31 }
32 32
33 size_t Allocate(Zone* zone) { 33 size_t Allocate(Zone* zone) {
34 size_t bytes = rng.NextInt(25) + 7; 34 size_t bytes = rng.NextInt(25) + 7;
35 size_t size_before = zone->allocation_size(); 35 size_t size_before = zone->allocation_size();
36 zone->New(bytes); 36 zone->New(bytes);
37 return zone->allocation_size() - size_before; 37 return zone->allocation_size() - size_before;
38 } 38 }
39 39
40 private: 40 private:
41 v8::internal::AccountingAllocator allocator_; 41 v8::internal::AccountingAllocator allocator_;
42 ZoneStats zone_stats_; 42 ZonePool zone_pool_;
43 base::RandomNumberGenerator rng; 43 base::RandomNumberGenerator rng;
44 }; 44 };
45 45
46 TEST_F(ZoneStatsTest, Empty) { 46
47 TEST_F(ZonePoolTest, Empty) {
47 ExpectForPool(0, 0, 0); 48 ExpectForPool(0, 0, 0);
48 { 49 {
49 ZoneStats::StatsScope stats(zone_stats()); 50 ZonePool::StatsScope stats(zone_pool());
50 Expect(&stats, 0, 0, 0); 51 Expect(&stats, 0, 0, 0);
51 } 52 }
52 ExpectForPool(0, 0, 0); 53 ExpectForPool(0, 0, 0);
53 { 54 {
54 ZoneStats::Scope scope(zone_stats()); 55 ZonePool::Scope scope(zone_pool());
55 scope.zone(); 56 scope.zone();
56 } 57 }
57 ExpectForPool(0, 0, 0); 58 ExpectForPool(0, 0, 0);
58 } 59 }
59 60
60 TEST_F(ZoneStatsTest, MultipleZonesWithDeletion) { 61
62 TEST_F(ZonePoolTest, MultipleZonesWithDeletion) {
61 static const size_t kArraySize = 10; 63 static const size_t kArraySize = 10;
62 64
63 ZoneStats::Scope* scopes[kArraySize]; 65 ZonePool::Scope* scopes[kArraySize];
64 66
65 // Initialize. 67 // Initialize.
66 size_t before_stats = 0; 68 size_t before_stats = 0;
67 for (size_t i = 0; i < kArraySize; ++i) { 69 for (size_t i = 0; i < kArraySize; ++i) {
68 scopes[i] = new ZoneStats::Scope(zone_stats()); 70 scopes[i] = new ZonePool::Scope(zone_pool());
69 before_stats += Allocate(scopes[i]->zone()); // Add some stuff. 71 before_stats += Allocate(scopes[i]->zone()); // Add some stuff.
70 } 72 }
71 73
72 ExpectForPool(before_stats, before_stats, before_stats); 74 ExpectForPool(before_stats, before_stats, before_stats);
73 75
74 ZoneStats::StatsScope stats(zone_stats()); 76 ZonePool::StatsScope stats(zone_pool());
75 77
76 size_t before_deletion = 0; 78 size_t before_deletion = 0;
77 for (size_t i = 0; i < kArraySize; ++i) { 79 for (size_t i = 0; i < kArraySize; ++i) {
78 before_deletion += Allocate(scopes[i]->zone()); // Add some stuff. 80 before_deletion += Allocate(scopes[i]->zone()); // Add some stuff.
79 } 81 }
80 82
81 Expect(&stats, before_deletion, before_deletion, before_deletion); 83 Expect(&stats, before_deletion, before_deletion, before_deletion);
82 ExpectForPool(before_stats + before_deletion, before_stats + before_deletion, 84 ExpectForPool(before_stats + before_deletion, before_stats + before_deletion,
83 before_stats + before_deletion); 85 before_stats + before_deletion);
84 86
85 // Delete the scopes and create new ones. 87 // Delete the scopes and create new ones.
86 for (size_t i = 0; i < kArraySize; ++i) { 88 for (size_t i = 0; i < kArraySize; ++i) {
87 delete scopes[i]; 89 delete scopes[i];
88 scopes[i] = new ZoneStats::Scope(zone_stats()); 90 scopes[i] = new ZonePool::Scope(zone_pool());
89 } 91 }
90 92
91 Expect(&stats, 0, before_deletion, before_deletion); 93 Expect(&stats, 0, before_deletion, before_deletion);
92 ExpectForPool(0, before_stats + before_deletion, 94 ExpectForPool(0, before_stats + before_deletion,
93 before_stats + before_deletion); 95 before_stats + before_deletion);
94 96
95 size_t after_deletion = 0; 97 size_t after_deletion = 0;
96 for (size_t i = 0; i < kArraySize; ++i) { 98 for (size_t i = 0; i < kArraySize; ++i) {
97 after_deletion += Allocate(scopes[i]->zone()); // Add some stuff. 99 after_deletion += Allocate(scopes[i]->zone()); // Add some stuff.
98 } 100 }
99 101
100 Expect(&stats, after_deletion, std::max(after_deletion, before_deletion), 102 Expect(&stats, after_deletion, std::max(after_deletion, before_deletion),
101 before_deletion + after_deletion); 103 before_deletion + after_deletion);
102 ExpectForPool(after_deletion, 104 ExpectForPool(after_deletion,
103 std::max(after_deletion, before_stats + before_deletion), 105 std::max(after_deletion, before_stats + before_deletion),
104 before_stats + before_deletion + after_deletion); 106 before_stats + before_deletion + after_deletion);
105 107
106 // Cleanup. 108 // Cleanup.
107 for (size_t i = 0; i < kArraySize; ++i) { 109 for (size_t i = 0; i < kArraySize; ++i) {
108 delete scopes[i]; 110 delete scopes[i];
109 } 111 }
110 112
111 Expect(&stats, 0, std::max(after_deletion, before_deletion), 113 Expect(&stats, 0, std::max(after_deletion, before_deletion),
112 before_deletion + after_deletion); 114 before_deletion + after_deletion);
113 ExpectForPool(0, std::max(after_deletion, before_stats + before_deletion), 115 ExpectForPool(0, std::max(after_deletion, before_stats + before_deletion),
114 before_stats + before_deletion + after_deletion); 116 before_stats + before_deletion + after_deletion);
115 } 117 }
116 118
117 TEST_F(ZoneStatsTest, SimpleAllocationLoop) { 119
120 TEST_F(ZonePoolTest, SimpleAllocationLoop) {
118 int runs = 20; 121 int runs = 20;
119 size_t total_allocated = 0; 122 size_t total_allocated = 0;
120 size_t max_loop_allocation = 0; 123 size_t max_loop_allocation = 0;
121 ZoneStats::StatsScope outer_stats(zone_stats()); 124 ZonePool::StatsScope outer_stats(zone_pool());
122 { 125 {
123 ZoneStats::Scope outer_scope(zone_stats()); 126 ZonePool::Scope outer_scope(zone_pool());
124 size_t outer_allocated = 0; 127 size_t outer_allocated = 0;
125 for (int i = 0; i < runs; ++i) { 128 for (int i = 0; i < runs; ++i) {
126 { 129 {
127 size_t bytes = Allocate(outer_scope.zone()); 130 size_t bytes = Allocate(outer_scope.zone());
128 outer_allocated += bytes; 131 outer_allocated += bytes;
129 total_allocated += bytes; 132 total_allocated += bytes;
130 } 133 }
131 ZoneStats::StatsScope inner_stats(zone_stats()); 134 ZonePool::StatsScope inner_stats(zone_pool());
132 size_t allocated = 0; 135 size_t allocated = 0;
133 { 136 {
134 ZoneStats::Scope inner_scope(zone_stats()); 137 ZonePool::Scope inner_scope(zone_pool());
135 for (int j = 0; j < 20; ++j) { 138 for (int j = 0; j < 20; ++j) {
136 size_t bytes = Allocate(inner_scope.zone()); 139 size_t bytes = Allocate(inner_scope.zone());
137 allocated += bytes; 140 allocated += bytes;
138 total_allocated += bytes; 141 total_allocated += bytes;
139 max_loop_allocation = 142 max_loop_allocation =
140 std::max(max_loop_allocation, outer_allocated + allocated); 143 std::max(max_loop_allocation, outer_allocated + allocated);
141 Expect(&inner_stats, allocated, allocated, allocated); 144 Expect(&inner_stats, allocated, allocated, allocated);
142 Expect(&outer_stats, outer_allocated + allocated, max_loop_allocation, 145 Expect(&outer_stats, outer_allocated + allocated, max_loop_allocation,
143 total_allocated); 146 total_allocated);
144 ExpectForPool(outer_allocated + allocated, max_loop_allocation, 147 ExpectForPool(outer_allocated + allocated, max_loop_allocation,
145 total_allocated); 148 total_allocated);
146 } 149 }
147 } 150 }
148 Expect(&inner_stats, 0, allocated, allocated); 151 Expect(&inner_stats, 0, allocated, allocated);
149 Expect(&outer_stats, outer_allocated, max_loop_allocation, 152 Expect(&outer_stats, outer_allocated, max_loop_allocation,
150 total_allocated); 153 total_allocated);
151 ExpectForPool(outer_allocated, max_loop_allocation, total_allocated); 154 ExpectForPool(outer_allocated, max_loop_allocation, total_allocated);
152 } 155 }
153 } 156 }
154 Expect(&outer_stats, 0, max_loop_allocation, total_allocated); 157 Expect(&outer_stats, 0, max_loop_allocation, total_allocated);
155 ExpectForPool(0, max_loop_allocation, total_allocated); 158 ExpectForPool(0, max_loop_allocation, total_allocated);
156 } 159 }
157 160
158 } // namespace compiler 161 } // namespace compiler
159 } // namespace internal 162 } // namespace internal
160 } // namespace v8 163 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/BUILD.gn ('k') | test/unittests/compiler/zone-stats-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698