comparison src/os/posix/vm/os_posix.cpp @ 8854:754c24457b20

7112912: Message "Error occurred during initialization of VM" on boxes with lots of RAM Summary: Ergonomics now also takes available virtual memory into account when deciding for a heap size. The helper method to determine the maximum allocatable memory block now uses the appropriate OS specific calls to retrieve available virtual memory for the java process. In 32 bit environments this method now also searches for the maximum actually reservable amount of memory. Merge previously separate implementations for Linux/BSD/Solaris into a single method. Reviewed-by: jmasa, tamao
author tschatzl
date Wed, 27 Mar 2013 19:21:18 +0100
parents 730cc4ddd550
children e12c9b3740db
comparison
equal deleted inserted replaced
8853:2e093b564241 8854:754c24457b20
186 st->print(name.version); st->print(" "); 186 st->print(name.version); st->print(" ");
187 st->print(name.machine); 187 st->print(name.machine);
188 st->cr(); 188 st->cr();
189 } 189 }
190 190
191 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) || (upper_limit <= min_allocation_size)) {
232 *limit = upper_limit;
233 } else if (!is_allocatable(min_allocation_size)) {
234 // we found that not even min_allocation_size is allocatable. Return it
235 // anyway. There is no point to search for a better value any more.
236 *limit = min_allocation_size;
237 } else {
238 // perform the binary search.
239 julong lower_limit = min_allocation_size;
240 while ((upper_limit - lower_limit) > min_allocation_size) {
241 julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit;
242 temp_limit = align_size_down_(temp_limit, min_allocation_size);
243 if (is_allocatable(temp_limit)) {
244 lower_limit = temp_limit;
245 } else {
246 upper_limit = temp_limit;
247 }
248 }
249 *limit = lower_limit;
250 }
251 return true;
252 #endif
253 }