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

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

Issue 525193004: Merge heap unit tests into src. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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') | test/heap-unittests/heap-unittests.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "test/heap-unittests/heap-unittest.h"
6
7 #include <limits>
8
9
10 namespace v8 {
11 namespace internal {
12
13 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeInitial) {
14 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(1, 0);
15 EXPECT_EQ(
16 static_cast<size_t>(GCIdleTimeHandler::kInitialConservativeMarkingSpeed *
17 GCIdleTimeHandler::kConservativeTimeRatio),
18 step_size);
19 }
20
21
22 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeNonZero) {
23 size_t marking_speed_in_bytes_per_millisecond = 100;
24 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(
25 1, marking_speed_in_bytes_per_millisecond);
26 EXPECT_EQ(static_cast<size_t>(marking_speed_in_bytes_per_millisecond *
27 GCIdleTimeHandler::kConservativeTimeRatio),
28 step_size);
29 }
30
31
32 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeOverflow1) {
33 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(
34 10, std::numeric_limits<size_t>::max());
35 EXPECT_EQ(static_cast<size_t>(GCIdleTimeHandler::kMaximumMarkingStepSize),
36 step_size);
37 }
38
39
40 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeOverflow2) {
41 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(
42 std::numeric_limits<size_t>::max(), 10);
43 EXPECT_EQ(static_cast<size_t>(GCIdleTimeHandler::kMaximumMarkingStepSize),
44 step_size);
45 }
46
47
48 TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeInitial) {
49 size_t size = 100 * MB;
50 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, 0);
51 EXPECT_EQ(size / GCIdleTimeHandler::kInitialConservativeMarkCompactSpeed,
52 time);
53 }
54
55
56 TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeNonZero) {
57 size_t size = 100 * MB;
58 size_t speed = 10 * KB;
59 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed);
60 EXPECT_EQ(size / speed, time);
61 }
62
63
64 TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeMax) {
65 size_t size = std::numeric_limits<size_t>::max();
66 size_t speed = 1;
67 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed);
68 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time);
69 }
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 =
78 static_cast<int>((heap_state.size_of_objects + speed - 1) / speed);
79 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
80 EXPECT_EQ(DO_FULL_GC, action.type);
81 }
82
83
84 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) {
85 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
86 heap_state.contexts_disposed = 1;
87 heap_state.incremental_marking_stopped = true;
88 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
89 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed - 1);
90 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
91 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
92 }
93
94
95 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) {
96 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
97 heap_state.contexts_disposed = 1;
98 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
99 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed - 1);
100 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
101 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
102 }
103
104
105 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) {
106 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
107 size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
108 int idle_time_ms = 10;
109 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
110 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
111 EXPECT_GT(speed * static_cast<size_t>(idle_time_ms),
112 static_cast<size_t>(action.parameter));
113 EXPECT_LT(0, action.parameter);
114 }
115
116
117 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking2) {
118 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
119 heap_state.incremental_marking_stopped = true;
120 size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
121 int idle_time_ms = 10;
122 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
123 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
124 EXPECT_GT(speed * static_cast<size_t>(idle_time_ms),
125 static_cast<size_t>(action.parameter));
126 EXPECT_LT(0, action.parameter);
127 }
128
129
130 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) {
131 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
132 heap_state.incremental_marking_stopped = true;
133 heap_state.can_start_incremental_marking = false;
134 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
135 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed - 1);
136 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
137 EXPECT_EQ(DO_NOTHING, action.type);
138 }
139
140
141 TEST_F(GCIdleTimeHandlerTest, StopEventually1) {
142 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
143 heap_state.incremental_marking_stopped = true;
144 heap_state.can_start_incremental_marking = false;
145 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
146 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed + 1);
147 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
148 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
149 EXPECT_EQ(DO_FULL_GC, action.type);
150 handler()->NotifyIdleMarkCompact();
151 }
152 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
153 EXPECT_EQ(DO_NOTHING, action.type);
154 }
155
156
157 TEST_F(GCIdleTimeHandlerTest, StopEventually2) {
158 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
159 int idle_time_ms = 10;
160 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
161 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
162 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
163 handler()->NotifyIdleMarkCompact();
164 }
165 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
166 EXPECT_EQ(DO_NOTHING, action.type);
167 }
168
169
170 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop1) {
171 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
172 heap_state.incremental_marking_stopped = true;
173 heap_state.can_start_incremental_marking = false;
174 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
175 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed + 1);
176 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
177 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
178 EXPECT_EQ(DO_FULL_GC, action.type);
179 handler()->NotifyIdleMarkCompact();
180 }
181 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
182 EXPECT_EQ(DO_NOTHING, action.type);
183 // Emulate mutator work.
184 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
185 handler()->NotifyScavenge();
186 }
187 action = handler()->Compute(idle_time_ms, heap_state);
188 EXPECT_EQ(DO_FULL_GC, action.type);
189 }
190
191
192 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop2) {
193 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
194 int idle_time_ms = 10;
195 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
196 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
197 if (action.type == DO_NOTHING) break;
198 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
199 handler()->NotifyIdleMarkCompact();
200 }
201 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
202 EXPECT_EQ(DO_NOTHING, action.type);
203 // Emulate mutator work.
204 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
205 handler()->NotifyScavenge();
206 }
207 action = handler()->Compute(idle_time_ms, heap_state);
208 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
209 }
210
211
212 } // namespace internal
213 } // namespace v8
OLDNEW
« no previous file with comments | « test/heap-unittests/heap-unittest.h ('k') | test/heap-unittests/heap-unittests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698