changeset 7641:022f7f1bfb4e

8066497: Update c.o.j.t.ByteCodeLoader to be able really reload given class Reviewed-by: drchase, fzhinkin, iignatyev
author pchistyakov
date Fri, 26 Dec 2014 14:47:35 +0300
parents a7adb22849d6
children ed3f650cff02
files test/testlibrary/com/oracle/java/testlibrary/ByteCodeLoader.java
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/test/testlibrary/com/oracle/java/testlibrary/ByteCodeLoader.java	Fri Dec 26 14:33:23 2014 +0300
+++ b/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);