Skip to content

Introduction to class data sharing

Sharing class data between Eclipse OpenJ9™ VMs improves start up performance and reduces memory footprint. Consider the following outcomes for two VMs that are running similar Java applications but sharing class data:

  • Start up performance is improved by placing classes that each application needs when initializing into a shared classes cache. The next time the application runs, it takes less time to start because the classes are already available.

  • Memory footprint is reduced by sharing common classes between the applications.

When class data sharing is enabled, OpenJ9 automatically creates shared memory that stores and shares the classes in memory between processes. This shared classes cache is updated dynamically; when an application loads new classes, the VM automatically stores them in the cache without any user intervention. By default, class data sharing is enabled for bootstrap classes, as described in Enabling class data sharing.

When class data sharing is enabled, Ahead-of-time (AOT) compilation is also enabled by default, which dynamically compiles certain methods into AOT code at runtime. By using these features in combination, startup performance is further improved because the cached AOT code can be used to quickly enable native code performance for subsequent runs of your application. For more information about AOT, see AOT Compiler. Further performance improvements are gained by storing JIT data and profiles in the shared classes cache.

The contents of a shared classes cache can include the following artifacts:

  • Bootstrap classes
  • Application classes
  • Metadata that describes the classes
  • AOT-compiled code
  • JIT data
  • GC hints (for initial Java heap size)
  • Start of content that applies only to Java 8 (LTS) Bootstrap jar file indexes

Cache utilities

Active caches can be managed by a set of cache utilities, which are invoked by specifying -Xshareclasses suboptions. These utilities control the following types of operations:

  • Displaying information about the caches on a system.
  • Adjusting the size of a cache and the amount of space that is reserved for AOT code or JIT data.
  • Creating a snapshot of a non-persistent cache to save to disk and restoring the cache from disk.
  • Troubleshooting cache problems.
  • Removing unwanted caches on a system.

These cache utilities are discussed in more detail in the sections that follow.

Enabling class data sharing

Class data sharing is enabled by default for bootstrap classes, unless your application is running in a container. Default behavior includes the following characteristics:

  • On Windows®, the cache is created in the user's C:\Users\<username>\AppData\Local\javasharedresources directory. On z/OS®, the default cache directory is /tmp/javasharedresources. On other systems, the cache is created in the .cache/javasharedresources directory in the user's home directory, unless the groupAccess parameter is specified, in which case it is created in /tmp/javasharedresources. Do not set the home directory on an NFS mount or shared mount across systems or LPARs.
  • The cache name is sharedcc_%u, where