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

PrintClassHistogram operation should be cancelled during GC locked

XMLWordPrintable

    • gc
    • x86
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      - OS
        Generic

      - java -version
      openjdk version "14-ea" 2020-03-17
      OpenJDK Runtime Environment (build 14-ea+19-824)
      OpenJDK 64-Bit Server VM (build 14-ea+19-824, mixed mode, sharing)


      A DESCRIPTION OF THE PROBLEM :
      Currently, when hotspot vm receives Class Histogram output
      request during GC locked, it prints warning message to own stdout
      and continues heap inspection.

      This process may be misleading for user as described in the
      following comment.

        // The following dump may then be a tad misleading to someone expecting
        // only live objects to show up in the dump (see CR 6944195). Just issue
        // a suitable warning in that case and do not attempt to do a collection.

      So it should be cancelled, and should notify to caller process
      such as jmap or jcmd.

      Attached sample is locking GC using GetPrimitiveArrayCritical,
      so can reproduce always.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Build a native library named critical.dll(libcritical.so)
      2. Compile and run test case at background process
      3. Invoke jmap -histo:live <pid> or jcmd <pid> GC.class_stats or jcmd <pid> GC.class_histogram

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Cancelled message is shown on caller process, and class histogram
      is not shown.
      ACTUAL -
      Warning message is shown on target process, but class histogram
      is shown on caller process.

      ---------- BEGIN SOURCE ----------
      critical.c:

      #include <jni.h>

      #ifndef _Included_GetArrayCritical
      #define _Included_GetArrayCritical
      #ifdef __cplusplus
      extern "C" {
      #endif
      /*
       * Class: GetArrayCritical
       * Method: get_critical_array
       * Signature: ()V
       */
      JNIEXPORT void JNICALL Java_GetArrayCritical_get_1critical_1array
        (JNIEnv *env, jclass cls) {
        jarray arr1 = (*env)->NewByteArray(env, 8);
        jbyte* buffer = (*env)->GetPrimitiveArrayCritical(env, arr1, 0);
      }

      #ifdef __cplusplus
      }
      #endif
      #endif

      -----
      GetArrayCritical.java:

      public class GetArrayCritical {
        static {
          System.loadLibrary("critical");
        }

        public static native void get_critical_array();
        public static void main(String[] args) {
          get_critical_array();
          System.out.println("ready");
          while(true);
          
        }
      }

      ---------- END SOURCE ----------

      FREQUENCY : occasionally

        1. critical.c
          0.5 kB
          Praveen Narayanaswamy
        2. GetArrayCritical.java
          0.3 kB
          Praveen Narayanaswamy

            Unassigned Unassigned
            tongwan Andrew Wang
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: