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

InterruptThread returns INVALID_THREAD instead of THREAD_NOT_ALIVE.

    XMLWordPrintable

    Details

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

      Description



      Name: vsR10008 Date: 10/15/2003



      JVMTI spec for InterruptThread says:

      jvmtiError
      InterruptThread(jvmtiEnv* env,
                   jthread thread)

      ...
      +------------------------------+-------------------------------------------------+
      | Error | Description |
      +------------------------------+-------------------------------------------------+
      | JVMTI_ERROR_THREAD_NOT_ALIVE | thread is not live (has not been started or is |
      | | now dead). |
      +------------------------------+-------------------------------------------------+

      But RI returns error code JVMTI_ERROR_INVALID_THREAD instead of
      JVMTI_ERROR_THREAD_NOT_ALIVE.

      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;
      static jvmtiCapabilities capa;

      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;
           }
           memset(&capa, 0, sizeof(jvmtiCapabilities));
           capa.can_signal_thread = 1;

           err = (*jvmti)->AddCapabilities(jvmti, &capa);
           if (err != JVMTI_ERROR_NONE && err != JVMTI_ERROR_NOT_AVAILABLE) {
               return JNI_ERR;
           }

           return JNI_OK;
      }

      void describe(jvmtiError err) {
           jvmtiError err0;
           char *descr;
           err0 = (*jvmti)->GetErrorName(jvmti, err, &descr);
           if (err0 == JVMTI_ERROR_NONE) {
               printf(descr);
           } else {
               printf("error [%d]", err);
           }
      }

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

           err = (*jvmti)->InterruptThread(jvmti, thr);
           if (err != JVMTI_ERROR_THREAD_NOT_ALIVE) {
               printf("(InterruptThread) Error expected: ");
               describe(JVMTI_ERROR_THREAD_NOT_ALIVE);
               printf(",\n got: ");
               describe(err);
               printf("\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 {
           native static void check(Thread thr);
           public static void main(String args[]) {
               System.loadLibrary("a");
               Thread thr = new Thread("TEST");
               check(thr);
           }
      }

      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)

      (InterruptThread) Error expected: JVMTI_ERROR_THREAD_NOT_ALIVE,
                                    got: JVMTI_ERROR_INVALID_THREAD
      ----------------------------------------------------------------------

      This bug is reproducible on builds 19-23 and affects JCK JVMTI test:
      vm/jvmti/InterruptThread/inth001/inth00102/inth00102.html

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

        Attachments

          Activity

            People

            Assignee:
            swamyv Swamy Venkataramanappa
            Reporter:
            atwosunw A2 A2 (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: