src/share/classes/sun/misc/Launcher.java

Print this page
rev 10187 : mq

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, 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.  Oracle designates this

@@ -160,10 +160,12 @@
         /*
          * Creates a new ExtClassLoader for the specified directories.
          */
         public ExtClassLoader(File[] dirs) throws IOException {
             super(getExtURLs(dirs), null, factory);
+            SharedSecrets.getJavaNetAccess().
+                getURLClassPath(this).initLookupCache(this);
         }
 
         private static File[] getExtDirs() {
             String s = System.getProperty("java.ext.dirs");
             File[] dirs;

@@ -283,15 +285,19 @@
                     return new AppClassLoader(urls, extcl);
                 }
             });
         }
 
+        final URLClassPath ucp;
+
         /*
          * Creates a new AppClassLoader
          */
         AppClassLoader(URL[] urls, ClassLoader parent) {
             super(urls, parent, factory);
+            ucp = SharedSecrets.getJavaNetAccess().getURLClassPath(this);
+            ucp.initLookupCache(this);
         }
 
         /**
          * Override loadClass so we can checkPackageAccess.
          */

@@ -303,10 +309,26 @@
                 SecurityManager sm = System.getSecurityManager();
                 if (sm != null) {
                     sm.checkPackageAccess(name.substring(0, i));
                 }
             }
+
+            if (ucp.knownToNotExist(name)) {
+                // The class of the given name is not found in the parent
+                // class loader as well as its local URLClassPath.
+                // Check if this class has already been defined dynamically;
+                // if so, return the loaded class; otherwise, skip the parent
+                // delegation and findClass.
+                synchronized (getClassLoadingLock(name)) {
+                    Class<?> c = findLoadedClass(name);
+                    if (c != null) {
+                        return c;
+                    }
+                }
+                throw new ClassNotFoundException(name);
+            }
+
             return (super.loadClass(name, resolve));
         }
 
         /**
          * allow any classes loaded from classpath to exit the VM.

@@ -384,10 +406,11 @@
                 );
             } else {
                 urls = new URL[0];
             }
             bcp = new URLClassPath(urls, factory);
+            bcp.initLookupCache(null);
         }
     }
 
     public static URLClassPath getBootstrapClassPath() {
         return BootClassPathHolder.bcp;