744 * 745 * @param filename the file to load. 746 * @throws SecurityException if a security manager exists and its 747 * {@code checkLink} method doesn't allow 748 * loading of the specified dynamic library 749 * @throws UnsatisfiedLinkError if either the filename is not an 750 * absolute path name, the native library is not statically 751 * linked with the VM, or the library cannot be mapped to 752 * a native library image by the host system. 753 * @throws NullPointerException if {@code filename} is 754 * {@code null} 755 * @see java.lang.Runtime#getRuntime() 756 * @see java.lang.SecurityException 757 * @see java.lang.SecurityManager#checkLink(java.lang.String) 758 */ 759 @CallerSensitive 760 public void load(String filename) { 761 load0(Reflection.getCallerClass(), filename); 762 } 763 764 synchronized void load0(Class<?> fromClass, String filename) { 765 SecurityManager security = System.getSecurityManager(); 766 if (security != null) { 767 security.checkLink(filename); 768 } 769 if (!(new File(filename).isAbsolute())) { 770 throw new UnsatisfiedLinkError( 771 "Expecting an absolute path of the library: " + filename); 772 } 773 ClassLoader.loadLibrary(fromClass, filename, true); 774 } 775 776 /** 777 * Loads the native library specified by the {@code libname} 778 * argument. The {@code libname} argument must not contain any platform 779 * specific prefix, file extension or path. If a native library 780 * called {@code libname} is statically linked with the VM, then the 781 * JNI_OnLoad_{@code libname} function exported by the library is invoked. 782 * See the <a href="{@docRoot}/../specs/jni/index.html"> JNI Specification</a> 783 * for more details. 784 * 785 * Otherwise, the libname argument is loaded from a system library 786 * location and mapped to a native library image in an implementation- 787 * dependent manner. 788 * <p> 789 * First, if there is a security manager, its {@code checkLink} 790 * method is called with the {@code libname} as its argument. 791 * This may result in a security exception. 792 * <p> 793 * The method {@link System#loadLibrary(String)} is the conventional 808 * @param libname the name of the library. 809 * @throws SecurityException if a security manager exists and its 810 * {@code checkLink} method doesn't allow 811 * loading of the specified dynamic library 812 * @throws UnsatisfiedLinkError if either the libname argument 813 * contains a file path, the native library is not statically 814 * linked with the VM, or the library cannot be mapped to a 815 * native library image by the host system. 816 * @throws NullPointerException if {@code libname} is 817 * {@code null} 818 * @see java.lang.SecurityException 819 * @see java.lang.SecurityManager#checkLink(java.lang.String) 820 */ 821 @CallerSensitive 822 public void loadLibrary(String libname) { 823 loadLibrary0(Reflection.getCallerClass(), libname); 824 } 825 826 /** 827 * Panama specific: find library given name and lookup. 828 * See {@link jdk.internal.misc.JavaLangAccess#findLibrary(Lookup, String)}. 829 */ 830 Library findLibrary(MethodHandles.Lookup lookup, String libname) { 831 return loadLibrary0(lookup.lookupClass(), libname); 832 } 833 834 /** 835 * Panama specific: find default system library. 836 * See {@link JavaLangAccess#defaultLibrary()}. 837 */ 838 Library defaultLibrary() { 839 return NativeLibrary.defaultLibrary; 840 } 841 842 synchronized NativeLibrary loadLibrary0(Class<?> fromClass, String libname) { 843 SecurityManager security = System.getSecurityManager(); 844 if (security != null) { 845 security.checkLink(libname); 846 } 847 if (libname.indexOf((int)File.separatorChar) != -1) { 848 throw new UnsatisfiedLinkError( 849 "Directory separator should not appear in library name: " + libname); 850 } | 744 * 745 * @param filename the file to load. 746 * @throws SecurityException if a security manager exists and its 747 * {@code checkLink} method doesn't allow 748 * loading of the specified dynamic library 749 * @throws UnsatisfiedLinkError if either the filename is not an 750 * absolute path name, the native library is not statically 751 * linked with the VM, or the library cannot be mapped to 752 * a native library image by the host system. 753 * @throws NullPointerException if {@code filename} is 754 * {@code null} 755 * @see java.lang.Runtime#getRuntime() 756 * @see java.lang.SecurityException 757 * @see java.lang.SecurityManager#checkLink(java.lang.String) 758 */ 759 @CallerSensitive 760 public void load(String filename) { 761 load0(Reflection.getCallerClass(), filename); 762 } 763 764 synchronized NativeLibrary load0(Class<?> fromClass, String filename) { 765 SecurityManager security = System.getSecurityManager(); 766 if (security != null) { 767 security.checkLink(filename); 768 } 769 if (!(new File(filename).isAbsolute())) { 770 throw new UnsatisfiedLinkError( 771 "Expecting an absolute path of the library: " + filename); 772 } 773 return ClassLoader.loadLibrary(fromClass, filename, true); 774 } 775 776 /** 777 * Loads the native library specified by the {@code libname} 778 * argument. The {@code libname} argument must not contain any platform 779 * specific prefix, file extension or path. If a native library 780 * called {@code libname} is statically linked with the VM, then the 781 * JNI_OnLoad_{@code libname} function exported by the library is invoked. 782 * See the <a href="{@docRoot}/../specs/jni/index.html"> JNI Specification</a> 783 * for more details. 784 * 785 * Otherwise, the libname argument is loaded from a system library 786 * location and mapped to a native library image in an implementation- 787 * dependent manner. 788 * <p> 789 * First, if there is a security manager, its {@code checkLink} 790 * method is called with the {@code libname} as its argument. 791 * This may result in a security exception. 792 * <p> 793 * The method {@link System#loadLibrary(String)} is the conventional 808 * @param libname the name of the library. 809 * @throws SecurityException if a security manager exists and its 810 * {@code checkLink} method doesn't allow 811 * loading of the specified dynamic library 812 * @throws UnsatisfiedLinkError if either the libname argument 813 * contains a file path, the native library is not statically 814 * linked with the VM, or the library cannot be mapped to a 815 * native library image by the host system. 816 * @throws NullPointerException if {@code libname} is 817 * {@code null} 818 * @see java.lang.SecurityException 819 * @see java.lang.SecurityManager#checkLink(java.lang.String) 820 */ 821 @CallerSensitive 822 public void loadLibrary(String libname) { 823 loadLibrary0(Reflection.getCallerClass(), libname); 824 } 825 826 /** 827 * Panama specific: find library given name and lookup. 828 * See {@link jdk.internal.misc.JavaLangAccess#loadLibrary(Lookup, String)}. 829 */ 830 Library loadLibrary(MethodHandles.Lookup lookup, String libname) { 831 return loadLibrary0(lookup.lookupClass(), libname); 832 } 833 834 /** 835 * Panama specific: find default system library. 836 * See {@link JavaLangAccess#defaultLibrary()}. 837 */ 838 Library defaultLibrary() { 839 return NativeLibrary.defaultLibrary; 840 } 841 842 synchronized NativeLibrary loadLibrary0(Class<?> fromClass, String libname) { 843 SecurityManager security = System.getSecurityManager(); 844 if (security != null) { 845 security.checkLink(libname); 846 } 847 if (libname.indexOf((int)File.separatorChar) != -1) { 848 throw new UnsatisfiedLinkError( 849 "Directory separator should not appear in library name: " + libname); 850 } |