Skip to content

Commit

Permalink
8299075: TestStringDeduplicationInterned.java fails because extra ded…
Browse files Browse the repository at this point in the history
…uplication

Backport-of: 682359cb4871d779425a9468e8a307169b3651d6
  • Loading branch information
GoeLin committed Oct 6, 2023
1 parent c8bc1c2 commit 9dc5ff0
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions test/hotspot/jtreg/gc/stringdedup/TestStringDeduplicationTools.java
Expand Up @@ -333,9 +333,8 @@ public static void main(String[] args) {
// Create duplicate of baseString
StringBuilder sb1 = new StringBuilder(baseString);
String dupString1 = sb1.toString();
if (getValue(dupString1) == getValue(baseString)) {
throw new RuntimeException("Values should not match");
}

checkNotDeduplicated(getValue(dupString1), getValue(baseString));

// Force baseString to be inspected for deduplication
// and be inserted into the deduplication hashtable.
Expand All @@ -348,9 +347,8 @@ public static void main(String[] args) {
// Create a new duplicate of baseString
StringBuilder sb2 = new StringBuilder(baseString);
String dupString2 = sb2.toString();
if (getValue(dupString2) == getValue(baseString)) {
throw new RuntimeException("Values should not match");
}

checkNotDeduplicated(getValue(dupString2), getValue(baseString));

// Intern the new duplicate
Object beforeInternedValue = getValue(dupString2);
Expand All @@ -369,16 +367,13 @@ public static void main(String[] args) {
// Check original value of interned string, to make sure
// deduplication happened on the interned string and not
// on the base string
if (beforeInternedValue == getValue(baseString)) {
throw new RuntimeException("Values should not match");
}
checkNotDeduplicated(beforeInternedValue, getValue(baseString));

// Create duplicate of baseString
StringBuilder sb3 = new StringBuilder(baseString);
String dupString3 = sb3.toString();
if (getValue(dupString3) == getValue(baseString)) {
throw new RuntimeException("Values should not match");
}

checkNotDeduplicated(dupString3, getValue(baseString));

forceDeduplication(ageThreshold, FullGC);

Expand All @@ -395,6 +390,15 @@ public static void main(String[] args) {
System.out.println("End: InternedTest");
}

private static void checkNotDeduplicated(Object value1, Object value2) {
// Note that the following check is invalid since a GC
// can run and actually deduplicate the strings.
//
// if (value1 == value2) {
// throw new RuntimeException("Values should not match");
// }
}

public static OutputAnalyzer run() throws Exception {
return runTest("-Xlog:gc=debug,stringdedup*=debug",
"-XX:+UseStringDeduplication",
Expand Down

1 comment on commit 9dc5ff0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.