JDK-8241722 : PrintClassHistogram operation should be cancelled during GC locked
  • Type: Bug
  • Component: hotspot
  • Sub-Component: gc
  • Affected Version: 14
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: x86
  • Submitted: 2020-01-30
  • Updated: 2020-04-08
  • Resolved: 2020-04-08
Related Reports
Duplicate :  
Relates :  
Description
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
Comments
Closing as duplicate of JDK-6944195. Documentation of the Jmap command at https://docs.oracle.com/en/java/javase/11/tools/jmap.html#GUID-D2340719-82BA-4077-B0F3-2803269B7F41 mentions that "This command is unsupported and might not be available in future releases of the JDK" i.e. unsupported. The output of the command clearly states that the GC has been skipped and so you will get a potentially confusing result.
08-04-2020