How to avoid Sharing is only supported for boot loader classes because bootstrap classpath has been appended warning during debug with Java 11?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Java 11 developers often face the common warning:
when debugging applications. This warning appears due to class data sharing (CDS) intricacies, the modification of the bootstrap classpath, and its association with the Java class loader. In this article, we explore how to avoid this specific warning, providing a deeper understanding of CDS and related configurations.
Understanding Class Data Sharing (CDS) in Java
Class Data Sharing (CDS) aims to improve startup time and memory footprint by enabling the sharing of class metadata across different Java processes. Introduced in Java 5, this feature allows many identical classes to be shared among Java Virtual Machines (JVMs), thereby enhancing performance on servers and reducing memory consumption.
How CDS Works
- Class Preloading: Classes are loaded once into a shared archive.
- Shared Archive: Classes are stored within a shared archive file, available for subsequent JVMs.
- Bootstrap Class Path: CDS primarily involves classes on the bootstrap classpath, which includes essential Java libraries.
However, when developers append or modify the bootstrap classpath for debugging or other purposes, an incompatibility with the CDS manifests through the warning in question.
Why Does This Warning Appear?
The warning message indicates that CDS can only support classes in the original bootstrap classpath. If you append additional libraries to this path, it causes the CDS mechanism to disable class sharing:
- Modification of Bootstrap Classpath: Debugging configurations often alter boot classpaths, introducing new paths or libraries not initially within the scope of the CDS.
- Class Loader Constraints: CDS has specific constraints on which class loaders it supports primarily due to the original classpath structure.
Avoiding the Warning
To mitigate this warning, we can take several approaches:
1. Separate Debugging Environment
Create a separate environment for debugging without altering the bootstrap classpath:
2. Use JDB or Other Debuggers That Accept Default Boot Classpath
Utilize debuggers that do not require modifications to the bootstrap classpath. Java's command-line debugger, JDB, allows remote debugging without altering default paths:
3. Bypass CDS When Debugging
Disable CDS during debugging sessions, allowing non-shared classes to load. This does sacrifice the CDS benefits temporarily:
This command will prevent the JVM from issuing that particular CDS warning during the debugging session.
4. Refigure Necessary CDS Classes
If alterations are essential, configure CDS classes appropriately so that the necessary libraries are considered in the shared set.
Implications and Considerations
- Performance Trade-offs: Disabling CDS may increase memory usage and startup time during debugging.
- Compatibility: For highly optimized environments, consistently appending libraries may necessitate re-evaluation of class sharing benefits on boot performance.
Summary Table
| Approach | Description | Pros | Cons |
| Separate Debugging Environment | Use classpaths without boot modifications | Avoids warning, retains some CDS benefits | Requires separate configuration management |
| Use JDB or Other Accepting Debuggers | Utilize debuggers with default boot classpath | No need to change CDS configuration | May lack advanced IDE-specific debug features |
| Bypass CDS When Debugging | Disable CDS temporarily with -Xshare:off | Simple implementation, quick testing option | Loses startup/memory optimizations temporarily |
| Refigure Necessary CDS Classes | Reconfigure how classes are included in CDS | Ensures nearly full CDS benefit retention | Complex setup, potential repeated reconfiguration |
Conclusion
Avoiding the "Sharing is only supported for boot loader classes" warning during Java 11 debugging can enhance your development experience while ensuring that your application's performance is not compromised. By understanding the underlying causes and carefully applying suggested strategies, you can maintain an efficient debugging process while leveraging the power of Java's Class Data Sharing feature.

