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

GetThreadInfo doesn't return context class loader

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b28
    • CPU:
      sparc
    • OS:
      solaris_8
    • Verification:
      Verified

      Description



      Name: vsR10008 Date: 10/15/2003



      JVMTI spec for GetThreadInfo says:

      typedef struct {
           char* name;
           jint priority;
           jboolean is_daemon;
           jthreadGroup thread_group;
           jobject context_class_loader;
      } jvmtiThreadInfo;

      jvmtiError
      GetThreadInfo(jvmtiEnv* env,
                   jthread thread,
                   jvmtiThreadInfo* info_ptr)

      ...
      +--------------------------------------------------------------------------------+
      | jvmtiThreadInfo - Thread information structure |
      +--------------------------+---------+-------------------------------------------+
      | Field | Type | Description |
      +--------------------------+---------+-------------------------------------------+
      ....
      +--------------------------+---------+-------------------------------------------+
      | context_class_loader | jobject | The context class loader associated with |
      | | | this thread. |
      +--------------------------+---------+-------------------------------------------+

      But RI returns NULL in field "context_class_loader".

      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"

      static jvmtiEnv *jvmti = NULL;

      JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
           jvmtiError err;
           jint res;

           res = (*jvm)->GetEnv(jvm, (void **) &jvmti,
                 JVMTI_VERSION_1_0);

           if (res != JNI_OK || jvmti == NULL) {
               return JNI_ERR;
           }
           return JNI_OK;
      }

      JNIEXPORT void JNICALL
      Java_a_check(JNIEnv *env, jclass cls, jthread thr, jobject clsl) {
           jvmtiError err;
           jvmtiThreadInfo info;

           err = (*jvmti)->GetThreadInfo(jvmti, thr, &info);
           if (err != JVMTI_ERROR_NONE) {
               printf("(GetThreadInfo) Error expected: %d, got: %d\n",
                       JVMTI_ERROR_NONE, err);
           }
           if ((*env)->IsSameObject(env, clsl, info.context_class_loader) != JNI_TRUE) {
               printf("Thread %s, wrong context class loader%s\n", info.name,
                            (info.context_class_loader == NULL ? ": NULL" : ""));
           }
      }

      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 {
           native static void check(Thread thr, ClassLoader cl);
           public static void main(String args[]) {
               System.loadLibrary("a");
               Thread thr = new Thread("TEST");
               check(thr, thr.getContextClassLoader());
           }
      }

      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$ sh runme.sh
      ...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)

      Thread TEST, wrong context class loader: NULL
      ----------------------------------------------------------------------

      This bug is reproducible on builds 19-23 and affects JCK JVMTI test:
      vm/jvmti/GetThreadInfo/gthi001/gthi00101/gthi00101.html

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

        Attachments

          Activity

            People

            Assignee:
            alanb Alan Bateman
            Reporter:
            atwosunw A2 A2 (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: