1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/emul/compact/src/main/java/java/lang/System.java Sat Sep 07 13:51:24 2013 +0200
1.3 @@ -0,0 +1,1206 @@
1.4 +/*
1.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +package java.lang;
1.29 +
1.30 +import java.io.*;
1.31 +import java.util.Properties;
1.32 +import java.util.PropertyPermission;
1.33 +import java.util.StringTokenizer;
1.34 +import java.security.AccessController;
1.35 +import java.security.PrivilegedAction;
1.36 +import java.security.AllPermission;
1.37 +import java.nio.channels.Channel;
1.38 +import java.nio.channels.spi.SelectorProvider;
1.39 +import sun.nio.ch.Interruptible;
1.40 +import sun.reflect.Reflection;
1.41 +import sun.security.util.SecurityConstants;
1.42 +import sun.reflect.annotation.AnnotationType;
1.43 +
1.44 +/**
1.45 + * The <code>System</code> class contains several useful class fields
1.46 + * and methods. It cannot be instantiated.
1.47 + *
1.48 + * <p>Among the facilities provided by the <code>System</code> class
1.49 + * are standard input, standard output, and error output streams;
1.50 + * access to externally defined properties and environment
1.51 + * variables; a means of loading files and libraries; and a utility
1.52 + * method for quickly copying a portion of an array.
1.53 + *
1.54 + * @author unascribed
1.55 + * @since JDK1.0
1.56 + */
1.57 +public final class System {
1.58 +
1.59 + /* register the natives via the static initializer.
1.60 + *
1.61 + * VM will invoke the initializeSystemClass method to complete
1.62 + * the initialization for this class separated from clinit.
1.63 + * Note that to use properties set by the VM, see the constraints
1.64 + * described in the initializeSystemClass method.
1.65 + */
1.66 + private static native void registerNatives();
1.67 + static {
1.68 + registerNatives();
1.69 + }
1.70 +
1.71 + /** Don't let anyone instantiate this class */
1.72 + private System() {
1.73 + }
1.74 +
1.75 + /**
1.76 + * The "standard" input stream. This stream is already
1.77 + * open and ready to supply input data. Typically this stream
1.78 + * corresponds to keyboard input or another input source specified by
1.79 + * the host environment or user.
1.80 + */
1.81 + public final static InputStream in = null;
1.82 +
1.83 + /**
1.84 + * The "standard" output stream. This stream is already
1.85 + * open and ready to accept output data. Typically this stream
1.86 + * corresponds to display output or another output destination
1.87 + * specified by the host environment or user.
1.88 + * <p>
1.89 + * For simple stand-alone Java applications, a typical way to write
1.90 + * a line of output data is:
1.91 + * <blockquote><pre>
1.92 + * System.out.println(data)
1.93 + * </pre></blockquote>
1.94 + * <p>
1.95 + * See the <code>println</code> methods in class <code>PrintStream</code>.
1.96 + *
1.97 + * @see java.io.PrintStream#println()
1.98 + * @see java.io.PrintStream#println(boolean)
1.99 + * @see java.io.PrintStream#println(char)
1.100 + * @see java.io.PrintStream#println(char[])
1.101 + * @see java.io.PrintStream#println(double)
1.102 + * @see java.io.PrintStream#println(float)
1.103 + * @see java.io.PrintStream#println(int)
1.104 + * @see java.io.PrintStream#println(long)
1.105 + * @see java.io.PrintStream#println(java.lang.Object)
1.106 + * @see java.io.PrintStream#println(java.lang.String)
1.107 + */
1.108 + public final static PrintStream out = null;
1.109 +
1.110 + /**
1.111 + * The "standard" error output stream. This stream is already
1.112 + * open and ready to accept output data.
1.113 + * <p>
1.114 + * Typically this stream corresponds to display output or another
1.115 + * output destination specified by the host environment or user. By
1.116 + * convention, this output stream is used to display error messages
1.117 + * or other information that should come to the immediate attention
1.118 + * of a user even if the principal output stream, the value of the
1.119 + * variable <code>out</code>, has been redirected to a file or other
1.120 + * destination that is typically not continuously monitored.
1.121 + */
1.122 + public final static PrintStream err = null;
1.123 +
1.124 + /* The security manager for the system.
1.125 + */
1.126 + private static volatile SecurityManager security = null;
1.127 +
1.128 + /**
1.129 + * Reassigns the "standard" input stream.
1.130 + *
1.131 + * <p>First, if there is a security manager, its <code>checkPermission</code>
1.132 + * method is called with a <code>RuntimePermission("setIO")</code> permission
1.133 + * to see if it's ok to reassign the "standard" input stream.
1.134 + * <p>
1.135 + *
1.136 + * @param in the new standard input stream.
1.137 + *
1.138 + * @throws SecurityException
1.139 + * if a security manager exists and its
1.140 + * <code>checkPermission</code> method doesn't allow
1.141 + * reassigning of the standard input stream.
1.142 + *
1.143 + * @see SecurityManager#checkPermission
1.144 + * @see java.lang.RuntimePermission
1.145 + *
1.146 + * @since JDK1.1
1.147 + */
1.148 + public static void setIn(InputStream in) {
1.149 + checkIO();
1.150 + setIn0(in);
1.151 + }
1.152 +
1.153 + /**
1.154 + * Reassigns the "standard" output stream.
1.155 + *
1.156 + * <p>First, if there is a security manager, its <code>checkPermission</code>
1.157 + * method is called with a <code>RuntimePermission("setIO")</code> permission
1.158 + * to see if it's ok to reassign the "standard" output stream.
1.159 + *
1.160 + * @param out the new standard output stream
1.161 + *
1.162 + * @throws SecurityException
1.163 + * if a security manager exists and its
1.164 + * <code>checkPermission</code> method doesn't allow
1.165 + * reassigning of the standard output stream.
1.166 + *
1.167 + * @see SecurityManager#checkPermission
1.168 + * @see java.lang.RuntimePermission
1.169 + *
1.170 + * @since JDK1.1
1.171 + */
1.172 + public static void setOut(PrintStream out) {
1.173 + checkIO();
1.174 + setOut0(out);
1.175 + }
1.176 +
1.177 + /**
1.178 + * Reassigns the "standard" error output stream.
1.179 + *
1.180 + * <p>First, if there is a security manager, its <code>checkPermission</code>
1.181 + * method is called with a <code>RuntimePermission("setIO")</code> permission
1.182 + * to see if it's ok to reassign the "standard" error output stream.
1.183 + *
1.184 + * @param err the new standard error output stream.
1.185 + *
1.186 + * @throws SecurityException
1.187 + * if a security manager exists and its
1.188 + * <code>checkPermission</code> method doesn't allow
1.189 + * reassigning of the standard error output stream.
1.190 + *
1.191 + * @see SecurityManager#checkPermission
1.192 + * @see java.lang.RuntimePermission
1.193 + *
1.194 + * @since JDK1.1
1.195 + */
1.196 + public static void setErr(PrintStream err) {
1.197 + checkIO();
1.198 + setErr0(err);
1.199 + }
1.200 +
1.201 + private static volatile Console cons = null;
1.202 + /**
1.203 + * Returns the unique {@link java.io.Console Console} object associated
1.204 + * with the current Java virtual machine, if any.
1.205 + *
1.206 + * @return The system console, if any, otherwise <tt>null</tt>.
1.207 + *
1.208 + * @since 1.6
1.209 + */
1.210 + public static Console console() {
1.211 + if (cons == null) {
1.212 + synchronized (System.class) {
1.213 + cons = sun.misc.SharedSecrets.getJavaIOAccess().console();
1.214 + }
1.215 + }
1.216 + return cons;
1.217 + }
1.218 +
1.219 + /**
1.220 + * Returns the channel inherited from the entity that created this
1.221 + * Java virtual machine.
1.222 + *
1.223 + * <p> This method returns the channel obtained by invoking the
1.224 + * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
1.225 + * inheritedChannel} method of the system-wide default
1.226 + * {@link java.nio.channels.spi.SelectorProvider} object. </p>
1.227 + *
1.228 + * <p> In addition to the network-oriented channels described in
1.229 + * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
1.230 + * inheritedChannel}, this method may return other kinds of
1.231 + * channels in the future.
1.232 + *
1.233 + * @return The inherited channel, if any, otherwise <tt>null</tt>.
1.234 + *
1.235 + * @throws IOException
1.236 + * If an I/O error occurs
1.237 + *
1.238 + * @throws SecurityException
1.239 + * If a security manager is present and it does not
1.240 + * permit access to the channel.
1.241 + *
1.242 + * @since 1.5
1.243 + */
1.244 + public static Channel inheritedChannel() throws IOException {
1.245 + return SelectorProvider.provider().inheritedChannel();
1.246 + }
1.247 +
1.248 + private static void checkIO() {
1.249 + SecurityManager sm = getSecurityManager();
1.250 + if (sm != null) {
1.251 + sm.checkPermission(new RuntimePermission("setIO"));
1.252 + }
1.253 + }
1.254 +
1.255 + private static native void setIn0(InputStream in);
1.256 + private static native void setOut0(PrintStream out);
1.257 + private static native void setErr0(PrintStream err);
1.258 +
1.259 + /**
1.260 + * Sets the System security.
1.261 + *
1.262 + * <p> If there is a security manager already installed, this method first
1.263 + * calls the security manager's <code>checkPermission</code> method
1.264 + * with a <code>RuntimePermission("setSecurityManager")</code>
1.265 + * permission to ensure it's ok to replace the existing
1.266 + * security manager.
1.267 + * This may result in throwing a <code>SecurityException</code>.
1.268 + *
1.269 + * <p> Otherwise, the argument is established as the current
1.270 + * security manager. If the argument is <code>null</code> and no
1.271 + * security manager has been established, then no action is taken and
1.272 + * the method simply returns.
1.273 + *
1.274 + * @param s the security manager.
1.275 + * @exception SecurityException if the security manager has already
1.276 + * been set and its <code>checkPermission</code> method
1.277 + * doesn't allow it to be replaced.
1.278 + * @see #getSecurityManager
1.279 + * @see SecurityManager#checkPermission
1.280 + * @see java.lang.RuntimePermission
1.281 + */
1.282 + public static
1.283 + void setSecurityManager(final SecurityManager s) {
1.284 + try {
1.285 + s.checkPackageAccess("java.lang");
1.286 + } catch (Exception e) {
1.287 + // no-op
1.288 + }
1.289 + setSecurityManager0(s);
1.290 + }
1.291 +
1.292 + private static synchronized
1.293 + void setSecurityManager0(final SecurityManager s) {
1.294 + SecurityManager sm = getSecurityManager();
1.295 + if (sm != null) {
1.296 + // ask the currently installed security manager if we
1.297 + // can replace it.
1.298 + sm.checkPermission(new RuntimePermission
1.299 + ("setSecurityManager"));
1.300 + }
1.301 +
1.302 + if ((s != null) && (s.getClass().getClassLoader() != null)) {
1.303 + // New security manager class is not on bootstrap classpath.
1.304 + // Cause policy to get initialized before we install the new
1.305 + // security manager, in order to prevent infinite loops when
1.306 + // trying to initialize the policy (which usually involves
1.307 + // accessing some security and/or system properties, which in turn
1.308 + // calls the installed security manager's checkPermission method
1.309 + // which will loop infinitely if there is a non-system class
1.310 + // (in this case: the new security manager class) on the stack).
1.311 + AccessController.doPrivileged(new PrivilegedAction<Object>() {
1.312 + public Object run() {
1.313 + s.getClass().getProtectionDomain().implies
1.314 + (SecurityConstants.ALL_PERMISSION);
1.315 + return null;
1.316 + }
1.317 + });
1.318 + }
1.319 +
1.320 + security = s;
1.321 + }
1.322 +
1.323 + /**
1.324 + * Gets the system security interface.
1.325 + *
1.326 + * @return if a security manager has already been established for the
1.327 + * current application, then that security manager is returned;
1.328 + * otherwise, <code>null</code> is returned.
1.329 + * @see #setSecurityManager
1.330 + */
1.331 + public static SecurityManager getSecurityManager() {
1.332 + return security;
1.333 + }
1.334 +
1.335 + /**
1.336 + * Returns the current time in milliseconds. Note that
1.337 + * while the unit of time of the return value is a millisecond,
1.338 + * the granularity of the value depends on the underlying
1.339 + * operating system and may be larger. For example, many
1.340 + * operating systems measure time in units of tens of
1.341 + * milliseconds.
1.342 + *
1.343 + * <p> See the description of the class <code>Date</code> for
1.344 + * a discussion of slight discrepancies that may arise between
1.345 + * "computer time" and coordinated universal time (UTC).
1.346 + *
1.347 + * @return the difference, measured in milliseconds, between
1.348 + * the current time and midnight, January 1, 1970 UTC.
1.349 + * @see java.util.Date
1.350 + */
1.351 + public static native long currentTimeMillis();
1.352 +
1.353 + /**
1.354 + * Returns the current value of the running Java Virtual Machine's
1.355 + * high-resolution time source, in nanoseconds.
1.356 + *
1.357 + * <p>This method can only be used to measure elapsed time and is
1.358 + * not related to any other notion of system or wall-clock time.
1.359 + * The value returned represents nanoseconds since some fixed but
1.360 + * arbitrary <i>origin</i> time (perhaps in the future, so values
1.361 + * may be negative). The same origin is used by all invocations of
1.362 + * this method in an instance of a Java virtual machine; other
1.363 + * virtual machine instances are likely to use a different origin.
1.364 + *
1.365 + * <p>This method provides nanosecond precision, but not necessarily
1.366 + * nanosecond resolution (that is, how frequently the value changes)
1.367 + * - no guarantees are made except that the resolution is at least as
1.368 + * good as that of {@link #currentTimeMillis()}.
1.369 + *
1.370 + * <p>Differences in successive calls that span greater than
1.371 + * approximately 292 years (2<sup>63</sup> nanoseconds) will not
1.372 + * correctly compute elapsed time due to numerical overflow.
1.373 + *
1.374 + * <p>The values returned by this method become meaningful only when
1.375 + * the difference between two such values, obtained within the same
1.376 + * instance of a Java virtual machine, is computed.
1.377 + *
1.378 + * <p> For example, to measure how long some code takes to execute:
1.379 + * <pre> {@code
1.380 + * long startTime = System.nanoTime();
1.381 + * // ... the code being measured ...
1.382 + * long estimatedTime = System.nanoTime() - startTime;}</pre>
1.383 + *
1.384 + * <p>To compare two nanoTime values
1.385 + * <pre> {@code
1.386 + * long t0 = System.nanoTime();
1.387 + * ...
1.388 + * long t1 = System.nanoTime();}</pre>
1.389 + *
1.390 + * one should use {@code t1 - t0 < 0}, not {@code t1 < t0},
1.391 + * because of the possibility of numerical overflow.
1.392 + *
1.393 + * @return the current value of the running Java Virtual Machine's
1.394 + * high-resolution time source, in nanoseconds
1.395 + * @since 1.5
1.396 + */
1.397 + public static native long nanoTime();
1.398 +
1.399 + /**
1.400 + * Copies an array from the specified source array, beginning at the
1.401 + * specified position, to the specified position of the destination array.
1.402 + * A subsequence of array components are copied from the source
1.403 + * array referenced by <code>src</code> to the destination array
1.404 + * referenced by <code>dest</code>. The number of components copied is
1.405 + * equal to the <code>length</code> argument. The components at
1.406 + * positions <code>srcPos</code> through
1.407 + * <code>srcPos+length-1</code> in the source array are copied into
1.408 + * positions <code>destPos</code> through
1.409 + * <code>destPos+length-1</code>, respectively, of the destination
1.410 + * array.
1.411 + * <p>
1.412 + * If the <code>src</code> and <code>dest</code> arguments refer to the
1.413 + * same array object, then the copying is performed as if the
1.414 + * components at positions <code>srcPos</code> through
1.415 + * <code>srcPos+length-1</code> were first copied to a temporary
1.416 + * array with <code>length</code> components and then the contents of
1.417 + * the temporary array were copied into positions
1.418 + * <code>destPos</code> through <code>destPos+length-1</code> of the
1.419 + * destination array.
1.420 + * <p>
1.421 + * If <code>dest</code> is <code>null</code>, then a
1.422 + * <code>NullPointerException</code> is thrown.
1.423 + * <p>
1.424 + * If <code>src</code> is <code>null</code>, then a
1.425 + * <code>NullPointerException</code> is thrown and the destination
1.426 + * array is not modified.
1.427 + * <p>
1.428 + * Otherwise, if any of the following is true, an
1.429 + * <code>ArrayStoreException</code> is thrown and the destination is
1.430 + * not modified:
1.431 + * <ul>
1.432 + * <li>The <code>src</code> argument refers to an object that is not an
1.433 + * array.
1.434 + * <li>The <code>dest</code> argument refers to an object that is not an
1.435 + * array.
1.436 + * <li>The <code>src</code> argument and <code>dest</code> argument refer
1.437 + * to arrays whose component types are different primitive types.
1.438 + * <li>The <code>src</code> argument refers to an array with a primitive
1.439 + * component type and the <code>dest</code> argument refers to an array
1.440 + * with a reference component type.
1.441 + * <li>The <code>src</code> argument refers to an array with a reference
1.442 + * component type and the <code>dest</code> argument refers to an array
1.443 + * with a primitive component type.
1.444 + * </ul>
1.445 + * <p>
1.446 + * Otherwise, if any of the following is true, an
1.447 + * <code>IndexOutOfBoundsException</code> is
1.448 + * thrown and the destination is not modified:
1.449 + * <ul>
1.450 + * <li>The <code>srcPos</code> argument is negative.
1.451 + * <li>The <code>destPos</code> argument is negative.
1.452 + * <li>The <code>length</code> argument is negative.
1.453 + * <li><code>srcPos+length</code> is greater than
1.454 + * <code>src.length</code>, the length of the source array.
1.455 + * <li><code>destPos+length</code> is greater than
1.456 + * <code>dest.length</code>, the length of the destination array.
1.457 + * </ul>
1.458 + * <p>
1.459 + * Otherwise, if any actual component of the source array from
1.460 + * position <code>srcPos</code> through
1.461 + * <code>srcPos+length-1</code> cannot be converted to the component
1.462 + * type of the destination array by assignment conversion, an
1.463 + * <code>ArrayStoreException</code> is thrown. In this case, let
1.464 + * <b><i>k</i></b> be the smallest nonnegative integer less than
1.465 + * length such that <code>src[srcPos+</code><i>k</i><code>]</code>
1.466 + * cannot be converted to the component type of the destination
1.467 + * array; when the exception is thrown, source array components from
1.468 + * positions <code>srcPos</code> through
1.469 + * <code>srcPos+</code><i>k</i><code>-1</code>
1.470 + * will already have been copied to destination array positions
1.471 + * <code>destPos</code> through
1.472 + * <code>destPos+</code><i>k</I><code>-1</code> and no other
1.473 + * positions of the destination array will have been modified.
1.474 + * (Because of the restrictions already itemized, this
1.475 + * paragraph effectively applies only to the situation where both
1.476 + * arrays have component types that are reference types.)
1.477 + *
1.478 + * @param src the source array.
1.479 + * @param srcPos starting position in the source array.
1.480 + * @param dest the destination array.
1.481 + * @param destPos starting position in the destination data.
1.482 + * @param length the number of array elements to be copied.
1.483 + * @exception IndexOutOfBoundsException if copying would cause
1.484 + * access of data outside array bounds.
1.485 + * @exception ArrayStoreException if an element in the <code>src</code>
1.486 + * array could not be stored into the <code>dest</code> array
1.487 + * because of a type mismatch.
1.488 + * @exception NullPointerException if either <code>src</code> or
1.489 + * <code>dest</code> is <code>null</code>.
1.490 + */
1.491 + public static native void arraycopy(Object src, int srcPos,
1.492 + Object dest, int destPos,
1.493 + int length);
1.494 +
1.495 + /**
1.496 + * Returns the same hash code for the given object as
1.497 + * would be returned by the default method hashCode(),
1.498 + * whether or not the given object's class overrides
1.499 + * hashCode().
1.500 + * The hash code for the null reference is zero.
1.501 + *
1.502 + * @param x object for which the hashCode is to be calculated
1.503 + * @return the hashCode
1.504 + * @since JDK1.1
1.505 + */
1.506 + public static native int identityHashCode(Object x);
1.507 +
1.508 + /**
1.509 + * System properties. The following properties are guaranteed to be defined:
1.510 + * <dl>
1.511 + * <dt>java.version <dd>Java version number
1.512 + * <dt>java.vendor <dd>Java vendor specific string
1.513 + * <dt>java.vendor.url <dd>Java vendor URL
1.514 + * <dt>java.home <dd>Java installation directory
1.515 + * <dt>java.class.version <dd>Java class version number
1.516 + * <dt>java.class.path <dd>Java classpath
1.517 + * <dt>os.name <dd>Operating System Name
1.518 + * <dt>os.arch <dd>Operating System Architecture
1.519 + * <dt>os.version <dd>Operating System Version
1.520 + * <dt>file.separator <dd>File separator ("/" on Unix)
1.521 + * <dt>path.separator <dd>Path separator (":" on Unix)
1.522 + * <dt>line.separator <dd>Line separator ("\n" on Unix)
1.523 + * <dt>user.name <dd>User account name
1.524 + * <dt>user.home <dd>User home directory
1.525 + * <dt>user.dir <dd>User's current working directory
1.526 + * </dl>
1.527 + */
1.528 +
1.529 + private static Properties props;
1.530 + private static native Properties initProperties(Properties props);
1.531 +
1.532 + /**
1.533 + * Determines the current system properties.
1.534 + * <p>
1.535 + * First, if there is a security manager, its
1.536 + * <code>checkPropertiesAccess</code> method is called with no
1.537 + * arguments. This may result in a security exception.
1.538 + * <p>
1.539 + * The current set of system properties for use by the
1.540 + * {@link #getProperty(String)} method is returned as a
1.541 + * <code>Properties</code> object. If there is no current set of
1.542 + * system properties, a set of system properties is first created and
1.543 + * initialized. This set of system properties always includes values
1.544 + * for the following keys:
1.545 + * <table summary="Shows property keys and associated values">
1.546 + * <tr><th>Key</th>
1.547 + * <th>Description of Associated Value</th></tr>
1.548 + * <tr><td><code>java.version</code></td>
1.549 + * <td>Java Runtime Environment version</td></tr>
1.550 + * <tr><td><code>java.vendor</code></td>
1.551 + * <td>Java Runtime Environment vendor</td></tr
1.552 + * <tr><td><code>java.vendor.url</code></td>
1.553 + * <td>Java vendor URL</td></tr>
1.554 + * <tr><td><code>java.home</code></td>
1.555 + * <td>Java installation directory</td></tr>
1.556 + * <tr><td><code>java.vm.specification.version</code></td>
1.557 + * <td>Java Virtual Machine specification version</td></tr>
1.558 + * <tr><td><code>java.vm.specification.vendor</code></td>
1.559 + * <td>Java Virtual Machine specification vendor</td></tr>
1.560 + * <tr><td><code>java.vm.specification.name</code></td>
1.561 + * <td>Java Virtual Machine specification name</td></tr>
1.562 + * <tr><td><code>java.vm.version</code></td>
1.563 + * <td>Java Virtual Machine implementation version</td></tr>
1.564 + * <tr><td><code>java.vm.vendor</code></td>
1.565 + * <td>Java Virtual Machine implementation vendor</td></tr>
1.566 + * <tr><td><code>java.vm.name</code></td>
1.567 + * <td>Java Virtual Machine implementation name</td></tr>
1.568 + * <tr><td><code>java.specification.version</code></td>
1.569 + * <td>Java Runtime Environment specification version</td></tr>
1.570 + * <tr><td><code>java.specification.vendor</code></td>
1.571 + * <td>Java Runtime Environment specification vendor</td></tr>
1.572 + * <tr><td><code>java.specification.name</code></td>
1.573 + * <td>Java Runtime Environment specification name</td></tr>
1.574 + * <tr><td><code>java.class.version</code></td>
1.575 + * <td>Java class format version number</td></tr>
1.576 + * <tr><td><code>java.class.path</code></td>
1.577 + * <td>Java class path</td></tr>
1.578 + * <tr><td><code>java.library.path</code></td>
1.579 + * <td>List of paths to search when loading libraries</td></tr>
1.580 + * <tr><td><code>java.io.tmpdir</code></td>
1.581 + * <td>Default temp file path</td></tr>
1.582 + * <tr><td><code>java.compiler</code></td>
1.583 + * <td>Name of JIT compiler to use</td></tr>
1.584 + * <tr><td><code>java.ext.dirs</code></td>
1.585 + * <td>Path of extension directory or directories</td></tr>
1.586 + * <tr><td><code>os.name</code></td>
1.587 + * <td>Operating system name</td></tr>
1.588 + * <tr><td><code>os.arch</code></td>
1.589 + * <td>Operating system architecture</td></tr>
1.590 + * <tr><td><code>os.version</code></td>
1.591 + * <td>Operating system version</td></tr>
1.592 + * <tr><td><code>file.separator</code></td>
1.593 + * <td>File separator ("/" on UNIX)</td></tr>
1.594 + * <tr><td><code>path.separator</code></td>
1.595 + * <td>Path separator (":" on UNIX)</td></tr>
1.596 + * <tr><td><code>line.separator</code></td>
1.597 + * <td>Line separator ("\n" on UNIX)</td></tr>
1.598 + * <tr><td><code>user.name</code></td>
1.599 + * <td>User's account name</td></tr>
1.600 + * <tr><td><code>user.home</code></td>
1.601 + * <td>User's home directory</td></tr>
1.602 + * <tr><td><code>user.dir</code></td>
1.603 + * <td>User's current working directory</td></tr>
1.604 + * </table>
1.605 + * <p>
1.606 + * Multiple paths in a system property value are separated by the path
1.607 + * separator character of the platform.
1.608 + * <p>
1.609 + * Note that even if the security manager does not permit the
1.610 + * <code>getProperties</code> operation, it may choose to permit the
1.611 + * {@link #getProperty(String)} operation.
1.612 + *
1.613 + * @return the system properties
1.614 + * @exception SecurityException if a security manager exists and its
1.615 + * <code>checkPropertiesAccess</code> method doesn't allow access
1.616 + * to the system properties.
1.617 + * @see #setProperties
1.618 + * @see java.lang.SecurityException
1.619 + * @see java.lang.SecurityManager#checkPropertiesAccess()
1.620 + * @see java.util.Properties
1.621 + */
1.622 + public static Properties getProperties() {
1.623 + SecurityManager sm = getSecurityManager();
1.624 + if (sm != null) {
1.625 + sm.checkPropertiesAccess();
1.626 + }
1.627 +
1.628 + return props;
1.629 + }
1.630 +
1.631 + /**
1.632 + * Returns the system-dependent line separator string. It always
1.633 + * returns the same value - the initial value of the {@linkplain
1.634 + * #getProperty(String) system property} {@code line.separator}.
1.635 + *
1.636 + * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
1.637 + * Windows systems it returns {@code "\r\n"}.
1.638 + */
1.639 + public static String lineSeparator() {
1.640 + return lineSeparator;
1.641 + }
1.642 +
1.643 + private static String lineSeparator;
1.644 +
1.645 + /**
1.646 + * Sets the system properties to the <code>Properties</code>
1.647 + * argument.
1.648 + * <p>
1.649 + * First, if there is a security manager, its
1.650 + * <code>checkPropertiesAccess</code> method is called with no
1.651 + * arguments. This may result in a security exception.
1.652 + * <p>
1.653 + * The argument becomes the current set of system properties for use
1.654 + * by the {@link #getProperty(String)} method. If the argument is
1.655 + * <code>null</code>, then the current set of system properties is
1.656 + * forgotten.
1.657 + *
1.658 + * @param props the new system properties.
1.659 + * @exception SecurityException if a security manager exists and its
1.660 + * <code>checkPropertiesAccess</code> method doesn't allow access
1.661 + * to the system properties.
1.662 + * @see #getProperties
1.663 + * @see java.util.Properties
1.664 + * @see java.lang.SecurityException
1.665 + * @see java.lang.SecurityManager#checkPropertiesAccess()
1.666 + */
1.667 + public static void setProperties(Properties props) {
1.668 + SecurityManager sm = getSecurityManager();
1.669 + if (sm != null) {
1.670 + sm.checkPropertiesAccess();
1.671 + }
1.672 + if (props == null) {
1.673 + props = new Properties();
1.674 + initProperties(props);
1.675 + }
1.676 + System.props = props;
1.677 + }
1.678 +
1.679 + /**
1.680 + * Gets the system property indicated by the specified key.
1.681 + * <p>
1.682 + * First, if there is a security manager, its
1.683 + * <code>checkPropertyAccess</code> method is called with the key as
1.684 + * its argument. This may result in a SecurityException.
1.685 + * <p>
1.686 + * If there is no current set of system properties, a set of system
1.687 + * properties is first created and initialized in the same manner as
1.688 + * for the <code>getProperties</code> method.
1.689 + *
1.690 + * @param key the name of the system property.
1.691 + * @return the string value of the system property,
1.692 + * or <code>null</code> if there is no property with that key.
1.693 + *
1.694 + * @exception SecurityException if a security manager exists and its
1.695 + * <code>checkPropertyAccess</code> method doesn't allow
1.696 + * access to the specified system property.
1.697 + * @exception NullPointerException if <code>key</code> is
1.698 + * <code>null</code>.
1.699 + * @exception IllegalArgumentException if <code>key</code> is empty.
1.700 + * @see #setProperty
1.701 + * @see java.lang.SecurityException
1.702 + * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
1.703 + * @see java.lang.System#getProperties()
1.704 + */
1.705 + public static String getProperty(String key) {
1.706 + checkKey(key);
1.707 + SecurityManager sm = getSecurityManager();
1.708 + if (sm != null) {
1.709 + sm.checkPropertyAccess(key);
1.710 + }
1.711 +
1.712 + return props.getProperty(key);
1.713 + }
1.714 +
1.715 + /**
1.716 + * Gets the system property indicated by the specified key.
1.717 + * <p>
1.718 + * First, if there is a security manager, its
1.719 + * <code>checkPropertyAccess</code> method is called with the
1.720 + * <code>key</code> as its argument.
1.721 + * <p>
1.722 + * If there is no current set of system properties, a set of system
1.723 + * properties is first created and initialized in the same manner as
1.724 + * for the <code>getProperties</code> method.
1.725 + *
1.726 + * @param key the name of the system property.
1.727 + * @param def a default value.
1.728 + * @return the string value of the system property,
1.729 + * or the default value if there is no property with that key.
1.730 + *
1.731 + * @exception SecurityException if a security manager exists and its
1.732 + * <code>checkPropertyAccess</code> method doesn't allow
1.733 + * access to the specified system property.
1.734 + * @exception NullPointerException if <code>key</code> is
1.735 + * <code>null</code>.
1.736 + * @exception IllegalArgumentException if <code>key</code> is empty.
1.737 + * @see #setProperty
1.738 + * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
1.739 + * @see java.lang.System#getProperties()
1.740 + */
1.741 + public static String getProperty(String key, String def) {
1.742 + checkKey(key);
1.743 + SecurityManager sm = getSecurityManager();
1.744 + if (sm != null) {
1.745 + sm.checkPropertyAccess(key);
1.746 + }
1.747 +
1.748 + return props.getProperty(key, def);
1.749 + }
1.750 +
1.751 + /**
1.752 + * Sets the system property indicated by the specified key.
1.753 + * <p>
1.754 + * First, if a security manager exists, its
1.755 + * <code>SecurityManager.checkPermission</code> method
1.756 + * is called with a <code>PropertyPermission(key, "write")</code>
1.757 + * permission. This may result in a SecurityException being thrown.
1.758 + * If no exception is thrown, the specified property is set to the given
1.759 + * value.
1.760 + * <p>
1.761 + *
1.762 + * @param key the name of the system property.
1.763 + * @param value the value of the system property.
1.764 + * @return the previous value of the system property,
1.765 + * or <code>null</code> if it did not have one.
1.766 + *
1.767 + * @exception SecurityException if a security manager exists and its
1.768 + * <code>checkPermission</code> method doesn't allow
1.769 + * setting of the specified property.
1.770 + * @exception NullPointerException if <code>key</code> or
1.771 + * <code>value</code> is <code>null</code>.
1.772 + * @exception IllegalArgumentException if <code>key</code> is empty.
1.773 + * @see #getProperty
1.774 + * @see java.lang.System#getProperty(java.lang.String)
1.775 + * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
1.776 + * @see java.util.PropertyPermission
1.777 + * @see SecurityManager#checkPermission
1.778 + * @since 1.2
1.779 + */
1.780 + public static String setProperty(String key, String value) {
1.781 + checkKey(key);
1.782 + SecurityManager sm = getSecurityManager();
1.783 + if (sm != null) {
1.784 + sm.checkPermission(new PropertyPermission(key,
1.785 + SecurityConstants.PROPERTY_WRITE_ACTION));
1.786 + }
1.787 +
1.788 + return (String) props.setProperty(key, value);
1.789 + }
1.790 +
1.791 + /**
1.792 + * Removes the system property indicated by the specified key.
1.793 + * <p>
1.794 + * First, if a security manager exists, its
1.795 + * <code>SecurityManager.checkPermission</code> method
1.796 + * is called with a <code>PropertyPermission(key, "write")</code>
1.797 + * permission. This may result in a SecurityException being thrown.
1.798 + * If no exception is thrown, the specified property is removed.
1.799 + * <p>
1.800 + *
1.801 + * @param key the name of the system property to be removed.
1.802 + * @return the previous string value of the system property,
1.803 + * or <code>null</code> if there was no property with that key.
1.804 + *
1.805 + * @exception SecurityException if a security manager exists and its
1.806 + * <code>checkPropertyAccess</code> method doesn't allow
1.807 + * access to the specified system property.
1.808 + * @exception NullPointerException if <code>key</code> is
1.809 + * <code>null</code>.
1.810 + * @exception IllegalArgumentException if <code>key</code> is empty.
1.811 + * @see #getProperty
1.812 + * @see #setProperty
1.813 + * @see java.util.Properties
1.814 + * @see java.lang.SecurityException
1.815 + * @see java.lang.SecurityManager#checkPropertiesAccess()
1.816 + * @since 1.5
1.817 + */
1.818 + public static String clearProperty(String key) {
1.819 + checkKey(key);
1.820 + SecurityManager sm = getSecurityManager();
1.821 + if (sm != null) {
1.822 + sm.checkPermission(new PropertyPermission(key, "write"));
1.823 + }
1.824 +
1.825 + return (String) props.remove(key);
1.826 + }
1.827 +
1.828 + private static void checkKey(String key) {
1.829 + if (key == null) {
1.830 + throw new NullPointerException("key can't be null");
1.831 + }
1.832 + if (key.equals("")) {
1.833 + throw new IllegalArgumentException("key can't be empty");
1.834 + }
1.835 + }
1.836 +
1.837 + /**
1.838 + * Gets the value of the specified environment variable. An
1.839 + * environment variable is a system-dependent external named
1.840 + * value.
1.841 + *
1.842 + * <p>If a security manager exists, its
1.843 + * {@link SecurityManager#checkPermission checkPermission}
1.844 + * method is called with a
1.845 + * <code>{@link RuntimePermission}("getenv."+name)</code>
1.846 + * permission. This may result in a {@link SecurityException}
1.847 + * being thrown. If no exception is thrown the value of the
1.848 + * variable <code>name</code> is returned.
1.849 + *
1.850 + * <p><a name="EnvironmentVSSystemProperties"><i>System
1.851 + * properties</i> and <i>environment variables</i></a> are both
1.852 + * conceptually mappings between names and values. Both
1.853 + * mechanisms can be used to pass user-defined information to a
1.854 + * Java process. Environment variables have a more global effect,
1.855 + * because they are visible to all descendants of the process
1.856 + * which defines them, not just the immediate Java subprocess.
1.857 + * They can have subtly different semantics, such as case
1.858 + * insensitivity, on different operating systems. For these
1.859 + * reasons, environment variables are more likely to have
1.860 + * unintended side effects. It is best to use system properties
1.861 + * where possible. Environment variables should be used when a
1.862 + * global effect is desired, or when an external system interface
1.863 + * requires an environment variable (such as <code>PATH</code>).
1.864 + *
1.865 + * <p>On UNIX systems the alphabetic case of <code>name</code> is
1.866 + * typically significant, while on Microsoft Windows systems it is
1.867 + * typically not. For example, the expression
1.868 + * <code>System.getenv("FOO").equals(System.getenv("foo"))</code>
1.869 + * is likely to be true on Microsoft Windows.
1.870 + *
1.871 + * @param name the name of the environment variable
1.872 + * @return the string value of the variable, or <code>null</code>
1.873 + * if the variable is not defined in the system environment
1.874 + * @throws NullPointerException if <code>name</code> is <code>null</code>
1.875 + * @throws SecurityException
1.876 + * if a security manager exists and its
1.877 + * {@link SecurityManager#checkPermission checkPermission}
1.878 + * method doesn't allow access to the environment variable
1.879 + * <code>name</code>
1.880 + * @see #getenv()
1.881 + * @see ProcessBuilder#environment()
1.882 + */
1.883 + public static String getenv(String name) {
1.884 + SecurityManager sm = getSecurityManager();
1.885 + if (sm != null) {
1.886 + sm.checkPermission(new RuntimePermission("getenv."+name));
1.887 + }
1.888 +
1.889 + return ProcessEnvironment.getenv(name);
1.890 + }
1.891 +
1.892 +
1.893 + /**
1.894 + * Returns an unmodifiable string map view of the current system environment.
1.895 + * The environment is a system-dependent mapping from names to
1.896 + * values which is passed from parent to child processes.
1.897 + *
1.898 + * <p>If the system does not support environment variables, an
1.899 + * empty map is returned.
1.900 + *
1.901 + * <p>The returned map will never contain null keys or values.
1.902 + * Attempting to query the presence of a null key or value will
1.903 + * throw a {@link NullPointerException}. Attempting to query
1.904 + * the presence of a key or value which is not of type
1.905 + * {@link String} will throw a {@link ClassCastException}.
1.906 + *
1.907 + * <p>The returned map and its collection views may not obey the
1.908 + * general contract of the {@link Object#equals} and
1.909 + * {@link Object#hashCode} methods.
1.910 + *
1.911 + * <p>The returned map is typically case-sensitive on all platforms.
1.912 + *
1.913 + * <p>If a security manager exists, its
1.914 + * {@link SecurityManager#checkPermission checkPermission}
1.915 + * method is called with a
1.916 + * <code>{@link RuntimePermission}("getenv.*")</code>
1.917 + * permission. This may result in a {@link SecurityException} being
1.918 + * thrown.
1.919 + *
1.920 + * <p>When passing information to a Java subprocess,
1.921 + * <a href=#EnvironmentVSSystemProperties>system properties</a>
1.922 + * are generally preferred over environment variables.
1.923 + *
1.924 + * @return the environment as a map of variable names to values
1.925 + * @throws SecurityException
1.926 + * if a security manager exists and its
1.927 + * {@link SecurityManager#checkPermission checkPermission}
1.928 + * method doesn't allow access to the process environment
1.929 + * @see #getenv(String)
1.930 + * @see ProcessBuilder#environment()
1.931 + * @since 1.5
1.932 + */
1.933 + public static java.util.Map<String,String> getenv() {
1.934 + SecurityManager sm = getSecurityManager();
1.935 + if (sm != null) {
1.936 + sm.checkPermission(new RuntimePermission("getenv.*"));
1.937 + }
1.938 +
1.939 + return ProcessEnvironment.getenv();
1.940 + }
1.941 +
1.942 + /**
1.943 + * Terminates the currently running Java Virtual Machine. The
1.944 + * argument serves as a status code; by convention, a nonzero status
1.945 + * code indicates abnormal termination.
1.946 + * <p>
1.947 + * This method calls the <code>exit</code> method in class
1.948 + * <code>Runtime</code>. This method never returns normally.
1.949 + * <p>
1.950 + * The call <code>System.exit(n)</code> is effectively equivalent to
1.951 + * the call:
1.952 + * <blockquote><pre>
1.953 + * Runtime.getRuntime().exit(n)
1.954 + * </pre></blockquote>
1.955 + *
1.956 + * @param status exit status.
1.957 + * @throws SecurityException
1.958 + * if a security manager exists and its <code>checkExit</code>
1.959 + * method doesn't allow exit with the specified status.
1.960 + * @see java.lang.Runtime#exit(int)
1.961 + */
1.962 + public static void exit(int status) {
1.963 + Runtime.getRuntime().exit(status);
1.964 + }
1.965 +
1.966 + /**
1.967 + * Runs the garbage collector.
1.968 + * <p>
1.969 + * Calling the <code>gc</code> method suggests that the Java Virtual
1.970 + * Machine expend effort toward recycling unused objects in order to
1.971 + * make the memory they currently occupy available for quick reuse.
1.972 + * When control returns from the method call, the Java Virtual
1.973 + * Machine has made a best effort to reclaim space from all discarded
1.974 + * objects.
1.975 + * <p>
1.976 + * The call <code>System.gc()</code> is effectively equivalent to the
1.977 + * call:
1.978 + * <blockquote><pre>
1.979 + * Runtime.getRuntime().gc()
1.980 + * </pre></blockquote>
1.981 + *
1.982 + * @see java.lang.Runtime#gc()
1.983 + */
1.984 + public static void gc() {
1.985 + Runtime.getRuntime().gc();
1.986 + }
1.987 +
1.988 + /**
1.989 + * Runs the finalization methods of any objects pending finalization.
1.990 + * <p>
1.991 + * Calling this method suggests that the Java Virtual Machine expend
1.992 + * effort toward running the <code>finalize</code> methods of objects
1.993 + * that have been found to be discarded but whose <code>finalize</code>
1.994 + * methods have not yet been run. When control returns from the
1.995 + * method call, the Java Virtual Machine has made a best effort to
1.996 + * complete all outstanding finalizations.
1.997 + * <p>
1.998 + * The call <code>System.runFinalization()</code> is effectively
1.999 + * equivalent to the call:
1.1000 + * <blockquote><pre>
1.1001 + * Runtime.getRuntime().runFinalization()
1.1002 + * </pre></blockquote>
1.1003 + *
1.1004 + * @see java.lang.Runtime#runFinalization()
1.1005 + */
1.1006 + public static void runFinalization() {
1.1007 + Runtime.getRuntime().runFinalization();
1.1008 + }
1.1009 +
1.1010 + /**
1.1011 + * Enable or disable finalization on exit; doing so specifies that the
1.1012 + * finalizers of all objects that have finalizers that have not yet been
1.1013 + * automatically invoked are to be run before the Java runtime exits.
1.1014 + * By default, finalization on exit is disabled.
1.1015 + *
1.1016 + * <p>If there is a security manager,
1.1017 + * its <code>checkExit</code> method is first called
1.1018 + * with 0 as its argument to ensure the exit is allowed.
1.1019 + * This could result in a SecurityException.
1.1020 + *
1.1021 + * @deprecated This method is inherently unsafe. It may result in
1.1022 + * finalizers being called on live objects while other threads are
1.1023 + * concurrently manipulating those objects, resulting in erratic
1.1024 + * behavior or deadlock.
1.1025 + * @param value indicating enabling or disabling of finalization
1.1026 + * @throws SecurityException
1.1027 + * if a security manager exists and its <code>checkExit</code>
1.1028 + * method doesn't allow the exit.
1.1029 + *
1.1030 + * @see java.lang.Runtime#exit(int)
1.1031 + * @see java.lang.Runtime#gc()
1.1032 + * @see java.lang.SecurityManager#checkExit(int)
1.1033 + * @since JDK1.1
1.1034 + */
1.1035 + @Deprecated
1.1036 + public static void runFinalizersOnExit(boolean value) {
1.1037 + Runtime.getRuntime().runFinalizersOnExit(value);
1.1038 + }
1.1039 +
1.1040 + /**
1.1041 + * Loads a code file with the specified filename from the local file
1.1042 + * system as a dynamic library. The filename
1.1043 + * argument must be a complete path name.
1.1044 + * <p>
1.1045 + * The call <code>System.load(name)</code> is effectively equivalent
1.1046 + * to the call:
1.1047 + * <blockquote><pre>
1.1048 + * Runtime.getRuntime().load(name)
1.1049 + * </pre></blockquote>
1.1050 + *
1.1051 + * @param filename the file to load.
1.1052 + * @exception SecurityException if a security manager exists and its
1.1053 + * <code>checkLink</code> method doesn't allow
1.1054 + * loading of the specified dynamic library
1.1055 + * @exception UnsatisfiedLinkError if the file does not exist.
1.1056 + * @exception NullPointerException if <code>filename</code> is
1.1057 + * <code>null</code>
1.1058 + * @see java.lang.Runtime#load(java.lang.String)
1.1059 + * @see java.lang.SecurityManager#checkLink(java.lang.String)
1.1060 + */
1.1061 + public static void load(String filename) {
1.1062 + Runtime.getRuntime().load0(getCallerClass(), filename);
1.1063 + }
1.1064 +
1.1065 + /**
1.1066 + * Loads the system library specified by the <code>libname</code>
1.1067 + * argument. The manner in which a library name is mapped to the
1.1068 + * actual system library is system dependent.
1.1069 + * <p>
1.1070 + * The call <code>System.loadLibrary(name)</code> is effectively
1.1071 + * equivalent to the call
1.1072 + * <blockquote><pre>
1.1073 + * Runtime.getRuntime().loadLibrary(name)
1.1074 + * </pre></blockquote>
1.1075 + *
1.1076 + * @param libname the name of the library.
1.1077 + * @exception SecurityException if a security manager exists and its
1.1078 + * <code>checkLink</code> method doesn't allow
1.1079 + * loading of the specified dynamic library
1.1080 + * @exception UnsatisfiedLinkError if the library does not exist.
1.1081 + * @exception NullPointerException if <code>libname</code> is
1.1082 + * <code>null</code>
1.1083 + * @see java.lang.Runtime#loadLibrary(java.lang.String)
1.1084 + * @see java.lang.SecurityManager#checkLink(java.lang.String)
1.1085 + */
1.1086 + public static void loadLibrary(String libname) {
1.1087 + Runtime.getRuntime().loadLibrary0(getCallerClass(), libname);
1.1088 + }
1.1089 +
1.1090 + /**
1.1091 + * Maps a library name into a platform-specific string representing
1.1092 + * a native library.
1.1093 + *
1.1094 + * @param libname the name of the library.
1.1095 + * @return a platform-dependent native library name.
1.1096 + * @exception NullPointerException if <code>libname</code> is
1.1097 + * <code>null</code>
1.1098 + * @see java.lang.System#loadLibrary(java.lang.String)
1.1099 + * @see java.lang.ClassLoader#findLibrary(java.lang.String)
1.1100 + * @since 1.2
1.1101 + */
1.1102 + public static native String mapLibraryName(String libname);
1.1103 +
1.1104 + /**
1.1105 + * Initialize the system class. Called after thread initialization.
1.1106 + */
1.1107 + private static void initializeSystemClass() {
1.1108 +
1.1109 + // VM might invoke JNU_NewStringPlatform() to set those encoding
1.1110 + // sensitive properties (user.home, user.name, boot.class.path, etc.)
1.1111 + // during "props" initialization, in which it may need access, via
1.1112 + // System.getProperty(), to the related system encoding property that
1.1113 + // have been initialized (put into "props") at early stage of the
1.1114 + // initialization. So make sure the "props" is available at the
1.1115 + // very beginning of the initialization and all system properties to
1.1116 + // be put into it directly.
1.1117 + props = new Properties();
1.1118 + initProperties(props); // initialized by the VM
1.1119 +
1.1120 + // There are certain system configurations that may be controlled by
1.1121 + // VM options such as the maximum amount of direct memory and
1.1122 + // Integer cache size used to support the object identity semantics
1.1123 + // of autoboxing. Typically, the library will obtain these values
1.1124 + // from the properties set by the VM. If the properties are for
1.1125 + // internal implementation use only, these properties should be
1.1126 + // removed from the system properties.
1.1127 + //
1.1128 + // See java.lang.Integer.IntegerCache and the
1.1129 + // sun.misc.VM.saveAndRemoveProperties method for example.
1.1130 + //
1.1131 + // Save a private copy of the system properties object that
1.1132 + // can only be accessed by the internal implementation. Remove
1.1133 + // certain system properties that are not intended for public access.
1.1134 + sun.misc.VM.saveAndRemoveProperties(props);
1.1135 +
1.1136 +
1.1137 + lineSeparator = props.getProperty("line.separator");
1.1138 + sun.misc.Version.init();
1.1139 +
1.1140 + FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
1.1141 + FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
1.1142 + FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
1.1143 + setIn0(new BufferedInputStream(fdIn));
1.1144 + setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
1.1145 + setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
1.1146 + // Load the zip library now in order to keep java.util.zip.ZipFile
1.1147 + // from trying to use itself to load this library later.
1.1148 + loadLibrary("zip");
1.1149 +
1.1150 + // Setup Java signal handlers for HUP, TERM, and INT (where available).
1.1151 + Terminator.setup();
1.1152 +
1.1153 + // Initialize any miscellenous operating system settings that need to be
1.1154 + // set for the class libraries. Currently this is no-op everywhere except
1.1155 + // for Windows where the process-wide error mode is set before the java.io
1.1156 + // classes are used.
1.1157 + sun.misc.VM.initializeOSEnvironment();
1.1158 +
1.1159 + // Subsystems that are invoked during initialization can invoke
1.1160 + // sun.misc.VM.isBooted() in order to avoid doing things that should
1.1161 + // wait until the application class loader has been set up.
1.1162 + sun.misc.VM.booted();
1.1163 +
1.1164 + // The main thread is not added to its thread group in the same
1.1165 + // way as other threads; we must do it ourselves here.
1.1166 + Thread current = Thread.currentThread();
1.1167 + current.getThreadGroup().add(current);
1.1168 +
1.1169 + // register shared secrets
1.1170 + setJavaLangAccess();
1.1171 + }
1.1172 +
1.1173 + private static void setJavaLangAccess() {
1.1174 + // Allow privileged classes outside of java.lang
1.1175 + sun.misc.SharedSecrets.setJavaLangAccess(new sun.misc.JavaLangAccess(){
1.1176 + public sun.reflect.ConstantPool getConstantPool(Class klass) {
1.1177 + return klass.getConstantPool();
1.1178 + }
1.1179 + public void setAnnotationType(Class klass, AnnotationType type) {
1.1180 + klass.setAnnotationType(type);
1.1181 + }
1.1182 + public AnnotationType getAnnotationType(Class klass) {
1.1183 + return klass.getAnnotationType();
1.1184 + }
1.1185 + public <E extends Enum<E>>
1.1186 + E[] getEnumConstantsShared(Class<E> klass) {
1.1187 + return klass.getEnumConstantsShared();
1.1188 + }
1.1189 + public void blockedOn(Thread t, Interruptible b) {
1.1190 + t.blockedOn(b);
1.1191 + }
1.1192 + public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) {
1.1193 + Shutdown.add(slot, registerShutdownInProgress, hook);
1.1194 + }
1.1195 + public int getStackTraceDepth(Throwable t) {
1.1196 + return t.getStackTraceDepth();
1.1197 + }
1.1198 + public StackTraceElement getStackTraceElement(Throwable t, int i) {
1.1199 + return t.getStackTraceElement(i);
1.1200 + }
1.1201 + });
1.1202 + }
1.1203 +
1.1204 + /* returns the class of the caller. */
1.1205 + static Class<?> getCallerClass() {
1.1206 + // NOTE use of more generic Reflection.getCallerClass()
1.1207 + return Reflection.getCallerClass(3);
1.1208 + }
1.1209 +}