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

Side by Side Diff: test/heap-unittests/heap-unittest.cc

Issue 496273002: First tests for GCIdleTimeHandler. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebase Created 6 years, 4 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/heap-unittests/heap-unittest.h ('k') | no next file » | 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 "test/heap-unittests/heap-unittest.h"
6
5 #include <limits> 7 #include <limits>
6 8
7 #include "src/heap/gc-idle-time-handler.h"
8
9 #include "testing/gtest/include/gtest/gtest.h"
10 9
11 namespace v8 { 10 namespace v8 {
12 namespace internal { 11 namespace internal {
13 12
14 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeInitial) { 13 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeInitial) {
15 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(1, 0); 14 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(1, 0);
16 EXPECT_EQ( 15 EXPECT_EQ(
17 static_cast<size_t>(GCIdleTimeHandler::kInitialConservativeMarkingSpeed * 16 static_cast<size_t>(GCIdleTimeHandler::kInitialConservativeMarkingSpeed *
18 GCIdleTimeHandler::kConservativeTimeRatio), 17 GCIdleTimeHandler::kConservativeTimeRatio),
19 step_size); 18 step_size);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 61 }
63 62
64 63
65 TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeMax) { 64 TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeMax) {
66 size_t size = std::numeric_limits<size_t>::max(); 65 size_t size = std::numeric_limits<size_t>::max();
67 size_t speed = 1; 66 size_t speed = 1;
68 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); 67 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed);
69 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); 68 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time);
70 } 69 }
71 70
71
72 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) {
73 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
74 heap_state.contexts_disposed = 1;
75 heap_state.incremental_marking_stopped = true;
76 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
77 int idle_time_ms = (heap_state.size_of_objects + speed - 1) / speed;
78 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
79 EXPECT_EQ(DO_FULL_GC, action.type);
80 }
81
82
83 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) {
84 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
85 heap_state.contexts_disposed = 1;
86 heap_state.incremental_marking_stopped = true;
87 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
88 int idle_time_ms = heap_state.size_of_objects / speed - 1;
89 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
90 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
91 }
92
93
94 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) {
95 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
96 heap_state.contexts_disposed = 1;
97 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
98 int idle_time_ms = heap_state.size_of_objects / speed - 1;
99 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
100 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
101 }
102
103
104 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) {
105 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
106 size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
107 int idle_time_ms = 10;
108 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
109 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
110 EXPECT_GT(speed * idle_time_ms, action.parameter);
111 EXPECT_LT(0, action.parameter);
112 }
113
114
115 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking2) {
116 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
117 heap_state.incremental_marking_stopped = true;
118 size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
119 int idle_time_ms = 10;
120 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
121 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
122 EXPECT_GT(speed * idle_time_ms, action.parameter);
123 EXPECT_LT(0, action.parameter);
124 }
125
126
127 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) {
128 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
129 heap_state.incremental_marking_stopped = true;
130 heap_state.can_start_incremental_marking = false;
131 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
132 int idle_time_ms = heap_state.size_of_objects / speed - 1;
133 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
134 EXPECT_EQ(DO_NOTHING, action.type);
135 }
136
137
138 TEST_F(GCIdleTimeHandlerTest, StopEventually1) {
139 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
140 heap_state.incremental_marking_stopped = true;
141 heap_state.can_start_incremental_marking = false;
142 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
143 int idle_time_ms = heap_state.size_of_objects / speed + 1;
144 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
145 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
146 EXPECT_EQ(DO_FULL_GC, action.type);
147 handler()->NotifyIdleMarkCompact();
148 }
149 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
150 EXPECT_EQ(DO_NOTHING, action.type);
151 }
152
153
154 TEST_F(GCIdleTimeHandlerTest, StopEventually2) {
155 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
156 int idle_time_ms = 10;
157 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
158 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
159 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
160 handler()->NotifyIdleMarkCompact();
161 }
162 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
163 EXPECT_EQ(DO_NOTHING, action.type);
164 }
165
166
167 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop1) {
168 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
169 heap_state.incremental_marking_stopped = true;
170 heap_state.can_start_incremental_marking = false;
171 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
172 int idle_time_ms = heap_state.size_of_objects / speed + 1;
173 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
174 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
175 EXPECT_EQ(DO_FULL_GC, action.type);
176 handler()->NotifyIdleMarkCompact();
177 }
178 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
179 EXPECT_EQ(DO_NOTHING, action.type);
180 // Emulate mutator work.
181 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
182 handler()->NotifyScavenge();
183 }
184 action = handler()->Compute(idle_time_ms, heap_state);
185 EXPECT_EQ(DO_FULL_GC, action.type);
186 }
187
188
189 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop2) {
190 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
191 int idle_time_ms = 10;
192 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
193 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
194 if (action.type == DO_NOTHING) break;
195 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
196 handler()->NotifyIdleMarkCompact();
197 }
198 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
199 EXPECT_EQ(DO_NOTHING, action.type);
200 // Emulate mutator work.
201 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
202 handler()->NotifyScavenge();
203 }
204 action = handler()->Compute(idle_time_ms, heap_state);
205 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
206 }
207
208
72 } // namespace internal 209 } // namespace internal
73 } // namespace v8 210 } // namespace v8
OLDNEW
« no previous file with comments | « test/heap-unittests/heap-unittest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698