Keywords: Java 11 | Debugging Warning | Class Data Sharing | IntelliJ IDEA | Bootstrap Class Loader
Abstract: This article provides a comprehensive analysis of the "Sharing is only supported for boot loader classes because bootstrap classpath has been appended" warning encountered during Java 11 debugging sessions. It explores the underlying mechanisms of class data sharing, the distinction between bootstrap and system class loaders, and the impact of IntelliJ IDEA's async stack tracing settings. The paper presents step-by-step instructions for disabling the Instrumenting agent and discusses alternative approaches including complete class data sharing disablement, along with their performance implications.
Problem Background and Phenomenon Analysis
After upgrading to Java 11, many developers encounter a specific warning message during application debugging: OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended. This warning typically appears when using integrated development environments like IntelliJ IDEA for debugging, indicating limitations in the class data sharing mechanism.
Class Data Sharing Mechanism Explained
Class data sharing is a JVM optimization technique designed to reduce application startup times. The JVM preloads commonly used JDK classes into a shared archive file, allowing direct reuse of these loaded class data during subsequent launches. According to the Java class loader architecture, the bootstrap class loader is responsible for loading core Java class libraries, while the system class loader handles application classes.
When IntelliJ IDEA performs debugging operations, it appends additional class paths to the JVM's bootstrap classpath. This action causes classes that were originally loaded by the system class loader to potentially be loaded through the bootstrap class loader instead, thereby compromising the integrity of the class data sharing archive. Upon detecting this inconsistency, the JVM partially disables the class data sharing functionality, maintaining support only for classes loaded by the bootstrap class loader, which generates the observed warning message.
Solution: Disabling Instrumenting Agent
Based on practical verification, the most effective solution involves disabling the Instrumenting agent functionality in IntelliJ IDEA. The specific operational steps are as follows:
- Open the IntelliJ IDEA settings interface
- Enter "async" in the search box to perform a search
- Locate the "Instrumenting agent" related options
- Deselect the corresponding checkbox
- Apply the settings and restart the debugging session
The core principle of this solution is that the Instrumenting agent modifies class bytecode during debugging to support features like async stack tracing, and these modifications trigger the bootstrap classpath append operation. By disabling this functionality, the JVM no longer needs to modify the bootstrap classpath, thereby avoiding partial disablement of the class data sharing mechanism.
Alternative Approaches and Performance Considerations
In addition to the primary solution mentioned above, developers may consider completely disabling the class data sharing functionality. By adding the -Xshare:off option to JVM startup parameters, the class data sharing mechanism can be entirely disabled:
java -Xshare:off -jar your-application.jar
However, this approach requires careful consideration since completely disabling class data sharing may significantly increase application startup times. In scenarios requiring rapid iterative development, increased startup time could impact development efficiency.
Impact Assessment and Best Practices
From a functional perspective, this warning typically does not affect normal application operation or debugging capabilities. It is primarily an informational warning indicating that certain performance optimization features have been partially disabled. In most development scenarios, developers can safely ignore this warning, particularly when it doesn't impact debugging functionality.
However, for development environments pursuing optimal performance, the solution of disabling the Instrumenting agent is recommended. This approach both eliminates the warning message and maintains the optimization effects of the class data sharing mechanism for classes loaded by the bootstrap class loader, achieving a good balance between warning elimination and performance preservation.
Technical Implementation Details
From a technical implementation perspective, an in-depth analysis reveals that the class data sharing mechanism's operation involves JVM internal memory management and class loading optimization. When the bootstrap classpath is modified, the JVM needs to revalidate the integrity of classes in the shared archive, a process that involves complex class dependency analysis and memory mapping adjustments.
At the code level, developers can check the current class data sharing status using the following approach:
public class CDSCheck {
public static void main(String[] args) {
String vmName = System.getProperty("java.vm.name");
String shareMode = System.getProperty("java.vm.options");
System.out.println("VM: " + vmName);
System.out.println("Share mode: " + shareMode);
}
}
This simple diagnostic code can help developers understand the current JVM's class data sharing configuration status, providing additional information for problem troubleshooting.