How to get name of jar from which class is loaded at runtime by JVM in Java 11

318 Views Asked by At

I used JAVA_OPTS -Xlog:class+load=debug (inside Tomcat 9 startup.bat), though it is showing the class name but it shows source as source: __JVMDefineClass__. Is there any way I can know the name of Jar, like it showed in JAVA 8?

For e.g

in JAVA 8: [Loaded java.lang.Object from C:\Program Files\Java\jdk1.7.0_04\jre\lib\rt.jar], but,

in JAVA 11: com.fasterxml.jackson.databind.util.ClassUtil$Ctor source: __JVM_DefineClass__

Update: I am using TomeePlus.

1

There are 1 best solutions below

1
dbaltor On

I've run some tests using Spring Boot's embedded Tomcat and the __JVM_DefineClass__ string used as class source has nothing to do with the JVM version. It happened on the logs during my tests due to:

  • inner classes such as the one you mention, or
  • dynamic generated classes, for example jdk.internal.reflect.GeneratedConstructorAccessor1

It seems to me that this is due to the source location URL has not been made available to the ClassLoader. You can read below the snippet of the OpenJDK 11 source code responsible for defining the __JVM_DefineClass__ string.

// common code for JVM_DefineClass() and JVM_DefineClassWithSource()
static jclass jvm_define_class_common(JNIEnv *env, const char *name,
                                  jobject loader, const jbyte *buf,
                                  jsize len, jobject pd, const char *source,
                                  TRAPS) {
  if (source == NULL)  source = "__JVM_DefineClass__";
  ...

OpenJDK / jdk / jdk11