@@ -713,7 +713,7 @@ bool os::get_host_name(char* buf, size_t buflen) {
713713}
714714
715715#ifndef _LP64
716- // Helper, on 32bit, for os::has_allocatable_memory_limit
716+ // Helper, on 32bit, for os::commit_memory_limit
717717static bool is_allocatable (size_t s) {
718718 if (s < 2 * G) {
719719 return true ;
@@ -731,31 +731,19 @@ static bool is_allocatable(size_t s) {
731731}
732732#endif // !_LP64
733733
734+ size_t os::commit_memory_limit () {
735+ // On POSIX systems, the amount of memory that can be commmitted is limited
736+ // by the size of the reservable memory.
737+ size_t reserve_limit = reserve_memory_limit ();
734738
735- bool os::has_allocatable_memory_limit (size_t * limit) {
736- struct rlimit rlim;
737- int getrlimit_res = getrlimit (RLIMIT_AS, &rlim);
738- // if there was an error when calling getrlimit, assume that there is no limitation
739- // on virtual memory.
740- bool result;
741- if ((getrlimit_res != 0 ) || (rlim.rlim_cur == RLIM_INFINITY)) {
742- result = false ;
743- } else {
744- *limit = (size_t )rlim.rlim_cur ;
745- result = true ;
746- }
747739#ifdef _LP64
748- return result ;
740+ return reserve_limit ;
749741#else
750- // arbitrary virtual space limit for 32 bit Unices found by testing. If
751- // getrlimit above returned a limit, bound it with this limit. Otherwise
752- // directly use it.
753- const size_t max_virtual_limit = 3800 *M;
754- if (result) {
755- *limit = MIN2 (*limit, max_virtual_limit);
756- } else {
757- *limit = max_virtual_limit;
758- }
742+ // Arbitrary max reserve limit for 32 bit Unices found by testing.
743+ const size_t max_reserve_limit = 3800 * M;
744+
745+ // Bound the reserve limit with the arbitrary max.
746+ size_t actual_limit = MIN2 (reserve_limit, max_reserve_limit);
759747
760748 // bound by actually allocatable memory. The algorithm uses two bounds, an
761749 // upper and a lower limit. The upper limit is the current highest amount of
@@ -769,15 +757,15 @@ bool os::has_allocatable_memory_limit(size_t* limit) {
769757 // the minimum amount of memory we care about allocating.
770758 const size_t min_allocation_size = M;
771759
772- size_t upper_limit = *limit ;
760+ size_t upper_limit = actual_limit ;
773761
774762 // first check a few trivial cases
775763 if (is_allocatable (upper_limit) || (upper_limit <= min_allocation_size)) {
776- * limit = upper_limit;
764+ // The actual limit is allocatable, no need to do anything.
777765 } else if (!is_allocatable (min_allocation_size)) {
778766 // we found that not even min_allocation_size is allocatable. Return it
779767 // anyway. There is no point to search for a better value any more.
780- *limit = min_allocation_size;
768+ actual_limit = min_allocation_size;
781769 } else {
782770 // perform the binary search.
783771 size_t lower_limit = min_allocation_size;
@@ -790,12 +778,31 @@ bool os::has_allocatable_memory_limit(size_t* limit) {
790778 upper_limit = temp_limit;
791779 }
792780 }
793- *limit = lower_limit;
781+ actual_limit = lower_limit;
794782 }
795- return true ;
783+
784+ return actual_limit;
796785#endif
797786}
798787
788+ size_t os::reserve_memory_limit () {
789+ struct rlimit rlim;
790+ int getrlimit_res = getrlimit (RLIMIT_AS, &rlim);
791+
792+ // If there was an error calling getrlimit, conservatively assume no limit.
793+ if (getrlimit_res != 0 ) {
794+ return SIZE_MAX;
795+ }
796+
797+ // If the current limit is not infinity, there is a limit.
798+ if (rlim.rlim_cur != RLIM_INFINITY) {
799+ return (size_t )rlim.rlim_cur ;
800+ }
801+
802+ // No limit
803+ return SIZE_MAX;
804+ }
805+
799806void * os::get_default_process_handle () {
800807#ifdef __APPLE__
801808 // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY
0 commit comments