Name: yyT116575 Date: 10/12/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
I wrote a C program which creates a JVM using the JNI invocation
interfaces . The hotspot JVM crashes C program's exit hook has called
after Java program called System.exit() .
Using classic JVM and following each case doesn't crashes hotspot JVM:
1. Don't call System.exit() in Java Program .
2. Don't set exit hook to JavaOption in C Program .
I compiled C program with Microsoft VC++ version 5 .
I run C program , and got following message ( with VC++ alart dialog
that notes 'abnormal program termination' ):
C:\>Jcmd
Starting JVM...
FINISHED CallStaticVoidMethod
CALL System.exit
CALLED y_exit
#
# HotSpot Virtual Machine Error, Internal Error
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
# Error ID: 4A4156410E435050012E
#
the reproductable code is follow:
/*** C program that named Jcmd.c ***/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <jni.h>
// JVM exit code
static int exitValue = 0;
FILE *fp;
void (JNICALL y_exit)(jint code) {
printf("CALLED y_exit\n");
exitValue = (int)code;
}
jint (JNICALL y_fprintf)(FILE *fp, const char *format, va_list args) {
jint rc;
if (fp == NULL)
if ((fp = fopen("vm.out", "w")) == NULL) return -1;
rc = vfprintf(fp, format, args);
fflush(fp);
return rc;
}
int main(int argc, char *argv[]) {
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jclass clazz;
jobjectArray str_array;
jmethodID mid;
jint ret;
JavaVMOption options[3];
options[0].optionString = "-Djava.class.path=.";
options[1].optionString = "exit";
options[1].extraInfo = y_exit;
options[2].optionString = "vfprintf";
options[2].extraInfo = y_fprintf;
vm_args.version = JNI_VERSION_1_2;
vm_args.nOptions = 3;
vm_args.options = options;
vm_args.ignoreUnrecognized = JNI_TRUE;
// create JavaVM
ret = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
if (ret < 0) {
printf("Can't create JVM. Error: %ld\n", ret);
return(1);
}
// find Test.class
clazz = (*env)->FindClass(env, "Test");
if (clazz == 0) {
printf("Can't locate the Test class.Exiting...\n");
return(1);
}
// get main method
mid = (*env)->GetStaticMethodID(env, clazz,"main","([Ljava/lang/String;)V");
if (mid == 0) {
printf("Can't locate the main method. Exiting...\n");
return(1);
}
printf("Starting JVM...\n");
// call main method
(*env)->CallStaticVoidMethod(env, clazz, mid, str_array);
printf("FINISHED CallStaticVoidMethod\n");
// destroy JavaVM
(*jvm)->DestroyJavaVM(jvm);
printf("FINISHED DestroyJavaVM\n");
return(exitValue);
}
/*** End of C program ***/
/*** Java program that named Test.java ***/
public class Test extends Thread {
public Test() {
start();
// If comment out above start() method and call System.exit(0)
// this position , JVM crashes too .
//System.exit(0);
}
public void run() {
System.out.println("CALL System.exit");
System.exit(0);
System.out.println("System.exit.");
}
public static void main(String[] argv) {
new Test();
}
}
/*** End of Java program ***/
(Review ID: 110685)
======================================================================
- duplicates
-
JDK-4378674 Hotspot does not support JNI_CreateJavaVM with exit hook
-
- Closed
-
- relates to
-
JDK-4323980 JNI exit_hook called prior to suspending VM threads
-
- Closed
-