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

JVMTI_THREAD_STATE_IN_NATIVE is not set properly

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: vsR10008 Date: 03/09/2004


      JVMTI spec (version 0.3.8) says:

      jvmtiError
      GetThreadState(jvmtiEnv* env,
                  jthread thread,
                  jint* thread_state_ptr)

      Get the state of a thread. The state of the thread is represented by the
      answers to the hierarchical set
      of questions below:

          * Alive?
                o Not alive.
                      + Why not alive?
                            # New.
                            # Terminated (JVMTI_THREAD_STATE_TERMINATED)
                o Alive (JVMTI_THREAD_STATE_ALIVE)
                      + Suspended?
                            # Suspended (JVMTI_THREAD_STATE_SUSPENDED)
                            # Not suspended
                      + Interrupted?
                            # Interrupted (JVMTI_THREAD_STATE_INTERRUPTED)
                            # Not interrupted.
                      + In native?
                            # In native code (JVMTI_THREAD_STATE_IN_NATIVE)
                            # In Java programming language code
                            ...

      JVMTI_THREAD_STATE_IN_NATIVE 0x400000

          Thread is in native code--that is, a native method is running.
          This flag is not set when running VM compiled Java programming
          language code nor is it set when running VM code or
          VM support code.
          ...

      But RI (b41) doesn't set the flag JVMTI_THREAD_STATE_IN_NATIVE
      when native method is running.

      To reproduce the failure please run the following script:

      --- 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) {
          jvmtiError err;
          jint stat;

          err = (*jvmti)->GetThreadState(jvmti, thr, &stat);
          if (err != JVMTI_ERROR_NONE) {
              printf("(GetThreadState) unexpected error: %d\n", err);
      return;
          }
          if ( !(stat & JVMTI_THREAD_STATE_IN_NATIVE)) {
           printf("FAILURE: Thread state bit JVMTI_THREAD_STATE_IN_NATIVE
      is not set\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");
               check(Thread.currentThread());
           }
      }

      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 b41, the execution log is as follows:

      ...creating a.c
      ...creating liba.so
      ...creating a.java
      ...creating a.class
      ...running a.class
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b41)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b41, mixed mode)

      FAILURE: Thread state bit JVMTI_THREAD_STATE_IN_NATIVE is not set

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rfield Robert Field
                Reporter:
                atwosunw A2 A2 (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: