Wednesday, 20 January 2021

Java10: Application class-data sharing

Class Data Sharing (CDS) is a feature that allow multiple JVM processes to share common class metadata. This feature is introduced in Java1.5 allows a set of classes to be pre-processed into a shared archive file that can then be memory-mapped at runtime to reduce startup time.

 

Prior to Java9, CDS looks like below.

 

 


Advantages Of Class Data Sharing

a.   Reduce footprint by sharing common class metadata across multiple Java processes

b.   Startup time is increased

 

Problem in current Approach (Prior to Java9)

when CDS stores classes into the Shared archive, the CONSTANT_String items in the constant pools are represented by UTF-8 strings. When the class is loaded, the UTF-8 strings are converted into java.lang.String objects on demand. This potentially wastes memory, since each character in each interned string takes up three bytes or more (two bytes in the String, 1-3 bytes in the UTF-8). Also, because the strings are created dynamically, they cannot easily be shared across JVM processes.

 

Solution in Java9

Dedicated string space is allocated within Java heap during heap initialization. The string table is compressed and then stored in the archive at dump time.

 

Is Shared-String table and regular string table are same?

No, the shared-string table is distinct from the regular string table at runtime.

 

Is both the tables are searched in interning process?

Yes, both tables are searched when looking up interned strings. The shared-string table is a read-only table at run time. no entries can be added or removed from it.

 

Application Class-Data sharing in Java10

Java10 extended the existing Class-Data Sharing ("CDS") feature to allow application classes to be placed in the shared archive.

 

How to enable Application CDS?

By default, Class-Data Sharing is enabled only for the JVM's bootstrap class loader. Specify the -XX:+UseAppCDS command-line option to enable class data sharing for the system class loader, the platform class loader, and other user-defined class loaders.

 

Reference

https://openjdk.java.net/jeps/310


Previous                                                    Next                                                    Home

No comments:

Post a Comment