From ec858596f78dd4ddc318edd3d3f4ec537780c854 Mon Sep 17 00:00:00 2001 From: Archie Cobbs Date: Fri, 7 Jan 2005 15:08:21 +0000 Subject: Re-committing now that the 0.13 release has been tagged: * NEWS: Document changes. * java/lang/Class.java (newInstance(), getClassLoader(), forName(String), forName(String, boolean, ClassLoader)): Use new VMStackWalker methods. * java/lang/ClassLoader.java (getParent(), getSystemClassLoader()): Likewise. * java/lang/Package.java (getPackages()): Likewise. * java/lang/SecurityManager.java (getClassContext()): Likewise. * java/util/ResourceBundle.java (getBundle()): Likewise. * java/lang/Runtime.java (load(), loadLibrary()): Load the native library using the calling class' class loader. * java/lang/System.java (load(), loadLibrary()): Likewise. (currentClassLoader()): implement via currentLoadedClass(). * vm/reference/gnu/classpath/VMStackWalker.java: New class. * vm/reference/java/lang/VMRuntime.java (nativeLoad()): Add a ClassLoader parameter. * vm/reference/java/lang/VMSecurityManager.java: Removed. --- java/lang/Runtime.java | 72 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 21 deletions(-) (limited to 'java/lang/Runtime.java') diff --git a/java/lang/Runtime.java b/java/lang/Runtime.java index 58d1f5c0d..d0e7ac593 100644 --- a/java/lang/Runtime.java +++ b/java/lang/Runtime.java @@ -39,6 +39,7 @@ exception statement from your version. */ package java.lang; import gnu.classpath.SystemProperties; +import gnu.classpath.VMStackWalker; import java.io.File; import java.io.IOException; @@ -628,16 +629,33 @@ public class Runtime * before the final ".so" if the VM was invoked by the name "java_g". There * may be a security check, of checkLink. * + *

+ * The library is loaded using the class loader associated with the + * class associated with the invoking method. + * * @param filename the file to load * @throws SecurityException if permission is denied * @throws UnsatisfiedLinkError if the library is not found */ public void load(String filename) + { + load(filename, VMStackWalker.getCallingClassLoader()); + } + + /** + * Same as load(String) but using the given loader. + * + * @param filename the file to load + * @param loader class loader, or null for the boot loader + * @throws SecurityException if permission is denied + * @throws UnsatisfiedLinkError if the library is not found + */ + void load(String filename, ClassLoader loader) { SecurityManager sm = SecurityManager.current; // Be thread-safe! if (sm != null) sm.checkLink(filename); - if (loadLib(filename) == 0) + if (loadLib(filename, loader) == 0) throw new UnsatisfiedLinkError("Could not load library " + filename); } @@ -645,15 +663,16 @@ public class Runtime * Do a security check on the filename and then load the native library. * * @param filename the file to load + * @param loader class loader, or null for the boot loader * @return 0 on failure, nonzero on success * @throws SecurityException if file read permission is denied */ - private static int loadLib(String filename) + private static int loadLib(String filename, ClassLoader loader) { SecurityManager sm = SecurityManager.current; // Be thread-safe! if (sm != null) sm.checkRead(filename); - return VMRuntime.nativeLoad(filename); + return VMRuntime.nativeLoad(filename, loader); } /** @@ -668,6 +687,10 @@ public class Runtime * System.mapLibraryName(libname). There may be a security * check, of checkLink. * + *

+ * The library is loaded using the class loader associated with the + * class associated with the invoking method. + * * @param libname the library to load * * @throws SecurityException if permission is denied @@ -677,31 +700,38 @@ public class Runtime * @see ClassLoader#findLibrary(String) */ public void loadLibrary(String libname) + { + loadLibrary(libname, VMStackWalker.getCallingClassLoader()); + } + + /** + * Same as loadLibrary(String) but using the given loader. + * + * @param libname the library to load + * @param loader class loader, or null for the boot loader + * @throws SecurityException if permission is denied + * @throws UnsatisfiedLinkError if the library is not found + */ + void loadLibrary(String libname, ClassLoader loader) { SecurityManager sm = SecurityManager.current; // Be thread-safe! if (sm != null) sm.checkLink(libname); - String filename; - ClassLoader cl = VMSecurityManager.currentClassLoader(); - if (cl != null) + if (loader != null && (filename = loader.findLibrary(libname)) != null) { - filename = cl.findLibrary(libname); - if (filename != null) - { - if (loadLib(filename) != 0) - return; - else - throw new UnsatisfiedLinkError("Could not load library " + filename); - } + if (loadLib(filename, loader) != 0) + return; } - - filename = VMRuntime.mapLibraryName(libname); - for (int i = 0; i < libpath.length; i++) - if (loadLib(libpath[i] + filename) != 0) - return; - - throw new UnsatisfiedLinkError("Could not find library " + libname + "."); + else + { + filename = VMRuntime.mapLibraryName(libname); + for (int i = 0; i < libpath.length; i++) + if (loadLib(libpath[i] + filename, loader) != 0) + return; + } + throw new UnsatisfiedLinkError("Native library `" + libname + + "' not found (as file `" + filename + "')"); } /** -- cgit v1.2.1