21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "oops/markOop.hpp"
27 #include "oops/oop.inline.hpp"
28 #include "runtime/virtualspace.hpp"
29 #include "services/memTracker.hpp"
30
31 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
32
33 // ReservedSpace
34
35 // Dummy constructor
36 ReservedSpace::ReservedSpace() : _base(NULL), _size(0), _noaccess_prefix(0),
37 _alignment(0), _special(false), _executable(false) {
38 }
39
40 ReservedSpace::ReservedSpace(size_t size) {
41 size_t page_size = os::page_size_for_region(size, 1);
42 bool large_pages = page_size != (size_t)os::vm_page_size();
43 // Don't force the alignment to be large page aligned,
44 // since that will waste memory.
45 size_t alignment = os::vm_allocation_granularity();
46 initialize(size, alignment, large_pages, NULL, 0, false);
47 }
48
49 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
50 bool large,
51 char* requested_address,
52 const size_t noaccess_prefix) {
53 initialize(size+noaccess_prefix, alignment, large, requested_address,
54 noaccess_prefix, false);
55 }
56
57 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
58 bool large,
59 bool executable) {
60 initialize(size, alignment, large, NULL, 0, executable);
61 }
340 VirtualSpace::VirtualSpace() {
341 _low_boundary = NULL;
342 _high_boundary = NULL;
343 _low = NULL;
344 _high = NULL;
345 _lower_high = NULL;
346 _middle_high = NULL;
347 _upper_high = NULL;
348 _lower_high_boundary = NULL;
349 _middle_high_boundary = NULL;
350 _upper_high_boundary = NULL;
351 _lower_alignment = 0;
352 _middle_alignment = 0;
353 _upper_alignment = 0;
354 _special = false;
355 _executable = false;
356 }
357
358
359 bool VirtualSpace::initialize(ReservedSpace rs, size_t committed_size) {
360 const size_t max_commit_granularity = os::page_size_for_region(rs.size(), 1);
361 return initialize_with_granularity(rs, committed_size, max_commit_granularity);
362 }
363
364 bool VirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t committed_size, size_t max_commit_granularity) {
365 if(!rs.is_reserved()) return false; // allocation failed.
366 assert(_low_boundary == NULL, "VirtualSpace already initialized");
367 assert(max_commit_granularity > 0, "Granularity must be non-zero.");
368
369 _low_boundary = rs.base();
370 _high_boundary = low_boundary() + rs.size();
371
372 _low = low_boundary();
373 _high = low();
374
375 _special = rs.special();
376 _executable = rs.executable();
377
378 // When a VirtualSpace begins life at a large size, make all future expansion
379 // and shrinking occur aligned to a granularity of large pages. This avoids
380 // fragmentation of physical addresses that inhibits the use of large pages
975 case Default:
976 case Reserve:
977 return ReservedSpace(reserve_size_aligned);
978 case Disable:
979 case Commit:
980 return ReservedSpace(reserve_size_aligned,
981 os::vm_allocation_granularity(),
982 /* large */ false, /* exec */ false);
983 }
984 }
985
986 static bool initialize_virtual_space(VirtualSpace& vs, ReservedSpace rs, TestLargePages mode) {
987 switch(mode) {
988 default:
989 case Default:
990 case Reserve:
991 return vs.initialize(rs, 0);
992 case Disable:
993 return vs.initialize_with_granularity(rs, 0, os::vm_page_size());
994 case Commit:
995 return vs.initialize_with_granularity(rs, 0, os::page_size_for_region(rs.size(), 1));
996 }
997 }
998
999 public:
1000 static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size,
1001 TestLargePages mode = Default) {
1002 size_t granularity = os::vm_allocation_granularity();
1003 size_t reserve_size_aligned = align_size_up(reserve_size, granularity);
1004
1005 ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode);
1006
1007 assert(reserved.is_reserved(), "Must be");
1008
1009 VirtualSpace vs;
1010 bool initialized = initialize_virtual_space(vs, reserved, mode);
1011 assert(initialized, "Failed to initialize VirtualSpace");
1012
1013 vs.expand_by(commit_size, false);
1014
1015 if (vs.special()) {
|
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "oops/markOop.hpp"
27 #include "oops/oop.inline.hpp"
28 #include "runtime/virtualspace.hpp"
29 #include "services/memTracker.hpp"
30
31 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
32
33 // ReservedSpace
34
35 // Dummy constructor
36 ReservedSpace::ReservedSpace() : _base(NULL), _size(0), _noaccess_prefix(0),
37 _alignment(0), _special(false), _executable(false) {
38 }
39
40 ReservedSpace::ReservedSpace(size_t size) {
41 size_t page_size = os::page_size_for_region_aligned(size, 1);
42 bool large_pages = page_size != (size_t)os::vm_page_size();
43 // Don't force the alignment to be large page aligned,
44 // since that will waste memory.
45 size_t alignment = os::vm_allocation_granularity();
46 initialize(size, alignment, large_pages, NULL, 0, false);
47 }
48
49 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
50 bool large,
51 char* requested_address,
52 const size_t noaccess_prefix) {
53 initialize(size+noaccess_prefix, alignment, large, requested_address,
54 noaccess_prefix, false);
55 }
56
57 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
58 bool large,
59 bool executable) {
60 initialize(size, alignment, large, NULL, 0, executable);
61 }
340 VirtualSpace::VirtualSpace() {
341 _low_boundary = NULL;
342 _high_boundary = NULL;
343 _low = NULL;
344 _high = NULL;
345 _lower_high = NULL;
346 _middle_high = NULL;
347 _upper_high = NULL;
348 _lower_high_boundary = NULL;
349 _middle_high_boundary = NULL;
350 _upper_high_boundary = NULL;
351 _lower_alignment = 0;
352 _middle_alignment = 0;
353 _upper_alignment = 0;
354 _special = false;
355 _executable = false;
356 }
357
358
359 bool VirtualSpace::initialize(ReservedSpace rs, size_t committed_size) {
360 const size_t max_commit_granularity = os::page_size_for_region_unaligned(rs.size(), 1);
361 return initialize_with_granularity(rs, committed_size, max_commit_granularity);
362 }
363
364 bool VirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t committed_size, size_t max_commit_granularity) {
365 if(!rs.is_reserved()) return false; // allocation failed.
366 assert(_low_boundary == NULL, "VirtualSpace already initialized");
367 assert(max_commit_granularity > 0, "Granularity must be non-zero.");
368
369 _low_boundary = rs.base();
370 _high_boundary = low_boundary() + rs.size();
371
372 _low = low_boundary();
373 _high = low();
374
375 _special = rs.special();
376 _executable = rs.executable();
377
378 // When a VirtualSpace begins life at a large size, make all future expansion
379 // and shrinking occur aligned to a granularity of large pages. This avoids
380 // fragmentation of physical addresses that inhibits the use of large pages
975 case Default:
976 case Reserve:
977 return ReservedSpace(reserve_size_aligned);
978 case Disable:
979 case Commit:
980 return ReservedSpace(reserve_size_aligned,
981 os::vm_allocation_granularity(),
982 /* large */ false, /* exec */ false);
983 }
984 }
985
986 static bool initialize_virtual_space(VirtualSpace& vs, ReservedSpace rs, TestLargePages mode) {
987 switch(mode) {
988 default:
989 case Default:
990 case Reserve:
991 return vs.initialize(rs, 0);
992 case Disable:
993 return vs.initialize_with_granularity(rs, 0, os::vm_page_size());
994 case Commit:
995 return vs.initialize_with_granularity(rs, 0, os::page_size_for_region_unaligned(rs.size(), 1));
996 }
997 }
998
999 public:
1000 static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size,
1001 TestLargePages mode = Default) {
1002 size_t granularity = os::vm_allocation_granularity();
1003 size_t reserve_size_aligned = align_size_up(reserve_size, granularity);
1004
1005 ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode);
1006
1007 assert(reserved.is_reserved(), "Must be");
1008
1009 VirtualSpace vs;
1010 bool initialized = initialize_virtual_space(vs, reserved, mode);
1011 assert(initialized, "Failed to initialize VirtualSpace");
1012
1013 vs.expand_by(commit_size, false);
1014
1015 if (vs.special()) {
|