src/os/posix/vm/os_posix.cpp

Print this page




 171 
 172   st->print(", AS ");
 173   getrlimit(RLIMIT_AS, &rlim);
 174   if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
 175   else st->print("%uk", rlim.rlim_cur >> 10);
 176   st->cr();
 177 }
 178 
 179 void os::Posix::print_uname_info(outputStream* st) {
 180   // kernel
 181   st->print("uname:");
 182   struct utsname name;
 183   uname(&name);
 184   st->print(name.sysname); st->print(" ");
 185   st->print(name.release); st->print(" ");
 186   st->print(name.version); st->print(" ");
 187   st->print(name.machine);
 188   st->cr();
 189 }
 190 
























 191 










































 171 
 172   st->print(", AS ");
 173   getrlimit(RLIMIT_AS, &rlim);
 174   if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
 175   else st->print("%uk", rlim.rlim_cur >> 10);
 176   st->cr();
 177 }
 178 
 179 void os::Posix::print_uname_info(outputStream* st) {
 180   // kernel
 181   st->print("uname:");
 182   struct utsname name;
 183   uname(&name);
 184   st->print(name.sysname); st->print(" ");
 185   st->print(name.release); st->print(" ");
 186   st->print(name.version); st->print(" ");
 187   st->print(name.machine);
 188   st->cr();
 189 }
 190 
 191 bool os::has_allocatable_memory_limit(julong* limit) {
 192   struct rlimit rlim;
 193   int getrlimit_res = getrlimit(RLIMIT_AS, &rlim);
 194   // if there was an error when calling getrlimit, assume that there is no limitation
 195   // on virtual memory.
 196   bool result;
 197   if ((getrlimit_res != 0) || (rlim.rlim_cur == RLIM_INFINITY)) {
 198     result = false;
 199   } else {
 200     *limit = (julong)rlim.rlim_cur;
 201     result = true;
 202   }
 203 #ifdef _LP64
 204   return result;
 205 #else
 206   // arbitrary virtual space limit for 32 bit Unices found by testing. If 
 207   // getrlimit above returned a limit, bound it with this limit. Otherwise
 208   // directly use it.
 209   const julong max_virtual_limit = (julong)3800*M;
 210   if (result) {
 211     *limit = MIN2(*limit, max_virtual_limit);
 212   } else {
 213     *limit = max_virtual_limit;
 214   }
 215 
 216   // bound by actually allocatable memory. The algorithm uses two bounds, an
 217   // upper and a lower limit. The upper limit is the current highest amount of
 218   // memory that could not be allocated, the lower limit is the current highest
 219   // amount of memory that could be allocated.
 220   // The algorithm iteratively refines the result by halving the difference
 221   // between these limits, updating either the upper limit (if that value could
 222   // not be allocated) or the lower limit (if the that value could be allocated)
 223   // until the difference between these limits is "small".
 224   
 225   // the minimum amount of memory we care about allocating.
 226   const julong min_allocation_size = M;
 227   
 228   julong upper_limit = *limit;
 229 
 230   // first check a few trivial cases
 231   if (is_allocatable(upper_limit)) {
 232     *limit = upper_limit;
 233   } else if (upper_limit < min_allocation_size) {
 234     *limit = upper_limit;
 235   } else if (!is_allocatable(min_allocation_size)) {
 236     // we found that not even min_allocation_size is allocatable. Return it
 237     // anyway. There is no point to search for a better value any more.
 238     *limit = min_allocation_size;
 239   } else {
 240     // perform the binary search.
 241     julong lower_limit = min_allocation_size;
 242     while ((upper_limit - lower_limit) > min_allocation_size) {
 243       julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit;
 244       temp_limit = align_size_down_(temp_limit, min_allocation_size);
 245       if (is_allocatable(temp_limit)) {
 246         lower_limit = temp_limit;
 247       } else {
 248         upper_limit = temp_limit;
 249       }
 250     }
 251     *limit = lower_limit;
 252   }
 253   return true;
 254 #endif
 255 }