8066497: Update c.o.j.t.ByteCodeLoader to be able really reload given class
authorpchistyakov
Fri, 26 Dec 2014 14:47:35 +0300
changeset 28391 899a849e55f8
parent 28390 263a69157012
child 28392 f64a0abbff20
8066497: Update c.o.j.t.ByteCodeLoader to be able really reload given class Reviewed-by: drchase, fzhinkin, iignatyev
hotspot/test/testlibrary/com/oracle/java/testlibrary/ByteCodeLoader.java
--- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/ByteCodeLoader.java	Fri Dec 26 14:33:23 2014 +0300
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/ByteCodeLoader.java	Fri Dec 26 14:47:35 2014 +0300
@@ -37,6 +37,7 @@
 public class ByteCodeLoader extends SecureClassLoader {
     private final String className;
     private final byte[] byteCode;
+    private volatile Class<?> holder;
 
     /**
      * Creates a new {@code ByteCodeLoader} ready to load a class with the
@@ -51,6 +52,21 @@
     }
 
     @Override
+    public Class<?> loadClass(String name) throws ClassNotFoundException {
+        if (!name.equals(className)) {
+            return super.loadClass(name);
+        }
+        if (holder == null) {
+            synchronized(this) {
+                if (holder == null) {
+                    holder = findClass(name);
+                }
+            }
+        }
+        return holder;
+    }
+
+    @Override
     protected Class<?> findClass(String name) throws ClassNotFoundException {
         if (!name.equals(className)) {
             throw new ClassNotFoundException(name);