< prev index next >

test/hotspot/jtreg/vmTestbase/gc/g1/unloading/keepref/NullClassloaderHolder.java

Print this page
rev 59093 : imported patch randomness-code_vmTestbase_unloading

*** 31,40 **** --- 31,41 ---- */ public class NullClassloaderHolder implements RefHolder { private static final int NUMBER_OF_CLASSES = 1000; private static Set<Class<?>> classesPool = Collections.synchronizedSet(new HashSet<Class<?>>()); + private final Random random; static { for (int i = 1; i <= NUMBER_OF_CLASSES; i++) { String className = "gc.g1.unloading.rootSetHelper.classesPool.Class" + i; try {
*** 47,56 **** --- 48,61 ---- throw new RuntimeException("Test bug", e); } } } + public NullClassloaderHolder(long seed) { + random = new Random(seed); + } + @Override public Object hold(Object object) { if (classesPool.isEmpty()) { return null; } else {
*** 64,79 **** throw new RuntimeException("Test bug", e); } } } ! private static Field getRandomField(Class<?> clazz) { ArrayList<Field> fields = new ArrayList<>(); for (Field f : clazz.getFields()) { if (f.getName().startsWith("staticField")) { fields.add(f); } } ! return fields.get(new Random().nextInt(fields.size())); } } --- 69,84 ---- throw new RuntimeException("Test bug", e); } } } ! private Field getRandomField(Class<?> clazz) { ArrayList<Field> fields = new ArrayList<>(); for (Field f : clazz.getFields()) { if (f.getName().startsWith("staticField")) { fields.add(f); } } ! return fields.get(random.nextInt(fields.size())); } }
< prev index next >