在rt.jar下的sun.misc包的类Launcher中
AppClassLoader和ExtClassLoader是内部类 所以 类名中含有$ $前面是外部类 后面是内部类
sun.misc.Launcher$AppClassLoader和sun.misc.Launcher.ExtClassLoader
这个包下面的类不是开源的 所以在java安装路径下的src.zip中没有这个包的源码
之前我对这个类做过反编译 代码如下:
AppClassLoader源码 (从Launcher内部摘取)
由于AppClassLoader是静态内部类,依附于Launcher这个外部类,以下是源码。- static class AppClassLoader extends URLClassLoader{
- public static ClassLoader getAppClassLoader(ClassLoader paramClassLoader)
- throws IOException{
- String str = System.getProperty("java.class.path");
- File[] arrayOfFile = str == null ? new File[0] : Launcher.access$200(str);
- return (ClassLoader)AccessController.doPrivileged(new PrivilegedAction(str, arrayOfFile, paramClassLoader)
- {
- public Launcher.AppClassLoader run() {
- URL[] arrayOfURL = this.val$s == null ? new URL[0] : Launcher.access$300(this.val$path);
- return new Launcher.AppClassLoader(arrayOfURL, this.val$extcl);
- }
- });
- }
- AppClassLoader(URL[] paramArrayOfURL, ClassLoader paramClassLoader){
- super(paramClassLoader, Launcher.factory);
- }
- public Class loadClass(String paramString, boolean paramBoolean) throws ClassNotFoundException{
- int i = paramString.lastIndexOf('.');
- if (i != -1) {
- SecurityManager localSecurityManager = System.getSecurityManager();
- if (localSecurityManager != null) {
- localSecurityManager.checkPackageAccess(paramString.substring(0, i));
- }
- }
- return super.loadClass(paramString, paramBoolean);
- }
- protected PermissionCollection getPermissions(CodeSource paramCodeSource){
- PermissionCollection localPermissionCollection = super.getPermissions(paramCodeSource);
- localPermissionCollection.add(new RuntimePermission("exitVM"));
- return localPermissionCollection;
- }
- private void appendToClassPathForInstrumentation(String paramString){
- assert (Thread.holdsLock(this));
- super.addURL(Launcher.getFileURL(new File(paramString)));
- }
- private static AccessControlContext getContext(File[] paramArrayOfFile)throws MalformedURLException{
- PathPermissions localPathPermissions = new PathPermissions(paramArrayOfFile);
- ProtectionDomain localProtectionDomain = new ProtectionDomain(new CodeSource(localPathPermissions.getCodeBase(), (Certificate[])null), localPathPermissions);
- AccessControlContext localAccessControlContext = new AccessControlContext(new ProtectionDomain[] { localProtectionDomain });
- return localAccessControlContext;
- }
- static
- {
- ClassLoader.registerAsParallelCapable();
- }
- }
复制代码 下面是ExtClassLoader的源码这两个类所依附的外部类sun.misc.Launcher的部分源码:
|
|