< prev index next >
test/gc/shenandoah/TestStringDedup.java
Print this page
rev 10789 : [backport] Drop Shenandoah from test names
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2017, 2018 Red Hat, Inc. and/or its affiliates.
+ * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
@@ -20,36 +20,38 @@
* questions.
*
*/
/*
- * @test TestShenandoahStringDedup.java
+ * @test TestStringDedup
* @summary Test Shenandoah string deduplication implementation
* @key gc
*
- * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+UseStringDeduplication -Xmx256M TestShenandoahStrDedup
- * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+UseStringDeduplication -Xmx256M TestShenandoahStrDedup
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahDegeneratedGC -XX:+UseStringDeduplication -Xmx256M TestStringDedup
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=passive -XX:-ShenandoahDegeneratedGC -XX:+UseStringDeduplication -Xmx256M TestStringDedup
*
- * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseStringDeduplication -Xmx256M TestShenandoahStrDedup
- * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=aggressive -XX:+UseStringDeduplication -Xmx256M TestShenandoahStrDedup
- * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:ShenandoahGCHeuristics=compact -XX:+UseStringDeduplication -Xmx256M TestShenandoahStrDedup
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+UseStringDeduplication -Xmx256M TestStringDedup
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive -XX:+UseStringDeduplication -Xmx256M TestStringDedup
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact -XX:+UseStringDeduplication -Xmx256M TestStringDedup
*/
import java.lang.reflect.*;
import java.util.*;
+
import sun.misc.*;
-public class TestShenandoahStrDedup {
+public class TestStringDedup {
private static Field valueField;
private static Unsafe unsafe;
private static final int UniqueStrings = 20;
+
static {
try {
Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
- unsafe = (Unsafe)field.get(null);
+ unsafe = (Unsafe) field.get(null);
valueField = String.class.getDeclaredField("value");
valueField.setAccessible(true);
} catch (Exception e) {
throw new RuntimeException(e);
@@ -65,25 +67,31 @@
}
static class StringAndId {
private String str;
private int id;
+
public StringAndId(String str, int id) {
this.str = str;
this.id = id;
}
- public String str() { return str; }
- public int id() { return id; }
+ public String str() {
+ return str;
+ }
+
+ public int id() {
+ return id;
+ }
}
private static void generateStrings(ArrayList<StringAndId> strs, int unique_strs) {
Random rn = new Random();
- for (int u = 0; u < unique_strs; u ++) {
+ for (int u = 0; u < unique_strs; u++) {
int n = rn.nextInt() % 10;
n = Math.max(n, 2);
- for (int index = 0; index < n; index ++) {
+ for (int index = 0; index < n; index++) {
strs.add(new StringAndId("Unique String " + u, u));
}
}
}
@@ -91,22 +99,22 @@
HashMap<Object, StringAndId> seen = new HashMap<>();
int total = 0;
int dedup = 0;
for (StringAndId item : strs) {
- total ++;
+ total++;
StringAndId existing_item = seen.get(getValue(item.str()));
if (existing_item == null) {
seen.put(getValue(item.str()), item);
} else {
if (item.id() != existing_item.id() ||
!item.str().equals(existing_item.str())) {
System.out.println("StringDedup error:");
System.out.println("String: " + item.str() + " != " + existing_item.str());
throw new RuntimeException("StringDedup Test failed");
} else {
- dedup ++;
+ dedup++;
}
}
}
System.out.println("Dedup: " + dedup + "/" + total + " unique: " + (total - dedup));
return (total - dedup);
< prev index next >