Thursday 28 January 2021

Java9: Storing interned strings in CDS archives

 

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.

 

Reference

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


Previous                                                    Next                                                    Home

No comments:

Post a Comment