188 EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 3, lp , true)); |
188 EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 3, lp , true)); |
189 EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 2, lp * 2, true)); |
189 EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 2, lp * 2, true)); |
190 EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 4, lp * 2, true)); |
190 EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 4, lp * 2, true)); |
191 EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 8, lp * 2, true)); |
191 EXPECT_NO_FATAL_FAILURE(test_reserved_size_alignment_page_type(lp * 8, lp * 2, true)); |
192 } |
192 } |
|
193 |
|
194 namespace { |
|
195 enum TestLargePages { |
|
196 Default, |
|
197 Disable, |
|
198 Reserve, |
|
199 Commit |
|
200 }; |
|
201 |
|
202 class ReservedSpaceReleaser { |
|
203 ReservedSpace* const _rs; |
|
204 public: |
|
205 ReservedSpaceReleaser(ReservedSpace* rs) : _rs(rs) { } |
|
206 ~ReservedSpaceReleaser() { |
|
207 _rs->release(); |
|
208 } |
|
209 }; |
|
210 |
|
211 ReservedSpace reserve_memory(size_t reserve_size_aligned, TestLargePages mode) { |
|
212 switch(mode) { |
|
213 default: |
|
214 case Default: |
|
215 case Reserve: |
|
216 return ReservedSpace(reserve_size_aligned); |
|
217 case Disable: |
|
218 case Commit: |
|
219 return ReservedSpace(reserve_size_aligned, |
|
220 os::vm_allocation_granularity(), |
|
221 /* large */ false, /* exec */ false); |
|
222 } |
|
223 } |
|
224 |
|
225 bool initialize_virtual_space(VirtualSpace& vs, ReservedSpace rs, TestLargePages mode) { |
|
226 switch(mode) { |
|
227 default: |
|
228 case Default: |
|
229 case Reserve: |
|
230 return vs.initialize(rs, 0); |
|
231 case Disable: |
|
232 return vs.initialize_with_granularity(rs, 0, os::vm_page_size()); |
|
233 case Commit: |
|
234 return vs.initialize_with_granularity(rs, 0, os::page_size_for_region_unaligned(rs.size(), 1)); |
|
235 } |
|
236 } |
|
237 |
|
238 void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size, |
|
239 TestLargePages mode = Default) { |
|
240 size_t granularity = os::vm_allocation_granularity(); |
|
241 size_t reserve_size_aligned = align_up(reserve_size, granularity); |
|
242 |
|
243 ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode); |
|
244 ReservedSpaceReleaser releaser(&reserved); |
|
245 |
|
246 ASSERT_TRUE(reserved.is_reserved()); |
|
247 |
|
248 VirtualSpace vs; |
|
249 ASSERT_TRUE(initialize_virtual_space(vs, reserved, mode)) << "Failed to initialize VirtualSpace"; |
|
250 vs.expand_by(commit_size, false); |
|
251 |
|
252 if (vs.special()) { |
|
253 EXPECT_EQ(reserve_size_aligned, vs.actual_committed_size()); |
|
254 } else { |
|
255 EXPECT_GE(vs.actual_committed_size(), commit_size); |
|
256 // Approximate the commit granularity. |
|
257 // Make sure that we don't commit using large pages |
|
258 // if large pages has been disabled for this VirtualSpace. |
|
259 size_t commit_granularity = (mode == Disable || !UseLargePages) ? |
|
260 os::vm_page_size() : os::large_page_size(); |
|
261 EXPECT_LT(vs.actual_committed_size(), commit_size + commit_granularity); |
|
262 } |
|
263 } |
|
264 } |
|
265 |
|
266 TEST_VM(VirtualSpace, actual_committed_space) { |
|
267 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(4 * K, 0)); |
|
268 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(4 * K, 4 * K)); |
|
269 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(8 * K, 0)); |
|
270 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(8 * K, 4 * K)); |
|
271 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(8 * K, 8 * K)); |
|
272 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(12 * K, 0)); |
|
273 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(12 * K, 4 * K)); |
|
274 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(12 * K, 8 * K)); |
|
275 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(12 * K, 12 * K)); |
|
276 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(64 * K, 0)); |
|
277 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(64 * K, 32 * K)); |
|
278 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(64 * K, 64 * K)); |
|
279 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(2 * M, 0)); |
|
280 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(2 * M, 4 * K)); |
|
281 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(2 * M, 64 * K)); |
|
282 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(2 * M, 1 * M)); |
|
283 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(2 * M, 2 * M)); |
|
284 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0)); |
|
285 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K)); |
|
286 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K)); |
|
287 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M)); |
|
288 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M)); |
|
289 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M)); |
|
290 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M)); |
|
291 } |
|
292 |
|
293 TEST_VM(VirtualSpace, actual_committed_space_one_large_page) { |
|
294 if (!UseLargePages) { |
|
295 return; |
|
296 } |
|
297 |
|
298 size_t large_page_size = os::large_page_size(); |
|
299 |
|
300 ReservedSpace reserved(large_page_size, large_page_size, true, false); |
|
301 ReservedSpaceReleaser releaser(&reserved); |
|
302 ASSERT_TRUE(reserved.is_reserved()); |
|
303 |
|
304 VirtualSpace vs; |
|
305 ASSERT_TRUE(vs.initialize(reserved, 0)) << "Failed to initialize VirtualSpace"; |
|
306 vs.expand_by(large_page_size, false); |
|
307 |
|
308 EXPECT_EQ(large_page_size, vs.actual_committed_size()); |
|
309 } |
|
310 |
|
311 TEST_VM(VirtualSpace, disable_large_pages) { |
|
312 if (!UseLargePages) { |
|
313 return; |
|
314 } |
|
315 // These test cases verify that if we force VirtualSpace to disable large pages |
|
316 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0, Disable)); |
|
317 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K, Disable)); |
|
318 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K, Disable)); |
|
319 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M, Disable)); |
|
320 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M, Disable)); |
|
321 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M, Disable)); |
|
322 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M, Disable)); |
|
323 |
|
324 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0, Reserve)); |
|
325 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K, Reserve)); |
|
326 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K, Reserve)); |
|
327 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M, Reserve)); |
|
328 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M, Reserve)); |
|
329 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M, Reserve)); |
|
330 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M, Reserve)); |
|
331 |
|
332 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 0, Commit)); |
|
333 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 4 * K, Commit)); |
|
334 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 8 * K, Commit)); |
|
335 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 1 * M, Commit)); |
|
336 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 2 * M, Commit)); |
|
337 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 5 * M, Commit)); |
|
338 EXPECT_NO_FATAL_FAILURE(test_virtual_space_actual_committed_space(10 * M, 10 * M, Commit)); |
|
339 } |