< prev index next >

src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java

Print this page




 115 
 116         @Override
 117         protected Class<?> loadClassOrNull(String cn, boolean resolve) {
 118             return JLA.findBootstrapClassOrNull(this, cn);
 119         }
 120     };
 121 
 122     /**
 123      * The platform class loader, a unique type to make it easier to distinguish
 124      * from the application class loader.
 125      */
 126     private static class PlatformClassLoader extends BuiltinClassLoader {
 127         static {
 128             if (!ClassLoader.registerAsParallelCapable())
 129                 throw new InternalError();
 130         }
 131 
 132         PlatformClassLoader(BootClassLoader parent) {
 133             super("platform", parent, null);
 134         }
 135 
 136         /**
 137          * Called by the VM to support define package for AppCDS.
 138          *
 139          * Shared classes are returned in ClassLoader::findLoadedClass
 140          * that bypass the defineClass call.
 141          */
 142         private Package definePackage(String pn, Module module) {
 143             return JLA.definePackage(this, pn, module);
 144         }
 145     }
 146 
 147     /**
 148      * The application class loader that is a {@code BuiltinClassLoader} with
 149      * customizations to be compatible with long standing behavior.
 150      */
 151     private static class AppClassLoader extends BuiltinClassLoader {
 152         static {
 153             if (!ClassLoader.registerAsParallelCapable())
 154                 throw new InternalError();
 155         }
 156 
 157         final URLClassPath ucp;
 158 
 159         AppClassLoader(PlatformClassLoader parent, URLClassPath ucp) {
 160             super("app", parent, ucp);
 161             this.ucp = ucp;
 162         }
 163 
 164         @Override


 175                 }
 176             }
 177 
 178             return super.loadClass(cn, resolve);
 179         }
 180 
 181         @Override
 182         protected PermissionCollection getPermissions(CodeSource cs) {
 183             PermissionCollection perms = super.getPermissions(cs);
 184             perms.add(new RuntimePermission("exitVM"));
 185             return perms;
 186         }
 187 
 188         /**
 189          * Called by the VM to support dynamic additions to the class path
 190          *
 191          * @see java.lang.instrument.Instrumentation#appendToSystemClassLoaderSearch
 192          */
 193         void appendToClassPathForInstrumentation(String path) {
 194             ucp.addFile(path);
 195         }
 196 
 197         /**
 198          * Called by the VM to support define package for AppCDS
 199          *
 200          * Shared classes are returned in ClassLoader::findLoadedClass
 201          * that bypass the defineClass call.
 202          */
 203         private Package definePackage(String pn, Module module) {
 204             return JLA.definePackage(this, pn, module);
 205         }
 206 
 207         /**
 208          * Called by the VM to support define package for AppCDS
 209          */
 210         protected Package defineOrCheckPackage(String pn, Manifest man, URL url) {
 211             return super.defineOrCheckPackage(pn, man, url);
 212         }
 213     }
 214 
 215     /**
 216      * Attempts to convert the given string to a file URL.
 217      *
 218      * @apiNote This is called by the VM
 219      */
 220     @Deprecated
 221     private static URL toFileURL(String s) {
 222         try {
 223             // Use an intermediate File object to construct a URI/URL without
 224             // authority component as URLClassPath can't handle URLs with a UNC


 115 
 116         @Override
 117         protected Class<?> loadClassOrNull(String cn, boolean resolve) {
 118             return JLA.findBootstrapClassOrNull(this, cn);
 119         }
 120     };
 121 
 122     /**
 123      * The platform class loader, a unique type to make it easier to distinguish
 124      * from the application class loader.
 125      */
 126     private static class PlatformClassLoader extends BuiltinClassLoader {
 127         static {
 128             if (!ClassLoader.registerAsParallelCapable())
 129                 throw new InternalError();
 130         }
 131 
 132         PlatformClassLoader(BootClassLoader parent) {
 133             super("platform", parent, null);
 134         }










 135     }
 136 
 137     /**
 138      * The application class loader that is a {@code BuiltinClassLoader} with
 139      * customizations to be compatible with long standing behavior.
 140      */
 141     private static class AppClassLoader extends BuiltinClassLoader {
 142         static {
 143             if (!ClassLoader.registerAsParallelCapable())
 144                 throw new InternalError();
 145         }
 146 
 147         final URLClassPath ucp;
 148 
 149         AppClassLoader(PlatformClassLoader parent, URLClassPath ucp) {
 150             super("app", parent, ucp);
 151             this.ucp = ucp;
 152         }
 153 
 154         @Override


 165                 }
 166             }
 167 
 168             return super.loadClass(cn, resolve);
 169         }
 170 
 171         @Override
 172         protected PermissionCollection getPermissions(CodeSource cs) {
 173             PermissionCollection perms = super.getPermissions(cs);
 174             perms.add(new RuntimePermission("exitVM"));
 175             return perms;
 176         }
 177 
 178         /**
 179          * Called by the VM to support dynamic additions to the class path
 180          *
 181          * @see java.lang.instrument.Instrumentation#appendToSystemClassLoaderSearch
 182          */
 183         void appendToClassPathForInstrumentation(String path) {
 184             ucp.addFile(path);










 185         }
 186 
 187         /**
 188          * Called by the VM to support define package for AppCDS
 189          */
 190         protected Package defineOrCheckPackage(String pn, Manifest man, URL url) {
 191             return super.defineOrCheckPackage(pn, man, url);
 192         }
 193     }
 194 
 195     /**
 196      * Attempts to convert the given string to a file URL.
 197      *
 198      * @apiNote This is called by the VM
 199      */
 200     @Deprecated
 201     private static URL toFileURL(String s) {
 202         try {
 203             // Use an intermediate File object to construct a URI/URL without
 204             // authority component as URLClassPath can't handle URLs with a UNC
< prev index next >