mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-17 17:44:40 +02:00
8224871: os::attempt_reserve_memory_at() tries too hard
Reviewed-by: pliden, coleenp, stuefe
This commit is contained in:
parent
2f25526470
commit
cf79907536
3 changed files with 6 additions and 200 deletions
|
@ -4105,11 +4105,6 @@ char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int f
|
|||
// available (and not reserved for something else).
|
||||
|
||||
char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
|
||||
const int max_tries = 10;
|
||||
char* base[max_tries];
|
||||
size_t size[max_tries];
|
||||
const size_t gap = 0x000000;
|
||||
|
||||
// Assert only that the size is a multiple of the page size, since
|
||||
// that's all that mmap requires, and since that's all we really know
|
||||
// about at this low abstraction level. If we need higher alignment,
|
||||
|
@ -4132,50 +4127,7 @@ char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
|
|||
anon_munmap(addr, bytes);
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i < max_tries; ++i) {
|
||||
base[i] = reserve_memory(bytes);
|
||||
|
||||
if (base[i] != NULL) {
|
||||
// Is this the block we wanted?
|
||||
if (base[i] == requested_addr) {
|
||||
size[i] = bytes;
|
||||
break;
|
||||
}
|
||||
|
||||
// Does this overlap the block we wanted? Give back the overlapped
|
||||
// parts and try again.
|
||||
|
||||
ptrdiff_t top_overlap = requested_addr + (bytes + gap) - base[i];
|
||||
if (top_overlap >= 0 && (size_t)top_overlap < bytes) {
|
||||
unmap_memory(base[i], top_overlap);
|
||||
base[i] += top_overlap;
|
||||
size[i] = bytes - top_overlap;
|
||||
} else {
|
||||
ptrdiff_t bottom_overlap = base[i] + bytes - requested_addr;
|
||||
if (bottom_overlap >= 0 && (size_t)bottom_overlap < bytes) {
|
||||
unmap_memory(requested_addr, bottom_overlap);
|
||||
size[i] = bytes - bottom_overlap;
|
||||
} else {
|
||||
size[i] = bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Give back the unused reserved pieces.
|
||||
|
||||
for (int j = 0; j < i; ++j) {
|
||||
if (base[j] != NULL) {
|
||||
unmap_memory(base[j], size[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (i < max_tries) {
|
||||
return requested_addr;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Sleep forever; naked call to OS-specific sleep; use with CAUTION
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue