emul/compact/src/main/java/java/lang/System.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 07 Sep 2013 13:51:24 +0200
branchjdk7-b147
changeset 1258 724f3e1ea53e
permissions -rw-r--r--
Additional set of classes to make porting of lookup library more easier
jaroslav@1258
     1
/*
jaroslav@1258
     2
 * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
jaroslav@1258
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@1258
     4
 *
jaroslav@1258
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@1258
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@1258
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@1258
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@1258
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@1258
    10
 *
jaroslav@1258
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@1258
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@1258
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@1258
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@1258
    15
 * accompanied this code).
jaroslav@1258
    16
 *
jaroslav@1258
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@1258
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@1258
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@1258
    20
 *
jaroslav@1258
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@1258
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@1258
    23
 * questions.
jaroslav@1258
    24
 */
jaroslav@1258
    25
package java.lang;
jaroslav@1258
    26
jaroslav@1258
    27
import java.io.*;
jaroslav@1258
    28
import java.util.Properties;
jaroslav@1258
    29
import java.util.PropertyPermission;
jaroslav@1258
    30
import java.util.StringTokenizer;
jaroslav@1258
    31
import java.security.AccessController;
jaroslav@1258
    32
import java.security.PrivilegedAction;
jaroslav@1258
    33
import java.security.AllPermission;
jaroslav@1258
    34
import java.nio.channels.Channel;
jaroslav@1258
    35
import java.nio.channels.spi.SelectorProvider;
jaroslav@1258
    36
import sun.nio.ch.Interruptible;
jaroslav@1258
    37
import sun.reflect.Reflection;
jaroslav@1258
    38
import sun.security.util.SecurityConstants;
jaroslav@1258
    39
import sun.reflect.annotation.AnnotationType;
jaroslav@1258
    40
jaroslav@1258
    41
/**
jaroslav@1258
    42
 * The <code>System</code> class contains several useful class fields
jaroslav@1258
    43
 * and methods. It cannot be instantiated.
jaroslav@1258
    44
 *
jaroslav@1258
    45
 * <p>Among the facilities provided by the <code>System</code> class
jaroslav@1258
    46
 * are standard input, standard output, and error output streams;
jaroslav@1258
    47
 * access to externally defined properties and environment
jaroslav@1258
    48
 * variables; a means of loading files and libraries; and a utility
jaroslav@1258
    49
 * method for quickly copying a portion of an array.
jaroslav@1258
    50
 *
jaroslav@1258
    51
 * @author  unascribed
jaroslav@1258
    52
 * @since   JDK1.0
jaroslav@1258
    53
 */
jaroslav@1258
    54
public final class System {
jaroslav@1258
    55
jaroslav@1258
    56
    /* register the natives via the static initializer.
jaroslav@1258
    57
     *
jaroslav@1258
    58
     * VM will invoke the initializeSystemClass method to complete
jaroslav@1258
    59
     * the initialization for this class separated from clinit.
jaroslav@1258
    60
     * Note that to use properties set by the VM, see the constraints
jaroslav@1258
    61
     * described in the initializeSystemClass method.
jaroslav@1258
    62
     */
jaroslav@1258
    63
    private static native void registerNatives();
jaroslav@1258
    64
    static {
jaroslav@1258
    65
        registerNatives();
jaroslav@1258
    66
    }
jaroslav@1258
    67
jaroslav@1258
    68
    /** Don't let anyone instantiate this class */
jaroslav@1258
    69
    private System() {
jaroslav@1258
    70
    }
jaroslav@1258
    71
jaroslav@1258
    72
    /**
jaroslav@1258
    73
     * The "standard" input stream. This stream is already
jaroslav@1258
    74
     * open and ready to supply input data. Typically this stream
jaroslav@1258
    75
     * corresponds to keyboard input or another input source specified by
jaroslav@1258
    76
     * the host environment or user.
jaroslav@1258
    77
     */
jaroslav@1258
    78
    public final static InputStream in = null;
jaroslav@1258
    79
jaroslav@1258
    80
    /**
jaroslav@1258
    81
     * The "standard" output stream. This stream is already
jaroslav@1258
    82
     * open and ready to accept output data. Typically this stream
jaroslav@1258
    83
     * corresponds to display output or another output destination
jaroslav@1258
    84
     * specified by the host environment or user.
jaroslav@1258
    85
     * <p>
jaroslav@1258
    86
     * For simple stand-alone Java applications, a typical way to write
jaroslav@1258
    87
     * a line of output data is:
jaroslav@1258
    88
     * <blockquote><pre>
jaroslav@1258
    89
     *     System.out.println(data)
jaroslav@1258
    90
     * </pre></blockquote>
jaroslav@1258
    91
     * <p>
jaroslav@1258
    92
     * See the <code>println</code> methods in class <code>PrintStream</code>.
jaroslav@1258
    93
     *
jaroslav@1258
    94
     * @see     java.io.PrintStream#println()
jaroslav@1258
    95
     * @see     java.io.PrintStream#println(boolean)
jaroslav@1258
    96
     * @see     java.io.PrintStream#println(char)
jaroslav@1258
    97
     * @see     java.io.PrintStream#println(char[])
jaroslav@1258
    98
     * @see     java.io.PrintStream#println(double)
jaroslav@1258
    99
     * @see     java.io.PrintStream#println(float)
jaroslav@1258
   100
     * @see     java.io.PrintStream#println(int)
jaroslav@1258
   101
     * @see     java.io.PrintStream#println(long)
jaroslav@1258
   102
     * @see     java.io.PrintStream#println(java.lang.Object)
jaroslav@1258
   103
     * @see     java.io.PrintStream#println(java.lang.String)
jaroslav@1258
   104
     */
jaroslav@1258
   105
    public final static PrintStream out = null;
jaroslav@1258
   106
jaroslav@1258
   107
    /**
jaroslav@1258
   108
     * The "standard" error output stream. This stream is already
jaroslav@1258
   109
     * open and ready to accept output data.
jaroslav@1258
   110
     * <p>
jaroslav@1258
   111
     * Typically this stream corresponds to display output or another
jaroslav@1258
   112
     * output destination specified by the host environment or user. By
jaroslav@1258
   113
     * convention, this output stream is used to display error messages
jaroslav@1258
   114
     * or other information that should come to the immediate attention
jaroslav@1258
   115
     * of a user even if the principal output stream, the value of the
jaroslav@1258
   116
     * variable <code>out</code>, has been redirected to a file or other
jaroslav@1258
   117
     * destination that is typically not continuously monitored.
jaroslav@1258
   118
     */
jaroslav@1258
   119
    public final static PrintStream err = null;
jaroslav@1258
   120
jaroslav@1258
   121
    /* The security manager for the system.
jaroslav@1258
   122
     */
jaroslav@1258
   123
    private static volatile SecurityManager security = null;
jaroslav@1258
   124
jaroslav@1258
   125
    /**
jaroslav@1258
   126
     * Reassigns the "standard" input stream.
jaroslav@1258
   127
     *
jaroslav@1258
   128
     * <p>First, if there is a security manager, its <code>checkPermission</code>
jaroslav@1258
   129
     * method is called with a <code>RuntimePermission("setIO")</code> permission
jaroslav@1258
   130
     *  to see if it's ok to reassign the "standard" input stream.
jaroslav@1258
   131
     * <p>
jaroslav@1258
   132
     *
jaroslav@1258
   133
     * @param in the new standard input stream.
jaroslav@1258
   134
     *
jaroslav@1258
   135
     * @throws SecurityException
jaroslav@1258
   136
     *        if a security manager exists and its
jaroslav@1258
   137
     *        <code>checkPermission</code> method doesn't allow
jaroslav@1258
   138
     *        reassigning of the standard input stream.
jaroslav@1258
   139
     *
jaroslav@1258
   140
     * @see SecurityManager#checkPermission
jaroslav@1258
   141
     * @see java.lang.RuntimePermission
jaroslav@1258
   142
     *
jaroslav@1258
   143
     * @since   JDK1.1
jaroslav@1258
   144
     */
jaroslav@1258
   145
    public static void setIn(InputStream in) {
jaroslav@1258
   146
        checkIO();
jaroslav@1258
   147
        setIn0(in);
jaroslav@1258
   148
    }
jaroslav@1258
   149
jaroslav@1258
   150
    /**
jaroslav@1258
   151
     * Reassigns the "standard" output stream.
jaroslav@1258
   152
     *
jaroslav@1258
   153
     * <p>First, if there is a security manager, its <code>checkPermission</code>
jaroslav@1258
   154
     * method is called with a <code>RuntimePermission("setIO")</code> permission
jaroslav@1258
   155
     *  to see if it's ok to reassign the "standard" output stream.
jaroslav@1258
   156
     *
jaroslav@1258
   157
     * @param out the new standard output stream
jaroslav@1258
   158
     *
jaroslav@1258
   159
     * @throws SecurityException
jaroslav@1258
   160
     *        if a security manager exists and its
jaroslav@1258
   161
     *        <code>checkPermission</code> method doesn't allow
jaroslav@1258
   162
     *        reassigning of the standard output stream.
jaroslav@1258
   163
     *
jaroslav@1258
   164
     * @see SecurityManager#checkPermission
jaroslav@1258
   165
     * @see java.lang.RuntimePermission
jaroslav@1258
   166
     *
jaroslav@1258
   167
     * @since   JDK1.1
jaroslav@1258
   168
     */
jaroslav@1258
   169
    public static void setOut(PrintStream out) {
jaroslav@1258
   170
        checkIO();
jaroslav@1258
   171
        setOut0(out);
jaroslav@1258
   172
    }
jaroslav@1258
   173
jaroslav@1258
   174
    /**
jaroslav@1258
   175
     * Reassigns the "standard" error output stream.
jaroslav@1258
   176
     *
jaroslav@1258
   177
     * <p>First, if there is a security manager, its <code>checkPermission</code>
jaroslav@1258
   178
     * method is called with a <code>RuntimePermission("setIO")</code> permission
jaroslav@1258
   179
     *  to see if it's ok to reassign the "standard" error output stream.
jaroslav@1258
   180
     *
jaroslav@1258
   181
     * @param err the new standard error output stream.
jaroslav@1258
   182
     *
jaroslav@1258
   183
     * @throws SecurityException
jaroslav@1258
   184
     *        if a security manager exists and its
jaroslav@1258
   185
     *        <code>checkPermission</code> method doesn't allow
jaroslav@1258
   186
     *        reassigning of the standard error output stream.
jaroslav@1258
   187
     *
jaroslav@1258
   188
     * @see SecurityManager#checkPermission
jaroslav@1258
   189
     * @see java.lang.RuntimePermission
jaroslav@1258
   190
     *
jaroslav@1258
   191
     * @since   JDK1.1
jaroslav@1258
   192
     */
jaroslav@1258
   193
    public static void setErr(PrintStream err) {
jaroslav@1258
   194
        checkIO();
jaroslav@1258
   195
        setErr0(err);
jaroslav@1258
   196
    }
jaroslav@1258
   197
jaroslav@1258
   198
    private static volatile Console cons = null;
jaroslav@1258
   199
    /**
jaroslav@1258
   200
     * Returns the unique {@link java.io.Console Console} object associated
jaroslav@1258
   201
     * with the current Java virtual machine, if any.
jaroslav@1258
   202
     *
jaroslav@1258
   203
     * @return  The system console, if any, otherwise <tt>null</tt>.
jaroslav@1258
   204
     *
jaroslav@1258
   205
     * @since   1.6
jaroslav@1258
   206
     */
jaroslav@1258
   207
     public static Console console() {
jaroslav@1258
   208
         if (cons == null) {
jaroslav@1258
   209
             synchronized (System.class) {
jaroslav@1258
   210
                 cons = sun.misc.SharedSecrets.getJavaIOAccess().console();
jaroslav@1258
   211
             }
jaroslav@1258
   212
         }
jaroslav@1258
   213
         return cons;
jaroslav@1258
   214
     }
jaroslav@1258
   215
jaroslav@1258
   216
    /**
jaroslav@1258
   217
     * Returns the channel inherited from the entity that created this
jaroslav@1258
   218
     * Java virtual machine.
jaroslav@1258
   219
     *
jaroslav@1258
   220
     * <p> This method returns the channel obtained by invoking the
jaroslav@1258
   221
     * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
jaroslav@1258
   222
     * inheritedChannel} method of the system-wide default
jaroslav@1258
   223
     * {@link java.nio.channels.spi.SelectorProvider} object. </p>
jaroslav@1258
   224
     *
jaroslav@1258
   225
     * <p> In addition to the network-oriented channels described in
jaroslav@1258
   226
     * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
jaroslav@1258
   227
     * inheritedChannel}, this method may return other kinds of
jaroslav@1258
   228
     * channels in the future.
jaroslav@1258
   229
     *
jaroslav@1258
   230
     * @return  The inherited channel, if any, otherwise <tt>null</tt>.
jaroslav@1258
   231
     *
jaroslav@1258
   232
     * @throws  IOException
jaroslav@1258
   233
     *          If an I/O error occurs
jaroslav@1258
   234
     *
jaroslav@1258
   235
     * @throws  SecurityException
jaroslav@1258
   236
     *          If a security manager is present and it does not
jaroslav@1258
   237
     *          permit access to the channel.
jaroslav@1258
   238
     *
jaroslav@1258
   239
     * @since 1.5
jaroslav@1258
   240
     */
jaroslav@1258
   241
    public static Channel inheritedChannel() throws IOException {
jaroslav@1258
   242
        return SelectorProvider.provider().inheritedChannel();
jaroslav@1258
   243
    }
jaroslav@1258
   244
jaroslav@1258
   245
    private static void checkIO() {
jaroslav@1258
   246
        SecurityManager sm = getSecurityManager();
jaroslav@1258
   247
        if (sm != null) {
jaroslav@1258
   248
            sm.checkPermission(new RuntimePermission("setIO"));
jaroslav@1258
   249
        }
jaroslav@1258
   250
    }
jaroslav@1258
   251
jaroslav@1258
   252
    private static native void setIn0(InputStream in);
jaroslav@1258
   253
    private static native void setOut0(PrintStream out);
jaroslav@1258
   254
    private static native void setErr0(PrintStream err);
jaroslav@1258
   255
jaroslav@1258
   256
    /**
jaroslav@1258
   257
     * Sets the System security.
jaroslav@1258
   258
     *
jaroslav@1258
   259
     * <p> If there is a security manager already installed, this method first
jaroslav@1258
   260
     * calls the security manager's <code>checkPermission</code> method
jaroslav@1258
   261
     * with a <code>RuntimePermission("setSecurityManager")</code>
jaroslav@1258
   262
     * permission to ensure it's ok to replace the existing
jaroslav@1258
   263
     * security manager.
jaroslav@1258
   264
     * This may result in throwing a <code>SecurityException</code>.
jaroslav@1258
   265
     *
jaroslav@1258
   266
     * <p> Otherwise, the argument is established as the current
jaroslav@1258
   267
     * security manager. If the argument is <code>null</code> and no
jaroslav@1258
   268
     * security manager has been established, then no action is taken and
jaroslav@1258
   269
     * the method simply returns.
jaroslav@1258
   270
     *
jaroslav@1258
   271
     * @param      s   the security manager.
jaroslav@1258
   272
     * @exception  SecurityException  if the security manager has already
jaroslav@1258
   273
     *             been set and its <code>checkPermission</code> method
jaroslav@1258
   274
     *             doesn't allow it to be replaced.
jaroslav@1258
   275
     * @see #getSecurityManager
jaroslav@1258
   276
     * @see SecurityManager#checkPermission
jaroslav@1258
   277
     * @see java.lang.RuntimePermission
jaroslav@1258
   278
     */
jaroslav@1258
   279
    public static
jaroslav@1258
   280
    void setSecurityManager(final SecurityManager s) {
jaroslav@1258
   281
        try {
jaroslav@1258
   282
            s.checkPackageAccess("java.lang");
jaroslav@1258
   283
        } catch (Exception e) {
jaroslav@1258
   284
            // no-op
jaroslav@1258
   285
        }
jaroslav@1258
   286
        setSecurityManager0(s);
jaroslav@1258
   287
    }
jaroslav@1258
   288
jaroslav@1258
   289
    private static synchronized
jaroslav@1258
   290
    void setSecurityManager0(final SecurityManager s) {
jaroslav@1258
   291
        SecurityManager sm = getSecurityManager();
jaroslav@1258
   292
        if (sm != null) {
jaroslav@1258
   293
            // ask the currently installed security manager if we
jaroslav@1258
   294
            // can replace it.
jaroslav@1258
   295
            sm.checkPermission(new RuntimePermission
jaroslav@1258
   296
                                     ("setSecurityManager"));
jaroslav@1258
   297
        }
jaroslav@1258
   298
jaroslav@1258
   299
        if ((s != null) && (s.getClass().getClassLoader() != null)) {
jaroslav@1258
   300
            // New security manager class is not on bootstrap classpath.
jaroslav@1258
   301
            // Cause policy to get initialized before we install the new
jaroslav@1258
   302
            // security manager, in order to prevent infinite loops when
jaroslav@1258
   303
            // trying to initialize the policy (which usually involves
jaroslav@1258
   304
            // accessing some security and/or system properties, which in turn
jaroslav@1258
   305
            // calls the installed security manager's checkPermission method
jaroslav@1258
   306
            // which will loop infinitely if there is a non-system class
jaroslav@1258
   307
            // (in this case: the new security manager class) on the stack).
jaroslav@1258
   308
            AccessController.doPrivileged(new PrivilegedAction<Object>() {
jaroslav@1258
   309
                public Object run() {
jaroslav@1258
   310
                    s.getClass().getProtectionDomain().implies
jaroslav@1258
   311
                        (SecurityConstants.ALL_PERMISSION);
jaroslav@1258
   312
                    return null;
jaroslav@1258
   313
                }
jaroslav@1258
   314
            });
jaroslav@1258
   315
        }
jaroslav@1258
   316
jaroslav@1258
   317
        security = s;
jaroslav@1258
   318
    }
jaroslav@1258
   319
jaroslav@1258
   320
    /**
jaroslav@1258
   321
     * Gets the system security interface.
jaroslav@1258
   322
     *
jaroslav@1258
   323
     * @return  if a security manager has already been established for the
jaroslav@1258
   324
     *          current application, then that security manager is returned;
jaroslav@1258
   325
     *          otherwise, <code>null</code> is returned.
jaroslav@1258
   326
     * @see     #setSecurityManager
jaroslav@1258
   327
     */
jaroslav@1258
   328
    public static SecurityManager getSecurityManager() {
jaroslav@1258
   329
        return security;
jaroslav@1258
   330
    }
jaroslav@1258
   331
jaroslav@1258
   332
    /**
jaroslav@1258
   333
     * Returns the current time in milliseconds.  Note that
jaroslav@1258
   334
     * while the unit of time of the return value is a millisecond,
jaroslav@1258
   335
     * the granularity of the value depends on the underlying
jaroslav@1258
   336
     * operating system and may be larger.  For example, many
jaroslav@1258
   337
     * operating systems measure time in units of tens of
jaroslav@1258
   338
     * milliseconds.
jaroslav@1258
   339
     *
jaroslav@1258
   340
     * <p> See the description of the class <code>Date</code> for
jaroslav@1258
   341
     * a discussion of slight discrepancies that may arise between
jaroslav@1258
   342
     * "computer time" and coordinated universal time (UTC).
jaroslav@1258
   343
     *
jaroslav@1258
   344
     * @return  the difference, measured in milliseconds, between
jaroslav@1258
   345
     *          the current time and midnight, January 1, 1970 UTC.
jaroslav@1258
   346
     * @see     java.util.Date
jaroslav@1258
   347
     */
jaroslav@1258
   348
    public static native long currentTimeMillis();
jaroslav@1258
   349
jaroslav@1258
   350
    /**
jaroslav@1258
   351
     * Returns the current value of the running Java Virtual Machine's
jaroslav@1258
   352
     * high-resolution time source, in nanoseconds.
jaroslav@1258
   353
     *
jaroslav@1258
   354
     * <p>This method can only be used to measure elapsed time and is
jaroslav@1258
   355
     * not related to any other notion of system or wall-clock time.
jaroslav@1258
   356
     * The value returned represents nanoseconds since some fixed but
jaroslav@1258
   357
     * arbitrary <i>origin</i> time (perhaps in the future, so values
jaroslav@1258
   358
     * may be negative).  The same origin is used by all invocations of
jaroslav@1258
   359
     * this method in an instance of a Java virtual machine; other
jaroslav@1258
   360
     * virtual machine instances are likely to use a different origin.
jaroslav@1258
   361
     *
jaroslav@1258
   362
     * <p>This method provides nanosecond precision, but not necessarily
jaroslav@1258
   363
     * nanosecond resolution (that is, how frequently the value changes)
jaroslav@1258
   364
     * - no guarantees are made except that the resolution is at least as
jaroslav@1258
   365
     * good as that of {@link #currentTimeMillis()}.
jaroslav@1258
   366
     *
jaroslav@1258
   367
     * <p>Differences in successive calls that span greater than
jaroslav@1258
   368
     * approximately 292 years (2<sup>63</sup> nanoseconds) will not
jaroslav@1258
   369
     * correctly compute elapsed time due to numerical overflow.
jaroslav@1258
   370
     *
jaroslav@1258
   371
     * <p>The values returned by this method become meaningful only when
jaroslav@1258
   372
     * the difference between two such values, obtained within the same
jaroslav@1258
   373
     * instance of a Java virtual machine, is computed.
jaroslav@1258
   374
     *
jaroslav@1258
   375
     * <p> For example, to measure how long some code takes to execute:
jaroslav@1258
   376
     *  <pre> {@code
jaroslav@1258
   377
     * long startTime = System.nanoTime();
jaroslav@1258
   378
     * // ... the code being measured ...
jaroslav@1258
   379
     * long estimatedTime = System.nanoTime() - startTime;}</pre>
jaroslav@1258
   380
     *
jaroslav@1258
   381
     * <p>To compare two nanoTime values
jaroslav@1258
   382
     *  <pre> {@code
jaroslav@1258
   383
     * long t0 = System.nanoTime();
jaroslav@1258
   384
     * ...
jaroslav@1258
   385
     * long t1 = System.nanoTime();}</pre>
jaroslav@1258
   386
     *
jaroslav@1258
   387
     * one should use {@code t1 - t0 < 0}, not {@code t1 < t0},
jaroslav@1258
   388
     * because of the possibility of numerical overflow.
jaroslav@1258
   389
     *
jaroslav@1258
   390
     * @return the current value of the running Java Virtual Machine's
jaroslav@1258
   391
     *         high-resolution time source, in nanoseconds
jaroslav@1258
   392
     * @since 1.5
jaroslav@1258
   393
     */
jaroslav@1258
   394
    public static native long nanoTime();
jaroslav@1258
   395
jaroslav@1258
   396
    /**
jaroslav@1258
   397
     * Copies an array from the specified source array, beginning at the
jaroslav@1258
   398
     * specified position, to the specified position of the destination array.
jaroslav@1258
   399
     * A subsequence of array components are copied from the source
jaroslav@1258
   400
     * array referenced by <code>src</code> to the destination array
jaroslav@1258
   401
     * referenced by <code>dest</code>. The number of components copied is
jaroslav@1258
   402
     * equal to the <code>length</code> argument. The components at
jaroslav@1258
   403
     * positions <code>srcPos</code> through
jaroslav@1258
   404
     * <code>srcPos+length-1</code> in the source array are copied into
jaroslav@1258
   405
     * positions <code>destPos</code> through
jaroslav@1258
   406
     * <code>destPos+length-1</code>, respectively, of the destination
jaroslav@1258
   407
     * array.
jaroslav@1258
   408
     * <p>
jaroslav@1258
   409
     * If the <code>src</code> and <code>dest</code> arguments refer to the
jaroslav@1258
   410
     * same array object, then the copying is performed as if the
jaroslav@1258
   411
     * components at positions <code>srcPos</code> through
jaroslav@1258
   412
     * <code>srcPos+length-1</code> were first copied to a temporary
jaroslav@1258
   413
     * array with <code>length</code> components and then the contents of
jaroslav@1258
   414
     * the temporary array were copied into positions
jaroslav@1258
   415
     * <code>destPos</code> through <code>destPos+length-1</code> of the
jaroslav@1258
   416
     * destination array.
jaroslav@1258
   417
     * <p>
jaroslav@1258
   418
     * If <code>dest</code> is <code>null</code>, then a
jaroslav@1258
   419
     * <code>NullPointerException</code> is thrown.
jaroslav@1258
   420
     * <p>
jaroslav@1258
   421
     * If <code>src</code> is <code>null</code>, then a
jaroslav@1258
   422
     * <code>NullPointerException</code> is thrown and the destination
jaroslav@1258
   423
     * array is not modified.
jaroslav@1258
   424
     * <p>
jaroslav@1258
   425
     * Otherwise, if any of the following is true, an
jaroslav@1258
   426
     * <code>ArrayStoreException</code> is thrown and the destination is
jaroslav@1258
   427
     * not modified:
jaroslav@1258
   428
     * <ul>
jaroslav@1258
   429
     * <li>The <code>src</code> argument refers to an object that is not an
jaroslav@1258
   430
     *     array.
jaroslav@1258
   431
     * <li>The <code>dest</code> argument refers to an object that is not an
jaroslav@1258
   432
     *     array.
jaroslav@1258
   433
     * <li>The <code>src</code> argument and <code>dest</code> argument refer
jaroslav@1258
   434
     *     to arrays whose component types are different primitive types.
jaroslav@1258
   435
     * <li>The <code>src</code> argument refers to an array with a primitive
jaroslav@1258
   436
     *    component type and the <code>dest</code> argument refers to an array
jaroslav@1258
   437
     *     with a reference component type.
jaroslav@1258
   438
     * <li>The <code>src</code> argument refers to an array with a reference
jaroslav@1258
   439
     *    component type and the <code>dest</code> argument refers to an array
jaroslav@1258
   440
     *     with a primitive component type.
jaroslav@1258
   441
     * </ul>
jaroslav@1258
   442
     * <p>
jaroslav@1258
   443
     * Otherwise, if any of the following is true, an
jaroslav@1258
   444
     * <code>IndexOutOfBoundsException</code> is
jaroslav@1258
   445
     * thrown and the destination is not modified:
jaroslav@1258
   446
     * <ul>
jaroslav@1258
   447
     * <li>The <code>srcPos</code> argument is negative.
jaroslav@1258
   448
     * <li>The <code>destPos</code> argument is negative.
jaroslav@1258
   449
     * <li>The <code>length</code> argument is negative.
jaroslav@1258
   450
     * <li><code>srcPos+length</code> is greater than
jaroslav@1258
   451
     *     <code>src.length</code>, the length of the source array.
jaroslav@1258
   452
     * <li><code>destPos+length</code> is greater than
jaroslav@1258
   453
     *     <code>dest.length</code>, the length of the destination array.
jaroslav@1258
   454
     * </ul>
jaroslav@1258
   455
     * <p>
jaroslav@1258
   456
     * Otherwise, if any actual component of the source array from
jaroslav@1258
   457
     * position <code>srcPos</code> through
jaroslav@1258
   458
     * <code>srcPos+length-1</code> cannot be converted to the component
jaroslav@1258
   459
     * type of the destination array by assignment conversion, an
jaroslav@1258
   460
     * <code>ArrayStoreException</code> is thrown. In this case, let
jaroslav@1258
   461
     * <b><i>k</i></b> be the smallest nonnegative integer less than
jaroslav@1258
   462
     * length such that <code>src[srcPos+</code><i>k</i><code>]</code>
jaroslav@1258
   463
     * cannot be converted to the component type of the destination
jaroslav@1258
   464
     * array; when the exception is thrown, source array components from
jaroslav@1258
   465
     * positions <code>srcPos</code> through
jaroslav@1258
   466
     * <code>srcPos+</code><i>k</i><code>-1</code>
jaroslav@1258
   467
     * will already have been copied to destination array positions
jaroslav@1258
   468
     * <code>destPos</code> through
jaroslav@1258
   469
     * <code>destPos+</code><i>k</I><code>-1</code> and no other
jaroslav@1258
   470
     * positions of the destination array will have been modified.
jaroslav@1258
   471
     * (Because of the restrictions already itemized, this
jaroslav@1258
   472
     * paragraph effectively applies only to the situation where both
jaroslav@1258
   473
     * arrays have component types that are reference types.)
jaroslav@1258
   474
     *
jaroslav@1258
   475
     * @param      src      the source array.
jaroslav@1258
   476
     * @param      srcPos   starting position in the source array.
jaroslav@1258
   477
     * @param      dest     the destination array.
jaroslav@1258
   478
     * @param      destPos  starting position in the destination data.
jaroslav@1258
   479
     * @param      length   the number of array elements to be copied.
jaroslav@1258
   480
     * @exception  IndexOutOfBoundsException  if copying would cause
jaroslav@1258
   481
     *               access of data outside array bounds.
jaroslav@1258
   482
     * @exception  ArrayStoreException  if an element in the <code>src</code>
jaroslav@1258
   483
     *               array could not be stored into the <code>dest</code> array
jaroslav@1258
   484
     *               because of a type mismatch.
jaroslav@1258
   485
     * @exception  NullPointerException if either <code>src</code> or
jaroslav@1258
   486
     *               <code>dest</code> is <code>null</code>.
jaroslav@1258
   487
     */
jaroslav@1258
   488
    public static native void arraycopy(Object src,  int  srcPos,
jaroslav@1258
   489
                                        Object dest, int destPos,
jaroslav@1258
   490
                                        int length);
jaroslav@1258
   491
jaroslav@1258
   492
    /**
jaroslav@1258
   493
     * Returns the same hash code for the given object as
jaroslav@1258
   494
     * would be returned by the default method hashCode(),
jaroslav@1258
   495
     * whether or not the given object's class overrides
jaroslav@1258
   496
     * hashCode().
jaroslav@1258
   497
     * The hash code for the null reference is zero.
jaroslav@1258
   498
     *
jaroslav@1258
   499
     * @param x object for which the hashCode is to be calculated
jaroslav@1258
   500
     * @return  the hashCode
jaroslav@1258
   501
     * @since   JDK1.1
jaroslav@1258
   502
     */
jaroslav@1258
   503
    public static native int identityHashCode(Object x);
jaroslav@1258
   504
jaroslav@1258
   505
    /**
jaroslav@1258
   506
     * System properties. The following properties are guaranteed to be defined:
jaroslav@1258
   507
     * <dl>
jaroslav@1258
   508
     * <dt>java.version         <dd>Java version number
jaroslav@1258
   509
     * <dt>java.vendor          <dd>Java vendor specific string
jaroslav@1258
   510
     * <dt>java.vendor.url      <dd>Java vendor URL
jaroslav@1258
   511
     * <dt>java.home            <dd>Java installation directory
jaroslav@1258
   512
     * <dt>java.class.version   <dd>Java class version number
jaroslav@1258
   513
     * <dt>java.class.path      <dd>Java classpath
jaroslav@1258
   514
     * <dt>os.name              <dd>Operating System Name
jaroslav@1258
   515
     * <dt>os.arch              <dd>Operating System Architecture
jaroslav@1258
   516
     * <dt>os.version           <dd>Operating System Version
jaroslav@1258
   517
     * <dt>file.separator       <dd>File separator ("/" on Unix)
jaroslav@1258
   518
     * <dt>path.separator       <dd>Path separator (":" on Unix)
jaroslav@1258
   519
     * <dt>line.separator       <dd>Line separator ("\n" on Unix)
jaroslav@1258
   520
     * <dt>user.name            <dd>User account name
jaroslav@1258
   521
     * <dt>user.home            <dd>User home directory
jaroslav@1258
   522
     * <dt>user.dir             <dd>User's current working directory
jaroslav@1258
   523
     * </dl>
jaroslav@1258
   524
     */
jaroslav@1258
   525
jaroslav@1258
   526
    private static Properties props;
jaroslav@1258
   527
    private static native Properties initProperties(Properties props);
jaroslav@1258
   528
jaroslav@1258
   529
    /**
jaroslav@1258
   530
     * Determines the current system properties.
jaroslav@1258
   531
     * <p>
jaroslav@1258
   532
     * First, if there is a security manager, its
jaroslav@1258
   533
     * <code>checkPropertiesAccess</code> method is called with no
jaroslav@1258
   534
     * arguments. This may result in a security exception.
jaroslav@1258
   535
     * <p>
jaroslav@1258
   536
     * The current set of system properties for use by the
jaroslav@1258
   537
     * {@link #getProperty(String)} method is returned as a
jaroslav@1258
   538
     * <code>Properties</code> object. If there is no current set of
jaroslav@1258
   539
     * system properties, a set of system properties is first created and
jaroslav@1258
   540
     * initialized. This set of system properties always includes values
jaroslav@1258
   541
     * for the following keys:
jaroslav@1258
   542
     * <table summary="Shows property keys and associated values">
jaroslav@1258
   543
     * <tr><th>Key</th>
jaroslav@1258
   544
     *     <th>Description of Associated Value</th></tr>
jaroslav@1258
   545
     * <tr><td><code>java.version</code></td>
jaroslav@1258
   546
     *     <td>Java Runtime Environment version</td></tr>
jaroslav@1258
   547
     * <tr><td><code>java.vendor</code></td>
jaroslav@1258
   548
     *     <td>Java Runtime Environment vendor</td></tr
jaroslav@1258
   549
     * <tr><td><code>java.vendor.url</code></td>
jaroslav@1258
   550
     *     <td>Java vendor URL</td></tr>
jaroslav@1258
   551
     * <tr><td><code>java.home</code></td>
jaroslav@1258
   552
     *     <td>Java installation directory</td></tr>
jaroslav@1258
   553
     * <tr><td><code>java.vm.specification.version</code></td>
jaroslav@1258
   554
     *     <td>Java Virtual Machine specification version</td></tr>
jaroslav@1258
   555
     * <tr><td><code>java.vm.specification.vendor</code></td>
jaroslav@1258
   556
     *     <td>Java Virtual Machine specification vendor</td></tr>
jaroslav@1258
   557
     * <tr><td><code>java.vm.specification.name</code></td>
jaroslav@1258
   558
     *     <td>Java Virtual Machine specification name</td></tr>
jaroslav@1258
   559
     * <tr><td><code>java.vm.version</code></td>
jaroslav@1258
   560
     *     <td>Java Virtual Machine implementation version</td></tr>
jaroslav@1258
   561
     * <tr><td><code>java.vm.vendor</code></td>
jaroslav@1258
   562
     *     <td>Java Virtual Machine implementation vendor</td></tr>
jaroslav@1258
   563
     * <tr><td><code>java.vm.name</code></td>
jaroslav@1258
   564
     *     <td>Java Virtual Machine implementation name</td></tr>
jaroslav@1258
   565
     * <tr><td><code>java.specification.version</code></td>
jaroslav@1258
   566
     *     <td>Java Runtime Environment specification  version</td></tr>
jaroslav@1258
   567
     * <tr><td><code>java.specification.vendor</code></td>
jaroslav@1258
   568
     *     <td>Java Runtime Environment specification  vendor</td></tr>
jaroslav@1258
   569
     * <tr><td><code>java.specification.name</code></td>
jaroslav@1258
   570
     *     <td>Java Runtime Environment specification  name</td></tr>
jaroslav@1258
   571
     * <tr><td><code>java.class.version</code></td>
jaroslav@1258
   572
     *     <td>Java class format version number</td></tr>
jaroslav@1258
   573
     * <tr><td><code>java.class.path</code></td>
jaroslav@1258
   574
     *     <td>Java class path</td></tr>
jaroslav@1258
   575
     * <tr><td><code>java.library.path</code></td>
jaroslav@1258
   576
     *     <td>List of paths to search when loading libraries</td></tr>
jaroslav@1258
   577
     * <tr><td><code>java.io.tmpdir</code></td>
jaroslav@1258
   578
     *     <td>Default temp file path</td></tr>
jaroslav@1258
   579
     * <tr><td><code>java.compiler</code></td>
jaroslav@1258
   580
     *     <td>Name of JIT compiler to use</td></tr>
jaroslav@1258
   581
     * <tr><td><code>java.ext.dirs</code></td>
jaroslav@1258
   582
     *     <td>Path of extension directory or directories</td></tr>
jaroslav@1258
   583
     * <tr><td><code>os.name</code></td>
jaroslav@1258
   584
     *     <td>Operating system name</td></tr>
jaroslav@1258
   585
     * <tr><td><code>os.arch</code></td>
jaroslav@1258
   586
     *     <td>Operating system architecture</td></tr>
jaroslav@1258
   587
     * <tr><td><code>os.version</code></td>
jaroslav@1258
   588
     *     <td>Operating system version</td></tr>
jaroslav@1258
   589
     * <tr><td><code>file.separator</code></td>
jaroslav@1258
   590
     *     <td>File separator ("/" on UNIX)</td></tr>
jaroslav@1258
   591
     * <tr><td><code>path.separator</code></td>
jaroslav@1258
   592
     *     <td>Path separator (":" on UNIX)</td></tr>
jaroslav@1258
   593
     * <tr><td><code>line.separator</code></td>
jaroslav@1258
   594
     *     <td>Line separator ("\n" on UNIX)</td></tr>
jaroslav@1258
   595
     * <tr><td><code>user.name</code></td>
jaroslav@1258
   596
     *     <td>User's account name</td></tr>
jaroslav@1258
   597
     * <tr><td><code>user.home</code></td>
jaroslav@1258
   598
     *     <td>User's home directory</td></tr>
jaroslav@1258
   599
     * <tr><td><code>user.dir</code></td>
jaroslav@1258
   600
     *     <td>User's current working directory</td></tr>
jaroslav@1258
   601
     * </table>
jaroslav@1258
   602
     * <p>
jaroslav@1258
   603
     * Multiple paths in a system property value are separated by the path
jaroslav@1258
   604
     * separator character of the platform.
jaroslav@1258
   605
     * <p>
jaroslav@1258
   606
     * Note that even if the security manager does not permit the
jaroslav@1258
   607
     * <code>getProperties</code> operation, it may choose to permit the
jaroslav@1258
   608
     * {@link #getProperty(String)} operation.
jaroslav@1258
   609
     *
jaroslav@1258
   610
     * @return     the system properties
jaroslav@1258
   611
     * @exception  SecurityException  if a security manager exists and its
jaroslav@1258
   612
     *             <code>checkPropertiesAccess</code> method doesn't allow access
jaroslav@1258
   613
     *              to the system properties.
jaroslav@1258
   614
     * @see        #setProperties
jaroslav@1258
   615
     * @see        java.lang.SecurityException
jaroslav@1258
   616
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
jaroslav@1258
   617
     * @see        java.util.Properties
jaroslav@1258
   618
     */
jaroslav@1258
   619
    public static Properties getProperties() {
jaroslav@1258
   620
        SecurityManager sm = getSecurityManager();
jaroslav@1258
   621
        if (sm != null) {
jaroslav@1258
   622
            sm.checkPropertiesAccess();
jaroslav@1258
   623
        }
jaroslav@1258
   624
jaroslav@1258
   625
        return props;
jaroslav@1258
   626
    }
jaroslav@1258
   627
jaroslav@1258
   628
    /**
jaroslav@1258
   629
     * Returns the system-dependent line separator string.  It always
jaroslav@1258
   630
     * returns the same value - the initial value of the {@linkplain
jaroslav@1258
   631
     * #getProperty(String) system property} {@code line.separator}.
jaroslav@1258
   632
     *
jaroslav@1258
   633
     * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
jaroslav@1258
   634
     * Windows systems it returns {@code "\r\n"}.
jaroslav@1258
   635
     */
jaroslav@1258
   636
    public static String lineSeparator() {
jaroslav@1258
   637
        return lineSeparator;
jaroslav@1258
   638
    }
jaroslav@1258
   639
jaroslav@1258
   640
    private static String lineSeparator;
jaroslav@1258
   641
jaroslav@1258
   642
    /**
jaroslav@1258
   643
     * Sets the system properties to the <code>Properties</code>
jaroslav@1258
   644
     * argument.
jaroslav@1258
   645
     * <p>
jaroslav@1258
   646
     * First, if there is a security manager, its
jaroslav@1258
   647
     * <code>checkPropertiesAccess</code> method is called with no
jaroslav@1258
   648
     * arguments. This may result in a security exception.
jaroslav@1258
   649
     * <p>
jaroslav@1258
   650
     * The argument becomes the current set of system properties for use
jaroslav@1258
   651
     * by the {@link #getProperty(String)} method. If the argument is
jaroslav@1258
   652
     * <code>null</code>, then the current set of system properties is
jaroslav@1258
   653
     * forgotten.
jaroslav@1258
   654
     *
jaroslav@1258
   655
     * @param      props   the new system properties.
jaroslav@1258
   656
     * @exception  SecurityException  if a security manager exists and its
jaroslav@1258
   657
     *             <code>checkPropertiesAccess</code> method doesn't allow access
jaroslav@1258
   658
     *              to the system properties.
jaroslav@1258
   659
     * @see        #getProperties
jaroslav@1258
   660
     * @see        java.util.Properties
jaroslav@1258
   661
     * @see        java.lang.SecurityException
jaroslav@1258
   662
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
jaroslav@1258
   663
     */
jaroslav@1258
   664
    public static void setProperties(Properties props) {
jaroslav@1258
   665
        SecurityManager sm = getSecurityManager();
jaroslav@1258
   666
        if (sm != null) {
jaroslav@1258
   667
            sm.checkPropertiesAccess();
jaroslav@1258
   668
        }
jaroslav@1258
   669
        if (props == null) {
jaroslav@1258
   670
            props = new Properties();
jaroslav@1258
   671
            initProperties(props);
jaroslav@1258
   672
        }
jaroslav@1258
   673
        System.props = props;
jaroslav@1258
   674
    }
jaroslav@1258
   675
jaroslav@1258
   676
    /**
jaroslav@1258
   677
     * Gets the system property indicated by the specified key.
jaroslav@1258
   678
     * <p>
jaroslav@1258
   679
     * First, if there is a security manager, its
jaroslav@1258
   680
     * <code>checkPropertyAccess</code> method is called with the key as
jaroslav@1258
   681
     * its argument. This may result in a SecurityException.
jaroslav@1258
   682
     * <p>
jaroslav@1258
   683
     * If there is no current set of system properties, a set of system
jaroslav@1258
   684
     * properties is first created and initialized in the same manner as
jaroslav@1258
   685
     * for the <code>getProperties</code> method.
jaroslav@1258
   686
     *
jaroslav@1258
   687
     * @param      key   the name of the system property.
jaroslav@1258
   688
     * @return     the string value of the system property,
jaroslav@1258
   689
     *             or <code>null</code> if there is no property with that key.
jaroslav@1258
   690
     *
jaroslav@1258
   691
     * @exception  SecurityException  if a security manager exists and its
jaroslav@1258
   692
     *             <code>checkPropertyAccess</code> method doesn't allow
jaroslav@1258
   693
     *              access to the specified system property.
jaroslav@1258
   694
     * @exception  NullPointerException if <code>key</code> is
jaroslav@1258
   695
     *             <code>null</code>.
jaroslav@1258
   696
     * @exception  IllegalArgumentException if <code>key</code> is empty.
jaroslav@1258
   697
     * @see        #setProperty
jaroslav@1258
   698
     * @see        java.lang.SecurityException
jaroslav@1258
   699
     * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
jaroslav@1258
   700
     * @see        java.lang.System#getProperties()
jaroslav@1258
   701
     */
jaroslav@1258
   702
    public static String getProperty(String key) {
jaroslav@1258
   703
        checkKey(key);
jaroslav@1258
   704
        SecurityManager sm = getSecurityManager();
jaroslav@1258
   705
        if (sm != null) {
jaroslav@1258
   706
            sm.checkPropertyAccess(key);
jaroslav@1258
   707
        }
jaroslav@1258
   708
jaroslav@1258
   709
        return props.getProperty(key);
jaroslav@1258
   710
    }
jaroslav@1258
   711
jaroslav@1258
   712
    /**
jaroslav@1258
   713
     * Gets the system property indicated by the specified key.
jaroslav@1258
   714
     * <p>
jaroslav@1258
   715
     * First, if there is a security manager, its
jaroslav@1258
   716
     * <code>checkPropertyAccess</code> method is called with the
jaroslav@1258
   717
     * <code>key</code> as its argument.
jaroslav@1258
   718
     * <p>
jaroslav@1258
   719
     * If there is no current set of system properties, a set of system
jaroslav@1258
   720
     * properties is first created and initialized in the same manner as
jaroslav@1258
   721
     * for the <code>getProperties</code> method.
jaroslav@1258
   722
     *
jaroslav@1258
   723
     * @param      key   the name of the system property.
jaroslav@1258
   724
     * @param      def   a default value.
jaroslav@1258
   725
     * @return     the string value of the system property,
jaroslav@1258
   726
     *             or the default value if there is no property with that key.
jaroslav@1258
   727
     *
jaroslav@1258
   728
     * @exception  SecurityException  if a security manager exists and its
jaroslav@1258
   729
     *             <code>checkPropertyAccess</code> method doesn't allow
jaroslav@1258
   730
     *             access to the specified system property.
jaroslav@1258
   731
     * @exception  NullPointerException if <code>key</code> is
jaroslav@1258
   732
     *             <code>null</code>.
jaroslav@1258
   733
     * @exception  IllegalArgumentException if <code>key</code> is empty.
jaroslav@1258
   734
     * @see        #setProperty
jaroslav@1258
   735
     * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
jaroslav@1258
   736
     * @see        java.lang.System#getProperties()
jaroslav@1258
   737
     */
jaroslav@1258
   738
    public static String getProperty(String key, String def) {
jaroslav@1258
   739
        checkKey(key);
jaroslav@1258
   740
        SecurityManager sm = getSecurityManager();
jaroslav@1258
   741
        if (sm != null) {
jaroslav@1258
   742
            sm.checkPropertyAccess(key);
jaroslav@1258
   743
        }
jaroslav@1258
   744
jaroslav@1258
   745
        return props.getProperty(key, def);
jaroslav@1258
   746
    }
jaroslav@1258
   747
jaroslav@1258
   748
    /**
jaroslav@1258
   749
     * Sets the system property indicated by the specified key.
jaroslav@1258
   750
     * <p>
jaroslav@1258
   751
     * First, if a security manager exists, its
jaroslav@1258
   752
     * <code>SecurityManager.checkPermission</code> method
jaroslav@1258
   753
     * is called with a <code>PropertyPermission(key, "write")</code>
jaroslav@1258
   754
     * permission. This may result in a SecurityException being thrown.
jaroslav@1258
   755
     * If no exception is thrown, the specified property is set to the given
jaroslav@1258
   756
     * value.
jaroslav@1258
   757
     * <p>
jaroslav@1258
   758
     *
jaroslav@1258
   759
     * @param      key   the name of the system property.
jaroslav@1258
   760
     * @param      value the value of the system property.
jaroslav@1258
   761
     * @return     the previous value of the system property,
jaroslav@1258
   762
     *             or <code>null</code> if it did not have one.
jaroslav@1258
   763
     *
jaroslav@1258
   764
     * @exception  SecurityException  if a security manager exists and its
jaroslav@1258
   765
     *             <code>checkPermission</code> method doesn't allow
jaroslav@1258
   766
     *             setting of the specified property.
jaroslav@1258
   767
     * @exception  NullPointerException if <code>key</code> or
jaroslav@1258
   768
     *             <code>value</code> is <code>null</code>.
jaroslav@1258
   769
     * @exception  IllegalArgumentException if <code>key</code> is empty.
jaroslav@1258
   770
     * @see        #getProperty
jaroslav@1258
   771
     * @see        java.lang.System#getProperty(java.lang.String)
jaroslav@1258
   772
     * @see        java.lang.System#getProperty(java.lang.String, java.lang.String)
jaroslav@1258
   773
     * @see        java.util.PropertyPermission
jaroslav@1258
   774
     * @see        SecurityManager#checkPermission
jaroslav@1258
   775
     * @since      1.2
jaroslav@1258
   776
     */
jaroslav@1258
   777
    public static String setProperty(String key, String value) {
jaroslav@1258
   778
        checkKey(key);
jaroslav@1258
   779
        SecurityManager sm = getSecurityManager();
jaroslav@1258
   780
        if (sm != null) {
jaroslav@1258
   781
            sm.checkPermission(new PropertyPermission(key,
jaroslav@1258
   782
                SecurityConstants.PROPERTY_WRITE_ACTION));
jaroslav@1258
   783
        }
jaroslav@1258
   784
jaroslav@1258
   785
        return (String) props.setProperty(key, value);
jaroslav@1258
   786
    }
jaroslav@1258
   787
jaroslav@1258
   788
    /**
jaroslav@1258
   789
     * Removes the system property indicated by the specified key.
jaroslav@1258
   790
     * <p>
jaroslav@1258
   791
     * First, if a security manager exists, its
jaroslav@1258
   792
     * <code>SecurityManager.checkPermission</code> method
jaroslav@1258
   793
     * is called with a <code>PropertyPermission(key, "write")</code>
jaroslav@1258
   794
     * permission. This may result in a SecurityException being thrown.
jaroslav@1258
   795
     * If no exception is thrown, the specified property is removed.
jaroslav@1258
   796
     * <p>
jaroslav@1258
   797
     *
jaroslav@1258
   798
     * @param      key   the name of the system property to be removed.
jaroslav@1258
   799
     * @return     the previous string value of the system property,
jaroslav@1258
   800
     *             or <code>null</code> if there was no property with that key.
jaroslav@1258
   801
     *
jaroslav@1258
   802
     * @exception  SecurityException  if a security manager exists and its
jaroslav@1258
   803
     *             <code>checkPropertyAccess</code> method doesn't allow
jaroslav@1258
   804
     *              access to the specified system property.
jaroslav@1258
   805
     * @exception  NullPointerException if <code>key</code> is
jaroslav@1258
   806
     *             <code>null</code>.
jaroslav@1258
   807
     * @exception  IllegalArgumentException if <code>key</code> is empty.
jaroslav@1258
   808
     * @see        #getProperty
jaroslav@1258
   809
     * @see        #setProperty
jaroslav@1258
   810
     * @see        java.util.Properties
jaroslav@1258
   811
     * @see        java.lang.SecurityException
jaroslav@1258
   812
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
jaroslav@1258
   813
     * @since 1.5
jaroslav@1258
   814
     */
jaroslav@1258
   815
    public static String clearProperty(String key) {
jaroslav@1258
   816
        checkKey(key);
jaroslav@1258
   817
        SecurityManager sm = getSecurityManager();
jaroslav@1258
   818
        if (sm != null) {
jaroslav@1258
   819
            sm.checkPermission(new PropertyPermission(key, "write"));
jaroslav@1258
   820
        }
jaroslav@1258
   821
jaroslav@1258
   822
        return (String) props.remove(key);
jaroslav@1258
   823
    }
jaroslav@1258
   824
jaroslav@1258
   825
    private static void checkKey(String key) {
jaroslav@1258
   826
        if (key == null) {
jaroslav@1258
   827
            throw new NullPointerException("key can't be null");
jaroslav@1258
   828
        }
jaroslav@1258
   829
        if (key.equals("")) {
jaroslav@1258
   830
            throw new IllegalArgumentException("key can't be empty");
jaroslav@1258
   831
        }
jaroslav@1258
   832
    }
jaroslav@1258
   833
jaroslav@1258
   834
    /**
jaroslav@1258
   835
     * Gets the value of the specified environment variable. An
jaroslav@1258
   836
     * environment variable is a system-dependent external named
jaroslav@1258
   837
     * value.
jaroslav@1258
   838
     *
jaroslav@1258
   839
     * <p>If a security manager exists, its
jaroslav@1258
   840
     * {@link SecurityManager#checkPermission checkPermission}
jaroslav@1258
   841
     * method is called with a
jaroslav@1258
   842
     * <code>{@link RuntimePermission}("getenv."+name)</code>
jaroslav@1258
   843
     * permission.  This may result in a {@link SecurityException}
jaroslav@1258
   844
     * being thrown.  If no exception is thrown the value of the
jaroslav@1258
   845
     * variable <code>name</code> is returned.
jaroslav@1258
   846
     *
jaroslav@1258
   847
     * <p><a name="EnvironmentVSSystemProperties"><i>System
jaroslav@1258
   848
     * properties</i> and <i>environment variables</i></a> are both
jaroslav@1258
   849
     * conceptually mappings between names and values.  Both
jaroslav@1258
   850
     * mechanisms can be used to pass user-defined information to a
jaroslav@1258
   851
     * Java process.  Environment variables have a more global effect,
jaroslav@1258
   852
     * because they are visible to all descendants of the process
jaroslav@1258
   853
     * which defines them, not just the immediate Java subprocess.
jaroslav@1258
   854
     * They can have subtly different semantics, such as case
jaroslav@1258
   855
     * insensitivity, on different operating systems.  For these
jaroslav@1258
   856
     * reasons, environment variables are more likely to have
jaroslav@1258
   857
     * unintended side effects.  It is best to use system properties
jaroslav@1258
   858
     * where possible.  Environment variables should be used when a
jaroslav@1258
   859
     * global effect is desired, or when an external system interface
jaroslav@1258
   860
     * requires an environment variable (such as <code>PATH</code>).
jaroslav@1258
   861
     *
jaroslav@1258
   862
     * <p>On UNIX systems the alphabetic case of <code>name</code> is
jaroslav@1258
   863
     * typically significant, while on Microsoft Windows systems it is
jaroslav@1258
   864
     * typically not.  For example, the expression
jaroslav@1258
   865
     * <code>System.getenv("FOO").equals(System.getenv("foo"))</code>
jaroslav@1258
   866
     * is likely to be true on Microsoft Windows.
jaroslav@1258
   867
     *
jaroslav@1258
   868
     * @param  name the name of the environment variable
jaroslav@1258
   869
     * @return the string value of the variable, or <code>null</code>
jaroslav@1258
   870
     *         if the variable is not defined in the system environment
jaroslav@1258
   871
     * @throws NullPointerException if <code>name</code> is <code>null</code>
jaroslav@1258
   872
     * @throws SecurityException
jaroslav@1258
   873
     *         if a security manager exists and its
jaroslav@1258
   874
     *         {@link SecurityManager#checkPermission checkPermission}
jaroslav@1258
   875
     *         method doesn't allow access to the environment variable
jaroslav@1258
   876
     *         <code>name</code>
jaroslav@1258
   877
     * @see    #getenv()
jaroslav@1258
   878
     * @see    ProcessBuilder#environment()
jaroslav@1258
   879
     */
jaroslav@1258
   880
    public static String getenv(String name) {
jaroslav@1258
   881
        SecurityManager sm = getSecurityManager();
jaroslav@1258
   882
        if (sm != null) {
jaroslav@1258
   883
            sm.checkPermission(new RuntimePermission("getenv."+name));
jaroslav@1258
   884
        }
jaroslav@1258
   885
jaroslav@1258
   886
        return ProcessEnvironment.getenv(name);
jaroslav@1258
   887
    }
jaroslav@1258
   888
jaroslav@1258
   889
jaroslav@1258
   890
    /**
jaroslav@1258
   891
     * Returns an unmodifiable string map view of the current system environment.
jaroslav@1258
   892
     * The environment is a system-dependent mapping from names to
jaroslav@1258
   893
     * values which is passed from parent to child processes.
jaroslav@1258
   894
     *
jaroslav@1258
   895
     * <p>If the system does not support environment variables, an
jaroslav@1258
   896
     * empty map is returned.
jaroslav@1258
   897
     *
jaroslav@1258
   898
     * <p>The returned map will never contain null keys or values.
jaroslav@1258
   899
     * Attempting to query the presence of a null key or value will
jaroslav@1258
   900
     * throw a {@link NullPointerException}.  Attempting to query
jaroslav@1258
   901
     * the presence of a key or value which is not of type
jaroslav@1258
   902
     * {@link String} will throw a {@link ClassCastException}.
jaroslav@1258
   903
     *
jaroslav@1258
   904
     * <p>The returned map and its collection views may not obey the
jaroslav@1258
   905
     * general contract of the {@link Object#equals} and
jaroslav@1258
   906
     * {@link Object#hashCode} methods.
jaroslav@1258
   907
     *
jaroslav@1258
   908
     * <p>The returned map is typically case-sensitive on all platforms.
jaroslav@1258
   909
     *
jaroslav@1258
   910
     * <p>If a security manager exists, its
jaroslav@1258
   911
     * {@link SecurityManager#checkPermission checkPermission}
jaroslav@1258
   912
     * method is called with a
jaroslav@1258
   913
     * <code>{@link RuntimePermission}("getenv.*")</code>
jaroslav@1258
   914
     * permission.  This may result in a {@link SecurityException} being
jaroslav@1258
   915
     * thrown.
jaroslav@1258
   916
     *
jaroslav@1258
   917
     * <p>When passing information to a Java subprocess,
jaroslav@1258
   918
     * <a href=#EnvironmentVSSystemProperties>system properties</a>
jaroslav@1258
   919
     * are generally preferred over environment variables.
jaroslav@1258
   920
     *
jaroslav@1258
   921
     * @return the environment as a map of variable names to values
jaroslav@1258
   922
     * @throws SecurityException
jaroslav@1258
   923
     *         if a security manager exists and its
jaroslav@1258
   924
     *         {@link SecurityManager#checkPermission checkPermission}
jaroslav@1258
   925
     *         method doesn't allow access to the process environment
jaroslav@1258
   926
     * @see    #getenv(String)
jaroslav@1258
   927
     * @see    ProcessBuilder#environment()
jaroslav@1258
   928
     * @since  1.5
jaroslav@1258
   929
     */
jaroslav@1258
   930
    public static java.util.Map<String,String> getenv() {
jaroslav@1258
   931
        SecurityManager sm = getSecurityManager();
jaroslav@1258
   932
        if (sm != null) {
jaroslav@1258
   933
            sm.checkPermission(new RuntimePermission("getenv.*"));
jaroslav@1258
   934
        }
jaroslav@1258
   935
jaroslav@1258
   936
        return ProcessEnvironment.getenv();
jaroslav@1258
   937
    }
jaroslav@1258
   938
jaroslav@1258
   939
    /**
jaroslav@1258
   940
     * Terminates the currently running Java Virtual Machine. The
jaroslav@1258
   941
     * argument serves as a status code; by convention, a nonzero status
jaroslav@1258
   942
     * code indicates abnormal termination.
jaroslav@1258
   943
     * <p>
jaroslav@1258
   944
     * This method calls the <code>exit</code> method in class
jaroslav@1258
   945
     * <code>Runtime</code>. This method never returns normally.
jaroslav@1258
   946
     * <p>
jaroslav@1258
   947
     * The call <code>System.exit(n)</code> is effectively equivalent to
jaroslav@1258
   948
     * the call:
jaroslav@1258
   949
     * <blockquote><pre>
jaroslav@1258
   950
     * Runtime.getRuntime().exit(n)
jaroslav@1258
   951
     * </pre></blockquote>
jaroslav@1258
   952
     *
jaroslav@1258
   953
     * @param      status   exit status.
jaroslav@1258
   954
     * @throws  SecurityException
jaroslav@1258
   955
     *        if a security manager exists and its <code>checkExit</code>
jaroslav@1258
   956
     *        method doesn't allow exit with the specified status.
jaroslav@1258
   957
     * @see        java.lang.Runtime#exit(int)
jaroslav@1258
   958
     */
jaroslav@1258
   959
    public static void exit(int status) {
jaroslav@1258
   960
        Runtime.getRuntime().exit(status);
jaroslav@1258
   961
    }
jaroslav@1258
   962
jaroslav@1258
   963
    /**
jaroslav@1258
   964
     * Runs the garbage collector.
jaroslav@1258
   965
     * <p>
jaroslav@1258
   966
     * Calling the <code>gc</code> method suggests that the Java Virtual
jaroslav@1258
   967
     * Machine expend effort toward recycling unused objects in order to
jaroslav@1258
   968
     * make the memory they currently occupy available for quick reuse.
jaroslav@1258
   969
     * When control returns from the method call, the Java Virtual
jaroslav@1258
   970
     * Machine has made a best effort to reclaim space from all discarded
jaroslav@1258
   971
     * objects.
jaroslav@1258
   972
     * <p>
jaroslav@1258
   973
     * The call <code>System.gc()</code> is effectively equivalent to the
jaroslav@1258
   974
     * call:
jaroslav@1258
   975
     * <blockquote><pre>
jaroslav@1258
   976
     * Runtime.getRuntime().gc()
jaroslav@1258
   977
     * </pre></blockquote>
jaroslav@1258
   978
     *
jaroslav@1258
   979
     * @see     java.lang.Runtime#gc()
jaroslav@1258
   980
     */
jaroslav@1258
   981
    public static void gc() {
jaroslav@1258
   982
        Runtime.getRuntime().gc();
jaroslav@1258
   983
    }
jaroslav@1258
   984
jaroslav@1258
   985
    /**
jaroslav@1258
   986
     * Runs the finalization methods of any objects pending finalization.
jaroslav@1258
   987
     * <p>
jaroslav@1258
   988
     * Calling this method suggests that the Java Virtual Machine expend
jaroslav@1258
   989
     * effort toward running the <code>finalize</code> methods of objects
jaroslav@1258
   990
     * that have been found to be discarded but whose <code>finalize</code>
jaroslav@1258
   991
     * methods have not yet been run. When control returns from the
jaroslav@1258
   992
     * method call, the Java Virtual Machine has made a best effort to
jaroslav@1258
   993
     * complete all outstanding finalizations.
jaroslav@1258
   994
     * <p>
jaroslav@1258
   995
     * The call <code>System.runFinalization()</code> is effectively
jaroslav@1258
   996
     * equivalent to the call:
jaroslav@1258
   997
     * <blockquote><pre>
jaroslav@1258
   998
     * Runtime.getRuntime().runFinalization()
jaroslav@1258
   999
     * </pre></blockquote>
jaroslav@1258
  1000
     *
jaroslav@1258
  1001
     * @see     java.lang.Runtime#runFinalization()
jaroslav@1258
  1002
     */
jaroslav@1258
  1003
    public static void runFinalization() {
jaroslav@1258
  1004
        Runtime.getRuntime().runFinalization();
jaroslav@1258
  1005
    }
jaroslav@1258
  1006
jaroslav@1258
  1007
    /**
jaroslav@1258
  1008
     * Enable or disable finalization on exit; doing so specifies that the
jaroslav@1258
  1009
     * finalizers of all objects that have finalizers that have not yet been
jaroslav@1258
  1010
     * automatically invoked are to be run before the Java runtime exits.
jaroslav@1258
  1011
     * By default, finalization on exit is disabled.
jaroslav@1258
  1012
     *
jaroslav@1258
  1013
     * <p>If there is a security manager,
jaroslav@1258
  1014
     * its <code>checkExit</code> method is first called
jaroslav@1258
  1015
     * with 0 as its argument to ensure the exit is allowed.
jaroslav@1258
  1016
     * This could result in a SecurityException.
jaroslav@1258
  1017
     *
jaroslav@1258
  1018
     * @deprecated  This method is inherently unsafe.  It may result in
jaroslav@1258
  1019
     *      finalizers being called on live objects while other threads are
jaroslav@1258
  1020
     *      concurrently manipulating those objects, resulting in erratic
jaroslav@1258
  1021
     *      behavior or deadlock.
jaroslav@1258
  1022
     * @param value indicating enabling or disabling of finalization
jaroslav@1258
  1023
     * @throws  SecurityException
jaroslav@1258
  1024
     *        if a security manager exists and its <code>checkExit</code>
jaroslav@1258
  1025
     *        method doesn't allow the exit.
jaroslav@1258
  1026
     *
jaroslav@1258
  1027
     * @see     java.lang.Runtime#exit(int)
jaroslav@1258
  1028
     * @see     java.lang.Runtime#gc()
jaroslav@1258
  1029
     * @see     java.lang.SecurityManager#checkExit(int)
jaroslav@1258
  1030
     * @since   JDK1.1
jaroslav@1258
  1031
     */
jaroslav@1258
  1032
    @Deprecated
jaroslav@1258
  1033
    public static void runFinalizersOnExit(boolean value) {
jaroslav@1258
  1034
        Runtime.getRuntime().runFinalizersOnExit(value);
jaroslav@1258
  1035
    }
jaroslav@1258
  1036
jaroslav@1258
  1037
    /**
jaroslav@1258
  1038
     * Loads a code file with the specified filename from the local file
jaroslav@1258
  1039
     * system as a dynamic library. The filename
jaroslav@1258
  1040
     * argument must be a complete path name.
jaroslav@1258
  1041
     * <p>
jaroslav@1258
  1042
     * The call <code>System.load(name)</code> is effectively equivalent
jaroslav@1258
  1043
     * to the call:
jaroslav@1258
  1044
     * <blockquote><pre>
jaroslav@1258
  1045
     * Runtime.getRuntime().load(name)
jaroslav@1258
  1046
     * </pre></blockquote>
jaroslav@1258
  1047
     *
jaroslav@1258
  1048
     * @param      filename   the file to load.
jaroslav@1258
  1049
     * @exception  SecurityException  if a security manager exists and its
jaroslav@1258
  1050
     *             <code>checkLink</code> method doesn't allow
jaroslav@1258
  1051
     *             loading of the specified dynamic library
jaroslav@1258
  1052
     * @exception  UnsatisfiedLinkError  if the file does not exist.
jaroslav@1258
  1053
     * @exception  NullPointerException if <code>filename</code> is
jaroslav@1258
  1054
     *             <code>null</code>
jaroslav@1258
  1055
     * @see        java.lang.Runtime#load(java.lang.String)
jaroslav@1258
  1056
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
jaroslav@1258
  1057
     */
jaroslav@1258
  1058
    public static void load(String filename) {
jaroslav@1258
  1059
        Runtime.getRuntime().load0(getCallerClass(), filename);
jaroslav@1258
  1060
    }
jaroslav@1258
  1061
jaroslav@1258
  1062
    /**
jaroslav@1258
  1063
     * Loads the system library specified by the <code>libname</code>
jaroslav@1258
  1064
     * argument. The manner in which a library name is mapped to the
jaroslav@1258
  1065
     * actual system library is system dependent.
jaroslav@1258
  1066
     * <p>
jaroslav@1258
  1067
     * The call <code>System.loadLibrary(name)</code> is effectively
jaroslav@1258
  1068
     * equivalent to the call
jaroslav@1258
  1069
     * <blockquote><pre>
jaroslav@1258
  1070
     * Runtime.getRuntime().loadLibrary(name)
jaroslav@1258
  1071
     * </pre></blockquote>
jaroslav@1258
  1072
     *
jaroslav@1258
  1073
     * @param      libname   the name of the library.
jaroslav@1258
  1074
     * @exception  SecurityException  if a security manager exists and its
jaroslav@1258
  1075
     *             <code>checkLink</code> method doesn't allow
jaroslav@1258
  1076
     *             loading of the specified dynamic library
jaroslav@1258
  1077
     * @exception  UnsatisfiedLinkError  if the library does not exist.
jaroslav@1258
  1078
     * @exception  NullPointerException if <code>libname</code> is
jaroslav@1258
  1079
     *             <code>null</code>
jaroslav@1258
  1080
     * @see        java.lang.Runtime#loadLibrary(java.lang.String)
jaroslav@1258
  1081
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
jaroslav@1258
  1082
     */
jaroslav@1258
  1083
    public static void loadLibrary(String libname) {
jaroslav@1258
  1084
        Runtime.getRuntime().loadLibrary0(getCallerClass(), libname);
jaroslav@1258
  1085
    }
jaroslav@1258
  1086
jaroslav@1258
  1087
    /**
jaroslav@1258
  1088
     * Maps a library name into a platform-specific string representing
jaroslav@1258
  1089
     * a native library.
jaroslav@1258
  1090
     *
jaroslav@1258
  1091
     * @param      libname the name of the library.
jaroslav@1258
  1092
     * @return     a platform-dependent native library name.
jaroslav@1258
  1093
     * @exception  NullPointerException if <code>libname</code> is
jaroslav@1258
  1094
     *             <code>null</code>
jaroslav@1258
  1095
     * @see        java.lang.System#loadLibrary(java.lang.String)
jaroslav@1258
  1096
     * @see        java.lang.ClassLoader#findLibrary(java.lang.String)
jaroslav@1258
  1097
     * @since      1.2
jaroslav@1258
  1098
     */
jaroslav@1258
  1099
    public static native String mapLibraryName(String libname);
jaroslav@1258
  1100
jaroslav@1258
  1101
    /**
jaroslav@1258
  1102
     * Initialize the system class.  Called after thread initialization.
jaroslav@1258
  1103
     */
jaroslav@1258
  1104
    private static void initializeSystemClass() {
jaroslav@1258
  1105
jaroslav@1258
  1106
        // VM might invoke JNU_NewStringPlatform() to set those encoding
jaroslav@1258
  1107
        // sensitive properties (user.home, user.name, boot.class.path, etc.)
jaroslav@1258
  1108
        // during "props" initialization, in which it may need access, via
jaroslav@1258
  1109
        // System.getProperty(), to the related system encoding property that
jaroslav@1258
  1110
        // have been initialized (put into "props") at early stage of the
jaroslav@1258
  1111
        // initialization. So make sure the "props" is available at the
jaroslav@1258
  1112
        // very beginning of the initialization and all system properties to
jaroslav@1258
  1113
        // be put into it directly.
jaroslav@1258
  1114
        props = new Properties();
jaroslav@1258
  1115
        initProperties(props);  // initialized by the VM
jaroslav@1258
  1116
jaroslav@1258
  1117
        // There are certain system configurations that may be controlled by
jaroslav@1258
  1118
        // VM options such as the maximum amount of direct memory and
jaroslav@1258
  1119
        // Integer cache size used to support the object identity semantics
jaroslav@1258
  1120
        // of autoboxing.  Typically, the library will obtain these values
jaroslav@1258
  1121
        // from the properties set by the VM.  If the properties are for
jaroslav@1258
  1122
        // internal implementation use only, these properties should be
jaroslav@1258
  1123
        // removed from the system properties.
jaroslav@1258
  1124
        //
jaroslav@1258
  1125
        // See java.lang.Integer.IntegerCache and the
jaroslav@1258
  1126
        // sun.misc.VM.saveAndRemoveProperties method for example.
jaroslav@1258
  1127
        //
jaroslav@1258
  1128
        // Save a private copy of the system properties object that
jaroslav@1258
  1129
        // can only be accessed by the internal implementation.  Remove
jaroslav@1258
  1130
        // certain system properties that are not intended for public access.
jaroslav@1258
  1131
        sun.misc.VM.saveAndRemoveProperties(props);
jaroslav@1258
  1132
jaroslav@1258
  1133
jaroslav@1258
  1134
        lineSeparator = props.getProperty("line.separator");
jaroslav@1258
  1135
        sun.misc.Version.init();
jaroslav@1258
  1136
jaroslav@1258
  1137
        FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
jaroslav@1258
  1138
        FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
jaroslav@1258
  1139
        FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
jaroslav@1258
  1140
        setIn0(new BufferedInputStream(fdIn));
jaroslav@1258
  1141
        setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
jaroslav@1258
  1142
        setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
jaroslav@1258
  1143
        // Load the zip library now in order to keep java.util.zip.ZipFile
jaroslav@1258
  1144
        // from trying to use itself to load this library later.
jaroslav@1258
  1145
        loadLibrary("zip");
jaroslav@1258
  1146
jaroslav@1258
  1147
        // Setup Java signal handlers for HUP, TERM, and INT (where available).
jaroslav@1258
  1148
        Terminator.setup();
jaroslav@1258
  1149
jaroslav@1258
  1150
        // Initialize any miscellenous operating system settings that need to be
jaroslav@1258
  1151
        // set for the class libraries. Currently this is no-op everywhere except
jaroslav@1258
  1152
        // for Windows where the process-wide error mode is set before the java.io
jaroslav@1258
  1153
        // classes are used.
jaroslav@1258
  1154
        sun.misc.VM.initializeOSEnvironment();
jaroslav@1258
  1155
jaroslav@1258
  1156
        // Subsystems that are invoked during initialization can invoke
jaroslav@1258
  1157
        // sun.misc.VM.isBooted() in order to avoid doing things that should
jaroslav@1258
  1158
        // wait until the application class loader has been set up.
jaroslav@1258
  1159
        sun.misc.VM.booted();
jaroslav@1258
  1160
jaroslav@1258
  1161
        // The main thread is not added to its thread group in the same
jaroslav@1258
  1162
        // way as other threads; we must do it ourselves here.
jaroslav@1258
  1163
        Thread current = Thread.currentThread();
jaroslav@1258
  1164
        current.getThreadGroup().add(current);
jaroslav@1258
  1165
jaroslav@1258
  1166
        // register shared secrets
jaroslav@1258
  1167
        setJavaLangAccess();
jaroslav@1258
  1168
    }
jaroslav@1258
  1169
jaroslav@1258
  1170
    private static void setJavaLangAccess() {
jaroslav@1258
  1171
        // Allow privileged classes outside of java.lang
jaroslav@1258
  1172
        sun.misc.SharedSecrets.setJavaLangAccess(new sun.misc.JavaLangAccess(){
jaroslav@1258
  1173
            public sun.reflect.ConstantPool getConstantPool(Class klass) {
jaroslav@1258
  1174
                return klass.getConstantPool();
jaroslav@1258
  1175
            }
jaroslav@1258
  1176
            public void setAnnotationType(Class klass, AnnotationType type) {
jaroslav@1258
  1177
                klass.setAnnotationType(type);
jaroslav@1258
  1178
            }
jaroslav@1258
  1179
            public AnnotationType getAnnotationType(Class klass) {
jaroslav@1258
  1180
                return klass.getAnnotationType();
jaroslav@1258
  1181
            }
jaroslav@1258
  1182
            public <E extends Enum<E>>
jaroslav@1258
  1183
                    E[] getEnumConstantsShared(Class<E> klass) {
jaroslav@1258
  1184
                return klass.getEnumConstantsShared();
jaroslav@1258
  1185
            }
jaroslav@1258
  1186
            public void blockedOn(Thread t, Interruptible b) {
jaroslav@1258
  1187
                t.blockedOn(b);
jaroslav@1258
  1188
            }
jaroslav@1258
  1189
            public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) {
jaroslav@1258
  1190
                Shutdown.add(slot, registerShutdownInProgress, hook);
jaroslav@1258
  1191
            }
jaroslav@1258
  1192
            public int getStackTraceDepth(Throwable t) {
jaroslav@1258
  1193
                return t.getStackTraceDepth();
jaroslav@1258
  1194
            }
jaroslav@1258
  1195
            public StackTraceElement getStackTraceElement(Throwable t, int i) {
jaroslav@1258
  1196
                return t.getStackTraceElement(i);
jaroslav@1258
  1197
            }
jaroslav@1258
  1198
        });
jaroslav@1258
  1199
    }
jaroslav@1258
  1200
jaroslav@1258
  1201
    /* returns the class of the caller. */
jaroslav@1258
  1202
    static Class<?> getCallerClass() {
jaroslav@1258
  1203
        // NOTE use of more generic Reflection.getCallerClass()
jaroslav@1258
  1204
        return Reflection.getCallerClass(3);
jaroslav@1258
  1205
    }
jaroslav@1258
  1206
}