Java vm creation crashes if max heap is set too big

I start the jvm from deep within a c / fortran app. If I give a "decent" max heap size w/ -Xmx option, everything is fine. However, the JNI_CreateJavaVM crashes w/

Unhandled exception at 0x060b766b (jvm.dll) in tnapa.exe: 0xC0000005: Access violation reading location

0x00000ff1.

The violator being:

>jvm.dll!_findNonConsecutive() + 0x18b

if I give a large (e.g. -Xmx1g) max heap size. I first suspected that this is our own code that messes up some memory before the jvm gets into the picture (and still consider this a strong possibility). However, when trying to solve the problem, I looked at the reported memory location w/ MS Visual C++ debugger, and it showed ? for values there. I could not find it in the documentation, but my coworker said it means that memory is outside of the scope of the process in question. This makes it sound like jvm is trying to access illegal memory areas. Could this be a jni bug?

Environment:

jdk 1.5.0_09

win xp sp 2

ms cl compiler (/MD flag is used in compilation)

2GB of ram

The jvm is loaded dynamically, i.e. the reference to the func JNI_CreateJavaVM is fetched from the jvm.dll, which is loaded lazily, i.e. just in time when needed for the first time. A proper typecast is done to ensure that JNICALL calling convention is used.

-Antti-

[1371 byte] By [akarantaa] at [2007-10-3 8:01:36]
# 1
Sorry, blaming the wrong horse here... the jvm in use was actually jrockit (BEA JRockit(R) (build R26.4.0-63-63688-1.5.0_06-20060626-2259-win-ia32, jdk 1.5.0_06). W/ sun jdk everything is fine. Well, at least it does not crash, it just fails due to not enough memory.-Antti-
akarantaa at 2007-7-15 3:05:00 > top of Java-index,Java HotSpot Virtual Machine,Specifications...