312 // If the memory was requested at a particular address, use 313 // os::attempt_reserve_memory_at() to avoid over mapping something 314 // important. If available space is not detected, return NULL. 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"); | 312 // If the memory was requested at a particular address, use 313 // os::attempt_reserve_memory_at() to avoid over mapping something 314 // important. If available space is not detected, return NULL. 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 // Make sure that size is aligned 333 size = align_size_up(size, alignment); 334 base = os::reserve_memory_aligned(size, alignment); 335 336 if (requested_address != 0 && 337 failed_to_reserve_as_requested(base, requested_address, size, false)) { 338 // As a result of the alignment constraints, the allocated base differs 339 // from the requested address. Return back to the caller who can 340 // take remedial action (like try again without a requested address). 341 assert(_base == NULL, "should be"); 342 return; 343 } 344 } 345 } 346 // Done 347 _base = base; 348 _size = size; 349 _alignment = alignment; 350 _noaccess_prefix = noaccess_prefix; 351 352 // Assert that if noaccess_prefix is used, it is the same as alignment. 353 assert(noaccess_prefix == 0 || 354 noaccess_prefix == _alignment, "noaccess prefix wrong"); |