Can cause STW when execute jcmd GC.class_stats?

648 Views Asked by At

I'm gonna execute jcmd $PID GC.class_stats -csv=true command on my tomcat process, to get loaded class status.

I worry about the command effect to tomcat process, like creating heap dump.

Can cause stop the world or the other effect when execute the command?

I can't find about it.

thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, GC.class_stats is a high overhead diagnostic command, and it runs in a global safepoint (STW pause). Among other things, this operation walks through the whole heap to compute memory consumed by all instances of all loaded classes.

Furthermore, the operation causes Full GC. See the source code:

void ClassStatsDCmd::execute(DCmdSource source, TRAPS) {
  VM_GC_HeapInspection heapop(output(),
                              true /* request_full_gc */);
  heapop.set_csv_format(_csv.value());
  heapop.set_print_help(_help.value());
  heapop.set_print_class_stats(true);

  ...

  VMThread::execute(&heapop);  <-- VM_GC_HeapInspection runs in a global safepoint
}

jcmd <pid> help GC.class_stats also warns that the command has high impact on the VM:

GC.class_stats
Provide statistics about Java class meta data.

Impact: High: Depends on Java heap size and content.

By the way, GC.class_stats has been removed in JDK 15.