1 /*
2 * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
715 *
716 * @param filename the file to load.
717 * @throws SecurityException if a security manager exists and its
718 * {@code checkLink} method doesn't allow
719 * loading of the specified dynamic library
720 * @throws UnsatisfiedLinkError if either the filename is not an
721 * absolute path name, the native library is not statically
722 * linked with the VM, or the library cannot be mapped to
723 * a native library image by the host system.
724 * @throws NullPointerException if {@code filename} is
725 * {@code null}
726 * @see java.lang.Runtime#getRuntime()
727 * @see java.lang.SecurityException
728 * @see java.lang.SecurityManager#checkLink(java.lang.String)
729 */
730 @CallerSensitive
731 public void load(String filename) {
732 load0(Reflection.getCallerClass(), filename);
733 }
734
735 synchronized void load0(Class<?> fromClass, String filename) {
736 SecurityManager security = System.getSecurityManager();
737 if (security != null) {
738 security.checkLink(filename);
739 }
740 if (!(new File(filename).isAbsolute())) {
741 throw new UnsatisfiedLinkError(
742 "Expecting an absolute path of the library: " + filename);
743 }
744 ClassLoader.loadLibrary(fromClass, filename, true);
745 }
746
747 /**
748 * Loads the native library specified by the {@code libname}
749 * argument. The {@code libname} argument must not contain any platform
750 * specific prefix, file extension or path. If a native library
751 * called {@code libname} is statically linked with the VM, then the
752 * JNI_OnLoad_{@code libname} function exported by the library is invoked.
753 * See the <a href="{@docRoot}/../specs/jni/index.html"> JNI Specification</a>
754 * for more details.
755 *
777 * name, the second and subsequent calls are ignored.
778 *
779 * @param libname the name of the library.
780 * @throws SecurityException if a security manager exists and its
781 * {@code checkLink} method doesn't allow
782 * loading of the specified dynamic library
783 * @throws UnsatisfiedLinkError if either the libname argument
784 * contains a file path, the native library is not statically
785 * linked with the VM, or the library cannot be mapped to a
786 * native library image by the host system.
787 * @throws NullPointerException if {@code libname} is
788 * {@code null}
789 * @see java.lang.SecurityException
790 * @see java.lang.SecurityManager#checkLink(java.lang.String)
791 */
792 @CallerSensitive
793 public void loadLibrary(String libname) {
794 loadLibrary0(Reflection.getCallerClass(), libname);
795 }
796
797 synchronized void loadLibrary0(Class<?> fromClass, String libname) {
798 SecurityManager security = System.getSecurityManager();
799 if (security != null) {
800 security.checkLink(libname);
801 }
802 if (libname.indexOf((int)File.separatorChar) != -1) {
803 throw new UnsatisfiedLinkError(
804 "Directory separator should not appear in library name: " + libname);
805 }
806 ClassLoader.loadLibrary(fromClass, libname, false);
807 }
808
809 /**
810 * Returns the version of the Java Runtime Environment as a {@link Version}.
811 *
812 * @return the {@link Version} of the Java Runtime Environment
813 *
814 * @since 9
815 */
816 public static Version version() {
817 if (version == null) {
|
1 /*
2 * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2016-2019, Azul Systems, Inc. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation. Oracle designates this
9 * particular file as subject to the "Classpath" exception as provided
10 * by Oracle in the LICENSE file that accompanied this code.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23 * or visit www.oracle.com if you need additional information or have any
716 *
717 * @param filename the file to load.
718 * @throws SecurityException if a security manager exists and its
719 * {@code checkLink} method doesn't allow
720 * loading of the specified dynamic library
721 * @throws UnsatisfiedLinkError if either the filename is not an
722 * absolute path name, the native library is not statically
723 * linked with the VM, or the library cannot be mapped to
724 * a native library image by the host system.
725 * @throws NullPointerException if {@code filename} is
726 * {@code null}
727 * @see java.lang.Runtime#getRuntime()
728 * @see java.lang.SecurityException
729 * @see java.lang.SecurityManager#checkLink(java.lang.String)
730 */
731 @CallerSensitive
732 public void load(String filename) {
733 load0(Reflection.getCallerClass(), filename);
734 }
735
736 void load0(Class<?> fromClass, String filename) {
737 SecurityManager security = System.getSecurityManager();
738 if (security != null) {
739 security.checkLink(filename);
740 }
741 if (!(new File(filename).isAbsolute())) {
742 throw new UnsatisfiedLinkError(
743 "Expecting an absolute path of the library: " + filename);
744 }
745 ClassLoader.loadLibrary(fromClass, filename, true);
746 }
747
748 /**
749 * Loads the native library specified by the {@code libname}
750 * argument. The {@code libname} argument must not contain any platform
751 * specific prefix, file extension or path. If a native library
752 * called {@code libname} is statically linked with the VM, then the
753 * JNI_OnLoad_{@code libname} function exported by the library is invoked.
754 * See the <a href="{@docRoot}/../specs/jni/index.html"> JNI Specification</a>
755 * for more details.
756 *
778 * name, the second and subsequent calls are ignored.
779 *
780 * @param libname the name of the library.
781 * @throws SecurityException if a security manager exists and its
782 * {@code checkLink} method doesn't allow
783 * loading of the specified dynamic library
784 * @throws UnsatisfiedLinkError if either the libname argument
785 * contains a file path, the native library is not statically
786 * linked with the VM, or the library cannot be mapped to a
787 * native library image by the host system.
788 * @throws NullPointerException if {@code libname} is
789 * {@code null}
790 * @see java.lang.SecurityException
791 * @see java.lang.SecurityManager#checkLink(java.lang.String)
792 */
793 @CallerSensitive
794 public void loadLibrary(String libname) {
795 loadLibrary0(Reflection.getCallerClass(), libname);
796 }
797
798 void loadLibrary0(Class<?> fromClass, String libname) {
799 SecurityManager security = System.getSecurityManager();
800 if (security != null) {
801 security.checkLink(libname);
802 }
803 if (libname.indexOf((int)File.separatorChar) != -1) {
804 throw new UnsatisfiedLinkError(
805 "Directory separator should not appear in library name: " + libname);
806 }
807 ClassLoader.loadLibrary(fromClass, libname, false);
808 }
809
810 /**
811 * Returns the version of the Java Runtime Environment as a {@link Version}.
812 *
813 * @return the {@link Version} of the Java Runtime Environment
814 *
815 * @since 9
816 */
817 public static Version version() {
818 if (version == null) {
|