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, false);
47 }
48
49 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
50 bool large,
51 char* requested_address) {
52 initialize(size, alignment, large, requested_address, false);
53 }
54
55 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
56 bool large,
57 bool executable) {
58 initialize(size, alignment, large, NULL, executable);
59 }
60
61 // Helper method.
600 VirtualSpace::VirtualSpace() {
601 _low_boundary = NULL;
602 _high_boundary = NULL;
603 _low = NULL;
604 _high = NULL;
605 _lower_high = NULL;
606 _middle_high = NULL;
607 _upper_high = NULL;
608 _lower_high_boundary = NULL;
609 _middle_high_boundary = NULL;
610 _upper_high_boundary = NULL;
611 _lower_alignment = 0;
612 _middle_alignment = 0;
613 _upper_alignment = 0;
614 _special = false;
615 _executable = false;
616 }
617
618
619 bool VirtualSpace::initialize(ReservedSpace rs, size_t committed_size) {
620 const size_t max_commit_granularity = os::page_size_for_region(rs.size(), 1);
621 return initialize_with_granularity(rs, committed_size, max_commit_granularity);
622 }
623
624 bool VirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t committed_size, size_t max_commit_granularity) {
625 if(!rs.is_reserved()) return false; // allocation failed.
626 assert(_low_boundary == NULL, "VirtualSpace already initialized");
627 assert(max_commit_granularity > 0, "Granularity must be non-zero.");
628
629 _low_boundary = rs.base();
630 _high_boundary = low_boundary() + rs.size();
631
632 _low = low_boundary();
633 _high = low();
634
635 _special = rs.special();
636 _executable = rs.executable();
637
638 // When a VirtualSpace begins life at a large size, make all future expansion
639 // and shrinking occur aligned to a granularity of large pages. This avoids
640 // fragmentation of physical addresses that inhibits the use of large pages
1222 case Default:
1223 case Reserve:
1224 return ReservedSpace(reserve_size_aligned);
1225 case Disable:
1226 case Commit:
1227 return ReservedSpace(reserve_size_aligned,
1228 os::vm_allocation_granularity(),
1229 /* large */ false, /* exec */ false);
1230 }
1231 }
1232
1233 static bool initialize_virtual_space(VirtualSpace& vs, ReservedSpace rs, TestLargePages mode) {
1234 switch(mode) {
1235 default:
1236 case Default:
1237 case Reserve:
1238 return vs.initialize(rs, 0);
1239 case Disable:
1240 return vs.initialize_with_granularity(rs, 0, os::vm_page_size());
1241 case Commit:
1242 return vs.initialize_with_granularity(rs, 0, os::page_size_for_region(rs.size(), 1));
1243 }
1244 }
1245
1246 public:
1247 static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size,
1248 TestLargePages mode = Default) {
1249 size_t granularity = os::vm_allocation_granularity();
1250 size_t reserve_size_aligned = align_size_up(reserve_size, granularity);
1251
1252 ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode);
1253
1254 assert(reserved.is_reserved(), "Must be");
1255
1256 VirtualSpace vs;
1257 bool initialized = initialize_virtual_space(vs, reserved, mode);
1258 assert(initialized, "Failed to initialize VirtualSpace");
1259
1260 vs.expand_by(commit_size, false);
1261
1262 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 // Want to use large pages where possible and pad with small pages.
42 size_t page_size = os::page_size_for_region_unaligned(size, 1);
43 bool large_pages = page_size != (size_t)os::vm_page_size();
44 // Don't force the alignment to be large page aligned,
45 // since that will waste memory.
46 size_t alignment = os::vm_allocation_granularity();
47 initialize(size, alignment, large_pages, NULL, false);
48 }
49
50 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
51 bool large,
52 char* requested_address) {
53 initialize(size, alignment, large, requested_address, false);
54 }
55
56 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
57 bool large,
58 bool executable) {
59 initialize(size, alignment, large, NULL, executable);
60 }
61
62 // Helper method.
601 VirtualSpace::VirtualSpace() {
602 _low_boundary = NULL;
603 _high_boundary = NULL;
604 _low = NULL;
605 _high = NULL;
606 _lower_high = NULL;
607 _middle_high = NULL;
608 _upper_high = NULL;
609 _lower_high_boundary = NULL;
610 _middle_high_boundary = NULL;
611 _upper_high_boundary = NULL;
612 _lower_alignment = 0;
613 _middle_alignment = 0;
614 _upper_alignment = 0;
615 _special = false;
616 _executable = false;
617 }
618
619
620 bool VirtualSpace::initialize(ReservedSpace rs, size_t committed_size) {
621 const size_t max_commit_granularity = os::page_size_for_region_unaligned(rs.size(), 1);
622 return initialize_with_granularity(rs, committed_size, max_commit_granularity);
623 }
624
625 bool VirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t committed_size, size_t max_commit_granularity) {
626 if(!rs.is_reserved()) return false; // allocation failed.
627 assert(_low_boundary == NULL, "VirtualSpace already initialized");
628 assert(max_commit_granularity > 0, "Granularity must be non-zero.");
629
630 _low_boundary = rs.base();
631 _high_boundary = low_boundary() + rs.size();
632
633 _low = low_boundary();
634 _high = low();
635
636 _special = rs.special();
637 _executable = rs.executable();
638
639 // When a VirtualSpace begins life at a large size, make all future expansion
640 // and shrinking occur aligned to a granularity of large pages. This avoids
641 // fragmentation of physical addresses that inhibits the use of large pages
1223 case Default:
1224 case Reserve:
1225 return ReservedSpace(reserve_size_aligned);
1226 case Disable:
1227 case Commit:
1228 return ReservedSpace(reserve_size_aligned,
1229 os::vm_allocation_granularity(),
1230 /* large */ false, /* exec */ false);
1231 }
1232 }
1233
1234 static bool initialize_virtual_space(VirtualSpace& vs, ReservedSpace rs, TestLargePages mode) {
1235 switch(mode) {
1236 default:
1237 case Default:
1238 case Reserve:
1239 return vs.initialize(rs, 0);
1240 case Disable:
1241 return vs.initialize_with_granularity(rs, 0, os::vm_page_size());
1242 case Commit:
1243 return vs.initialize_with_granularity(rs, 0, os::page_size_for_region_unaligned(rs.size(), 1));
1244 }
1245 }
1246
1247 public:
1248 static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size,
1249 TestLargePages mode = Default) {
1250 size_t granularity = os::vm_allocation_granularity();
1251 size_t reserve_size_aligned = align_size_up(reserve_size, granularity);
1252
1253 ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode);
1254
1255 assert(reserved.is_reserved(), "Must be");
1256
1257 VirtualSpace vs;
1258 bool initialized = initialize_virtual_space(vs, reserved, mode);
1259 assert(initialized, "Failed to initialize VirtualSpace");
1260
1261 vs.expand_by(commit_size, false);
1262
1263 if (vs.special()) {
|