This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Crash in JNI test application
- From: Øyvind Harboe <oyvind dot harboe at zylin dot com>
- To: java at gcc dot gnu dot org
- Date: Mon, 19 Jan 2004 16:14:02 +0100
- Subject: Crash in JNI test application
- Organization: Zylin AS
My JNI superpowers are rather limited and I haven't tested it against
Sun's JRE, but the application is simple and is a subset of all the
JNI helloworld apps out there.
It appears as if JNI_CreateJavaVM succeeds, but returns garbage the
second time and thus (*env)->FindClass() causes an access violation.
To compile:
\wingcc\bin\gcj -c HelloWorld.java
\wingcc\bin\gcj -c jnitest.c
\wingcc\bin\gcj -o helloworld jnitest.o HelloWorld.o
Øyvind
public class HelloWorld
{
}
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void stressJNI()
{
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jint res;
jclass cls;
jmethodID mid;
jstring jstr;
char classpath[1024];
/* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond */
vm_args.version = 0x00010002;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm,(void**) &env,&vm_args);
if (res>=0)
{
cls = (*env)->FindClass(env, "HelloWorld");
if (cls != 0)
{
// write more code here...
}
(*jvm)->DestroyJavaVM(jvm);
}
}
int main(int argc, char **argv)
{
int i;
for (i=0; i<1000; i++)
{
// If no memory limit has been specified use the size of
// physical memory.
MEMORYSTATUS Info;
Info.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&Info);
printf("Available memory: %d\n", Info.dwAvailPageFile);
stressJNI();
}
return 0;
}