Skip to content

-XX:[+|-]CompactStrings

This HotSpot option is reimplemented by Eclipse OpenJ9™ and when enabled causes an ISO8859-1 (also known as Latin-1) character representation to be used internally for String objects, while preserving full API compatibility.

This feature provides heap space savings by using an 8-bit character set internally. Most benefit is gained when the majority of the String objects that your application uses can be encoded using the ISO8859-1 character encoding.

If the option is not enabled, the JIT compiler is nevertheless optimized so that although there is no saving in heap space, there is also no performance penalty.

Further details are available at JEP 254: Compact Strings.

Note: With OpenJ9, this option is supported on OpenJDK version 8 and later versions, whereas HotSpot supports it only from Java version 9.

Syntax

Setting Effect Default
-XX:+CompactStrings Enable String compression Start of content that applies only to Java 11+ (LTS) yes End of content that applies only to Java 11 and later
-XX:-CompactStrings Disable String compression Start of content that applies only to Java 8 yes End of content that applies only to Java 8