36 #ifdef TARGET_OS_FAMILY_windows
37 # include "os_windows.inline.hpp"
38 #endif
39 #ifdef TARGET_OS_FAMILY_aix
40 # include "os_aix.inline.hpp"
41 #endif
42 #ifdef TARGET_OS_FAMILY_bsd
43 # include "os_bsd.inline.hpp"
44 #endif
45
46 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
47
48 // ReservedSpace
49
50 // Dummy constructor
51 ReservedSpace::ReservedSpace() : _base(NULL), _size(0), _noaccess_prefix(0),
52 _alignment(0), _special(false), _executable(false) {
53 }
54
55 ReservedSpace::ReservedSpace(size_t size) {
56 size_t page_size = os::page_size_for_region(size, 1);
57 bool large_pages = page_size != (size_t)os::vm_page_size();
58 // Don't force the alignment to be large page aligned,
59 // since that will waste memory.
60 size_t alignment = os::vm_allocation_granularity();
61 initialize(size, alignment, large_pages, NULL, 0, false);
62 }
63
64 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
65 bool large,
66 char* requested_address,
67 const size_t noaccess_prefix) {
68 initialize(size+noaccess_prefix, alignment, large, requested_address,
69 noaccess_prefix, false);
70 }
71
72 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
73 bool large,
74 bool executable) {
75 initialize(size, alignment, large, NULL, 0, executable);
76 }
355 VirtualSpace::VirtualSpace() {
356 _low_boundary = NULL;
357 _high_boundary = NULL;
358 _low = NULL;
359 _high = NULL;
360 _lower_high = NULL;
361 _middle_high = NULL;
362 _upper_high = NULL;
363 _lower_high_boundary = NULL;
364 _middle_high_boundary = NULL;
365 _upper_high_boundary = NULL;
366 _lower_alignment = 0;
367 _middle_alignment = 0;
368 _upper_alignment = 0;
369 _special = false;
370 _executable = false;
371 }
372
373
374 bool VirtualSpace::initialize(ReservedSpace rs, size_t committed_size) {
375 const size_t max_commit_granularity = os::page_size_for_region(rs.size(), 1);
376 return initialize_with_granularity(rs, committed_size, max_commit_granularity);
377 }
378
379 bool VirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t committed_size, size_t max_commit_granularity) {
380 if(!rs.is_reserved()) return false; // allocation failed.
381 assert(_low_boundary == NULL, "VirtualSpace already initialized");
382 assert(max_commit_granularity > 0, "Granularity must be non-zero.");
383
384 _low_boundary = rs.base();
385 _high_boundary = low_boundary() + rs.size();
386
387 _low = low_boundary();
388 _high = low();
389
390 _special = rs.special();
391 _executable = rs.executable();
392
393 // When a VirtualSpace begins life at a large size, make all future expansion
394 // and shrinking occur aligned to a granularity of large pages. This avoids
395 // fragmentation of physical addresses that inhibits the use of large pages
978 case Default:
979 case Reserve:
980 return ReservedSpace(reserve_size_aligned);
981 case Disable:
982 case Commit:
983 return ReservedSpace(reserve_size_aligned,
984 os::vm_allocation_granularity(),
985 /* large */ false, /* exec */ false);
986 }
987 }
988
989 static bool initialize_virtual_space(VirtualSpace& vs, ReservedSpace rs, TestLargePages mode) {
990 switch(mode) {
991 default:
992 case Default:
993 case Reserve:
994 return vs.initialize(rs, 0);
995 case Disable:
996 return vs.initialize_with_granularity(rs, 0, os::vm_page_size());
997 case Commit:
998 return vs.initialize_with_granularity(rs, 0, os::page_size_for_region(rs.size(), 1));
999 }
1000 }
1001
1002 public:
1003 static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size,
1004 TestLargePages mode = Default) {
1005 size_t granularity = os::vm_allocation_granularity();
1006 size_t reserve_size_aligned = align_size_up(reserve_size, granularity);
1007
1008 ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode);
1009
1010 assert(reserved.is_reserved(), "Must be");
1011
1012 VirtualSpace vs;
1013 bool initialized = initialize_virtual_space(vs, reserved, mode);
1014 assert(initialized, "Failed to initialize VirtualSpace");
1015
1016 vs.expand_by(commit_size, false);
1017
1018 if (vs.special()) {
|
36 #ifdef TARGET_OS_FAMILY_windows
37 # include "os_windows.inline.hpp"
38 #endif
39 #ifdef TARGET_OS_FAMILY_aix
40 # include "os_aix.inline.hpp"
41 #endif
42 #ifdef TARGET_OS_FAMILY_bsd
43 # include "os_bsd.inline.hpp"
44 #endif
45
46 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
47
48 // ReservedSpace
49
50 // Dummy constructor
51 ReservedSpace::ReservedSpace() : _base(NULL), _size(0), _noaccess_prefix(0),
52 _alignment(0), _special(false), _executable(false) {
53 }
54
55 ReservedSpace::ReservedSpace(size_t size) {
56 // Want to use large pages where possible and pad with small pages.
57 size_t page_size = os::page_size_for_region_unaligned(size, 1);
58 bool large_pages = page_size != (size_t)os::vm_page_size();
59 // Don't force the alignment to be large page aligned,
60 // since that will waste memory.
61 size_t alignment = os::vm_allocation_granularity();
62 initialize(size, alignment, large_pages, NULL, 0, false);
63 }
64
65 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
66 bool large,
67 char* requested_address,
68 const size_t noaccess_prefix) {
69 initialize(size+noaccess_prefix, alignment, large, requested_address,
70 noaccess_prefix, false);
71 }
72
73 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
74 bool large,
75 bool executable) {
76 initialize(size, alignment, large, NULL, 0, executable);
77 }
356 VirtualSpace::VirtualSpace() {
357 _low_boundary = NULL;
358 _high_boundary = NULL;
359 _low = NULL;
360 _high = NULL;
361 _lower_high = NULL;
362 _middle_high = NULL;
363 _upper_high = NULL;
364 _lower_high_boundary = NULL;
365 _middle_high_boundary = NULL;
366 _upper_high_boundary = NULL;
367 _lower_alignment = 0;
368 _middle_alignment = 0;
369 _upper_alignment = 0;
370 _special = false;
371 _executable = false;
372 }
373
374
375 bool VirtualSpace::initialize(ReservedSpace rs, size_t committed_size) {
376 const size_t max_commit_granularity = os::page_size_for_region_unaligned(rs.size(), 1);
377 return initialize_with_granularity(rs, committed_size, max_commit_granularity);
378 }
379
380 bool VirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t committed_size, size_t max_commit_granularity) {
381 if(!rs.is_reserved()) return false; // allocation failed.
382 assert(_low_boundary == NULL, "VirtualSpace already initialized");
383 assert(max_commit_granularity > 0, "Granularity must be non-zero.");
384
385 _low_boundary = rs.base();
386 _high_boundary = low_boundary() + rs.size();
387
388 _low = low_boundary();
389 _high = low();
390
391 _special = rs.special();
392 _executable = rs.executable();
393
394 // When a VirtualSpace begins life at a large size, make all future expansion
395 // and shrinking occur aligned to a granularity of large pages. This avoids
396 // fragmentation of physical addresses that inhibits the use of large pages
979 case Default:
980 case Reserve:
981 return ReservedSpace(reserve_size_aligned);
982 case Disable:
983 case Commit:
984 return ReservedSpace(reserve_size_aligned,
985 os::vm_allocation_granularity(),
986 /* large */ false, /* exec */ false);
987 }
988 }
989
990 static bool initialize_virtual_space(VirtualSpace& vs, ReservedSpace rs, TestLargePages mode) {
991 switch(mode) {
992 default:
993 case Default:
994 case Reserve:
995 return vs.initialize(rs, 0);
996 case Disable:
997 return vs.initialize_with_granularity(rs, 0, os::vm_page_size());
998 case Commit:
999 return vs.initialize_with_granularity(rs, 0, os::page_size_for_region_unaligned(rs.size(), 1));
1000 }
1001 }
1002
1003 public:
1004 static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size,
1005 TestLargePages mode = Default) {
1006 size_t granularity = os::vm_allocation_granularity();
1007 size_t reserve_size_aligned = align_size_up(reserve_size, granularity);
1008
1009 ReservedSpace reserved = reserve_memory(reserve_size_aligned, mode);
1010
1011 assert(reserved.is_reserved(), "Must be");
1012
1013 VirtualSpace vs;
1014 bool initialized = initialize_virtual_space(vs, reserved, mode);
1015 assert(initialized, "Failed to initialize VirtualSpace");
1016
1017 vs.expand_by(commit_size, false);
1018
1019 if (vs.special()) {
|