Usage:
You can set the age of a string to be considered for deduplication with:
-XX:StringDeduplicationAgeThreshold=value , where value is the desired age.
Since:
Starting from JDK 8.
Examples:
This will instruct JVM to consider the age of 1 for string deduplication:
-XX:StringDeduplicationAgeThreshold=1
Description:
Most java applications memory contains a percentage of duplicate strings. A duplicate string, is a string that has the same content as another string but stored in a different object. For example:
String value = new String(“value”);
String sameValue = new String(“value”);
As we can see, the variables value and sameValue are using the same text, which is “value” but when we want to check if value equals to sameValue (value == sameValue) it will returns false even the content is the same. This means that the two variables are not stored in the same memory location. To eliminate these duplications, Java introduced the parameter “StringDeduplicationAgeThreshold” which will allow the JVM to eliminate duplicate strings using the Garbage Collector (GC). String objects reaching the specified age that are considered candidates for deduplication. An object's age is a measure of how many times it has survived garbage collection. This is sometimes referred to as tenuring.
Default Value:
Default is 3.
Errors:
The value should be between 1 et 16 (Based on the code markOop.hpp and Mark.java).
Arguments related:
PrintTenuringDistribution, UseStringDeduplication
Related Posts:
NOTE:
String objects that are promoted to an old heap region before this age has been reached are always considered candidates for deduplication. The default value for this option is 3. See the -XX:+UseStringDeduplication option.

Edit your Comment