@@ -73,12 +73,7 @@ ReservedSpace::ReservedSpace(char* base, size_t size, size_t alignment,
7373 bool special, bool executable) : _fd_for_heap(-1 ) {
7474 assert ((size % os::vm_allocation_granularity ()) == 0 ,
7575 " size not allocation aligned" );
76- _base = base;
77- _size = size;
78- _alignment = alignment;
79- _noaccess_prefix = 0 ;
80- _special = special;
81- _executable = executable;
76+ initialize_members (base, size, alignment, special, executable);
8277}
8378
8479// Helper method
@@ -140,6 +135,21 @@ static bool failed_to_reserve_as_requested(char* base, char* requested_address,
140135 return true ;
141136}
142137
138+ void ReservedSpace::clear_members () {
139+ initialize_members (NULL , 0 , 0 , false , false );
140+ }
141+
142+ void ReservedSpace::initialize_members (char * base, size_t size, size_t alignment,
143+ bool special, bool executable) {
144+ _base = base;
145+ _size = size;
146+ _alignment = alignment;
147+ _special = special;
148+ _executable = executable;
149+ _noaccess_prefix = 0 ;
150+ }
151+
152+
143153void ReservedSpace::initialize (size_t size, size_t alignment, bool large,
144154 char * requested_address,
145155 bool executable) {
@@ -151,18 +161,14 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
151161 assert (alignment == 0 || is_power_of_2 ((intptr_t )alignment),
152162 " not a power of 2" );
153163
154- alignment = MAX2 (alignment, ( size_t ) os::vm_page_size () );
164+ clear_members ( );
155165
156- _base = NULL ;
157- _size = 0 ;
158- _special = false ;
159- _executable = executable;
160- _alignment = 0 ;
161- _noaccess_prefix = 0 ;
162166 if (size == 0 ) {
163167 return ;
164168 }
165169
170+ alignment = MAX2 (alignment, (size_t )os::vm_page_size ());
171+
166172 // If OS doesn't support demand paging for large page memory, we need
167173 // to use reserve_memory_special() to reserve and pin the entire region.
168174 // If there is a backing file directory for this space then whether
@@ -193,9 +199,10 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
193199 " Large pages returned a non-aligned address, base: "
194200 PTR_FORMAT " alignment: " SIZE_FORMAT_HEX,
195201 p2i (base), alignment);
196- _special = true ;
197202 } else {
198- // failed; try to reserve regular memory below
203+ // failed; try to reserve regular memory below. Reservation
204+ // should not be marked as special.
205+ special = false ;
199206 if (UseLargePages && (!FLAG_IS_DEFAULT (UseLargePages) ||
200207 !FLAG_IS_DEFAULT (LargePageSizeInBytes))) {
201208 log_debug (gc, heap, coops)(" Reserve regular memory without large pages" );
@@ -213,13 +220,13 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
213220 // important. If available space is not detected, return NULL.
214221
215222 if (requested_address != 0 ) {
216- base = attempt_map_or_reserve_memory_at (requested_address, size, _fd_for_heap, _executable );
223+ base = attempt_map_or_reserve_memory_at (requested_address, size, _fd_for_heap, executable );
217224 if (failed_to_reserve_as_requested (base, requested_address, size, false , _fd_for_heap != -1 )) {
218225 // OS ignored requested address. Try different address.
219226 base = NULL ;
220227 }
221228 } else {
222- base = map_or_reserve_memory (size, _fd_for_heap, _executable );
229+ base = map_or_reserve_memory (size, _fd_for_heap, executable );
223230 }
224231
225232 if (base == NULL ) return ;
@@ -231,7 +238,7 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
231238
232239 // Make sure that size is aligned
233240 size = align_up (size, alignment);
234- base = map_or_reserve_memory_aligned (size, alignment, _fd_for_heap, _executable );
241+ base = map_or_reserve_memory_aligned (size, alignment, _fd_for_heap, executable );
235242
236243 if (requested_address != 0 &&
237244 failed_to_reserve_as_requested (base, requested_address, size, false , _fd_for_heap != -1 )) {
@@ -243,14 +250,13 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
243250 }
244251 }
245252 }
246- // Done
247- _base = base;
248- _size = size;
249- _alignment = alignment;
250- // If heap is reserved with a backing file, the entire space has been committed. So set the _special flag to true
253+ // If heap is reserved with a backing file, the entire space has been committed. So set the special flag to true
251254 if (_fd_for_heap != -1 ) {
252- _special = true ;
255+ special = true ;
253256 }
257+
258+ // Done
259+ initialize_members (base, size, alignment, special, executable);
254260}
255261
256262ReservedSpace ReservedSpace::first_part (size_t partition_size, size_t alignment) {
@@ -315,12 +321,7 @@ void ReservedSpace::release() {
315321 } else {
316322 os::release_memory (real_base, real_size);
317323 }
318- _base = NULL ;
319- _size = 0 ;
320- _noaccess_prefix = 0 ;
321- _alignment = 0 ;
322- _special = false ;
323- _executable = false ;
324+ clear_members ();
324325 }
325326}
326327
@@ -399,12 +400,13 @@ void ReservedHeapSpace::try_reserve_heap(size_t size,
399400 " Large pages returned a non-aligned address, base: "
400401 PTR_FORMAT " alignment: " SIZE_FORMAT_HEX,
401402 p2i (base), alignment);
402- _special = true ;
403403 }
404404 }
405405
406406 if (base == NULL ) {
407- // Failed; try to reserve regular memory below
407+ // Failed; try to reserve regular memory below. Reservation
408+ // should not be marked as special.
409+ special = false ;
408410 if (UseLargePages && (!FLAG_IS_DEFAULT (UseLargePages) ||
409411 !FLAG_IS_DEFAULT (LargePageSizeInBytes))) {
410412 log_debug (gc, heap, coops)(" Reserve regular memory without large pages" );
@@ -422,18 +424,16 @@ void ReservedHeapSpace::try_reserve_heap(size_t size,
422424 }
423425 if (base == NULL ) { return ; }
424426
425- // Done
426- _base = base;
427- _size = size;
428- _alignment = alignment;
429-
430- // If heap is reserved with a backing file, the entire space has been committed. So set the _special flag to true
427+ // If heap is reserved with a backing file, the entire space has been committed. So set the special flag to true
431428 if (_fd_for_heap != -1 ) {
432- _special = true ;
429+ special = true ;
433430 }
434431
432+ // Done
433+ initialize_members (base, size, alignment, special, false );
434+
435435 // Check alignment constraints
436- if (((( size_t ) base) & ( alignment - 1 )) != 0 ) {
436+ if (! is_aligned ( base, alignment) ) {
437437 // Base not aligned, retry.
438438 release ();
439439 }
0 commit comments