📄 classloader.java
字号:
/* libaegisvm - The Aegis Virtual Machine for executing Java bytecode by Philip W. L. Fong Copyright (C) 2001-2002 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/package java.lang;import aegis.*;import java.io.*;import java.net.*;import java.util.*;import java.security.*;/** * \todo Should be turned into an inner class of ClassLoader. */class ClassHashTable { Class[] values; String[] keys; int size; ClassHashTable() { values = new Class[16]; keys = new String[16]; size = 0; } void expand() { int oldCapacity = values.length; int newCapacity; Class[] newValues; String[] newKeys; int mask; if (oldCapacity == (1 << 30)) throw new aegis.ImplementationLimitError(); newCapacity = oldCapacity << 1; newValues = new Class[newCapacity]; newKeys = new String[newCapacity]; mask = newCapacity - 1; for (int i = 0; i < oldCapacity; i++) { if (keys[i] != null) { int index = keys[i].hashCode() & mask; while (newKeys[index] != null) index = (index + 1) & mask; newValues[index] = values[i]; newKeys[index] = keys[i]; } } values = newValues; keys = newKeys; } void put(String classname, Class C) { int capacity = keys.length; int mask, index; if (size + 1 > capacity / 2) expand(); mask = capacity - 1; index = classname.hashCode() & mask; while (keys[index] != null) index = (index + 1) & mask; keys[index] = classname; values[index] = C; ++size; } Class get(String classname) { int mask = keys.length - 1; int index = classname.hashCode() & mask; while (keys[index] != null) { if (classname.compareTo(keys[index]) == 0) return values[index]; index = (index + 1) & mask; } return null; }}public abstract class ClassLoader { private Namespace namespace; // The Aegis VM internal is dependent private ClassLoader parent; // on the exact layout of these fields private ClassHashTable table; public static ClassLoader getSystemClassLoader() { return SystemClassLoader.theSystemClassLoader; } protected final Class findSystemClass(String name) throws ClassNotFoundException { return SystemClassLoader.theSystemClassLoader.loadClass(name); } protected Class findClass(String name) throws ClassNotFoundException { throw new ClassNotFoundException(); } protected final Class findLoadedClass(String name) { if (name == null) throw new NullPointerException(); return table.get(name); } private static native Class defineClass(ClassLoader loader, String name, byte[] b, int off, int len); /** * \todo Security checks. */ protected final Class defineClass(String name, byte[] b, int off, int len) throws ClassFormatError { Class C; if (name == null || b == null) throw new NullPointerException(); if (off < 0 || off > b.length || len < 0 || len > b.length - off) throw new IndexOutOfBoundsException(); // security check goes here C = defineClass(this, name, b, off, len); table.put(name, C); return C; } /** * \todo Not implemented yet. */ protected final Class defineClass(String name, byte[] b, int off, int len, ProtectionDomain protectionDomain) throws ClassFormatError { throw new FeatureNotYetImplementedError(); } private static native Class bootstrapLoadClass(String name); protected final native void resolveClass(Class C); protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { Class C; C = findLoadedClass(name); if (C == null) { try { if (parent == null) C = bootstrapLoadClass(name); else C = parent.loadClass(name); if (C == null) throw new ClassNotFoundException(); } catch (ClassNotFoundException ex) { C = findClass(name); if (C == null) throw new ClassNotFoundException(); } } if (resolve) resolveClass(C); return C; } public Class loadClass(String name) throws ClassNotFoundException { return loadClass(name, false); } /** * \todo Security check. */ public final ClassLoader getParent() { // Bug: security checks goes here return parent; } private static native Namespace createNamespace(ClassLoader parent, ClassLoader loader); /** * \todo Not implemented yet. */ protected final void setSigners(Class c, Object[] signers) { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ public URL getResource(String name) { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ public final Enumeration getResources(String name) throws IOException { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ protected Enumeration findResources(String name) throws IOException { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ protected URL findResource(String name) { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ public static URL getSystemResource(String name) { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ public static Enumeration getSystemResources(String name) throws IOException { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ public InputStream getResourceAsStream(String name) { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ public static InputStream getSystemResourceAsStream(String name) { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ protected Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) throws IllegalArgumentException { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ protected Package getPackage(String name) { throw new FeatureNotYetImplementedError(); } /** * \todo Not implemented yet. */ protected Package[] getPackages() { throw new FeatureNotYetImplementedError(); } protected String findLibrary(String libname) { return null; } /** * \todo Security checks. */ protected ClassLoader(ClassLoader parent) { // security checks goes here this.parent = parent; namespace = createNamespace(parent, this); table = new ClassHashTable(); } protected ClassLoader(){ this(getSystemClassLoader()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -