JDK-4898900 : proper handling of HeapCreate failure through invocation interface
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.4.1,1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2003-07-30
  • Updated: 2016-05-25
  • Resolved: 2004-06-21
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.
Other
5.0 b57Fixed
Related Reports
Duplicate :  
Relates :  
Description

Name: gm110360			Date: 07/30/2003


FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

All windows 32-bit OSs (Win 9x, Me, 2000, & XP).




A DESCRIPTION OF THE PROBLEM :
If a create a JVM through the invocation interface using
JVM.DLL -> JNI_CreateJavaVM and the -Xmx parameter
specifies a heap larger than the VM can allocate, the VM
prints a message to stderr and *completely exits the
process*.

I am using the invocation interface to create a VM in-
process of another application. The application is not
JAVA.EXE but a GUI application. The message to stderr is
never seen, and the app disappears w/ no error or acces
violation messages of any kind.

Instead, the JNI_CreateJavaVM should return a failure code
and allow my application to continue and attempt to handle
the failure gracefully (at least giving the user an error
message).

ALSO- According to the Win32 API, specifying a maxSize of 0
to HeapCreate() allows a "virtually limitless" heap. It
will continue growing the heap as large as the operating
system can handle. This is how MSVCRT allocates its heap
for the C/C++ runtime alloc functions. This is far more
convenient - the heap will grow until memory is exhausted,
w/out the user having to "guess" a -Xmx parameter value
(which may cause the JVM to completely wipe out the
application).

Currently, when I try "-Xmx0" as a parameter, the VM
doesn't appear to even try HeapCreate() w/ that parameter,
but prematurely exits, assuming that 0 is indeed an invalid
value:
Invalid maximum heap size: -Xmx0
Could not create the Java virtual machine.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a GUI app that creates its own VM via the
invocation interface and passes a very large value as an -
Xmx parameter (like 1800M).
2. Watch the app disappear at runtime w/ no error message.
Running from the command line also results in no error
output since the app is not a console app. The only way to
capture the error message is to redirect the app's output
to a file (either from the command line or
programmatically) and view the output file after the app
disappears.

EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect the JNI_CreateJavaVM to return a failure
code and allow my application to continue, handling the
error gracefully if possible (for instance, if the VM is
only needed for one feature that can be disabled at runtime
if the VM create failed).

Also, I would expect -Xmx0 to work as documented in the
Win32 API for HeapCreate.

REPRODUCIBILITY :
This bug can be reproduced always.
(Incident Review ID: 166547) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-rc FIXED IN: tiger-rc INTEGRATED IN: tiger-b57 tiger-rc
25-06-2004

WORK AROUND Use a smaller -Xmx value.
25-06-2004

EVALUATION Within JNI_CreateVM, if the VM cannot reserve the requested amount of memory, it calls exit(), which exits the entire process. It must instead return an appropriate JNI error code. ###@###.### 2004-06-03
03-06-2004