315
316 if (requested_address != 0) {
317 base = os::attempt_reserve_memory_at(size, requested_address);
318 if (failed_to_reserve_as_requested(base, requested_address, size, false)) {
319 // OS ignored requested address. Try different address.
320 base = NULL;
321 }
322 } else {
323 base = os::reserve_memory(size, NULL, alignment);
324 }
325
326 if (base == NULL) return;
327
328 // Check alignment constraints
329 if ((((size_t)base + noaccess_prefix) & (alignment - 1)) != 0) {
330 // Base not aligned, retry
331 if (!os::release_memory(base, size)) fatal("os::release_memory failed");
332 // Reserve size large enough to do manual alignment and
333 // increase size to a multiple of the desired alignment
334 size = align_size_up(size, alignment);
335 size_t extra_size = size + alignment;
336 do {
337 char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
338 if (extra_base == NULL) return;
339 // Do manual alignement
340 base = (char*) align_size_up((uintptr_t) extra_base, alignment);
341 assert(base >= extra_base, "just checking");
342 // Re-reserve the region at the aligned base address.
343 os::release_memory(extra_base, extra_size);
344 base = os::reserve_memory(size, base);
345 } while (base == NULL);
346
347 if (requested_address != 0 &&
348 failed_to_reserve_as_requested(base, requested_address, size, false)) {
349 // As a result of the alignment constraints, the allocated base differs
350 // from the requested address. Return back to the caller who can
351 // take remedial action (like try again without a requested address).
352 assert(_base == NULL, "should be");
353 return;
354 }
355 }
356 }
357 // Done
358 _base = base;
359 _size = size;
360 _alignment = alignment;
361 _noaccess_prefix = noaccess_prefix;
362
363 // Assert that if noaccess_prefix is used, it is the same as alignment.
364 assert(noaccess_prefix == 0 ||
365 noaccess_prefix == _alignment, "noaccess prefix wrong");
|
315
316 if (requested_address != 0) {
317 base = os::attempt_reserve_memory_at(size, requested_address);
318 if (failed_to_reserve_as_requested(base, requested_address, size, false)) {
319 // OS ignored requested address. Try different address.
320 base = NULL;
321 }
322 } else {
323 base = os::reserve_memory(size, NULL, alignment);
324 }
325
326 if (base == NULL) return;
327
328 // Check alignment constraints
329 if ((((size_t)base + noaccess_prefix) & (alignment - 1)) != 0) {
330 // Base not aligned, retry
331 if (!os::release_memory(base, size)) fatal("os::release_memory failed");
332 // Reserve size large enough to do manual alignment and
333 // increase size to a multiple of the desired alignment
334 size = align_size_up(size, alignment);
335 base = os::reserve_memory_aligned(size, alignment);
336
337 if (requested_address != 0 &&
338 failed_to_reserve_as_requested(base, requested_address, size, false)) {
339 // As a result of the alignment constraints, the allocated base differs
340 // from the requested address. Return back to the caller who can
341 // take remedial action (like try again without a requested address).
342 assert(_base == NULL, "should be");
343 return;
344 }
345 }
346 }
347 // Done
348 _base = base;
349 _size = size;
350 _alignment = alignment;
351 _noaccess_prefix = noaccess_prefix;
352
353 // Assert that if noaccess_prefix is used, it is the same as alignment.
354 assert(noaccess_prefix == 0 ||
355 noaccess_prefix == _alignment, "noaccess prefix wrong");
|