JDK-6960437 : max-heap-size greater than maxMemory(
  • Type: Bug
  • Component: deploy
  • Sub-Component: webstart
  • Affected Version: 6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2010-06-11
  • Updated: 2011-02-12
  • Resolved: 2011-02-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
C:\dload>java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
A Java application is deployed using Java Web Start. The max-heap-size=512m attribute is specified in the jnlp file.  But when the application runs, a call to Runtime.getRuntime().maxMemory() returns a value smaller than the
requested max-heap-size.

I tried different versions of the JRE and got these results:
1.6.0_07   Max mem available [532742144]  = 2^29 -  4 128 768
1.6.0_18   Max mem available [518979584]  = 2^29 - 17 891 328
1.6.0_20   Max mem available [518979584]  = 2^29 - 17 891 328

It is difficult to determine how much heap space is available to
an application when the amount returned varies with the Java
version.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Copy MemCheck.jnlp to the default directory of your webserver.
(See source code section)

2. Copy MemCheck.jar to the same directory.
(See source code section)

3. Connect to the webserver from a browser and issue a GET
request for the jnlp file. When it executes, this output can be
seen in the Java console and in a popup:
Max memory available [518979584]


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Max memory available [536870912]

ACTUAL -
Max memory available [518979584]

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
1. MemCheck.jnlp
Adjust the codebase attribute value as needed.
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://192.168.1.1:8080/" href="MemCheck.jnlp">
  <information>
    <title>MemCheck</title>
    <vendor>Cisco Systems, Inc.</vendor>
  </information>
  <resources>
    <j2se version="1.4+" initial-heap-size="64m" max-heap-size="512m"/>
    <jar href="MemCheck.jar" main="true" />
  </resources>
  <application-desc main-class="MemCheck"/>
</jnlp>

2. MemCheck.java
import javax.swing.*;
public class MemCheck {
	public static void main(String[] args) {
        long curVal = Runtime.getRuntime().maxMemory();
        System.out.println("Max memory available [" +curVal+ "]");
        JOptionPane.showMessageDialog(null,
            "Max memory available ["
            +curVal+ "]",
            "MemCheck",
            JOptionPane.INFORMATION_MESSAGE);
        System.exit(0);
	}
}
---------- END SOURCE ----------

Comments
EVALUATION Runtime.maxMemory() is supposed to return approximation of available memory. See 4505762 for details. Not a bug.
12-02-2011