8257970: Remove julong types in os::limit_heap_by_allocatable_memory

Reviewed-by: stefank, tschatzl
This commit is contained in:
Per Liden 2020-12-11 10:17:21 +00:00
parent b28b0947d9
commit b5592c05ad
6 changed files with 19 additions and 19 deletions

View File

@ -546,7 +546,7 @@ bool os::get_host_name(char* buf, size_t buflen) {
return true; return true;
} }
bool os::has_allocatable_memory_limit(julong* limit) { bool os::has_allocatable_memory_limit(size_t* limit) {
struct rlimit rlim; struct rlimit rlim;
int getrlimit_res = getrlimit(RLIMIT_AS, &rlim); int getrlimit_res = getrlimit(RLIMIT_AS, &rlim);
// if there was an error when calling getrlimit, assume that there is no limitation // if there was an error when calling getrlimit, assume that there is no limitation
@ -555,7 +555,7 @@ bool os::has_allocatable_memory_limit(julong* limit) {
if ((getrlimit_res != 0) || (rlim.rlim_cur == RLIM_INFINITY)) { if ((getrlimit_res != 0) || (rlim.rlim_cur == RLIM_INFINITY)) {
result = false; result = false;
} else { } else {
*limit = (julong)rlim.rlim_cur; *limit = (size_t)rlim.rlim_cur;
result = true; result = true;
} }
#ifdef _LP64 #ifdef _LP64
@ -564,7 +564,7 @@ bool os::has_allocatable_memory_limit(julong* limit) {
// arbitrary virtual space limit for 32 bit Unices found by testing. If // arbitrary virtual space limit for 32 bit Unices found by testing. If
// getrlimit above returned a limit, bound it with this limit. Otherwise // getrlimit above returned a limit, bound it with this limit. Otherwise
// directly use it. // directly use it.
const julong max_virtual_limit = (julong)3800*M; const size_t max_virtual_limit = 3800*M;
if (result) { if (result) {
*limit = MIN2(*limit, max_virtual_limit); *limit = MIN2(*limit, max_virtual_limit);
} else { } else {
@ -581,9 +581,9 @@ bool os::has_allocatable_memory_limit(julong* limit) {
// until the difference between these limits is "small". // until the difference between these limits is "small".
// the minimum amount of memory we care about allocating. // the minimum amount of memory we care about allocating.
const julong min_allocation_size = M; const size_t min_allocation_size = M;
julong upper_limit = *limit; size_t upper_limit = *limit;
// first check a few trivial cases // first check a few trivial cases
if (is_allocatable(upper_limit) || (upper_limit <= min_allocation_size)) { if (is_allocatable(upper_limit) || (upper_limit <= min_allocation_size)) {
@ -594,9 +594,9 @@ bool os::has_allocatable_memory_limit(julong* limit) {
*limit = min_allocation_size; *limit = min_allocation_size;
} else { } else {
// perform the binary search. // perform the binary search.
julong lower_limit = min_allocation_size; size_t lower_limit = min_allocation_size;
while ((upper_limit - lower_limit) > min_allocation_size) { while ((upper_limit - lower_limit) > min_allocation_size) {
julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit; size_t temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit;
temp_limit = align_down(temp_limit, min_allocation_size); temp_limit = align_down(temp_limit, min_allocation_size);
if (is_allocatable(temp_limit)) { if (is_allocatable(temp_limit)) {
lower_limit = temp_limit; lower_limit = temp_limit;

View File

@ -852,16 +852,16 @@ julong os::physical_memory() {
return win32::physical_memory(); return win32::physical_memory();
} }
bool os::has_allocatable_memory_limit(julong* limit) { bool os::has_allocatable_memory_limit(size_t* limit) {
MEMORYSTATUSEX ms; MEMORYSTATUSEX ms;
ms.dwLength = sizeof(ms); ms.dwLength = sizeof(ms);
GlobalMemoryStatusEx(&ms); GlobalMemoryStatusEx(&ms);
#ifdef _LP64 #ifdef _LP64
*limit = (julong)ms.ullAvailVirtual; *limit = (size_t)ms.ullAvailVirtual;
return true; return true;
#else #else
// Limit to 1400m because of the 2gb address space wall // Limit to 1400m because of the 2gb address space wall
*limit = MIN2((julong)1400*M, (julong)ms.ullAvailVirtual); *limit = MIN2((size_t)1400*M, (size_t)ms.ullAvailVirtual);
return true; return true;
#endif #endif
} }

View File

@ -29,10 +29,10 @@
#include "utilities/align.hpp" #include "utilities/align.hpp"
static size_t address_space_limit() { static size_t address_space_limit() {
julong limit = 0; size_t limit = 0;
if (os::has_allocatable_memory_limit(&limit)) { if (os::has_allocatable_memory_limit(&limit)) {
return (size_t)limit; return limit;
} }
// No limit // No limit

View File

@ -1655,17 +1655,17 @@ jint Arguments::set_ergonomics_flags() {
return JNI_OK; return JNI_OK;
} }
julong Arguments::limit_heap_by_allocatable_memory(julong limit) { size_t Arguments::limit_heap_by_allocatable_memory(size_t limit) {
julong max_allocatable; size_t max_allocatable;
julong result = limit; size_t result = limit;
if (os::has_allocatable_memory_limit(&max_allocatable)) { if (os::has_allocatable_memory_limit(&max_allocatable)) {
// The AggressiveHeap check is a temporary workaround to avoid calling // The AggressiveHeap check is a temporary workaround to avoid calling
// GCarguments::heap_virtual_to_physical_ratio() before a GC has been // GCarguments::heap_virtual_to_physical_ratio() before a GC has been
// selected. This works because AggressiveHeap implies UseParallelGC // selected. This works because AggressiveHeap implies UseParallelGC
// where we know the ratio will be 1. Once the AggressiveHeap option is // where we know the ratio will be 1. Once the AggressiveHeap option is
// removed, this can be cleaned up. // removed, this can be cleaned up.
julong heap_virtual_to_physical_ratio = (AggressiveHeap ? 1 : GCConfig::arguments()->heap_virtual_to_physical_ratio()); size_t heap_virtual_to_physical_ratio = (AggressiveHeap ? 1 : GCConfig::arguments()->heap_virtual_to_physical_ratio());
julong fraction = MaxVirtMemFraction * heap_virtual_to_physical_ratio; size_t fraction = MaxVirtMemFraction * heap_virtual_to_physical_ratio;
result = MIN2(result, max_allocatable / fraction); result = MIN2(result, max_allocatable / fraction);
} }
return result; return result;

View File

@ -366,7 +366,7 @@ class Arguments : AllStatic {
// Limits the given heap size by the maximum amount of virtual // Limits the given heap size by the maximum amount of virtual
// memory this process is currently allowed to use. It also takes // memory this process is currently allowed to use. It also takes
// the virtual-to-physical ratio of the current GC into account. // the virtual-to-physical ratio of the current GC into account.
static julong limit_heap_by_allocatable_memory(julong size); static size_t limit_heap_by_allocatable_memory(size_t size);
// Setup heap size // Setup heap size
static void set_heap_size(); static void set_heap_size();

View File

@ -237,7 +237,7 @@ class os: AllStatic {
static julong available_memory(); static julong available_memory();
static julong physical_memory(); static julong physical_memory();
static bool has_allocatable_memory_limit(julong* limit); static bool has_allocatable_memory_limit(size_t* limit);
static bool is_server_class_machine(); static bool is_server_class_machine();
// Returns the id of the processor on which the calling thread is currently executing. // Returns the id of the processor on which the calling thread is currently executing.