jaroslav@1258: /* jaroslav@1258: * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. jaroslav@1258: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@1258: * jaroslav@1258: * This code is free software; you can redistribute it and/or modify it jaroslav@1258: * under the terms of the GNU General Public License version 2 only, as jaroslav@1258: * published by the Free Software Foundation. Oracle designates this jaroslav@1258: * particular file as subject to the "Classpath" exception as provided jaroslav@1258: * by Oracle in the LICENSE file that accompanied this code. jaroslav@1258: * jaroslav@1258: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@1258: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@1258: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@1258: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@1258: * accompanied this code). jaroslav@1258: * jaroslav@1258: * You should have received a copy of the GNU General Public License version jaroslav@1258: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@1258: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@1258: * jaroslav@1258: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@1258: * or visit www.oracle.com if you need additional information or have any jaroslav@1258: * questions. jaroslav@1258: */ jaroslav@1258: package java.lang; jaroslav@1258: jaroslav@1258: import java.io.*; jaroslav@1258: import java.util.Properties; jaroslav@1258: import java.util.PropertyPermission; jaroslav@1258: import java.util.StringTokenizer; jaroslav@1258: import java.security.AccessController; jaroslav@1258: import java.security.PrivilegedAction; jaroslav@1258: import java.security.AllPermission; jaroslav@1258: import java.nio.channels.Channel; jaroslav@1258: import java.nio.channels.spi.SelectorProvider; jaroslav@1258: import sun.nio.ch.Interruptible; jaroslav@1258: import sun.reflect.Reflection; jaroslav@1258: import sun.security.util.SecurityConstants; jaroslav@1258: import sun.reflect.annotation.AnnotationType; jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * The System class contains several useful class fields jaroslav@1258: * and methods. It cannot be instantiated. jaroslav@1258: * jaroslav@1258: *

Among the facilities provided by the System class jaroslav@1258: * are standard input, standard output, and error output streams; jaroslav@1258: * access to externally defined properties and environment jaroslav@1258: * variables; a means of loading files and libraries; and a utility jaroslav@1258: * method for quickly copying a portion of an array. jaroslav@1258: * jaroslav@1258: * @author unascribed jaroslav@1258: * @since JDK1.0 jaroslav@1258: */ jaroslav@1258: public final class System { jaroslav@1258: jaroslav@1258: /* register the natives via the static initializer. jaroslav@1258: * jaroslav@1258: * VM will invoke the initializeSystemClass method to complete jaroslav@1258: * the initialization for this class separated from clinit. jaroslav@1258: * Note that to use properties set by the VM, see the constraints jaroslav@1258: * described in the initializeSystemClass method. jaroslav@1258: */ jaroslav@1258: private static native void registerNatives(); jaroslav@1258: static { jaroslav@1258: registerNatives(); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** Don't let anyone instantiate this class */ jaroslav@1258: private System() { jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * The "standard" input stream. This stream is already jaroslav@1258: * open and ready to supply input data. Typically this stream jaroslav@1258: * corresponds to keyboard input or another input source specified by jaroslav@1258: * the host environment or user. jaroslav@1258: */ jaroslav@1258: public final static InputStream in = null; jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * The "standard" output stream. This stream is already jaroslav@1258: * open and ready to accept output data. Typically this stream jaroslav@1258: * corresponds to display output or another output destination jaroslav@1258: * specified by the host environment or user. jaroslav@1258: *

jaroslav@1258: * For simple stand-alone Java applications, a typical way to write jaroslav@1258: * a line of output data is: jaroslav@1258: *

jaroslav@1258:      *     System.out.println(data)
jaroslav@1258:      * 
jaroslav@1258: *

jaroslav@1258: * See the println methods in class PrintStream. jaroslav@1258: * jaroslav@1258: * @see java.io.PrintStream#println() jaroslav@1258: * @see java.io.PrintStream#println(boolean) jaroslav@1258: * @see java.io.PrintStream#println(char) jaroslav@1258: * @see java.io.PrintStream#println(char[]) jaroslav@1258: * @see java.io.PrintStream#println(double) jaroslav@1258: * @see java.io.PrintStream#println(float) jaroslav@1258: * @see java.io.PrintStream#println(int) jaroslav@1258: * @see java.io.PrintStream#println(long) jaroslav@1258: * @see java.io.PrintStream#println(java.lang.Object) jaroslav@1258: * @see java.io.PrintStream#println(java.lang.String) jaroslav@1258: */ jaroslav@1258: public final static PrintStream out = null; jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * The "standard" error output stream. This stream is already jaroslav@1258: * open and ready to accept output data. jaroslav@1258: *

jaroslav@1258: * Typically this stream corresponds to display output or another jaroslav@1258: * output destination specified by the host environment or user. By jaroslav@1258: * convention, this output stream is used to display error messages jaroslav@1258: * or other information that should come to the immediate attention jaroslav@1258: * of a user even if the principal output stream, the value of the jaroslav@1258: * variable out, has been redirected to a file or other jaroslav@1258: * destination that is typically not continuously monitored. jaroslav@1258: */ jaroslav@1258: public final static PrintStream err = null; jaroslav@1258: jaroslav@1258: /* The security manager for the system. jaroslav@1258: */ jaroslav@1258: private static volatile SecurityManager security = null; jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Reassigns the "standard" input stream. jaroslav@1258: * jaroslav@1258: *

First, if there is a security manager, its checkPermission jaroslav@1258: * method is called with a RuntimePermission("setIO") permission jaroslav@1258: * to see if it's ok to reassign the "standard" input stream. jaroslav@1258: *

jaroslav@1258: * jaroslav@1258: * @param in the new standard input stream. jaroslav@1258: * jaroslav@1258: * @throws SecurityException jaroslav@1258: * if a security manager exists and its jaroslav@1258: * checkPermission method doesn't allow jaroslav@1258: * reassigning of the standard input stream. jaroslav@1258: * jaroslav@1258: * @see SecurityManager#checkPermission jaroslav@1258: * @see java.lang.RuntimePermission jaroslav@1258: * jaroslav@1258: * @since JDK1.1 jaroslav@1258: */ jaroslav@1258: public static void setIn(InputStream in) { jaroslav@1258: checkIO(); jaroslav@1258: setIn0(in); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Reassigns the "standard" output stream. jaroslav@1258: * jaroslav@1258: *

First, if there is a security manager, its checkPermission jaroslav@1258: * method is called with a RuntimePermission("setIO") permission jaroslav@1258: * to see if it's ok to reassign the "standard" output stream. jaroslav@1258: * jaroslav@1258: * @param out the new standard output stream jaroslav@1258: * jaroslav@1258: * @throws SecurityException jaroslav@1258: * if a security manager exists and its jaroslav@1258: * checkPermission method doesn't allow jaroslav@1258: * reassigning of the standard output stream. jaroslav@1258: * jaroslav@1258: * @see SecurityManager#checkPermission jaroslav@1258: * @see java.lang.RuntimePermission jaroslav@1258: * jaroslav@1258: * @since JDK1.1 jaroslav@1258: */ jaroslav@1258: public static void setOut(PrintStream out) { jaroslav@1258: checkIO(); jaroslav@1258: setOut0(out); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Reassigns the "standard" error output stream. jaroslav@1258: * jaroslav@1258: *

First, if there is a security manager, its checkPermission jaroslav@1258: * method is called with a RuntimePermission("setIO") permission jaroslav@1258: * to see if it's ok to reassign the "standard" error output stream. jaroslav@1258: * jaroslav@1258: * @param err the new standard error output stream. jaroslav@1258: * jaroslav@1258: * @throws SecurityException jaroslav@1258: * if a security manager exists and its jaroslav@1258: * checkPermission method doesn't allow jaroslav@1258: * reassigning of the standard error output stream. jaroslav@1258: * jaroslav@1258: * @see SecurityManager#checkPermission jaroslav@1258: * @see java.lang.RuntimePermission jaroslav@1258: * jaroslav@1258: * @since JDK1.1 jaroslav@1258: */ jaroslav@1258: public static void setErr(PrintStream err) { jaroslav@1258: checkIO(); jaroslav@1258: setErr0(err); jaroslav@1258: } jaroslav@1258: jaroslav@1258: private static volatile Console cons = null; jaroslav@1258: /** jaroslav@1258: * Returns the unique {@link java.io.Console Console} object associated jaroslav@1258: * with the current Java virtual machine, if any. jaroslav@1258: * jaroslav@1258: * @return The system console, if any, otherwise null. jaroslav@1258: * jaroslav@1258: * @since 1.6 jaroslav@1258: */ jaroslav@1258: public static Console console() { jaroslav@1258: if (cons == null) { jaroslav@1258: synchronized (System.class) { jaroslav@1258: cons = sun.misc.SharedSecrets.getJavaIOAccess().console(); jaroslav@1258: } jaroslav@1258: } jaroslav@1258: return cons; jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Returns the channel inherited from the entity that created this jaroslav@1258: * Java virtual machine. jaroslav@1258: * jaroslav@1258: *

This method returns the channel obtained by invoking the jaroslav@1258: * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel jaroslav@1258: * inheritedChannel} method of the system-wide default jaroslav@1258: * {@link java.nio.channels.spi.SelectorProvider} object.

jaroslav@1258: * jaroslav@1258: *

In addition to the network-oriented channels described in jaroslav@1258: * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel jaroslav@1258: * inheritedChannel}, this method may return other kinds of jaroslav@1258: * channels in the future. jaroslav@1258: * jaroslav@1258: * @return The inherited channel, if any, otherwise null. jaroslav@1258: * jaroslav@1258: * @throws IOException jaroslav@1258: * If an I/O error occurs jaroslav@1258: * jaroslav@1258: * @throws SecurityException jaroslav@1258: * If a security manager is present and it does not jaroslav@1258: * permit access to the channel. jaroslav@1258: * jaroslav@1258: * @since 1.5 jaroslav@1258: */ jaroslav@1258: public static Channel inheritedChannel() throws IOException { jaroslav@1258: return SelectorProvider.provider().inheritedChannel(); jaroslav@1258: } jaroslav@1258: jaroslav@1258: private static void checkIO() { jaroslav@1258: SecurityManager sm = getSecurityManager(); jaroslav@1258: if (sm != null) { jaroslav@1258: sm.checkPermission(new RuntimePermission("setIO")); jaroslav@1258: } jaroslav@1258: } jaroslav@1258: jaroslav@1258: private static native void setIn0(InputStream in); jaroslav@1258: private static native void setOut0(PrintStream out); jaroslav@1258: private static native void setErr0(PrintStream err); jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Sets the System security. jaroslav@1258: * jaroslav@1258: *

If there is a security manager already installed, this method first jaroslav@1258: * calls the security manager's checkPermission method jaroslav@1258: * with a RuntimePermission("setSecurityManager") jaroslav@1258: * permission to ensure it's ok to replace the existing jaroslav@1258: * security manager. jaroslav@1258: * This may result in throwing a SecurityException. jaroslav@1258: * jaroslav@1258: *

Otherwise, the argument is established as the current jaroslav@1258: * security manager. If the argument is null and no jaroslav@1258: * security manager has been established, then no action is taken and jaroslav@1258: * the method simply returns. jaroslav@1258: * jaroslav@1258: * @param s the security manager. jaroslav@1258: * @exception SecurityException if the security manager has already jaroslav@1258: * been set and its checkPermission method jaroslav@1258: * doesn't allow it to be replaced. jaroslav@1258: * @see #getSecurityManager jaroslav@1258: * @see SecurityManager#checkPermission jaroslav@1258: * @see java.lang.RuntimePermission jaroslav@1258: */ jaroslav@1258: public static jaroslav@1258: void setSecurityManager(final SecurityManager s) { jaroslav@1258: try { jaroslav@1258: s.checkPackageAccess("java.lang"); jaroslav@1258: } catch (Exception e) { jaroslav@1258: // no-op jaroslav@1258: } jaroslav@1258: setSecurityManager0(s); jaroslav@1258: } jaroslav@1258: jaroslav@1258: private static synchronized jaroslav@1258: void setSecurityManager0(final SecurityManager s) { jaroslav@1258: SecurityManager sm = getSecurityManager(); jaroslav@1258: if (sm != null) { jaroslav@1258: // ask the currently installed security manager if we jaroslav@1258: // can replace it. jaroslav@1258: sm.checkPermission(new RuntimePermission jaroslav@1258: ("setSecurityManager")); jaroslav@1258: } jaroslav@1258: jaroslav@1258: if ((s != null) && (s.getClass().getClassLoader() != null)) { jaroslav@1258: // New security manager class is not on bootstrap classpath. jaroslav@1258: // Cause policy to get initialized before we install the new jaroslav@1258: // security manager, in order to prevent infinite loops when jaroslav@1258: // trying to initialize the policy (which usually involves jaroslav@1258: // accessing some security and/or system properties, which in turn jaroslav@1258: // calls the installed security manager's checkPermission method jaroslav@1258: // which will loop infinitely if there is a non-system class jaroslav@1258: // (in this case: the new security manager class) on the stack). jaroslav@1258: AccessController.doPrivileged(new PrivilegedAction() { jaroslav@1258: public Object run() { jaroslav@1258: s.getClass().getProtectionDomain().implies jaroslav@1258: (SecurityConstants.ALL_PERMISSION); jaroslav@1258: return null; jaroslav@1258: } jaroslav@1258: }); jaroslav@1258: } jaroslav@1258: jaroslav@1258: security = s; jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Gets the system security interface. jaroslav@1258: * jaroslav@1258: * @return if a security manager has already been established for the jaroslav@1258: * current application, then that security manager is returned; jaroslav@1258: * otherwise, null is returned. jaroslav@1258: * @see #setSecurityManager jaroslav@1258: */ jaroslav@1258: public static SecurityManager getSecurityManager() { jaroslav@1258: return security; jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Returns the current time in milliseconds. Note that jaroslav@1258: * while the unit of time of the return value is a millisecond, jaroslav@1258: * the granularity of the value depends on the underlying jaroslav@1258: * operating system and may be larger. For example, many jaroslav@1258: * operating systems measure time in units of tens of jaroslav@1258: * milliseconds. jaroslav@1258: * jaroslav@1258: *

See the description of the class Date for jaroslav@1258: * a discussion of slight discrepancies that may arise between jaroslav@1258: * "computer time" and coordinated universal time (UTC). jaroslav@1258: * jaroslav@1258: * @return the difference, measured in milliseconds, between jaroslav@1258: * the current time and midnight, January 1, 1970 UTC. jaroslav@1258: * @see java.util.Date jaroslav@1258: */ jaroslav@1258: public static native long currentTimeMillis(); jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Returns the current value of the running Java Virtual Machine's jaroslav@1258: * high-resolution time source, in nanoseconds. jaroslav@1258: * jaroslav@1258: *

This method can only be used to measure elapsed time and is jaroslav@1258: * not related to any other notion of system or wall-clock time. jaroslav@1258: * The value returned represents nanoseconds since some fixed but jaroslav@1258: * arbitrary origin time (perhaps in the future, so values jaroslav@1258: * may be negative). The same origin is used by all invocations of jaroslav@1258: * this method in an instance of a Java virtual machine; other jaroslav@1258: * virtual machine instances are likely to use a different origin. jaroslav@1258: * jaroslav@1258: *

This method provides nanosecond precision, but not necessarily jaroslav@1258: * nanosecond resolution (that is, how frequently the value changes) jaroslav@1258: * - no guarantees are made except that the resolution is at least as jaroslav@1258: * good as that of {@link #currentTimeMillis()}. jaroslav@1258: * jaroslav@1258: *

Differences in successive calls that span greater than jaroslav@1258: * approximately 292 years (263 nanoseconds) will not jaroslav@1258: * correctly compute elapsed time due to numerical overflow. jaroslav@1258: * jaroslav@1258: *

The values returned by this method become meaningful only when jaroslav@1258: * the difference between two such values, obtained within the same jaroslav@1258: * instance of a Java virtual machine, is computed. jaroslav@1258: * jaroslav@1258: *

For example, to measure how long some code takes to execute: jaroslav@1258: *

 {@code
jaroslav@1258:      * long startTime = System.nanoTime();
jaroslav@1258:      * // ... the code being measured ...
jaroslav@1258:      * long estimatedTime = System.nanoTime() - startTime;}
jaroslav@1258: * jaroslav@1258: *

To compare two nanoTime values jaroslav@1258: *

 {@code
jaroslav@1258:      * long t0 = System.nanoTime();
jaroslav@1258:      * ...
jaroslav@1258:      * long t1 = System.nanoTime();}
jaroslav@1258: * jaroslav@1258: * one should use {@code t1 - t0 < 0}, not {@code t1 < t0}, jaroslav@1258: * because of the possibility of numerical overflow. jaroslav@1258: * jaroslav@1258: * @return the current value of the running Java Virtual Machine's jaroslav@1258: * high-resolution time source, in nanoseconds jaroslav@1258: * @since 1.5 jaroslav@1258: */ jaroslav@1258: public static native long nanoTime(); jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Copies an array from the specified source array, beginning at the jaroslav@1258: * specified position, to the specified position of the destination array. jaroslav@1258: * A subsequence of array components are copied from the source jaroslav@1258: * array referenced by src to the destination array jaroslav@1258: * referenced by dest. The number of components copied is jaroslav@1258: * equal to the length argument. The components at jaroslav@1258: * positions srcPos through jaroslav@1258: * srcPos+length-1 in the source array are copied into jaroslav@1258: * positions destPos through jaroslav@1258: * destPos+length-1, respectively, of the destination jaroslav@1258: * array. jaroslav@1258: *

jaroslav@1258: * If the src and dest arguments refer to the jaroslav@1258: * same array object, then the copying is performed as if the jaroslav@1258: * components at positions srcPos through jaroslav@1258: * srcPos+length-1 were first copied to a temporary jaroslav@1258: * array with length components and then the contents of jaroslav@1258: * the temporary array were copied into positions jaroslav@1258: * destPos through destPos+length-1 of the jaroslav@1258: * destination array. jaroslav@1258: *

jaroslav@1258: * If dest is null, then a jaroslav@1258: * NullPointerException is thrown. jaroslav@1258: *

jaroslav@1258: * If src is null, then a jaroslav@1258: * NullPointerException is thrown and the destination jaroslav@1258: * array is not modified. jaroslav@1258: *

jaroslav@1258: * Otherwise, if any of the following is true, an jaroslav@1258: * ArrayStoreException is thrown and the destination is jaroslav@1258: * not modified: jaroslav@1258: *

jaroslav@1258: *

jaroslav@1258: * Otherwise, if any of the following is true, an jaroslav@1258: * IndexOutOfBoundsException is jaroslav@1258: * thrown and the destination is not modified: jaroslav@1258: *

jaroslav@1258: *

jaroslav@1258: * Otherwise, if any actual component of the source array from jaroslav@1258: * position srcPos through jaroslav@1258: * srcPos+length-1 cannot be converted to the component jaroslav@1258: * type of the destination array by assignment conversion, an jaroslav@1258: * ArrayStoreException is thrown. In this case, let jaroslav@1258: * k be the smallest nonnegative integer less than jaroslav@1258: * length such that src[srcPos+k] jaroslav@1258: * cannot be converted to the component type of the destination jaroslav@1258: * array; when the exception is thrown, source array components from jaroslav@1258: * positions srcPos through jaroslav@1258: * srcPos+k-1 jaroslav@1258: * will already have been copied to destination array positions jaroslav@1258: * destPos through jaroslav@1258: * destPos+k-1 and no other jaroslav@1258: * positions of the destination array will have been modified. jaroslav@1258: * (Because of the restrictions already itemized, this jaroslav@1258: * paragraph effectively applies only to the situation where both jaroslav@1258: * arrays have component types that are reference types.) jaroslav@1258: * jaroslav@1258: * @param src the source array. jaroslav@1258: * @param srcPos starting position in the source array. jaroslav@1258: * @param dest the destination array. jaroslav@1258: * @param destPos starting position in the destination data. jaroslav@1258: * @param length the number of array elements to be copied. jaroslav@1258: * @exception IndexOutOfBoundsException if copying would cause jaroslav@1258: * access of data outside array bounds. jaroslav@1258: * @exception ArrayStoreException if an element in the src jaroslav@1258: * array could not be stored into the dest array jaroslav@1258: * because of a type mismatch. jaroslav@1258: * @exception NullPointerException if either src or jaroslav@1258: * dest is null. jaroslav@1258: */ jaroslav@1258: public static native void arraycopy(Object src, int srcPos, jaroslav@1258: Object dest, int destPos, jaroslav@1258: int length); jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Returns the same hash code for the given object as jaroslav@1258: * would be returned by the default method hashCode(), jaroslav@1258: * whether or not the given object's class overrides jaroslav@1258: * hashCode(). jaroslav@1258: * The hash code for the null reference is zero. jaroslav@1258: * jaroslav@1258: * @param x object for which the hashCode is to be calculated jaroslav@1258: * @return the hashCode jaroslav@1258: * @since JDK1.1 jaroslav@1258: */ jaroslav@1258: public static native int identityHashCode(Object x); jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * System properties. The following properties are guaranteed to be defined: jaroslav@1258: *

jaroslav@1258: *
java.version
Java version number jaroslav@1258: *
java.vendor
Java vendor specific string jaroslav@1258: *
java.vendor.url
Java vendor URL jaroslav@1258: *
java.home
Java installation directory jaroslav@1258: *
java.class.version
Java class version number jaroslav@1258: *
java.class.path
Java classpath jaroslav@1258: *
os.name
Operating System Name jaroslav@1258: *
os.arch
Operating System Architecture jaroslav@1258: *
os.version
Operating System Version jaroslav@1258: *
file.separator
File separator ("/" on Unix) jaroslav@1258: *
path.separator
Path separator (":" on Unix) jaroslav@1258: *
line.separator
Line separator ("\n" on Unix) jaroslav@1258: *
user.name
User account name jaroslav@1258: *
user.home
User home directory jaroslav@1258: *
user.dir
User's current working directory jaroslav@1258: *
jaroslav@1258: */ jaroslav@1258: jaroslav@1258: private static Properties props; jaroslav@1258: private static native Properties initProperties(Properties props); jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Determines the current system properties. jaroslav@1258: *

jaroslav@1258: * First, if there is a security manager, its jaroslav@1258: * checkPropertiesAccess method is called with no jaroslav@1258: * arguments. This may result in a security exception. jaroslav@1258: *

jaroslav@1258: * The current set of system properties for use by the jaroslav@1258: * {@link #getProperty(String)} method is returned as a jaroslav@1258: * Properties object. If there is no current set of jaroslav@1258: * system properties, a set of system properties is first created and jaroslav@1258: * initialized. This set of system properties always includes values jaroslav@1258: * for the following keys: jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: * jaroslav@1258: *
KeyDescription of Associated Value
java.versionJava Runtime Environment version
java.vendorJava Runtime Environment vendor
java.vendor.urlJava vendor URL
java.homeJava installation directory
java.vm.specification.versionJava Virtual Machine specification version
java.vm.specification.vendorJava Virtual Machine specification vendor
java.vm.specification.nameJava Virtual Machine specification name
java.vm.versionJava Virtual Machine implementation version
java.vm.vendorJava Virtual Machine implementation vendor
java.vm.nameJava Virtual Machine implementation name
java.specification.versionJava Runtime Environment specification version
java.specification.vendorJava Runtime Environment specification vendor
java.specification.nameJava Runtime Environment specification name
java.class.versionJava class format version number
java.class.pathJava class path
java.library.pathList of paths to search when loading libraries
java.io.tmpdirDefault temp file path
java.compilerName of JIT compiler to use
java.ext.dirsPath of extension directory or directories
os.nameOperating system name
os.archOperating system architecture
os.versionOperating system version
file.separatorFile separator ("/" on UNIX)
path.separatorPath separator (":" on UNIX)
line.separatorLine separator ("\n" on UNIX)
user.nameUser's account name
user.homeUser's home directory
user.dirUser's current working directory
jaroslav@1258: *

jaroslav@1258: * Multiple paths in a system property value are separated by the path jaroslav@1258: * separator character of the platform. jaroslav@1258: *

jaroslav@1258: * Note that even if the security manager does not permit the jaroslav@1258: * getProperties operation, it may choose to permit the jaroslav@1258: * {@link #getProperty(String)} operation. jaroslav@1258: * jaroslav@1258: * @return the system properties jaroslav@1258: * @exception SecurityException if a security manager exists and its jaroslav@1258: * checkPropertiesAccess method doesn't allow access jaroslav@1258: * to the system properties. jaroslav@1258: * @see #setProperties jaroslav@1258: * @see java.lang.SecurityException jaroslav@1258: * @see java.lang.SecurityManager#checkPropertiesAccess() jaroslav@1258: * @see java.util.Properties jaroslav@1258: */ jaroslav@1258: public static Properties getProperties() { jaroslav@1258: SecurityManager sm = getSecurityManager(); jaroslav@1258: if (sm != null) { jaroslav@1258: sm.checkPropertiesAccess(); jaroslav@1258: } jaroslav@1258: jaroslav@1258: return props; jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Returns the system-dependent line separator string. It always jaroslav@1258: * returns the same value - the initial value of the {@linkplain jaroslav@1258: * #getProperty(String) system property} {@code line.separator}. jaroslav@1258: * jaroslav@1258: *

On UNIX systems, it returns {@code "\n"}; on Microsoft jaroslav@1258: * Windows systems it returns {@code "\r\n"}. jaroslav@1258: */ jaroslav@1258: public static String lineSeparator() { jaroslav@1258: return lineSeparator; jaroslav@1258: } jaroslav@1258: jaroslav@1258: private static String lineSeparator; jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Sets the system properties to the Properties jaroslav@1258: * argument. jaroslav@1258: *

jaroslav@1258: * First, if there is a security manager, its jaroslav@1258: * checkPropertiesAccess method is called with no jaroslav@1258: * arguments. This may result in a security exception. jaroslav@1258: *

jaroslav@1258: * The argument becomes the current set of system properties for use jaroslav@1258: * by the {@link #getProperty(String)} method. If the argument is jaroslav@1258: * null, then the current set of system properties is jaroslav@1258: * forgotten. jaroslav@1258: * jaroslav@1258: * @param props the new system properties. jaroslav@1258: * @exception SecurityException if a security manager exists and its jaroslav@1258: * checkPropertiesAccess method doesn't allow access jaroslav@1258: * to the system properties. jaroslav@1258: * @see #getProperties jaroslav@1258: * @see java.util.Properties jaroslav@1258: * @see java.lang.SecurityException jaroslav@1258: * @see java.lang.SecurityManager#checkPropertiesAccess() jaroslav@1258: */ jaroslav@1258: public static void setProperties(Properties props) { jaroslav@1258: SecurityManager sm = getSecurityManager(); jaroslav@1258: if (sm != null) { jaroslav@1258: sm.checkPropertiesAccess(); jaroslav@1258: } jaroslav@1258: if (props == null) { jaroslav@1258: props = new Properties(); jaroslav@1258: initProperties(props); jaroslav@1258: } jaroslav@1258: System.props = props; jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Gets the system property indicated by the specified key. jaroslav@1258: *

jaroslav@1258: * First, if there is a security manager, its jaroslav@1258: * checkPropertyAccess method is called with the key as jaroslav@1258: * its argument. This may result in a SecurityException. jaroslav@1258: *

jaroslav@1258: * If there is no current set of system properties, a set of system jaroslav@1258: * properties is first created and initialized in the same manner as jaroslav@1258: * for the getProperties method. jaroslav@1258: * jaroslav@1258: * @param key the name of the system property. jaroslav@1258: * @return the string value of the system property, jaroslav@1258: * or null if there is no property with that key. jaroslav@1258: * jaroslav@1258: * @exception SecurityException if a security manager exists and its jaroslav@1258: * checkPropertyAccess method doesn't allow jaroslav@1258: * access to the specified system property. jaroslav@1258: * @exception NullPointerException if key is jaroslav@1258: * null. jaroslav@1258: * @exception IllegalArgumentException if key is empty. jaroslav@1258: * @see #setProperty jaroslav@1258: * @see java.lang.SecurityException jaroslav@1258: * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) jaroslav@1258: * @see java.lang.System#getProperties() jaroslav@1258: */ jaroslav@1258: public static String getProperty(String key) { jaroslav@1258: checkKey(key); jaroslav@1258: SecurityManager sm = getSecurityManager(); jaroslav@1258: if (sm != null) { jaroslav@1258: sm.checkPropertyAccess(key); jaroslav@1258: } jaroslav@1258: jaroslav@1258: return props.getProperty(key); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Gets the system property indicated by the specified key. jaroslav@1258: *

jaroslav@1258: * First, if there is a security manager, its jaroslav@1258: * checkPropertyAccess method is called with the jaroslav@1258: * key as its argument. jaroslav@1258: *

jaroslav@1258: * If there is no current set of system properties, a set of system jaroslav@1258: * properties is first created and initialized in the same manner as jaroslav@1258: * for the getProperties method. jaroslav@1258: * jaroslav@1258: * @param key the name of the system property. jaroslav@1258: * @param def a default value. jaroslav@1258: * @return the string value of the system property, jaroslav@1258: * or the default value if there is no property with that key. jaroslav@1258: * jaroslav@1258: * @exception SecurityException if a security manager exists and its jaroslav@1258: * checkPropertyAccess method doesn't allow jaroslav@1258: * access to the specified system property. jaroslav@1258: * @exception NullPointerException if key is jaroslav@1258: * null. jaroslav@1258: * @exception IllegalArgumentException if key is empty. jaroslav@1258: * @see #setProperty jaroslav@1258: * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) jaroslav@1258: * @see java.lang.System#getProperties() jaroslav@1258: */ jaroslav@1258: public static String getProperty(String key, String def) { jaroslav@1258: checkKey(key); jaroslav@1258: SecurityManager sm = getSecurityManager(); jaroslav@1258: if (sm != null) { jaroslav@1258: sm.checkPropertyAccess(key); jaroslav@1258: } jaroslav@1258: jaroslav@1258: return props.getProperty(key, def); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Sets the system property indicated by the specified key. jaroslav@1258: *

jaroslav@1258: * First, if a security manager exists, its jaroslav@1258: * SecurityManager.checkPermission method jaroslav@1258: * is called with a PropertyPermission(key, "write") jaroslav@1258: * permission. This may result in a SecurityException being thrown. jaroslav@1258: * If no exception is thrown, the specified property is set to the given jaroslav@1258: * value. jaroslav@1258: *

jaroslav@1258: * jaroslav@1258: * @param key the name of the system property. jaroslav@1258: * @param value the value of the system property. jaroslav@1258: * @return the previous value of the system property, jaroslav@1258: * or null if it did not have one. jaroslav@1258: * jaroslav@1258: * @exception SecurityException if a security manager exists and its jaroslav@1258: * checkPermission method doesn't allow jaroslav@1258: * setting of the specified property. jaroslav@1258: * @exception NullPointerException if key or jaroslav@1258: * value is null. jaroslav@1258: * @exception IllegalArgumentException if key is empty. jaroslav@1258: * @see #getProperty jaroslav@1258: * @see java.lang.System#getProperty(java.lang.String) jaroslav@1258: * @see java.lang.System#getProperty(java.lang.String, java.lang.String) jaroslav@1258: * @see java.util.PropertyPermission jaroslav@1258: * @see SecurityManager#checkPermission jaroslav@1258: * @since 1.2 jaroslav@1258: */ jaroslav@1258: public static String setProperty(String key, String value) { jaroslav@1258: checkKey(key); jaroslav@1258: SecurityManager sm = getSecurityManager(); jaroslav@1258: if (sm != null) { jaroslav@1258: sm.checkPermission(new PropertyPermission(key, jaroslav@1258: SecurityConstants.PROPERTY_WRITE_ACTION)); jaroslav@1258: } jaroslav@1258: jaroslav@1258: return (String) props.setProperty(key, value); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Removes the system property indicated by the specified key. jaroslav@1258: *

jaroslav@1258: * First, if a security manager exists, its jaroslav@1258: * SecurityManager.checkPermission method jaroslav@1258: * is called with a PropertyPermission(key, "write") jaroslav@1258: * permission. This may result in a SecurityException being thrown. jaroslav@1258: * If no exception is thrown, the specified property is removed. jaroslav@1258: *

jaroslav@1258: * jaroslav@1258: * @param key the name of the system property to be removed. jaroslav@1258: * @return the previous string value of the system property, jaroslav@1258: * or null if there was no property with that key. jaroslav@1258: * jaroslav@1258: * @exception SecurityException if a security manager exists and its jaroslav@1258: * checkPropertyAccess method doesn't allow jaroslav@1258: * access to the specified system property. jaroslav@1258: * @exception NullPointerException if key is jaroslav@1258: * null. jaroslav@1258: * @exception IllegalArgumentException if key is empty. jaroslav@1258: * @see #getProperty jaroslav@1258: * @see #setProperty jaroslav@1258: * @see java.util.Properties jaroslav@1258: * @see java.lang.SecurityException jaroslav@1258: * @see java.lang.SecurityManager#checkPropertiesAccess() jaroslav@1258: * @since 1.5 jaroslav@1258: */ jaroslav@1258: public static String clearProperty(String key) { jaroslav@1258: checkKey(key); jaroslav@1258: SecurityManager sm = getSecurityManager(); jaroslav@1258: if (sm != null) { jaroslav@1258: sm.checkPermission(new PropertyPermission(key, "write")); jaroslav@1258: } jaroslav@1258: jaroslav@1258: return (String) props.remove(key); jaroslav@1258: } jaroslav@1258: jaroslav@1258: private static void checkKey(String key) { jaroslav@1258: if (key == null) { jaroslav@1258: throw new NullPointerException("key can't be null"); jaroslav@1258: } jaroslav@1258: if (key.equals("")) { jaroslav@1258: throw new IllegalArgumentException("key can't be empty"); jaroslav@1258: } jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Gets the value of the specified environment variable. An jaroslav@1258: * environment variable is a system-dependent external named jaroslav@1258: * value. jaroslav@1258: * jaroslav@1258: *

If a security manager exists, its jaroslav@1258: * {@link SecurityManager#checkPermission checkPermission} jaroslav@1258: * method is called with a jaroslav@1258: * {@link RuntimePermission}("getenv."+name) jaroslav@1258: * permission. This may result in a {@link SecurityException} jaroslav@1258: * being thrown. If no exception is thrown the value of the jaroslav@1258: * variable name is returned. jaroslav@1258: * jaroslav@1258: *

System jaroslav@1258: * properties and environment variables are both jaroslav@1258: * conceptually mappings between names and values. Both jaroslav@1258: * mechanisms can be used to pass user-defined information to a jaroslav@1258: * Java process. Environment variables have a more global effect, jaroslav@1258: * because they are visible to all descendants of the process jaroslav@1258: * which defines them, not just the immediate Java subprocess. jaroslav@1258: * They can have subtly different semantics, such as case jaroslav@1258: * insensitivity, on different operating systems. For these jaroslav@1258: * reasons, environment variables are more likely to have jaroslav@1258: * unintended side effects. It is best to use system properties jaroslav@1258: * where possible. Environment variables should be used when a jaroslav@1258: * global effect is desired, or when an external system interface jaroslav@1258: * requires an environment variable (such as PATH). jaroslav@1258: * jaroslav@1258: *

On UNIX systems the alphabetic case of name is jaroslav@1258: * typically significant, while on Microsoft Windows systems it is jaroslav@1258: * typically not. For example, the expression jaroslav@1258: * System.getenv("FOO").equals(System.getenv("foo")) jaroslav@1258: * is likely to be true on Microsoft Windows. jaroslav@1258: * jaroslav@1258: * @param name the name of the environment variable jaroslav@1258: * @return the string value of the variable, or null jaroslav@1258: * if the variable is not defined in the system environment jaroslav@1258: * @throws NullPointerException if name is null jaroslav@1258: * @throws SecurityException jaroslav@1258: * if a security manager exists and its jaroslav@1258: * {@link SecurityManager#checkPermission checkPermission} jaroslav@1258: * method doesn't allow access to the environment variable jaroslav@1258: * name jaroslav@1258: * @see #getenv() jaroslav@1258: * @see ProcessBuilder#environment() jaroslav@1258: */ jaroslav@1258: public static String getenv(String name) { jaroslav@1258: SecurityManager sm = getSecurityManager(); jaroslav@1258: if (sm != null) { jaroslav@1258: sm.checkPermission(new RuntimePermission("getenv."+name)); jaroslav@1258: } jaroslav@1258: jaroslav@1258: return ProcessEnvironment.getenv(name); jaroslav@1258: } jaroslav@1258: jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Returns an unmodifiable string map view of the current system environment. jaroslav@1258: * The environment is a system-dependent mapping from names to jaroslav@1258: * values which is passed from parent to child processes. jaroslav@1258: * jaroslav@1258: *

If the system does not support environment variables, an jaroslav@1258: * empty map is returned. jaroslav@1258: * jaroslav@1258: *

The returned map will never contain null keys or values. jaroslav@1258: * Attempting to query the presence of a null key or value will jaroslav@1258: * throw a {@link NullPointerException}. Attempting to query jaroslav@1258: * the presence of a key or value which is not of type jaroslav@1258: * {@link String} will throw a {@link ClassCastException}. jaroslav@1258: * jaroslav@1258: *

The returned map and its collection views may not obey the jaroslav@1258: * general contract of the {@link Object#equals} and jaroslav@1258: * {@link Object#hashCode} methods. jaroslav@1258: * jaroslav@1258: *

The returned map is typically case-sensitive on all platforms. jaroslav@1258: * jaroslav@1258: *

If a security manager exists, its jaroslav@1258: * {@link SecurityManager#checkPermission checkPermission} jaroslav@1258: * method is called with a jaroslav@1258: * {@link RuntimePermission}("getenv.*") jaroslav@1258: * permission. This may result in a {@link SecurityException} being jaroslav@1258: * thrown. jaroslav@1258: * jaroslav@1258: *

When passing information to a Java subprocess, jaroslav@1258: * system properties jaroslav@1258: * are generally preferred over environment variables. jaroslav@1258: * jaroslav@1258: * @return the environment as a map of variable names to values jaroslav@1258: * @throws SecurityException jaroslav@1258: * if a security manager exists and its jaroslav@1258: * {@link SecurityManager#checkPermission checkPermission} jaroslav@1258: * method doesn't allow access to the process environment jaroslav@1258: * @see #getenv(String) jaroslav@1258: * @see ProcessBuilder#environment() jaroslav@1258: * @since 1.5 jaroslav@1258: */ jaroslav@1258: public static java.util.Map getenv() { jaroslav@1258: SecurityManager sm = getSecurityManager(); jaroslav@1258: if (sm != null) { jaroslav@1258: sm.checkPermission(new RuntimePermission("getenv.*")); jaroslav@1258: } jaroslav@1258: jaroslav@1258: return ProcessEnvironment.getenv(); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Terminates the currently running Java Virtual Machine. The jaroslav@1258: * argument serves as a status code; by convention, a nonzero status jaroslav@1258: * code indicates abnormal termination. jaroslav@1258: *

jaroslav@1258: * This method calls the exit method in class jaroslav@1258: * Runtime. This method never returns normally. jaroslav@1258: *

jaroslav@1258: * The call System.exit(n) is effectively equivalent to jaroslav@1258: * the call: jaroslav@1258: *

jaroslav@1258:      * Runtime.getRuntime().exit(n)
jaroslav@1258:      * 
jaroslav@1258: * jaroslav@1258: * @param status exit status. jaroslav@1258: * @throws SecurityException jaroslav@1258: * if a security manager exists and its checkExit jaroslav@1258: * method doesn't allow exit with the specified status. jaroslav@1258: * @see java.lang.Runtime#exit(int) jaroslav@1258: */ jaroslav@1258: public static void exit(int status) { jaroslav@1258: Runtime.getRuntime().exit(status); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Runs the garbage collector. jaroslav@1258: *

jaroslav@1258: * Calling the gc method suggests that the Java Virtual jaroslav@1258: * Machine expend effort toward recycling unused objects in order to jaroslav@1258: * make the memory they currently occupy available for quick reuse. jaroslav@1258: * When control returns from the method call, the Java Virtual jaroslav@1258: * Machine has made a best effort to reclaim space from all discarded jaroslav@1258: * objects. jaroslav@1258: *

jaroslav@1258: * The call System.gc() is effectively equivalent to the jaroslav@1258: * call: jaroslav@1258: *

jaroslav@1258:      * Runtime.getRuntime().gc()
jaroslav@1258:      * 
jaroslav@1258: * jaroslav@1258: * @see java.lang.Runtime#gc() jaroslav@1258: */ jaroslav@1258: public static void gc() { jaroslav@1258: Runtime.getRuntime().gc(); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Runs the finalization methods of any objects pending finalization. jaroslav@1258: *

jaroslav@1258: * Calling this method suggests that the Java Virtual Machine expend jaroslav@1258: * effort toward running the finalize methods of objects jaroslav@1258: * that have been found to be discarded but whose finalize jaroslav@1258: * methods have not yet been run. When control returns from the jaroslav@1258: * method call, the Java Virtual Machine has made a best effort to jaroslav@1258: * complete all outstanding finalizations. jaroslav@1258: *

jaroslav@1258: * The call System.runFinalization() is effectively jaroslav@1258: * equivalent to the call: jaroslav@1258: *

jaroslav@1258:      * Runtime.getRuntime().runFinalization()
jaroslav@1258:      * 
jaroslav@1258: * jaroslav@1258: * @see java.lang.Runtime#runFinalization() jaroslav@1258: */ jaroslav@1258: public static void runFinalization() { jaroslav@1258: Runtime.getRuntime().runFinalization(); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Enable or disable finalization on exit; doing so specifies that the jaroslav@1258: * finalizers of all objects that have finalizers that have not yet been jaroslav@1258: * automatically invoked are to be run before the Java runtime exits. jaroslav@1258: * By default, finalization on exit is disabled. jaroslav@1258: * jaroslav@1258: *

If there is a security manager, jaroslav@1258: * its checkExit method is first called jaroslav@1258: * with 0 as its argument to ensure the exit is allowed. jaroslav@1258: * This could result in a SecurityException. jaroslav@1258: * jaroslav@1258: * @deprecated This method is inherently unsafe. It may result in jaroslav@1258: * finalizers being called on live objects while other threads are jaroslav@1258: * concurrently manipulating those objects, resulting in erratic jaroslav@1258: * behavior or deadlock. jaroslav@1258: * @param value indicating enabling or disabling of finalization jaroslav@1258: * @throws SecurityException jaroslav@1258: * if a security manager exists and its checkExit jaroslav@1258: * method doesn't allow the exit. jaroslav@1258: * jaroslav@1258: * @see java.lang.Runtime#exit(int) jaroslav@1258: * @see java.lang.Runtime#gc() jaroslav@1258: * @see java.lang.SecurityManager#checkExit(int) jaroslav@1258: * @since JDK1.1 jaroslav@1258: */ jaroslav@1258: @Deprecated jaroslav@1258: public static void runFinalizersOnExit(boolean value) { jaroslav@1258: Runtime.getRuntime().runFinalizersOnExit(value); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Loads a code file with the specified filename from the local file jaroslav@1258: * system as a dynamic library. The filename jaroslav@1258: * argument must be a complete path name. jaroslav@1258: *

jaroslav@1258: * The call System.load(name) is effectively equivalent jaroslav@1258: * to the call: jaroslav@1258: *

jaroslav@1258:      * Runtime.getRuntime().load(name)
jaroslav@1258:      * 
jaroslav@1258: * jaroslav@1258: * @param filename the file to load. jaroslav@1258: * @exception SecurityException if a security manager exists and its jaroslav@1258: * checkLink method doesn't allow jaroslav@1258: * loading of the specified dynamic library jaroslav@1258: * @exception UnsatisfiedLinkError if the file does not exist. jaroslav@1258: * @exception NullPointerException if filename is jaroslav@1258: * null jaroslav@1258: * @see java.lang.Runtime#load(java.lang.String) jaroslav@1258: * @see java.lang.SecurityManager#checkLink(java.lang.String) jaroslav@1258: */ jaroslav@1258: public static void load(String filename) { jaroslav@1258: Runtime.getRuntime().load0(getCallerClass(), filename); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Loads the system library specified by the libname jaroslav@1258: * argument. The manner in which a library name is mapped to the jaroslav@1258: * actual system library is system dependent. jaroslav@1258: *

jaroslav@1258: * The call System.loadLibrary(name) is effectively jaroslav@1258: * equivalent to the call jaroslav@1258: *

jaroslav@1258:      * Runtime.getRuntime().loadLibrary(name)
jaroslav@1258:      * 
jaroslav@1258: * jaroslav@1258: * @param libname the name of the library. jaroslav@1258: * @exception SecurityException if a security manager exists and its jaroslav@1258: * checkLink method doesn't allow jaroslav@1258: * loading of the specified dynamic library jaroslav@1258: * @exception UnsatisfiedLinkError if the library does not exist. jaroslav@1258: * @exception NullPointerException if libname is jaroslav@1258: * null jaroslav@1258: * @see java.lang.Runtime#loadLibrary(java.lang.String) jaroslav@1258: * @see java.lang.SecurityManager#checkLink(java.lang.String) jaroslav@1258: */ jaroslav@1258: public static void loadLibrary(String libname) { jaroslav@1258: Runtime.getRuntime().loadLibrary0(getCallerClass(), libname); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Maps a library name into a platform-specific string representing jaroslav@1258: * a native library. jaroslav@1258: * jaroslav@1258: * @param libname the name of the library. jaroslav@1258: * @return a platform-dependent native library name. jaroslav@1258: * @exception NullPointerException if libname is jaroslav@1258: * null jaroslav@1258: * @see java.lang.System#loadLibrary(java.lang.String) jaroslav@1258: * @see java.lang.ClassLoader#findLibrary(java.lang.String) jaroslav@1258: * @since 1.2 jaroslav@1258: */ jaroslav@1258: public static native String mapLibraryName(String libname); jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * Initialize the system class. Called after thread initialization. jaroslav@1258: */ jaroslav@1258: private static void initializeSystemClass() { jaroslav@1258: jaroslav@1258: // VM might invoke JNU_NewStringPlatform() to set those encoding jaroslav@1258: // sensitive properties (user.home, user.name, boot.class.path, etc.) jaroslav@1258: // during "props" initialization, in which it may need access, via jaroslav@1258: // System.getProperty(), to the related system encoding property that jaroslav@1258: // have been initialized (put into "props") at early stage of the jaroslav@1258: // initialization. So make sure the "props" is available at the jaroslav@1258: // very beginning of the initialization and all system properties to jaroslav@1258: // be put into it directly. jaroslav@1258: props = new Properties(); jaroslav@1258: initProperties(props); // initialized by the VM jaroslav@1258: jaroslav@1258: // There are certain system configurations that may be controlled by jaroslav@1258: // VM options such as the maximum amount of direct memory and jaroslav@1258: // Integer cache size used to support the object identity semantics jaroslav@1258: // of autoboxing. Typically, the library will obtain these values jaroslav@1258: // from the properties set by the VM. If the properties are for jaroslav@1258: // internal implementation use only, these properties should be jaroslav@1258: // removed from the system properties. jaroslav@1258: // jaroslav@1258: // See java.lang.Integer.IntegerCache and the jaroslav@1258: // sun.misc.VM.saveAndRemoveProperties method for example. jaroslav@1258: // jaroslav@1258: // Save a private copy of the system properties object that jaroslav@1258: // can only be accessed by the internal implementation. Remove jaroslav@1258: // certain system properties that are not intended for public access. jaroslav@1258: sun.misc.VM.saveAndRemoveProperties(props); jaroslav@1258: jaroslav@1258: jaroslav@1258: lineSeparator = props.getProperty("line.separator"); jaroslav@1258: sun.misc.Version.init(); jaroslav@1258: jaroslav@1258: FileInputStream fdIn = new FileInputStream(FileDescriptor.in); jaroslav@1258: FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out); jaroslav@1258: FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err); jaroslav@1258: setIn0(new BufferedInputStream(fdIn)); jaroslav@1258: setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true)); jaroslav@1258: setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true)); jaroslav@1258: // Load the zip library now in order to keep java.util.zip.ZipFile jaroslav@1258: // from trying to use itself to load this library later. jaroslav@1258: loadLibrary("zip"); jaroslav@1258: jaroslav@1258: // Setup Java signal handlers for HUP, TERM, and INT (where available). jaroslav@1258: Terminator.setup(); jaroslav@1258: jaroslav@1258: // Initialize any miscellenous operating system settings that need to be jaroslav@1258: // set for the class libraries. Currently this is no-op everywhere except jaroslav@1258: // for Windows where the process-wide error mode is set before the java.io jaroslav@1258: // classes are used. jaroslav@1258: sun.misc.VM.initializeOSEnvironment(); jaroslav@1258: jaroslav@1258: // Subsystems that are invoked during initialization can invoke jaroslav@1258: // sun.misc.VM.isBooted() in order to avoid doing things that should jaroslav@1258: // wait until the application class loader has been set up. jaroslav@1258: sun.misc.VM.booted(); jaroslav@1258: jaroslav@1258: // The main thread is not added to its thread group in the same jaroslav@1258: // way as other threads; we must do it ourselves here. jaroslav@1258: Thread current = Thread.currentThread(); jaroslav@1258: current.getThreadGroup().add(current); jaroslav@1258: jaroslav@1258: // register shared secrets jaroslav@1258: setJavaLangAccess(); jaroslav@1258: } jaroslav@1258: jaroslav@1258: private static void setJavaLangAccess() { jaroslav@1258: // Allow privileged classes outside of java.lang jaroslav@1258: sun.misc.SharedSecrets.setJavaLangAccess(new sun.misc.JavaLangAccess(){ jaroslav@1258: public sun.reflect.ConstantPool getConstantPool(Class klass) { jaroslav@1258: return klass.getConstantPool(); jaroslav@1258: } jaroslav@1258: public void setAnnotationType(Class klass, AnnotationType type) { jaroslav@1258: klass.setAnnotationType(type); jaroslav@1258: } jaroslav@1258: public AnnotationType getAnnotationType(Class klass) { jaroslav@1258: return klass.getAnnotationType(); jaroslav@1258: } jaroslav@1258: public > jaroslav@1258: E[] getEnumConstantsShared(Class klass) { jaroslav@1258: return klass.getEnumConstantsShared(); jaroslav@1258: } jaroslav@1258: public void blockedOn(Thread t, Interruptible b) { jaroslav@1258: t.blockedOn(b); jaroslav@1258: } jaroslav@1258: public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) { jaroslav@1258: Shutdown.add(slot, registerShutdownInProgress, hook); jaroslav@1258: } jaroslav@1258: public int getStackTraceDepth(Throwable t) { jaroslav@1258: return t.getStackTraceDepth(); jaroslav@1258: } jaroslav@1258: public StackTraceElement getStackTraceElement(Throwable t, int i) { jaroslav@1258: return t.getStackTraceElement(i); jaroslav@1258: } jaroslav@1258: }); jaroslav@1258: } jaroslav@1258: jaroslav@1258: /* returns the class of the caller. */ jaroslav@1258: static Class getCallerClass() { jaroslav@1258: // NOTE use of more generic Reflection.getCallerClass() jaroslav@1258: return Reflection.getCallerClass(3); jaroslav@1258: } jaroslav@1258: }