OpenJ9 class sharing is enabled by default

Class sharing is a feature in Eclipse OpenJ9 that improves your application’s startup performance. It also reduces the memory footprint if the same cache shared across multiple JVMs. Traditionally, this feature is turned on by explicitly specifying option -Xshareclasses in the command line.

Default Class Sharing

Class data sharing is enabled by default for bootstrap classes from release 0.16.0 of OpenJ9 onwards (unless you are running in a container). When the JVM starts up, it will attempt to create or connect to a default shared cache. If an error occurred during the start-up process of the default shared classes cache, the JVM treats the error as non-fatal, silently ignoring it and goes back to normal start-up process without using the default shared classes cache.

We introduced a new sub-option bootClassesOnly. If the default shared cache failed to start up, user can use option -Xshareclasses:bootClassesOnly,fatal,verbose in the command line to show information regarding the start-up error. The default class sharing is equivalent to specifying -Xshareclasses:bootClassesOnly,nonfatal,silent in the command line.

Command line utilities on default shared cache

You can use all -Xshareclasses command line utilities on the default shared cache as usual. For example, you can use -Xshareclasses:listAllCaches to find the default shared cache.

java -Xshareclasses:listAllCaches

Listing all caches in cacheDir /root/javasharedresources/

Cache name              level         cache-type      feature         layer       OS shmid       OS semid       last detach time

Compatible shared caches
sharedcc_root           Java11 64-bit  persistent      cr              0                                         Wed Oct  9 11:47:34 2019

Use -Xshareclasses:printStats to show the cache statistics.

java -Xshareclasses:printStats

Current statistics for cache "sharedcc_root":

Cache created with:
-Xnolinenumbers                      = false
BCI Enabled                          = true
Restrict Classpaths                  = false
Feature                              = cr

Cache contains only classes with line numbers

base address                         = 0x00007F1975459000
end address                          = 0x00007F1988000000
allocation pointer                   = 0x00007F197563DC68
cache layer                          = 0
cache size                           = 314572192
softmx bytes                         = 67108864
free bytes                           = 64208696
Reserved space for AOT bytes         = -1
Maximum space for AOT bytes          = -1
Reserved space for JIT data bytes    = -1
Maximum space for JIT data bytes     = -1
Metadata bytes                       = 29104
Metadata % used                      = 1%
Class debug area size                = 25133056
Class debug area used bytes          = 477352
Class debug area % used              = 1%

ROMClass bytes                       = 1985640
AOT bytes                            = 42624
JIT data bytes                       = 904
Zip cache bytes                      = 0
Startup hint bytes                   = 0
Data bytes                           = 363936

# ROMClasses                         = 610
# AOT Methods                        = 24
# Classpaths                         = 1
# URLs                               = 0
# Tokens                             = 0
# Zip caches                         = 0
# Startup hints                      = 0
# Stale classes                      = 0
% Stale classes                      = 0%

Cache is 4% soft full

Cache is accessible to current user = true

If the default shared cache is obsolete, you can use -Xshareclasses:destroy to delete it.

java -Xshareclasses:destroy

JVMSHRC806I Compressed references persistent shared cache "sharedcc_root" has been destroyed. Use option -Xnocompressedrefs if you want to destroy a non-compressed references cache.

The default shared cache is a normal cache under default cache directory (user home) with the default cache name (sharedcc_username). Another JVM explicitly specifying -Xshareclasses option can connect to the default shared cache as usual.

You can use -Xsharedclasses:none in the command line to completely turn off class data sharing, but disabling it hurts your applications startup. Visit here to find out more about class sharing in Eclipse OpenJ9.

Leave a Reply