Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4860727

-Xcheck:jni aborts JVM incorrectly with "Field type (static) mismatch..."

XMLWordPrintable

    • b24
    • generic, x86, sparc
    • generic, linux, solaris_7, windows_nt



        Name: rmT116609 Date: 05/08/2003


        FULL PRODUCT VERSION :
        Occurs in 1.4.0 and 1.4.2Beta (and presumably 1.4.1)

        j2sdk1.4.0/bin/java -version
        java version "1.4.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
        Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

        j2sdk1.4.2B/bin/java -version
        java version "1.4.2-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
        Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)


        FULL OS VERSION :
        Windows NT ( Windows NT Version 4.0 )
        Linux x86 (Linux rh71mp-pod 2.4.2-2smp #1 SMP Sun Apr 8 20:21:34 EDT 2001 i686 unknown)
        Solaris sparc (SunOS lorax 5.8 Generic_108528-01 sun4u sparc SUNW,Ultra-80)

        A DESCRIPTION OF THE PROBLEM :
        When running the JVM Invocation interface started with option -Xcheck:jni, a call to the JNI method GetStaticFieldID() on a static boolean array causes the the JVM to abort with the error:

        FATAL ERROR in native method: Field type (static) mismatch in JNI get/set field operations

        Notes:
        1. a call to a static boolean works fine.
        2. if Xcheck:jni is not specified, the call works without error, setting the value properly.
        3. The test case is Windows only, but a similar test case has the same result on Linux and Solaris







        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Build test code below.




        EXPECTED VERSUS ACTUAL BEHAVIOR :
        The JVM should not abort as the field being queried is a static member:

        JVM start success
        staticProp clazz=XXXXXXXX
        staticProp::arr_b fieldID=XXXXXXXX
        success calling SetStaticObjectField

        JVM start success
        staticProp clazz=XXXXXXXX
        staticProp::arr_b fieldID=XXXXXXXX
        FATAL ERROR in native method: Field type (static) mismatch in JNI get/set field operations


        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        FATAL ERROR in native method: Field type (static) mismatch in JNI get/set field operations

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        ------------------
        staticProp.java
        ------------------
        public class staticProp {
         public static boolean b=false;
         public static boolean[] arr_b=null;
        }

        ------------------
        bStaticField.c
        ------------------
        #include <jni.h>
        #include <stdio.h>
        #include <stdlib.h>
        #include <windows.h>

        // Note: This needs changed to point to the location of jvm.dll/libjvm.so
        #define JAVA14_JVMDLL "E:\\j2sdk1.4.0\\jre\\bin\\client\\jvm.dll"

        // Function pointer
        typedef jint (JNICALL *CreateJavaVM_t) (JavaVM**, void**, void*);


        // Dynamically load the JVM
        //
        void *JNU_FindCreateJavaVM(const char *vmLibPath)
        {
           HINSTANCE hJVMLib = LoadLibrary(vmLibPath);
           if (hJVMLib == NULL) {
             return NULL;
           }
           return GetProcAddress(hJVMLib, "JNI_CreateJavaVM");
        }


        int main()
        {
            CreateJavaVM_t pCreateJVM;
            JNIEnv* env = (JNIEnv*)0;
            JavaVM* jvm = (JavaVM*)0;
            JavaVMInitArgs vm_args;

            const char* sJVMLoc = JAVA14_JVMDLL;

            jclass clazz;
            jfieldID fID;

            jint status = JNI_OK;
            JavaVMOption options[12];
            int nOpts = 0;

            vm_args.version = JNI_VERSION_1_2;
            options[nOpts].extraInfo = NULL;
            options[nOpts++].optionString = "-Xcheck:jni";
            vm_args.nOptions = nOpts;
            vm_args.options = options;

            pCreateJVM = JNU_FindCreateJavaVM(sJVMLoc);

            vm_args.ignoreUnrecognized = JNI_TRUE;
            status = (*pCreateJVM)(&jvm, (void**)(&env), (void*)(&vm_args));
            if (0 != status) {
                printf( "(ERR starting JVM status=%p\n", status);
                return EXIT_FAILURE;
            }

        printf( "JVM start success\n");

            clazz = (*env)->FindClass(env, "staticProp");
            printf( "staticProp clazz=%p\n", clazz);

        #if 0
            // static member 'b' works fine
            fID = (*env)->GetStaticFieldID(env, clazz, "b", "Z");
            printf( "staticProp::b fieldID=%p\n", fID);
            (*env)->SetStaticBooleanField(env, clazz, fID, JNI_TRUE);
        #endif

            // This call exits the JVM with a FATAL error when -Xcheck:jni is turned on
            fID = (*env)->GetStaticFieldID(env, clazz, "arr_b", "[Z");
            printf( "staticProp::arr_b fieldID=%p\n", fID);
            (*env)->SetStaticObjectField(env, clazz, fID, 0);
            printf( "success calling SetStaticObjectField\n");

            return EXIT_SUCCESS;
        }

        ------------------
        Building and running the test case
        ------------------
        1. Change JAVA14_JVMDLL macro in bStaticField.c to point to your JVM.dll
        2. javac -classpath . staticProp.java
        3. cl -c -I<SDK14>\include -I<SDK14>\include\win32 bStaticField.c
        4. link -out:bStaticField.exe bStaticField.obj
        5. Run bStaticField
        ---------- END SOURCE ----------
        (Review ID: 184822)
        ======================================================================

              foliversunw Fred Oliver (Inactive)
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: