< prev index next >

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

Print this page
rev 59093 : imported patch randomness-code_vmTestbase_unloading
rev 59095 : [mq]: 8243434.00

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * 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.

@@ -31,10 +31,11 @@
  */
 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,10 +48,14 @@
                 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,16 +69,16 @@
                 throw new RuntimeException("Test bug", e);
             }
         }
     }
 
-    private static Field getRandomField(Class<?> clazz) {
+    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(new Random().nextInt(fields.size()));
+        return fields.get(random.nextInt(fields.size()));
     }
 
 }
< prev index next >