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

constructor invocation using jni function FromReflectedMethod()

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      kestrel
    • CPU:
      x86
    • OS:
      windows_nt

      Description



      Name: dkC59003 Date: 08/10/99



      The JCK1.3 test fails under win32 HotSpot VM (jdk1.3beta build M):
      vm/jni/FromReflectedMethod/frrm001/frrm00101m2/frrm00101m2.html

      The test uses jni function FromReflectedMethod() to obtain
      method ID of class constructor using object of Constructor type
      as argument. Then the ID is used to call constructor 'test(int i)',
      that set static field 'check' to 160.
      It looks like the constructor is not called because 'check' field
      remains to be equal zero.

      --------------------------------------------------------

      To reproduce the issue execute following test.

      Note, the failure is unstable and the test passes after any
      of the changes listed below:
      -if line marked * in test.java is commented out
      -if line marked ** in testlib.c is replaced with lines
      jclass jc = JNI_ENV_PTR(env) -> GetObjectClass(JNI_ENV_ARG(env, obj));
      jmethodID jmid = JNI_ENV_PTR(env) -> GetMethodID(JNI_ENV_ARG(env, jc), "<init>" ,"(I)V");
      -if test.java was compiled with jdk122W java compiler
      -if methods and fields in test.java are reshuffled
      -etc

      --- Sources --------------------------------------------
      ----- test.java -----
      import java.lang.reflect.Constructor;
      import java.io.PrintStream;

      public class test {

      static {
      System.loadLibrary("testlib");
      }

      public static void main(String argv[]) {
      try {
      test x = new test();
      Constructor obj = test.class.getConstructor(new Class[] {int.class});
      x.n(obj);
      if (check!=160) {
      System.out.println("Test is failed. check=" + check + " (must be 160)");
      }else{
      System.out.println("Test is passed");
      }
      }catch (Throwable e) {
      System.out.println(e);
      }
      }
      private void m() {} //*
      native int n(Constructor obj);
      static int check;
      public test(){}
      public test(int i) {
      check = (i+153);
      System.out.println("check is set to " + check);
      }
      }

      ----- testlib.c -----
      #include "jckjni.h"

      #ifdef __cplusplus
      extern "C" {
      #endif

      #ifndef JNI_ENV_ARG
      #ifdef __cplusplus
      #define JNI_ENV_ARG(x, y) y
      #define JNI_ENV_PTR(x) x
      #else
      #define JNI_ENV_ARG(x,y) x, y
      #define JNI_ENV_PTR(x) (*x)
      #endif
      #endif

      JNIEXPORT void JNICALL Java_test_n(JNIEnv *env, jobject obj, jobject o)
      {
      jmethodID jmid = JNI_ENV_PTR(env) -> FromReflectedMethod(JNI_ENV_ARG(env, o)); //**
      JNI_ENV_PTR(env) -> CallVoidMethod(JNI_ENV_ARG(env, obj), jmid, 7);
      return;
      }

      #ifdef __cplusplus
      }
      #endif
      -------------------

      --- Compilation ----------------------------------------

      C:\tmp>cl /D "WIN32" /D "_WINDOWS" /LD testlib.c
      Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
      Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

      testlib.c
      Microsoft (R) Incremental Linker Version 6.00.8168
      Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

      /out:testlib.dll
      /dll
      /implib:testlib.lib
      testlib.obj
         Creating library testlib.lib and object testlib.exp

      C:\tmp>javac test.java
      (java compiler: jdk1.1.7 or jdk13M)

      --- Execution ------------------------------------------

      C:\tmp>java -classic -version
      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-M)
      Classic VM (build 1.3beta-M, native threads, nojit)

      C:\tmp>java -classic test
      check is set to 160
      Test is passed

      C:\tmp>java -version
      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-M)
      Java Client VM (build 1.3beta-m, mixed mode)

      C:\tmp>java test
      Test is failed. check=0 (must be 160)

      --------------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            rschmidtsunw Rene Schmidt (Inactive)
            Reporter:
            dkhukhrosunw Dmitry Khukhro (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: