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

Tags are not local to the environment

XMLWordPrintable

    • sparc
    • solaris_8



      Name: vsR10008 Date: 10/16/2003



      JVMTI spec for Heap functions says:

      "Tags are local to the environment; that is, the tags of one environment are
      not visible in another"

      But the tag which is set in one environment is visible in another -
      even if the first one is disposed!

      To reproduce this bug please run on Solaris the following sh script
      (do not forget to change JDK_PATH var):

      ---- File: runme.sh ---------------------------------------------------
      JDK_PATH="/java/re/jdk/1.5.0/latest/binaries/solaris-sparc"

      JVMTI_H_PATH="${JDK_PATH}/include"
      CC="cc"

      echo "...creating a.c"
      cat - > a.c <<EOF
      #include <stdio.h>
      #include "jvmti.h"

      JavaVM *global_jvm;


      JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
             global_jvm = jvm;
             return JNI_OK;
      }

      jvmtiEnv *createEnv(int idx) {
             jvmtiEnv *jvmti = NULL;
             jvmtiError err;
             jvmtiCapabilities cap;

             jint res;

             memset(&cap, 0, sizeof(cap));
             cap.can_tag_objects = 1;

             res = (*global_jvm)->GetEnv(global_jvm, (void **) &jvmti, JVMTI_VERSION_1_0);
             if (res != JNI_OK || jvmti == NULL) {
                 printf("[%d] GetEnv ERROR: Could not create environment!\n", idx);
                 return NULL;
             }

             err = (*jvmti)->AddCapabilities(jvmti, &cap);
             if (err != JVMTI_ERROR_NONE) {
                printf("[%d] AddCapabilities ERROR: %d\n", idx, err);
             }

             return jvmti;
      }

      JNIEXPORT void JNICALL
      Java_a_check(JNIEnv *env, jclass cls) {
             jvmtiError err;
             jvmtiEnv *jvmti = NULL;
             jvmtiCapabilities cap;
             jlong tag;
             jint res;

             jvmti = createEnv(1);
             if (jvmti == NULL) return;

             err = (*jvmti)->SetTag(jvmti, cls, 123456l);
             if (err != JVMTI_ERROR_NONE) {
                printf("(SetTag) Unexpected error: %d ", err);
                return;
             }

             err = (*jvmti)->DisposeEnvironment(jvmti);
             if (err != JVMTI_ERROR_NONE) {
                printf("(DisposeEnvironment) Unexpected error: %d ", err);
                return;
             }

             jvmti = createEnv(2);
             if (jvmti == NULL) return;

             err = (*jvmti)->GetTag(jvmti, cls, &tag);
             if (err != JVMTI_ERROR_NONE) {
                printf("(GetTag) Unexpected error: %d\n", err);
                return;
             }
             if (tag == 123456l) {
                printf("FAILURE: Tag survives disposal!\n");
             }
      }


      EOF

      echo "...creating liba.so"

      ${CC} -G -KPIC -o liba.so -I${JDK_PATH}/include -I${JDK_PATH}/include/solaris -I${JVMTI_H_PATH} a.c

      echo "...creating a.java"

      cat - > a.java <<EOF
      public class a extends Thread {
             public static native void check();
             public static void main(String[] args) {
                 System.loadLibrary("a");
                 check();
             }
      }
      EOF

      echo "...creating a.class"

      ${JDK_PATH}/bin/javac -d . a.java

      echo "...running a.class"
      LD_LIBRARY_PATH=. CLASSPATH=. ${JDK_PATH}/bin/java -showversion -agentlib:a a
      -----------------------------------------------------------------------

      Running on b23, execution log is as follows:

      ----------------------------------------------------------------------
      bash-2.03$ runme
      ...creating a.c
      ...creating liba.so
      ...creating a.java
      ...creating a.class
      ...running a.class
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b23)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b23, mixed mode)

      FAILURE: Tag survives disposal!
      ----------------------------------------------------------------------

      This bug is reproducible on builds 22 and 23.

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

            Unassigned Unassigned
            atwosunw A2 A2 (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: