RFR: 8261743: Shenandoah: enable String deduplication with compact heuristics

Rui Li duke at openjdk.org
Thu Nov 6 20:46:13 UTC 2025


On Thu, 6 Nov 2025 09:36:06 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

> Looks good. Have you measured any impact on pauses / GC durations in testing?

Yeah. Had a simple benchmark below (credit to [here](https://muratakkan.medium.com/understanding-string-deduplication-in-java-how-it-works-and-when-to-use-it-fbda71711435)):



    @Benchmark
    public void testMethod(Blackhole bh) {
        // This is a demo/sample template for building your JMH benchmarks. Edit as needed.
        // Put your benchmark code here.
        String[] strings = new String[1000000];
        for (int i = 0; i < strings.length; i++) {
            strings[i] = "This is a test string";
        }
        bh.consume(strings);
    }


Results:

########
java  -jar target/benchmarks.jar --jvmArgs "-XX:-UseStringDeduplication -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:ShenandoahGCHeuristics=compact" -prof gc 
########
Benchmark                                   Mode  Cnt        Score     Error   Units
MyBenchmark.testMethod                     thrpt    3     3181.651 ± 248.835   ops/s
MyBenchmark.testMethod:gc.alloc.rate       thrpt    3    12136.888 ± 949.185  MB/sec
MyBenchmark.testMethod:gc.alloc.rate.norm  thrpt    3  4000016.188 ±   0.016    B/op
MyBenchmark.testMethod:gc.count            thrpt    3     1568.000            counts
MyBenchmark.testMethod:gc.time             thrpt    3     1882.000                ms

########
java  -jar target/benchmarks.jar --jvmArgs "-XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:ShenandoahGCHeuristics=compact" -prof gc 
########
Benchmark                                   Mode  Cnt        Score      Error   Units
MyBenchmark.testMethod                     thrpt    3     3155.961 ±  365.174   ops/s     # throuput decreased by 0.8% 
MyBenchmark.testMethod:gc.alloc.rate       thrpt    3    12038.882 ± 1394.186  MB/sec     # decreased by 0.8%
MyBenchmark.testMethod:gc.alloc.rate.norm  thrpt    3  4000016.190 ±    0.022    B/op     # same
MyBenchmark.testMethod:gc.count            thrpt    3     1172.000             counts     # decreased by 25%
MyBenchmark.testMethod:gc.time             thrpt    3      726.000                 ms     # decreased by 38.6%



The alloc rate / throughput didn't change much, but the gc count and gc time reduced by 25% and 38.6%. Not that familiar with string deduplication, but according to https://openjdk.org/jeps/192, the results seem to match the implementation - does not dedup at allocation time, but dedup the string internal char array at gc time and gc would be more efficient.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/28170#issuecomment-3499316594


More information about the hotspot-gc-dev mailing list