# HG changeset patch # User iignatyev # Date 1588287145 25200 # Thu Apr 30 15:52:25 2020 -0700 # Node ID 96d41ce72303f81d1ba97d229a5751c1a0aaccb9 # Parent c91f67c6ab3d12afa6bfac403b2866d035fceb6e [mq]: 8243434 # HG changeset patch # User iignatyev # Date 1588287163 25200 # Thu Apr 30 15:52:43 2020 -0700 # Node ID eeae611eb665dd2743aa2c45ef18b549dba6d6be # Parent 96d41ce72303f81d1ba97d229a5751c1a0aaccb9 imported patch randomness-code_vmTestbase_unloading diff --git a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/bytecode/DefaultTemplateClass.java b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/bytecode/DefaultTemplateClass.java --- a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/bytecode/DefaultTemplateClass.java +++ b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/bytecode/DefaultTemplateClass.java @@ -30,7 +30,7 @@ public class DefaultTemplateClass { public static void main() { - System.out.println("In method of generated class. Random.nextDouble = " + new Random().nextDouble()); + System.out.println("In method of generated class. Random.nextDouble = " + new Random(42).nextDouble()); System.out.println(" Printing bytesToReplace0 bytesToReplace2"); } diff --git a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/bytecode/HumongousTemplateClassGen.java b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/bytecode/HumongousTemplateClassGen.java --- a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/bytecode/HumongousTemplateClassGen.java +++ b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/bytecode/HumongousTemplateClassGen.java @@ -29,6 +29,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Random; +import jdk.test.lib.Utils; /* * This class is compiled and invoke due the build to produce @@ -59,6 +61,7 @@ } public static void addIteration(int itNum, List records) { + Random rng = Utils.getRandomInstance(); records.add(" public static Object public_static_object_" + itNum + " = new Object();\n"); records.add(" protected static Object protected_static_object_" + itNum @@ -68,7 +71,7 @@ records.add("\n"); records.add(" public static long public_static_long_" + itNum + ";\n"); records.add(" protected static long protected_static_long_" + itNum - + " = new Random().nextLong();\n"); + + " = " + rng.nextLong() + "L;\n"); records.add(" private static long private_static_long_" + itNum + " = 42;\n"); records.add("\n"); @@ -82,7 +85,7 @@ records.add(" public long public_long_" + itNum + " = 43;\n"); records.add(" protected long protected_long_" + itNum + " = 44;\n"); records.add(" private long private_long_" + itNum - + " = new Random().nextLong();\n"); + + " = " + rng.nextLong() + "L;\n"); } public static void main(String[] args) throws Exception { if (args.length < 1) { diff --git a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/configuration/TestConfiguration.java b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/configuration/TestConfiguration.java --- a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/configuration/TestConfiguration.java +++ b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/configuration/TestConfiguration.java @@ -118,7 +118,7 @@ c.inMemoryCompilation = "true".equals(args[i + 1]); } else if ("-numberOfChecksLimit".equalsIgnoreCase(args[i])) { c.numberOfChecksLimit = Integer.parseInt(args[i + 1]); - } else if (args[i].startsWith("-") && ! "-stressTime".equals(args[i]) && ! args[i].toLowerCase().contains("seed")) { + } else if (args[i].startsWith("-") && ! "-stressTime".equals(args[i])) { System.out.println("\n\nWarning!! Unrecognized option " + args[i] + "\n\n"); } } diff --git a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/keepref/NullClassloaderHolder.java b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/keepref/NullClassloaderHolder.java --- a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/keepref/NullClassloaderHolder.java +++ b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/keepref/NullClassloaderHolder.java @@ -33,6 +33,7 @@ private static final int NUMBER_OF_CLASSES = 1000; private static Set> classesPool = Collections.synchronizedSet(new HashSet>()); + private final Random random; static { for (int i = 1; i <= NUMBER_OF_CLASSES; i++) { @@ -49,6 +50,10 @@ } } + public NullClassloaderHolder(long seed) { + random = new Random(seed); + } + @Override public Object hold(Object object) { if (classesPool.isEmpty()) { @@ -66,14 +71,14 @@ } } - private static Field getRandomField(Class clazz) { + private Field getRandomField(Class clazz) { ArrayList fields = new ArrayList<>(); for (Field f : clazz.getFields()) { if (f.getName().startsWith("staticField")) { fields.add(f); } } - return fields.get(new Random().nextInt(fields.size())); + return fields.get(random.nextInt(fields.size())); } } diff --git a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/loading/ClassLoadingHelper.java b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/loading/ClassLoadingHelper.java --- a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/loading/ClassLoadingHelper.java +++ b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/loading/ClassLoadingHelper.java @@ -150,7 +150,7 @@ assertion.keepLink(new UnusedThreadKiller(objectThread.getId())); // UnusedThreadKiller break; case STATIC_FIELD_OF_ROOT_CLASS: - RefHolder holder4 = new NullClassloaderHolder(); + RefHolder holder4 = new NullClassloaderHolder(random.nextLong()); Object keep = holder4.hold(referenceToKeep); if (keep != null) { assertion.keepLink(keep);