JDK-8079408 : Improve class loading log (with unified logging)
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-05-05
  • Updated: 2024-11-06
  • Resolved: 2016-02-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b107Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Today the TraceClassLoading logging option is used to print out information related to class loading:

A typical log contains lines of the form:

[Loaded <classname> from <code_source>]

For example: with jdk9 as of 2015/05/05

$ java -cp /tmp -XX:+TraceClassLoading Foo
[Loaded java.lang.Object from java/lang/Object.class]
[Loaded java.io.Serializable from java/io/Serializable.class]
...
[Loaded Foo from file:/tmp/]

However, there are a few issues with the current implementation
[1] The logs are intermixed with the program's standard output,
    so it's hard to extract and process.
[2] Some logs are not atomic, so it could be corrupted by the output
    of other Java threads
[3] No information related to the class hierarchy and class loader

Planned optimizations of CDS require a more detailed and reliable logging
mechanism so that we can capture all the necessary information related
to class loading. This would make it possible to

[1] Store all classes loaded by a process into a CDS archive
[2] Analyze class loading performance using off-line tools.


=========== proposed fix ======================
The proposal is to implement the "classload" and "classloaderdata" tags for Unified Logging (JDK-8059747), and print out detailed information about the class hierarchy, code source location, and classfile data.

(a) -Xlog:classloaderdata=<level>

This logging tag replaces the old TraceClassLoaderData flag.

Also, when a ClassLoaderData is created, the log is augmented to print out the toString() value of the loader. This allows the user of the log to identify the class loader instance.

(b) -Xlog:classload=<level>

Note that as of this RFE, we are not changing the existing TraceClassLoading flag. Many external tools depend on this flag. If we want to replace TraceClassLoading with -Xlog:classload=<level>, that needs to be done in a different RFE.

    -Xlog:classload=<level>

Two levels are supported: debug and trace.

In "debug" level, the output is the same as with the old TraceClassLoading flag.

In "trace" level, each line in the log will correspond to a newly loaded class, of the following format

CLASSNAME klass: PTR super: PTR <interfaces: INTF_LIST> source: CODE_SOURCE by CLASS_LOADER bytes: CFSIZE checksum: CFCRC

    CLASSNAME is the dot-separated fully qualified class name

    PTR is in the form of a hex number: 0x[0-9a-f]+

    INTF_LIST is one or more PTRs, separated by a single space character

    CODE_SOURCE is the same output as before

    CLASS_LOADER has the one of the 2 forms:
        [NULL class_loader]
        [class loader PTR 'CLASS_LOADER_TYPE']

    CFNUM is a decimal integer

    CFCRC is in the form of a hex number: 0x[0-9a-f]+

Meaning of the log:

klass: PTR
PTR is the unique identifier for this class.

super: PTR
PTR is the unique identifier for the super class of the current class.

interfaces: INTF_LIST
This portion is optional. It's printed only if the current class has directly
implemented any interfaces. INTF_LIST is one of more unique identifiers
for the interfaces directly implemented by the current class.

CLASS_LOADER:
The PTR is the unique identifier for the instance of the defining class loader of the current class.

CFSIZE
The length of the classfile data (in number of bytes) that defined this class.

CFCRC
The 32-bit CFC of classfile data that defined this class.

===================================
See attachment for a sample log file:

java -cp ~/tmp -Xlog:classloaderdata=debug,classload=trace Foo > ~/sample_log.txt
Comments
URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/48719c6d683e User: lana Date: 2016-02-24 20:06:43 +0000
24-02-2016

URL: http://hg.openjdk.java.net/jdk9/jdk9/hotspot/rev/3637ec3e50c2 User: lana Date: 2016-02-24 20:06:28 +0000
24-02-2016

URL: http://hg.openjdk.java.net/jdk9/hs-rt/hotspot/rev/3637ec3e50c2 User: mockner Date: 2016-02-03 18:47:18 +0000
03-02-2016

URL: http://hg.openjdk.java.net/jdk9/hs-rt/jdk/rev/48719c6d683e User: mockner Date: 2016-02-03 18:47:16 +0000
03-02-2016

Attached sample log file.
10-11-2015

RFR http://cr.openjdk.java.net/~iklam/8079408-improve-class-load-log/
09-11-2015

It would be useful to add the module information in the class loading log as well. Depending on the progress of the Jigsaw project, such feature may be implemented in a separate RFE.
12-06-2015

Here's an extract from an example log: [Loaded klass: 0x00000007c0000fa8 super: 0x0000000000000000 java.lang.Object from java/lang/Object.class by NULL class_loader] [Loaded klass: 0x00000007c00011a8 super: 0x00000007c0000fa8 java.io.Serializable from java/io/Serializable.class by NULL class_loader] [Loaded klass: 0x00000007c00013a0 super: 0x00000007c0000fa8 java.lang.Comparable from java/lang/Comparable.class by NULL class_loader] [Loaded klass: 0x00000007c0001598 super: 0x00000007c0000fa8 java.lang.CharSequence from java/lang/CharSequence.class by NULL class_loader] [Loaded klass: 0x00000007c0001790 super: 0x00000007c0000fa8 interfaces: 0x00000007c00011a8 0x00000007c00013a0 0x00000007c0001598 java.lang.String from java/lang/String.class by NULL class_loader] ... [Loaded klass: 0x00000007c0060028 super: 0x00000007c0000fa8 Foo from file:/jdk/tmp/ by class loader 0x00007f84ac107bf0a 'sun/misc/Launcher$AppClassLoader']
12-06-2015