Skip to content

Commit

Permalink
Add warning for string deduplication with genertional zgc.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgm3746 committed Jan 9, 2025
1 parent d752bc4 commit d006879
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/github/joa/JvmOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4665,9 +4665,12 @@ public void doAnalysis() {
addAnalysis(Analysis.INFO_JFR_FLIGHT_RECORDER_DISABLED);
}
// String deduplication
if (jvmContext.getGarbageCollectors().contains(GarbageCollector.G1) || useG1Gc != null) {
if (jvmContext.getGarbageCollectors().contains(GarbageCollector.G1) || useG1Gc != null
|| jvmContext.getVersionMajor() > 18) {
if (JdkUtil.isOptionDisabled(useStringDeduplication)) {
addAnalysis(Analysis.INFO_USE_STRING_DEDUPLICATION_REDUNDANT);
} else if (jvmContext.getGarbageCollectors().contains(GarbageCollector.ZGC_GENERATIONAL)) {
addAnalysis(Analysis.WARN_USE_STRING_DEDUPLICATION_Z_GENERATIONAL);
}
} else if (JdkUtil.isOptionEnabled(useStringDeduplication)) {
addAnalysis(Analysis.INFO_USE_STRING_DEDUPLICATION_UNSUPPORTED);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/github/joa/domain/JvmContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class JvmContext {
private boolean container = false;

/**
* Identified garbage collectors (not just expected). It should agree with the JVM options unless options are
* overriden or ignored for some reason (e.g. nonsense values).
* Identified garbage collectors (not just expected). It should agree with the expected garbage collector(s)
* determined from JVM options unless options are overriden or ignored for some reason (e.g. nonsense values).
*/
List<GarbageCollector> garbageCollectors = new ArrayList<>();

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/github/joa/util/Analysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,11 @@ public enum Analysis {
*/
WARN_USE_MEMBAR("warn.use.membar"),

/**
* Property key for -XX:+ZGenerational -XX:+UseStringDeduplication.
*/
WARN_USE_STRING_DEDUPLICATION_Z_GENERATIONAL("warn.use.string.deduplication.z.generational"),

/**
* Property key for disabling the Java Thread API with -XX:-UseThreadPriorities.
*/
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/org/github/joa/analysis.properties
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ warn.thread.stack.size.small=Thread stack size is less than 128K.
warn.thread.stack.size.tiny=Thread stack size is less than 1K. Were units (e.g. 'K') left off by mistake?
warn.use.cond.card.mark=Conditional dirty card marking enabled with -XX:+UseCondCardMark. This is not a standard recommended option and can negatively impact performance (e.g. on single cpu/cores). Unless testing has shown this improves performance, consider removing this option.
warn.use.membar=The -XX:+UseMembar option is used. This was a workaround for a bug in old versions of JDK 1.6 (see https://bugs.openjdk.org/browse/JDK-6822370) and is not necessary with modern JVMs. If there is not a good use case for using this option, remove it, as it causes the JVM to use a memory barrier that slows down the JVM.
warn.use.string.deduplication.z.generational=Generational ZGC is affected by the following bug when string deduplication is enabled: https://bugs.openjdk.org/browse/JDK-8347337. Otherwise short-lived strings are kept artificially alive and promoted to the old generation, filling up the old generation and causing long old generation collections.
warn.use.thread.priorities.disabled=The Java Thread API is disabled with -XX:+UseThreadPriorities.
warn.verify.none=Class verification during loading is disabled with -Xverify:none. This is unsupported and can result in corrupt or invalid classes being loaded, causing undetermined JVM behavior and crashes.
warn.zgc.heap.32g.lt=ZGC and heap < 32G. ZGC is generally for larger heaps (e.g. it does not support compressed object references).
32 changes: 22 additions & 10 deletions src/test/java/org/github/joa/util/TestAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,20 @@ void testUseStringCache() {
}

@Test
void testUseStringDeduplicationDisabledCMS() {
void testUseStringDeduplicationDisabledG1() {
String opts = "-Xss128k -XX:-UseStringDeduplication -Xmx2048M";
JvmContext context = new JvmContext(opts);
JvmOptions jvmOptions = new JvmOptions(context);
context.getGarbageCollectors().add(GarbageCollector.G1);
jvmOptions.doAnalysis();
assertTrue(jvmOptions.hasAnalysis(Analysis.INFO_USE_STRING_DEDUPLICATION_REDUNDANT.getKey()),
Analysis.INFO_USE_STRING_DEDUPLICATION_REDUNDANT + " analysis not identified.");
assertNull(jvmOptions.getUnaccountedDisabledOptions(),
"-XX:-UseStringDeduplication incorrectly identified as an unaccounted disabled option.");
}

@Test
void testUseStringDeduplicationEnabledCMS() {
String opts = "-Xss128k -XX:+UseStringDeduplication -Xmx2048M";
JvmContext context = new JvmContext(opts);
JvmOptions jvmOptions = new JvmOptions(context);
Expand All @@ -2932,7 +2945,7 @@ void testUseStringDeduplicationDisabledCMS() {
}

@Test
void testUseStringDeduplicationDisabledDefaultCollectorJdk11() {
void testUseStringDeduplicationEnabledDefaultCollectorJdk11() {
String opts = "-Xss128k -XX:+UseStringDeduplication -Xmx2048M";
JvmContext context = new JvmContext(opts);
JvmOptions jvmOptions = new JvmOptions(context);
Expand All @@ -2943,7 +2956,7 @@ void testUseStringDeduplicationDisabledDefaultCollectorJdk11() {
}

@Test
void testUseStringDeduplicationDisabledDefaultCollectorJdk8() {
void testUseStringDeduplicationEnabledDefaultCollectorJdk8() {
String opts = "-Xss128k -XX:+UseStringDeduplication -Xmx2048M";
JvmContext context = new JvmContext(opts);
JvmOptions jvmOptions = new JvmOptions(context);
Expand All @@ -2954,16 +2967,15 @@ void testUseStringDeduplicationDisabledDefaultCollectorJdk8() {
}

@Test
void testUseStringDeduplicationDisabledG1() {
String opts = "-Xss128k -XX:-UseStringDeduplication -Xmx2048M";
void testUseStringDeduplicationEnabledZgcGenerational() {
String opts = "-XX:+UseStringDeduplication -Xmx32g";
JvmContext context = new JvmContext(opts);
JvmOptions jvmOptions = new JvmOptions(context);
context.getGarbageCollectors().add(GarbageCollector.G1);
context.setVersionMajor(21);
context.getGarbageCollectors().add(GarbageCollector.ZGC_GENERATIONAL);
jvmOptions.doAnalysis();
assertTrue(jvmOptions.hasAnalysis(Analysis.INFO_USE_STRING_DEDUPLICATION_REDUNDANT.getKey()),
Analysis.INFO_USE_STRING_DEDUPLICATION_REDUNDANT + " analysis not identified.");
assertNull(jvmOptions.getUnaccountedDisabledOptions(),
"-XX:-UseStringDeduplication incorrectly identified as an unaccounted disabled option.");
assertTrue(jvmOptions.hasAnalysis(Analysis.WARN_USE_STRING_DEDUPLICATION_Z_GENERATIONAL.getKey()),
Analysis.WARN_USE_STRING_DEDUPLICATION_Z_GENERATIONAL + " analysis not identified.");
}

@Test
Expand Down

0 comments on commit d006879

Please sign in to comment.