src/share/classes/java/lang/Runtime.java

Print this page




 732 
 733     /**
 734      * Enables/Disables tracing of method calls.
 735      * If the <code>boolean</code> argument is <code>true</code>, this
 736      * method suggests that the Java virtual machine emit debugging
 737      * information for each method in the virtual machine as it is
 738      * called. The format of this information, and the file or other output
 739      * stream to which it is emitted, depends on the host environment. The
 740      * virtual machine may ignore this request if it does not support
 741      * this feature.
 742      * <p>
 743      * Calling this method with argument false suggests that the
 744      * virtual machine cease emitting per-call debugging information.
 745      *
 746      * @param   on   <code>true</code> to enable instruction tracing;
 747      *               <code>false</code> to disable this feature.
 748      */
 749     public native void traceMethodCalls(boolean on);
 750 
 751     /**
 752      * Loads the specified filename as a dynamic library. The filename
 753      * argument must be a complete path name,
 754      * (for example
 755      * <code>Runtime.getRuntime().load("/home/avh/lib/libX11.so");</code>).











 756      * <p>
 757      * First, if there is a security manager, its <code>checkLink</code>
 758      * method is called with the <code>filename</code> as its argument.
 759      * This may result in a security exception.
 760      * <p>
 761      * This is similar to the method {@link #loadLibrary(String)}, but it
 762      * accepts a general file name as an argument rather than just a library
 763      * name, allowing any file of native code to be loaded.
 764      * <p>
 765      * The method {@link System#load(String)} is the conventional and
 766      * convenient means of invoking this method.
 767      *
 768      * @param      filename   the file to load.
 769      * @exception  SecurityException  if a security manager exists and its
 770      *             <code>checkLink</code> method doesn't allow
 771      *             loading of the specified dynamic library
 772      * @exception  UnsatisfiedLinkError  if the file does not exist.



 773      * @exception  NullPointerException if <code>filename</code> is
 774      *             <code>null</code>
 775      * @see        java.lang.Runtime#getRuntime()
 776      * @see        java.lang.SecurityException
 777      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
 778      */
 779     public void load(String filename) {
 780         load0(System.getCallerClass(), filename);
 781     }
 782 
 783     synchronized void load0(Class<?> fromClass, String filename) {
 784         SecurityManager security = System.getSecurityManager();
 785         if (security != null) {
 786             security.checkLink(filename);
 787         }
 788         if (!(new File(filename).isAbsolute())) {
 789             throw new UnsatisfiedLinkError(
 790                 "Expecting an absolute path of the library: " + filename);
 791         }
 792         ClassLoader.loadLibrary(fromClass, filename, true);
 793     }
 794 
 795     /**
 796      * Loads the dynamic library with the specified library name.
 797      * A file containing native code is loaded from the local file system
 798      * from a place where library files are conventionally obtained. The
 799      * details of this process are implementation-dependent. The
 800      * mapping from a library name to a specific filename is done in a
 801      * system-specific manner.




 802      * <p>
 803      * First, if there is a security manager, its <code>checkLink</code>
 804      * method is called with the <code>libname</code> as its argument.
 805      * This may result in a security exception.
 806      * <p>
 807      * The method {@link System#loadLibrary(String)} is the conventional
 808      * and convenient means of invoking this method. If native
 809      * methods are to be used in the implementation of a class, a standard
 810      * strategy is to put the native code in a library file (call it
 811      * <code>LibFile</code>) and then to put a static initializer:
 812      * <blockquote><pre>
 813      * static { System.loadLibrary("LibFile"); }
 814      * </pre></blockquote>
 815      * within the class declaration. When the class is loaded and
 816      * initialized, the necessary native code implementation for the native
 817      * methods will then be loaded as well.
 818      * <p>
 819      * If this method is called more than once with the same library
 820      * name, the second and subsequent calls are ignored.
 821      *
 822      * @param      libname   the name of the library.
 823      * @exception  SecurityException  if a security manager exists and its
 824      *             <code>checkLink</code> method doesn't allow
 825      *             loading of the specified dynamic library
 826      * @exception  UnsatisfiedLinkError  if the library does not exist.



 827      * @exception  NullPointerException if <code>libname</code> is
 828      *             <code>null</code>
 829      * @see        java.lang.SecurityException
 830      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
 831      */
 832     public void loadLibrary(String libname) {
 833         loadLibrary0(System.getCallerClass(), libname);
 834     }
 835 
 836     synchronized void loadLibrary0(Class<?> fromClass, String libname) {
 837         SecurityManager security = System.getSecurityManager();
 838         if (security != null) {
 839             security.checkLink(libname);
 840         }
 841         if (libname.indexOf((int)File.separatorChar) != -1) {
 842             throw new UnsatisfiedLinkError(
 843     "Directory separator should not appear in library name: " + libname);
 844         }
 845         ClassLoader.loadLibrary(fromClass, libname, false);
 846     }




 732 
 733     /**
 734      * Enables/Disables tracing of method calls.
 735      * If the <code>boolean</code> argument is <code>true</code>, this
 736      * method suggests that the Java virtual machine emit debugging
 737      * information for each method in the virtual machine as it is
 738      * called. The format of this information, and the file or other output
 739      * stream to which it is emitted, depends on the host environment. The
 740      * virtual machine may ignore this request if it does not support
 741      * this feature.
 742      * <p>
 743      * Calling this method with argument false suggests that the
 744      * virtual machine cease emitting per-call debugging information.
 745      *
 746      * @param   on   <code>true</code> to enable instruction tracing;
 747      *               <code>false</code> to disable this feature.
 748      */
 749     public native void traceMethodCalls(boolean on);
 750 
 751     /**
 752      * Loads the native library specified by the filename argument.  The filename
 753      * argument must be an absolute path name.
 754      * (for example
 755      * <code>Runtime.getRuntime().load("/home/avh/lib/libX11.so");</code>).
 756      *
 757      * If the filename argument, when stripped of any platform-specific library
 758      * prefix, path, and file extension, indicates a library whose name is L,
 759      * and a native library called L is statically linked with the VM, then the
 760      * JNI_OnLoad_L function exported by the library is invoked rather than
 761      * attempting to load a dynamic library.  A filename matching the argument
 762      * does not have to exist in the file system.   See the JNI Specification
 763      * for more details.
 764      *
 765      * Otherwise, the filename argument is mapped to a native library image in
 766      * an implementation-dependent manner.
 767      * <p>
 768      * First, if there is a security manager, its <code>checkLink</code>
 769      * method is called with the <code>filename</code> as its argument.
 770      * This may result in a security exception.
 771      * <p>
 772      * This is similar to the method {@link #loadLibrary(String)}, but it
 773      * accepts a general file name as an argument rather than just a library
 774      * name, allowing any file of native code to be loaded.
 775      * <p>
 776      * The method {@link System#load(String)} is the conventional and
 777      * convenient means of invoking this method.
 778      *
 779      * @param      filename   the file to load.
 780      * @exception  SecurityException  if a security manager exists and its
 781      *             <code>checkLink</code> method doesn't allow
 782      *             loading of the specified dynamic library
 783      * @exception  UnsatisfiedLinkError  if either the filename is not an 
 784      *             absolute path name, the native library is not statically 
 785      *             linked with the VM, or the library cannot be mapped to 
 786      *             a native library image by the host system.
 787      * @exception  NullPointerException if <code>filename</code> is
 788      *             <code>null</code>
 789      * @see        java.lang.Runtime#getRuntime()
 790      * @see        java.lang.SecurityException
 791      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
 792      */
 793     public void load(String filename) {
 794         load0(System.getCallerClass(), filename);
 795     }
 796 
 797     synchronized void load0(Class<?> fromClass, String filename) {
 798         SecurityManager security = System.getSecurityManager();
 799         if (security != null) {
 800             security.checkLink(filename);
 801         }
 802         if (!(new File(filename).isAbsolute())) {
 803             throw new UnsatisfiedLinkError(
 804                 "Expecting an absolute path of the library: " + filename);
 805         }
 806         ClassLoader.loadLibrary(fromClass, filename, true);
 807     }
 808 
 809     /**
 810      * Loads the native library specified by the <code>libname</code>
 811      * argument.  The <code>libname</code> argument must not contain any platform
 812      * specific prefix, file extension or path. If a native library
 813      * called <code>libname</code> is statically linked with the VM, then the
 814      * JNI_OnLoad_<code>libname</code> function exported by the library is invoked.
 815      * See the JNI Specification for more details.
 816      *
 817      * Otherwise, the libname argument is loaded from a system library
 818      * location and mapped to a native library image in an implementation-
 819      * dependent manner.
 820      * <p>
 821      * First, if there is a security manager, its <code>checkLink</code>
 822      * method is called with the <code>libname</code> as its argument.
 823      * This may result in a security exception.
 824      * <p>
 825      * The method {@link System#loadLibrary(String)} is the conventional
 826      * and convenient means of invoking this method. If native
 827      * methods are to be used in the implementation of a class, a standard
 828      * strategy is to put the native code in a library file (call it
 829      * <code>LibFile</code>) and then to put a static initializer:
 830      * <blockquote><pre>
 831      * static { System.loadLibrary("LibFile"); }
 832      * </pre></blockquote>
 833      * within the class declaration. When the class is loaded and
 834      * initialized, the necessary native code implementation for the native
 835      * methods will then be loaded as well.
 836      * <p>
 837      * If this method is called more than once with the same library
 838      * name, the second and subsequent calls are ignored.
 839      *
 840      * @param      libname   the name of the library.
 841      * @exception  SecurityException  if a security manager exists and its
 842      *             <code>checkLink</code> method doesn't allow
 843      *             loading of the specified dynamic library
 844      * @exception  UnsatisfiedLinkError if either the libname argument 
 845      *             contains a file path, the native library is not statically 
 846      *             linked with the VM,  or the library cannot be mapped to a 
 847      *             native library image by the host system.
 848      * @exception  NullPointerException if <code>libname</code> is
 849      *             <code>null</code>
 850      * @see        java.lang.SecurityException
 851      * @see        java.lang.SecurityManager#checkLink(java.lang.String)
 852      */
 853     public void loadLibrary(String libname) {
 854         loadLibrary0(System.getCallerClass(), libname);
 855     }
 856 
 857     synchronized void loadLibrary0(Class<?> fromClass, String libname) {
 858         SecurityManager security = System.getSecurityManager();
 859         if (security != null) {
 860             security.checkLink(libname);
 861         }
 862         if (libname.indexOf((int)File.separatorChar) != -1) {
 863             throw new UnsatisfiedLinkError(
 864     "Directory separator should not appear in library name: " + libname);
 865         }
 866         ClassLoader.loadLibrary(fromClass, libname, false);
 867     }