United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-8006431 : os::Bsd::initialize_system_info() sets _physical_memory too large

Details
Type:
Bug
Submit Date:
2013-01-16
Status:
Closed
Updated Date:
2014-06-26
Project Name:
JDK
Resolved Date:
2013-01-21
Component:
hotspot
OS:
Sub-Component:
runtime
CPU:
Priority:
P3
Resolution:
Fixed
Affected Versions:
Fixed Versions:
hs25 (b17)

Related Reports
Backport:
Backport:
Backport:
Backport:

Sub Tasks

Description
On my 8GB OSX laptop os::Bsd::initialize_system_info()  sets up _physical_memory to be 140733629517824, which is 127TB.

Since we base for example the maximum Java heap size on os::physical_memory() which on BSD returns this value we get ~30GB max heap size even for just running "java -version".

Here is the code in os::Bsd::initialize_system_info() that returns a too large value:

  mib[0] = CTL_HW;
  mib[1] = HW_USERMEM;
  len = sizeof(mem_val);
  if (sysctl(mib, 2, &mem_val, &len, NULL, 0) != -1) 
       _physical_memory = mem_val;

Somehow the sysctl() call sets mem_val to 140733629517824.

Impact=Medium since we normally don't crash but just use up much more memory than necessary (we don't commit the maximum heap size, but there are several data structures that are O(MaxHeapSize) in size.
Likelihood: High. Seem to happen on all OSX machine where I've tried it.
Workaround: Low. Set -Xmx on the command line.

ILW=MHL -> P3
                                    

Comments
URL:   http://hg.openjdk.java.net/hsx/hsx25/hotspot/rev/c07c102cbad7
User:  amurillo
Date:  2013-01-25 20:42:57 +0000

                                     
2013-01-25
URL:   http://hg.openjdk.java.net/hsx/hotspot-rt/hotspot/rev/c07c102cbad7
User:  brutisso
Date:  2013-01-21 10:37:08 +0000

                                     
2013-01-21
Staffan, you are correct.

Changing from HW_USERMEM to HW_MEMSIZE, gives me 8GB in mem_val instead of 127TB. This is correct on my machine and it also gives me a default maximum heap size of 2 GB instead of 30GB.
                                     
2013-01-18
Man page for sysctl:
https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/sysctl.3.html

HW_MEMSIZE is the 64 bit value we want.
                                     
2013-01-18
I think mem_val should be an int, not a u_long. (You can see the value with "sysctl hw.usermem" on the command line).

But on the other hand, that means it's not really going to work if you have lots of memory... Most likely it is HW_MEMSIZE we want, which is documented as a 64-bit value. 
                                     
2013-01-16



Hardware and Software, Engineered to Work Together