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

the jni function GetDirectBufferAddress() works incorrectly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • hotspot
    • sparc
    • solaris_8



      Name: viR10068 Date: 08/14/2001


      The simple test for jni function GetDirectBufferAddress() is failed
      on the jdk1.4.0-beta_refresh-b75. This function seems to return invalid address.

      To reproduce:
      1. compile the gdba00101m1.java
         Used: javac -d . gdba00101m1.java
      2. compile the gdbc00101m1.c
         Used: cc -G -KPIC -o libjckjni.so -Iinclude gdba00101m1.c
         In 'include' directory you should place 3 files (see attachments):
         % ls include
         jckjlong_md.h jckjni.h jckjni_md.h

      3. set environment variable LD_LIBRARY_PATH to working directory
      4. run ndbb00101m1
         Used: java -Xfuture javasoft.sqe.tests.vm.jni.gdba001.gdba00101m1.gdba00101m1

      Execution log:
      % java -version
      java version "1.4.0-beta_refresh"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta_refresh-b75)
      Java HotSpot(TM) Client VM (build 1.4.0-beta_refresh-b75, mixed mode)
      % java -Xfuture javasoft.sqe.tests.vm.jni.gdba001.gdba00101m1.gdba00101m1
      JAVA: Checks data in buffer
      JAVA: Put val: 3 Get val: 3
      JAVA: Put val: 4 Get val: 4
      JNI: data -12, testData 3
      JAVA: Check of data in buffer failed
      JAVA: Checks data in sliced buffer
      JNI: data -12, testData 0
      JAVA: Check of data in sliced buffer failed
      %
      ---------------------------gdba00101m1.java ---------------------------
      package javasoft.sqe.tests.vm.jni.gdba001.gdba00101m1;

      import java.io.PrintStream;
      import java.nio.ByteBuffer;
      import java.nio.Buffer;

      public class gdba00101m1 {

          private static native boolean checkBufferContents(Buffer buf, byte[] data);

          public static int testChecks(PrintStream out) {

              boolean res = false;
              try {
                  byte[] testData = new byte[]{3, 4};

                  ByteBuffer buf = ByteBuffer.allocateDirect(8);

                  out.println("JAVA: Checks data in buffer");
                  for(int i=0; i<testData.length; i++) {
                      buf.put(i, testData[i]);
                      out.println("JAVA: Put val: "+testData[i]+"\tGet val: "+buf.get(i));
                  }

                  if (!checkBufferContents(buf, testData)) {
                      out.println("JAVA: Check of data in buffer failed");
                      res = true;
                  }

                  buf.position(3);
                  ByteBuffer buf2 = buf.slice();
                  out.println("JAVA: Checks data in sliced buffer");

                  if (!checkBufferContents(buf2, new byte[]{0, 2})) {
                      out.println("JAVA: Check of data in sliced buffer failed");
                      res = true;
                  }

              } catch (Exception e) {
                  e.printStackTrace();
                  out.println("Unexpected exception: " + e);
                  res = true;
              }

              if(res)
                  return 2/*STATUS_FAILED*/;
              return 0/*STATUS_PASSED*/;
          }

          static String loadLibraryStatus = "";
          static {
              if(!loadLib("gdba00101m1"))
                  loadLib("jckjni");
          }

          static boolean loadLib(String libName){
              try {
                  System.loadLibrary(libName);
                  loadLibraryStatus = null;
                  return true;
              } catch (SecurityException e) {
                  loadLibraryStatus += "loadLibrary(\"" + libName + "\") throws: " + e + "\n";
              } catch (UnsatisfiedLinkError e) {
                  loadLibraryStatus += "loadLibrary(\"" + libName + "\") throws: " + e + "\n";
              }
              return false;
          }

          public static int run(String argv[], PrintStream out) {

              if (loadLibraryStatus!=null) {
                  out.println("Library loading:\n" + loadLibraryStatus);
              }
              return testChecks(out);
          }

          public static void main(String argv[]) {
              System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
          }
      }
      ---------------------------gdba00101m1.c ---------------------------

      #include <stdlib.h>
      #include <string.h>
      #include <stdio.h>
      #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 jboolean JNICALL
      Java_javasoft_sqe_tests_vm_jni_gdba001_gdba00101m1_gdba00101m1_checkBufferContents
      (JNIEnv *env, jobject obj, jobject buf, jbyteArray arr) {

          jbyte* data = (jbyte*) JNI_ENV_PTR(env)->GetDirectBufferAddress(JNI_ENV_ARG(env,buf));
          jbyte* testData = JNI_ENV_PTR(env)->GetByteArrayElements(JNI_ENV_ARG(env,arr), NULL);

          if (data[0] != testData[0]) {
              printf("JNI: data %d, testData %d\n", data[0], testData[0]);
              return JNI_FALSE;
          }
          return JNI_TRUE;
      }

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

      The new JCK test
      vm/jni/GetDirectBufferAddress/gdba001/gdba00101m1/gdba00101m1.html
      is failed due to this bug.

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

            kbr Kenneth Russell (Inactive)
            vivsunw Viv Viv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: