This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Crash in JNI test application


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;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]