/[classpath]/classpath/java/lang/Runtime.java
ViewVC logotype

Diff of /classpath/java/lang/Runtime.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by archie172, Tue Jan 4 17:45:50 2005 UTC revision 1.17 by archie172, Tue Jan 4 19:18:30 2005 UTC
# Line 39  exception statement from your version. * Line 39  exception statement from your version. *
39  package java.lang;  package java.lang;
40    
41  import gnu.classpath.SystemProperties;  import gnu.classpath.SystemProperties;
 import gnu.classpath.VMStackWalker;  
42    
43  import java.io.File;  import java.io.File;
44  import java.io.IOException;  import java.io.IOException;
# Line 629  public class Runtime Line 628  public class Runtime
628     * before the final ".so" if the VM was invoked by the name "java_g". There     * before the final ".so" if the VM was invoked by the name "java_g". There
629     * may be a security check, of <code>checkLink</code>.     * may be a security check, of <code>checkLink</code>.
630     *     *
    * <p>  
    * The library is loaded using the class loader associated with the  
    * class associated with the invoking method.  
    *  
631     * @param filename the file to load     * @param filename the file to load
632     * @throws SecurityException if permission is denied     * @throws SecurityException if permission is denied
633     * @throws UnsatisfiedLinkError if the library is not found     * @throws UnsatisfiedLinkError if the library is not found
634     */     */
635    public void load(String filename)    public void load(String filename)
636    {    {
     load(filename, VMStackWalker.getCallingClassLoader());  
   }  
   
   /**  
    * Same as <code>load(String)</code> but using the given loader.  
    *  
    * @param filename the file to load  
    * @param loader class loader, or <code>null</code> for the boot loader  
    * @throws SecurityException if permission is denied  
    * @throws UnsatisfiedLinkError if the library is not found  
    */  
   void load(String filename, ClassLoader loader)  
   {  
637      SecurityManager sm = SecurityManager.current; // Be thread-safe!      SecurityManager sm = SecurityManager.current; // Be thread-safe!
638      if (sm != null)      if (sm != null)
639        sm.checkLink(filename);        sm.checkLink(filename);
640      if (loadLib(filename, loader) == 0)      if (loadLib(filename) == 0)
641        throw new UnsatisfiedLinkError("Could not load library " + filename);        throw new UnsatisfiedLinkError("Could not load library " + filename);
642    }    }
643    
# Line 663  public class Runtime Line 645  public class Runtime
645     * Do a security check on the filename and then load the native library.     * Do a security check on the filename and then load the native library.
646     *     *
647     * @param filename the file to load     * @param filename the file to load
    * @param loader class loader, or <code>null</code> for the boot loader  
648     * @return 0 on failure, nonzero on success     * @return 0 on failure, nonzero on success
649     * @throws SecurityException if file read permission is denied     * @throws SecurityException if file read permission is denied
650     */     */
651    private static int loadLib(String filename, ClassLoader loader)    private static int loadLib(String filename)
652    {    {
653      SecurityManager sm = SecurityManager.current; // Be thread-safe!      SecurityManager sm = SecurityManager.current; // Be thread-safe!
654      if (sm != null)      if (sm != null)
655        sm.checkRead(filename);        sm.checkRead(filename);
656      return VMRuntime.nativeLoad(filename, loader);      return VMRuntime.nativeLoad(filename);
657    }    }
658    
659    /**    /**
# Line 687  public class Runtime Line 668  public class Runtime
668     * <code>System.mapLibraryName(libname)</code>. There may be a security     * <code>System.mapLibraryName(libname)</code>. There may be a security
669     * check, of <code>checkLink</code>.     * check, of <code>checkLink</code>.
670     *     *
    * <p>  
    * The library is loaded using the class loader associated with the  
    * class associated with the invoking method.  
    *  
671     * @param libname the library to load     * @param libname the library to load
672     *     *
673     * @throws SecurityException if permission is denied     * @throws SecurityException if permission is denied
# Line 701  public class Runtime Line 678  public class Runtime
678     */     */
679    public void loadLibrary(String libname)    public void loadLibrary(String libname)
680    {    {
     loadLibrary(libname, VMStackWalker.getCallingClassLoader());  
   }  
   
   /**  
    * Same as <code>loadLibrary(String)</code> but using the given loader.  
    *  
    * @param libname the library to load  
    * @param loader class loader, or <code>null</code> for the boot loader  
    * @throws SecurityException if permission is denied  
    * @throws UnsatisfiedLinkError if the library is not found  
    */  
   void loadLibrary(String libname, ClassLoader loader)  
   {  
681      SecurityManager sm = SecurityManager.current; // Be thread-safe!      SecurityManager sm = SecurityManager.current; // Be thread-safe!
682      if (sm != null)      if (sm != null)
683        sm.checkLink(libname);        sm.checkLink(libname);
684    
685      String filename;      String filename;
686      if (loader != null && (filename = loader.findLibrary(libname)) != null)      ClassLoader cl = VMSecurityManager.currentClassLoader();
687        if (cl != null)
688        {        {
689          if (loadLib(filename, loader) != 0)          filename = cl.findLibrary(libname);
690            return;          if (filename != null)
691        }            {
692      else              if (loadLib(filename) != 0)
693        {                return;
694          filename = VMRuntime.mapLibraryName(libname);              else
695          for (int i = 0; i < libpath.length; i++)                throw new UnsatisfiedLinkError("Could not load library " + filename);
696            if (loadLib(libpath[i] + filename, loader) != 0)            }
             return;  
697        }        }
698      throw new UnsatisfiedLinkError("Native library `" + libname  
699        + "' not found (as file `" + filename + "')");      filename = VMRuntime.mapLibraryName(libname);
700        for (int i = 0; i < libpath.length; i++)
701          if (loadLib(libpath[i] + filename) != 0)
702            return;
703    
704        throw new UnsatisfiedLinkError("Could not find library " + libname + ".");
705    }    }
706    
707    /**    /**

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26