src/os/solaris/vm/os_solaris.cpp
Print this page
@@ -474,25 +474,45 @@
julong os::physical_memory() {
return Solaris::physical_memory();
}
-julong os::allocatable_physical_memory(julong size) {
+bool os::has_allocatable_memory_limit(julong& limit) {
+ struct rlimit rlim;
+ // Solaris defines RLIMIT_AS as RLIMIT_VMEM.
+ int getrlimit_res = getrlimit(RLIMIT_AS, &rlim);
+ // if there was an error when calling getrlimit, assume that there is no limitation
+ // on virtual memory.
+ bool result;
+ if ((getrlimit_res != 0) || (rlim.rlim_cur == RLIM_INFINITY)) {
+ result = false;
+ } else {
+ limit = (julong)rlim.rlim_cur;
+ result = true;
+ }
#ifdef _LP64
- return size;
+ return result;
#else
- julong result = MIN2(size, (julong)3835*M);
- if (!is_allocatable(result)) {
+ // arbitrary virtual space limit for Solaris found by testing. If getrlimit
+ // above returned a limit, bound it with this limit. Otherwise directly use
+ // it as limit.
+ const julong max_virtual_limit = (julong)3835*M;
+ if (result) {
+ limit = MIN2(limit, max_virtual_limit);
+ } else {
+ limit = max_virtual_limit;
+ }
+ if (!is_allocatable(limit)) {
// Memory allocations will be aligned but the alignment
// is not known at this point. Alignments will
// be at most to LargePageSizeInBytes. Protect
// allocations from alignments up to illegal
// values. If at this point 2G is illegal.
- julong reasonable_size = (julong)2*G - 2 * LargePageSizeInBytes;
- result = MIN2(size, reasonable_size);
+ julong reasonable_limit = (julong)2*G - 2 * LargePageSizeInBytes;
+ limit = MIN2(limit, reasonable_limit);
}
- return result;
+ return true;
#endif
}
static hrtime_t first_hrtime = 0;
static const hrtime_t hrtime_hz = 1000*1000*1000;