Methods Summary |
---|
public void | clearAssertionStatus()Sets the default assertion status for this class loader to {@code false}
and removes any package default and class assertion status settings.
Note: This method does nothing in the Android reference
implementation.
return;
|
private static java.lang.ClassLoader | createSystemClassLoader()Create the system class loader. Note this is NOT the bootstrap class
loader (which is managed by the VM). We use a null value for the parent
to indicate that the bootstrap loader is our parent.
String classPath = System.getProperty("java.class.path", ".");
// String[] paths = classPath.split(":");
// URL[] urls = new URL[paths.length];
// for (int i = 0; i < paths.length; i++) {
// try {
// urls[i] = new URL("file://" + paths[i]);
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// }
//
// return new java.net.URLClassLoader(urls, null);
// TODO Make this a java.net.URLClassLoader once we have those?
return new PathClassLoader(classPath, BootClassLoader.getInstance());
|
protected final java.lang.Class | defineClass(java.lang.String className, byte[] classRep, int offset, int length)Constructs a new class from an array of bytes containing a class
definition in class file format.
// TODO Define a default ProtectionDomain on first use
return defineClass(className, classRep, offset, length, null);
|
protected final java.lang.Class | defineClass(java.lang.String className, byte[] classRep, int offset, int length, java.security.ProtectionDomain protectionDomain)Constructs a new class from an array of bytes containing a class
definition in class file format and assigns the specified protection
domain to the new class. If the provided protection domain is
{@code null} then a default protection domain is assigned to the class.
return VMClassLoader.defineClass(this, className, classRep, offset, length,
protectionDomain);
|
protected final java.lang.Class | defineClass(java.lang.String name, java.nio.ByteBuffer b, java.security.ProtectionDomain protectionDomain)Defines a new class with the specified name, byte code from the byte
buffer and the optional protection domain. If the provided protection
domain is {@code null} then a default protection domain is assigned to
the class.
byte[] temp = new byte[b.remaining()];
b.get(temp);
return defineClass(name, temp, 0, temp.length, protectionDomain);
|
protected final java.lang.Class | defineClass(byte[] classRep, int offset, int length)Constructs a new class from an array of bytes containing a class
definition in class file format.
return VMClassLoader.defineClass(this, classRep, offset, length, null);
|
protected java.lang.Package | definePackage(java.lang.String name, java.lang.String specTitle, java.lang.String specVersion, java.lang.String specVendor, java.lang.String implTitle, java.lang.String implVersion, java.lang.String implVendor, java.net.URL sealBase)Defines and returns a new {@code Package} using the specified
information. If {@code sealBase} is {@code null}, the package is left
unsealed. Otherwise, the package is sealed using this URL.
synchronized (packages) {
if (packages.containsKey(name)) {
throw new IllegalArgumentException("Package " + name + " already defined");
}
Package newPackage = new Package(name, specTitle, specVersion, specVendor, implTitle,
implVersion, implVendor, sealBase);
packages.put(name, newPackage);
return newPackage;
}
|
protected java.lang.Class | findClass(java.lang.String className)Overridden by subclasses, throws a {@code ClassNotFoundException} by
default. This method is called by {@code loadClass} after the parent
{@code ClassLoader} has failed to find a loaded class of the same name.
throw new ClassNotFoundException(className);
|
protected java.lang.String | findLibrary(java.lang.String libName)Returns the absolute path of the native library with the specified name,
or {@code null}. If this method returns {@code null} then the virtual
machine searches the directories specified by the system property
"java.library.path".
This implementation always returns {@code null}.
return null;
|
protected final java.lang.Class | findLoadedClass(java.lang.String className)Returns the class with the specified name if it has already been loaded
by the virtual machine or {@code null} if it has not yet been loaded.
ClassLoader loader;
if (this == BootClassLoader.getInstance())
loader = null;
else
loader = this;
return VMClassLoader.findLoadedClass(loader, className);
|
protected java.net.URL | findResource(java.lang.String resName)Finds the URL of the resource with the specified name. This
implementation just returns {@code null}; it should be overridden in
subclasses.
return null;
|
protected java.util.Enumeration | findResources(java.lang.String resName)Finds an enumeration of URLs for the resource with the specified name.
This implementation just returns an empty {@code Enumeration}; it should
be overridden in subclasses.
return EmptyEnumeration.getInstance();
|
protected final java.lang.Class | findSystemClass(java.lang.String className)Finds the class with the specified name, loading it using the system
class loader if necessary.
return Class.forName(className, false, getSystemClassLoader());
|
boolean | getClassAssertionStatus(java.lang.String cname)Returns the assertion status of the named class Returns the assertion
status of the class or nested class if it has been set. Otherwise returns
the assertion status of its package or superpackage if that has been set.
Otherwise returns the default assertion status. Returns 1 for enabled and
0 for disabled.
return false;
|
boolean | getDefaultAssertionStatus()Returns the default assertion status
return false;
|
protected java.lang.Package | getPackage(java.lang.String name)Returns the package with the specified name. Package information is
searched in this class loader.
synchronized (packages) {
Package p = packages.get(name);
return p;
}
|
static java.lang.Package | getPackage(java.lang.ClassLoader loader, java.lang.String name)Gets the package with the specified name, searching it in the specified
class loader.
return loader.getPackage(name);
|
boolean | getPackageAssertionStatus(java.lang.String pname)Returns the assertion status of the named package Returns the assertion
status of the named package or superpackage if that has been set.
Otherwise returns the default assertion status. Returns 1 for enabled and
0 for disabled.
return false;
|
protected java.lang.Package[] | getPackages()Returns all the packages known to this class loader.
synchronized (packages) {
Collection<Package> col = packages.values();
Package[] result = new Package[col.size()];
col.toArray(result);
return result;
}
|
public final java.lang.ClassLoader | getParent()Returns this class loader's parent.
SecurityManager smgr = System.getSecurityManager();
if (smgr != null) {
smgr.checkPermission(new RuntimePermission("getClassLoader"));
}
return parent;
|
public java.net.URL | getResource(java.lang.String resName)Returns the URL of the resource with the specified name. This
implementation first tries to use the parent class loader to find the
resource; if this fails then {@link #findResource(String)} is called to
find the requested resource.
URL resource = null;
resource = parent.getResource(resName);
if (resource == null) {
resource = findResource(resName);
}
return resource;
|
public java.io.InputStream | getResourceAsStream(java.lang.String resName)Returns a stream for the resource with the specified name. See
{@link #getResource(String)} for a description of the lookup algorithm
used to find the resource.
try {
URL url = getResource(resName);
if (url != null) {
return url.openStream();
}
} catch (IOException ex) {
// Don't want to see the exception.
}
return null;
|
public java.util.Enumeration | getResources(java.lang.String resName)Returns an enumeration of URLs for the resource with the specified name.
This implementation first uses this class loader's parent to find the
resource, then it calls {@link #findResources(String)} to get additional
URLs. The returned enumeration contains the {@code URL} objects of both
find operations.
Enumeration first = parent.getResources(resName);
Enumeration second = findResources(resName);
return new TwoEnumerationsInOne(first, second);
|
final java.lang.Object[] | getSigners(java.lang.Class c)Gets the signers of the specified class. This implementation returns
{@code null}.
return null;
|
static final java.lang.ClassLoader | getStackClassLoader(int depth)
This must be provided by the VM vendor. It is used by
SecurityManager.checkMemberAccess() with depth = 3. Note that
checkMemberAccess() assumes the following stack when called:
< user code > <- want this class
Class.getDeclared*();
Class.checkMemberAccess();
SecurityManager.checkMemberAccess(); <- current frame
Returns the ClassLoader of the method (including natives) at the
specified depth on the stack of the calling thread. Frames representing
the VM implementation of java.lang.reflect are not included in the list.
Notes:
- This method operates on the defining classes of methods on stack.
NOT the classes of receivers.
- The item at depth zero is the caller of this method
Class<?>[] stack = VMStack.getClasses(depth + 1, false);
if(stack.length < depth + 1) {
return null;
}
return stack[depth].getClassLoader();
|
public static java.lang.ClassLoader | getSystemClassLoader()Returns the system class loader. This is the parent for new
{@code ClassLoader} instances and is typically the class loader used to
start the application. If a security manager is present and the caller's
class loader is neither {@code null} nor the same as or an ancestor of
the system class loader, then this method calls the security manager's
checkPermission method with a RuntimePermission("getClassLoader")
permission to ensure that it is ok to access the system class loader. If
not, a {@code SecurityException} is thrown.
SecurityManager smgr = System.getSecurityManager();
if (smgr != null) {
ClassLoader caller = VMStack.getCallingClassLoader();
if (caller != null && !caller.isAncestorOf(SystemClassLoader.loader)) {
smgr.checkPermission(new RuntimePermission("getClassLoader"));
}
}
return SystemClassLoader.loader;
|
public static java.net.URL | getSystemResource(java.lang.String resName)Finds the URL of the resource with the specified name. The system class
loader's resource lookup algorithm is used to find the resource.
return SystemClassLoader.loader.getResource(resName);
|
public static java.io.InputStream | getSystemResourceAsStream(java.lang.String resName)Returns a stream for the resource with the specified name. The system
class loader's resource lookup algorithm is used to find the resource.
Basically, the contents of the java.class.path are searched in order,
looking for a path which matches the specified resource.
return SystemClassLoader.loader.getResourceAsStream(resName);
|
public static java.util.Enumeration | getSystemResources(java.lang.String resName)Returns an enumeration of URLs for the resource with the specified name.
The system class loader's resource lookup algorithm is used to find the
resource.
return SystemClassLoader.loader.getResources(resName);
|
final boolean | isAncestorOf(java.lang.ClassLoader child)
Returns true if the receiver is ancestor of another class loader. It also
returns true if the two class loader are equal.
Note that this method has package visibility only. It is defined here to
avoid the security manager check in getParent, which would be required to
implement this method anywhere else. The method is also required in other
places where class loaders are accesses.
for (ClassLoader current = child; current != null;
current = child.parent) {
if (current == this) {
return true;
}
}
return false;
|
final boolean | isSystemClassLoader()Indicates whether this class loader is the system class loader. This
method must be provided by the virtual machine vendor, as it is used by
other provided class implementations in this package. A sample
implementation of this method is provided by the reference
implementation. This method is used by
SecurityManager.classLoaderDepth(), currentClassLoader() and
currentLoadedClass(). Returns true if the receiver is a system class
loader.
Note that this method has package visibility only. It is defined here to
avoid the security manager check in getSystemClassLoader, which would be
required to implement this method anywhere else.
return false;
|
public java.lang.Class | loadClass(java.lang.String className)Loads the class with the specified name. Invoking this method is
equivalent to calling {@code loadClass(className, false)}.
Note: In the Android reference implementation, the
second parameter of {@link #loadClass(String, boolean)} is ignored
anyway.
return loadClass(className, false);
|
protected java.lang.Class | loadClass(java.lang.String className, boolean resolve)Loads the class with the specified name, optionally linking it after
loading. The following steps are performed:
- Call {@link #findLoadedClass(String)} to determine if the requested
class has already been loaded.
- If the class has not yet been loaded: Invoke this method on the
parent class loader.
- If the class has still not been loaded: Call
{@link #findClass(String)} to find the class.
Note: In the Android reference implementation, the
{@code resolve} parameter is ignored; classes are never linked.
Class<?> clazz = findLoadedClass(className);
if (clazz == null) {
try {
clazz = parent.loadClass(className, false);
} catch (ClassNotFoundException e) {
// Don't want to see this.
}
if (clazz == null) {
clazz = findClass(className);
}
}
return clazz;
|
static void | loadLibraryWithClassLoader(java.lang.String libName, java.lang.ClassLoader loader)This method must be provided by the VM vendor, as it is called by
java.lang.System.loadLibrary(). System.loadLibrary() cannot call
Runtime.loadLibrary() because this method loads the library using the
ClassLoader of the calling method. Loads and links the library specified
by the argument.
return;
|
static void | loadLibraryWithPath(java.lang.String libName, java.lang.ClassLoader loader, java.lang.String libraryPath)This method must be provided by the VM vendor, as it is called by
java.lang.System.load(). System.load() cannot call Runtime.load() because
the library is loaded using the ClassLoader of the calling method. Loads
and links the library specified by the argument. No security check is
done.
Note: This method does nothing in the Android reference
implementation.
return;
|
protected final void | resolveClass(java.lang.Class clazz)Forces a class to be linked (initialized). If the class has already been
linked this operation has no effect.
Note: In the Android reference implementation, this
method has no effect.
// no-op, doesn't make sense on android.
|
public void | setClassAssertionStatus(java.lang.String cname, boolean enable)Sets the assertion status of the class with the specified name.
Note: This method does nothing in the Android reference
implementation.
return;
|
public void | setDefaultAssertionStatus(boolean enable)Sets the default assertion status for this class loader.
Note: This method does nothing in the Android reference
implementation.
return;
|
public void | setPackageAssertionStatus(java.lang.String pname, boolean enable)Sets the assertion status of the package with the specified name.
Note: This method does nothing in the Android reference
implementation.
return;
|
protected final void | setSigners(java.lang.Class c, java.lang.Object[] signers)Sets the signers of the specified class. This implementation does
nothing.
return;
|