jdk/src/java.base/share/classes/java/lang/Runtime.java
author chegar
Fri, 15 Apr 2016 16:19:15 +0100
changeset 37363 329dba26ffd2
parent 34350 6beb09485bdd
child 37521 b6e0f285c998
permissions -rw-r--r--
8137058: Clear out all non-Critical APIs from sun.reflect Reviewed-by: alanb, jfranck, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24367
705490680527 8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents: 18776
diff changeset
     2
 * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.StringTokenizer;
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 34350
diff changeset
    30
import jdk.internal.reflect.CallerSensitive;
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 34350
diff changeset
    31
import jdk.internal.reflect.Reflection;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Every Java application has a single instance of class
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    35
 * {@code Runtime} that allows the application to interface with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * the environment in which the application is running. The current
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    37
 * runtime can be obtained from the {@code getRuntime} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * An application cannot create its own instance of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author  unascribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see     java.lang.Runtime#getRuntime()
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
    43
 * @since   1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class Runtime {
34350
6beb09485bdd 8144210: Runtime.currentRuntime should be final
alanb
parents: 30042
diff changeset
    47
    private static final Runtime currentRuntime = new Runtime();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Returns the runtime object associated with the current Java application.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    51
     * Most of the methods of class {@code Runtime} are instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * methods and must be invoked with respect to the current runtime object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    54
     * @return  the {@code Runtime} object associated with the current
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     *          Java application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static Runtime getRuntime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        return currentRuntime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /** Don't let anyone else instantiate this class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private Runtime() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Terminates the currently running Java virtual machine by initiating its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * shutdown sequence.  This method never returns normally.  The argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * serves as a status code; by convention, a nonzero status code indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * abnormal termination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * <p> The virtual machine's shutdown sequence consists of two phases.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * the first phase all registered {@link #addShutdownHook shutdown hooks},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * if any, are started in some unspecified order and allowed to run
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * concurrently until they finish.  In the second phase all uninvoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * finalizers are run if {@link #runFinalizersOnExit finalization-on-exit}
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    75
     * has been enabled.  Once this is done the virtual machine {@link #halt halts}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * <p> If this method is invoked after the virtual machine has begun its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * shutdown sequence then if shutdown hooks are being run this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * block indefinitely.  If shutdown hooks have already been run and on-exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * finalization has been enabled then this method halts the virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * with the given status code if the status is nonzero; otherwise, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * blocks indefinitely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    84
     * <p> The {@link System#exit(int) System.exit} method is the
24367
705490680527 8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents: 18776
diff changeset
    85
     * conventional and convenient means of invoking this method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param  status
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *         Termination status.  By convention, a nonzero status code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *         indicates abnormal termination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @throws SecurityException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    92
     *         If a security manager is present and its
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
    93
     *         {@link SecurityManager#checkExit checkExit} method does not permit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *         exiting with the specified status
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @see java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @see java.lang.SecurityManager#checkExit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @see #addShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see #removeShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see #runFinalizersOnExit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see #halt(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public void exit(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            security.checkExit(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        Shutdown.exit(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Registers a new virtual-machine shutdown hook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * <p> The Java virtual machine <i>shuts down</i> in response to two kinds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * of events:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *   <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
   119
     *   <li> The program <i>exits</i> normally, when the last non-daemon
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   120
     *   thread exits or when the {@link #exit exit} (equivalently,
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
   121
     *   {@link System#exit(int) System.exit}) method is invoked, or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 16906
diff changeset
   123
     *   <li> The virtual machine is <i>terminated</i> in response to a
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   124
     *   user interrupt, such as typing {@code ^C}, or a system-wide event,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *   such as user logoff or system shutdown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *   </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <p> A <i>shutdown hook</i> is simply an initialized but unstarted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * thread.  When the virtual machine begins its shutdown sequence it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * start all registered shutdown hooks in some unspecified order and let
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * them run concurrently.  When all the hooks have finished it will then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * run all uninvoked finalizers if finalization-on-exit has been enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Finally, the virtual machine will halt.  Note that daemon threads will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * continue to run during the shutdown sequence, as will non-daemon threads
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   136
     * if shutdown was initiated by invoking the {@link #exit exit} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <p> Once the shutdown sequence has begun it can be stopped only by
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   139
     * invoking the {@link #halt halt} method, which forcibly
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * terminates the virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <p> Once the shutdown sequence has begun it is impossible to register a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * new shutdown hook or de-register a previously-registered hook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Attempting either of these operations will cause an
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   145
     * {@link IllegalStateException} to be thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <p> Shutdown hooks run at a delicate time in the life cycle of a virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * machine and should therefore be coded defensively.  They should, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * particular, be written to be thread-safe and to avoid deadlocks insofar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * as possible.  They should also not rely blindly upon services that may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * have registered their own shutdown hooks and therefore may themselves in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * the process of shutting down.  Attempts to use other thread-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * services such as the AWT event-dispatch thread, for example, may lead to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * deadlocks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <p> Shutdown hooks should also finish their work quickly.  When a
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   157
     * program invokes {@link #exit exit} the expectation is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * that the virtual machine will promptly shut down and exit.  When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * virtual machine is terminated due to user logoff or system shutdown the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * underlying operating system may only allow a fixed amount of time in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * which to shut down and exit.  It is therefore inadvisable to attempt any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * user interaction or to perform a long-running computation in a shutdown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * hook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <p> Uncaught exceptions are handled in shutdown hooks just as in any
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   166
     * other thread, by invoking the
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   167
     * {@link ThreadGroup#uncaughtException uncaughtException} method of the
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   168
     * thread's {@link ThreadGroup} object. The default implementation of this
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   169
     * method prints the exception's stack trace to {@link System#err} and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * terminates the thread; it does not cause the virtual machine to exit or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * halt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * <p> In rare circumstances the virtual machine may <i>abort</i>, that is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * stop running without shutting down cleanly.  This occurs when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * virtual machine is terminated externally, for example with the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   176
     * {@code SIGKILL} signal on Unix or the {@code TerminateProcess} call on
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Microsoft Windows.  The virtual machine may also abort if a native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * method goes awry by, for example, corrupting internal data structures or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * attempting to access nonexistent memory.  If the virtual machine aborts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * then no guarantee can be made about whether or not any shutdown hooks
24367
705490680527 8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents: 18776
diff changeset
   181
     * will be run.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param   hook
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   184
     *          An initialized but unstarted {@link Thread} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *          If the specified hook has already been registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *          or if it can be determined that the hook is already running or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *          has already been run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @throws  IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *          If the virtual machine is already in the process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *          of shutting down
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *          If a security manager is present and it denies
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   197
     *          {@link RuntimePermission}("shutdownHooks")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see #removeShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @see #halt(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see #exit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void addShutdownHook(Thread hook) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            sm.checkPermission(new RuntimePermission("shutdownHooks"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        ApplicationShutdownHooks.add(hook);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   213
     * De-registers a previously-registered virtual-machine shutdown hook.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param hook the hook to remove
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   216
     * @return {@code true} if the specified hook had previously been
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   217
     * registered and was successfully de-registered, {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @throws  IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *          If the virtual machine is already in the process of shutting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *          down
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *          If a security manager is present and it denies
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   226
     *          {@link RuntimePermission}("shutdownHooks")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @see #addShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @see #exit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public boolean removeShutdownHook(Thread hook) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            sm.checkPermission(new RuntimePermission("shutdownHooks"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return ApplicationShutdownHooks.remove(hook);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Forcibly terminates the currently running Java virtual machine.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * method never returns normally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <p> This method should be used with extreme caution.  Unlike the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   245
     * {@link #exit exit} method, this method does not cause shutdown
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * hooks to be started and does not run uninvoked finalizers if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * finalization-on-exit has been enabled.  If the shutdown sequence has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * already been initiated then this method does not wait for any running
24367
705490680527 8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents: 18776
diff changeset
   249
     * shutdown hooks or finalizers to finish their work.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param  status
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   252
     *         Termination status. By convention, a nonzero status code
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   253
     *         indicates abnormal termination. If the {@link Runtime#exit exit}
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   254
     *         (equivalently, {@link System#exit(int) System.exit}) method
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   255
     *         has already been invoked then this status code
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   256
     *         will override the status code passed to that method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @throws SecurityException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   259
     *         If a security manager is present and its
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   260
     *         {@link SecurityManager#checkExit checkExit} method
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   261
     *         does not permit an exit with the specified status
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @see #exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @see #addShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see #removeShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public void halt(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            sm.checkExit(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        Shutdown.halt(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Enable or disable finalization on exit; doing so specifies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * finalizers of all objects that have finalizers that have not yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * automatically invoked are to be run before the Java runtime exits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * By default, finalization on exit is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * <p>If there is a security manager,
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   283
     * its {@code checkExit} method is first called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * with 0 as its argument to ensure the exit is allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * This could result in a SecurityException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @param value true to enable finalization on exit, false to disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @deprecated  This method is inherently unsafe.  It may result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *      finalizers being called on live objects while other threads are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *      concurrently manipulating those objects, resulting in erratic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *      behavior or deadlock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @throws  SecurityException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   294
     *        if a security manager exists and its {@code checkExit}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *        method doesn't allow the exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @see     java.lang.Runtime#exit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @see     java.lang.Runtime#gc()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @see     java.lang.SecurityManager#checkExit(int)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
   300
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public static void runFinalizersOnExit(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                security.checkExit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                throw new SecurityException("runFinalizersOnExit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        Shutdown.setRunFinalizersOnExit(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Executes the specified string command in a separate process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <p>This is a convenience method.  An invocation of the form
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   319
     * {@code exec(command)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * behaves in exactly the same way as the invocation
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   321
     * {@link #exec(String, String[], File) exec}{@code (command, null, null)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @param   command   a specified system command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   336
     *          If {@code command} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @throws  IllegalArgumentException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   339
     *          If {@code command} is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see     #exec(String[], String[], File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public Process exec(String command) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return exec(command, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Executes the specified string command in a separate process with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * specified environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <p>This is a convenience method.  An invocation of the form
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   353
     * {@code exec(command, envp)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * behaves in exactly the same way as the invocation
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   355
     * {@link #exec(String, String[], File) exec}{@code (command, envp, null)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @param   command   a specified system command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @param   envp      array of strings, each element of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *                    has environment variable settings in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *                    <i>name</i>=<i>value</i>, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   362
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *                    the environment of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   376
     *          If {@code command} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   377
     *          or one of the elements of {@code envp} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @throws  IllegalArgumentException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   380
     *          If {@code command} is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @see     #exec(String[], String[], File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public Process exec(String command, String[] envp) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return exec(command, envp, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Executes the specified string command in a separate process with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * specified environment and working directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * <p>This is a convenience method.  An invocation of the form
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   394
     * {@code exec(command, envp, dir)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * behaves in exactly the same way as the invocation
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   396
     * {@link #exec(String[], String[], File) exec}{@code (cmdarray, envp, dir)},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   397
     * where {@code cmdarray} is an array of all the tokens in
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   398
     * {@code command}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   400
     * <p>More precisely, the {@code command} string is broken
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * into tokens using a {@link StringTokenizer} created by the call
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   402
     * {@code new {@link StringTokenizer}(command)} with no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * further modification of the character categories.  The tokens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * produced by the tokenizer are then placed in the new string
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   405
     * array {@code cmdarray}, in the same order.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @param   command   a specified system command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @param   envp      array of strings, each element of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *                    has environment variable settings in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *                    <i>name</i>=<i>value</i>, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   412
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *                    the environment of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param   dir       the working directory of the subprocess, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   416
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *                    the working directory of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   430
     *          If {@code command} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   431
     *          or one of the elements of {@code envp} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @throws  IllegalArgumentException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   434
     *          If {@code command} is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public Process exec(String command, String[] envp, File dir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        if (command.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            throw new IllegalArgumentException("Empty command");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        StringTokenizer st = new StringTokenizer(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        String[] cmdarray = new String[st.countTokens()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        for (int i = 0; st.hasMoreTokens(); i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            cmdarray[i] = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return exec(cmdarray, envp, dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * Executes the specified command and arguments in a separate process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <p>This is a convenience method.  An invocation of the form
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   455
     * {@code exec(cmdarray)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * behaves in exactly the same way as the invocation
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   457
     * {@link #exec(String[], String[], File) exec}{@code (cmdarray, null, null)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param   cmdarray  array containing the command to call and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *                    its arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   473
     *          If {@code cmdarray} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   474
     *          or one of the elements of {@code cmdarray} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @throws  IndexOutOfBoundsException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   477
     *          If {@code cmdarray} is an empty array
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   478
     *          (has length {@code 0})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public Process exec(String cmdarray[]) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return exec(cmdarray, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Executes the specified command and arguments in a separate process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * with the specified environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * <p>This is a convenience method.  An invocation of the form
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   491
     * {@code exec(cmdarray, envp)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * behaves in exactly the same way as the invocation
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   493
     * {@link #exec(String[], String[], File) exec}{@code (cmdarray, envp, null)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @param   cmdarray  array containing the command to call and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *                    its arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @param   envp      array of strings, each element of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *                    has environment variable settings in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *                    <i>name</i>=<i>value</i>, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   501
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *                    the environment of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   515
     *          If {@code cmdarray} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   516
     *          or one of the elements of {@code cmdarray} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   517
     *          or one of the elements of {@code envp} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @throws  IndexOutOfBoundsException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   520
     *          If {@code cmdarray} is an empty array
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   521
     *          (has length {@code 0})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    public Process exec(String[] cmdarray, String[] envp) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        return exec(cmdarray, envp, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Executes the specified command and arguments in a separate process with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * the specified environment and working directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   534
     * <p>Given an array of strings {@code cmdarray}, representing the
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   535
     * tokens of a command line, and an array of strings {@code envp},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * representing "environment" variable settings, this method creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * a new process in which to execute the specified command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   539
     * <p>This method checks that {@code cmdarray} is a valid operating
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * system command.  Which commands are valid is system-dependent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * but at the very least the command must be a non-empty list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * non-null strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   544
     * <p>If {@code envp} is {@code null}, the subprocess inherits the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * environment settings of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
9500
268f823d9e1c 7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents: 5506
diff changeset
   547
     * <p>A minimal set of system dependent environment variables may
268f823d9e1c 7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents: 5506
diff changeset
   548
     * be required to start a process on some operating systems.
268f823d9e1c 7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents: 5506
diff changeset
   549
     * As a result, the subprocess may inherit additional environment variable
268f823d9e1c 7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents: 5506
diff changeset
   550
     * settings beyond those in the specified environment.
268f823d9e1c 7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents: 5506
diff changeset
   551
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * <p>{@link ProcessBuilder#start()} is now the preferred way to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * start a process with a modified environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   555
     * <p>The working directory of the new subprocess is specified by {@code dir}.
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   556
     * If {@code dir} is {@code null}, the subprocess inherits the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * current working directory of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * <p>If a security manager exists, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * method is invoked with the first component of the array
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   562
     * {@code cmdarray} as its argument. This may result in a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * {@link SecurityException} being thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * <p>Starting an operating system process is highly system-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * Among the many things that can go wrong are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * <li>The operating system program file was not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * <li>Access to the program file was denied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * <li>The working directory does not exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <p>In such cases an exception will be thrown.  The exact nature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * of the exception is system-dependent, but it will always be a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * subclass of {@link IOException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *
28872
82a09f5a7ed6 8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents: 28750
diff changeset
   577
     * <p>If the operating system does not support the creation of
82a09f5a7ed6 8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents: 28750
diff changeset
   578
     * processes, an {@link UnsupportedOperationException} will be thrown.
82a09f5a7ed6 8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents: 28750
diff changeset
   579
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @param   cmdarray  array containing the command to call and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *                    its arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @param   envp      array of strings, each element of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *                    has environment variable settings in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     *                    <i>name</i>=<i>value</i>, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   587
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     *                    the environment of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @param   dir       the working directory of the subprocess, or
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   591
     *                    {@code null} if the subprocess should inherit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *                    the working directory of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
28750
a1dae439cdab 8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents: 27184
diff changeset
   601
     * @throws  UnsupportedOperationException
a1dae439cdab 8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents: 27184
diff changeset
   602
     *          If the operating system does not support the creation of processes.
a1dae439cdab 8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents: 27184
diff changeset
   603
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @throws  NullPointerException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   608
     *          If {@code cmdarray} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   609
     *          or one of the elements of {@code cmdarray} is {@code null},
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   610
     *          or one of the elements of {@code envp} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @throws  IndexOutOfBoundsException
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   613
     *          If {@code cmdarray} is an empty array
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   614
     *          (has length {@code 0})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    public Process exec(String[] cmdarray, String[] envp, File dir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        return new ProcessBuilder(cmdarray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            .environment(envp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            .directory(dir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            .start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * Returns the number of processors available to the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * <p> This value may change during a particular invocation of the virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * machine.  Applications that are sensitive to the number of available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * processors should therefore occasionally poll this property and adjust
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * their resource usage appropriately. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @return  the maximum number of processors available to the virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *          machine; never smaller than one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    public native int availableProcessors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Returns the amount of free memory in the Java Virtual Machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * Calling the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   644
     * {@code gc} method may result in increasing the value returned
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   645
     * by {@code freeMemory.}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @return  an approximation to the total amount of memory currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *          available for future allocated objects, measured in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public native long freeMemory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * Returns the total amount of memory in the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * The value returned by this method may vary over time, depending on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * the host environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * Note that the amount of memory required to hold an object of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * given type may be implementation-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @return  the total amount of memory currently available for current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *          and future objects, measured in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public native long totalMemory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /**
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   666
     * Returns the maximum amount of memory that the Java virtual machine
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   667
     * will attempt to use.  If there is no inherent limit then the value
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   668
     * {@link java.lang.Long#MAX_VALUE} will be returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @return  the maximum amount of memory that the virtual machine will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     *          attempt to use, measured in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public native long maxMemory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * Runs the garbage collector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Calling this method suggests that the Java virtual machine expend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * effort toward recycling unused objects in order to make the memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * they currently occupy available for quick reuse. When control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * returns from the method call, the virtual machine has made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * its best effort to recycle all discarded objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * <p>
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   684
     * The name {@code gc} stands for "garbage
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * collector". The virtual machine performs this recycling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * process automatically as needed, in a separate thread, even if the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   687
     * {@code gc} method is not invoked explicitly.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * The method {@link System#gc()} is the conventional and convenient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * means of invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    public native void gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    /* Wormhole for calling java.lang.ref.Finalizer.runFinalization */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    private static native void runFinalization0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * Runs the finalization methods of any objects pending finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Calling this method suggests that the Java virtual machine expend
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   700
     * effort toward running the {@code finalize} methods of objects
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   701
     * that have been found to be discarded but whose {@code finalize}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * methods have not yet been run. When control returns from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * method call, the virtual machine has made a best effort to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * complete all outstanding finalizations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * The virtual machine performs the finalization process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * automatically as needed, in a separate thread, if the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   708
     * {@code runFinalization} method is not invoked explicitly.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * The method {@link System#runFinalization()} is the conventional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * and convenient means of invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @see     java.lang.Object#finalize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    public void runFinalization() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        runFinalization0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * Enables/Disables tracing of instructions.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   721
     * If the {@code boolean} argument is {@code true}, this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * method suggests that the Java virtual machine emit debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * information for each instruction in the virtual machine as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * is executed. The format of this information, and the file or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * output stream to which it is emitted, depends on the host environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * The virtual machine may ignore this request if it does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * this feature. The destination of the trace output is system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * <p>
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   730
     * If the {@code boolean} argument is {@code false}, this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * method causes the virtual machine to stop performing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * detailed instruction trace it is performing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   734
     * @param   on   {@code true} to enable instruction tracing;
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   735
     *               {@code false} to disable this feature.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     */
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
   737
    public void traceInstructions(boolean on) { }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * Enables/Disables tracing of method calls.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   741
     * If the {@code boolean} argument is {@code true}, this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * method suggests that the Java virtual machine emit debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * information for each method in the virtual machine as it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * called. The format of this information, and the file or other output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * stream to which it is emitted, depends on the host environment. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * virtual machine may ignore this request if it does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * Calling this method with argument false suggests that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * virtual machine cease emitting per-call debugging information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     *
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   752
     * @param   on   {@code true} to enable instruction tracing;
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   753
     *               {@code false} to disable this feature.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
   755
    public void traceMethodCalls(boolean on) { }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   758
     * Loads the native library specified by the filename argument.  The filename
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   759
     * argument must be an absolute path name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * (for example
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   761
     * {@code Runtime.getRuntime().load("/home/avh/lib/libX11.so");}).
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   762
     *
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   763
     * If the filename argument, when stripped of any platform-specific library
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   764
     * prefix, path, and file extension, indicates a library whose name is,
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   765
     * for example, L, and a native library called L is statically linked
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   766
     * with the VM, then the JNI_OnLoad_L function exported by the library
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   767
     * is invoked rather than attempting to load a dynamic library.
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   768
     * A filename matching the argument does not have to exist in the file
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   769
     * system. See the JNI Specification for more details.
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   770
     *
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   771
     * Otherwise, the filename argument is mapped to a native library image in
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   772
     * an implementation-dependent manner.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * <p>
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   774
     * First, if there is a security manager, its {@code checkLink}
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   775
     * method is called with the {@code filename} as its argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * This may result in a security exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * This is similar to the method {@link #loadLibrary(String)}, but it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * accepts a general file name as an argument rather than just a library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * name, allowing any file of native code to be loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * The method {@link System#load(String)} is the conventional and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * convenient means of invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * @param      filename   the file to load.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * @exception  SecurityException  if a security manager exists and its
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   787
     *             {@code checkLink} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *             loading of the specified dynamic library
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   789
     * @exception  UnsatisfiedLinkError  if either the filename is not an
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   790
     *             absolute path name, the native library is not statically
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   791
     *             linked with the VM, or the library cannot be mapped to
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   792
     *             a native library image by the host system.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   793
     * @exception  NullPointerException if {@code filename} is
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   794
     *             {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @see        java.lang.Runtime#getRuntime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
   799
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    public void load(String filename) {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
   801
        load0(Reflection.getCallerClass(), filename);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
11117
b6e68b1344d4 7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents: 9500
diff changeset
   804
    synchronized void load0(Class<?> fromClass, String filename) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            security.checkLink(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        if (!(new File(filename).isAbsolute())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            throw new UnsatisfiedLinkError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                "Expecting an absolute path of the library: " + filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        ClassLoader.loadLibrary(fromClass, filename, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    /**
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   817
     * Loads the native library specified by the {@code libname}
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   818
     * argument.  The {@code libname} argument must not contain any platform
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   819
     * specific prefix, file extension or path. If a native library
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   820
     * called {@code libname} is statically linked with the VM, then the
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   821
     * JNI_OnLoad_{@code libname} function exported by the library is invoked.
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   822
     * See the JNI Specification for more details.
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   823
     *
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   824
     * Otherwise, the libname argument is loaded from a system library
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   825
     * location and mapped to a native library image in an implementation-
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   826
     * dependent manner.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * <p>
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   828
     * First, if there is a security manager, its {@code checkLink}
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   829
     * method is called with the {@code libname} as its argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * This may result in a security exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * The method {@link System#loadLibrary(String)} is the conventional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * and convenient means of invoking this method. If native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * methods are to be used in the implementation of a class, a standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * strategy is to put the native code in a library file (call it
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   836
     * {@code LibFile}) and then to put a static initializer:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * static { System.loadLibrary("LibFile"); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * within the class declaration. When the class is loaded and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * initialized, the necessary native code implementation for the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * methods will then be loaded as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * If this method is called more than once with the same library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * name, the second and subsequent calls are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @param      libname   the name of the library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @exception  SecurityException  if a security manager exists and its
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   849
     *             {@code checkLink} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     *             loading of the specified dynamic library
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   851
     * @exception  UnsatisfiedLinkError if either the libname argument
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   852
     *             contains a file path, the native library is not statically
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   853
     *             linked with the VM,  or the library cannot be mapped to a
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 14342
diff changeset
   854
     *             native library image by the host system.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   855
     * @exception  NullPointerException if {@code libname} is
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   856
     *             {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
   860
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    public void loadLibrary(String libname) {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
   862
        loadLibrary0(Reflection.getCallerClass(), libname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
11117
b6e68b1344d4 7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents: 9500
diff changeset
   865
    synchronized void loadLibrary0(Class<?> fromClass, String libname) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            security.checkLink(libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        if (libname.indexOf((int)File.separatorChar) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            throw new UnsatisfiedLinkError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    "Directory separator should not appear in library name: " + libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        ClassLoader.loadLibrary(fromClass, libname, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * Creates a localized version of an input stream. This method takes
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   879
     * an {@code InputStream} and returns an {@code InputStream}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * equivalent to the argument in all respects except that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * localized: as characters in the local character set are read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * the stream, they are automatically converted from the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * character set to Unicode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * If the argument is already a localized stream, it may be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * as the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @param      in InputStream to localize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @return     a localized input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * @see        java.io.InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * @see        java.io.BufferedReader#BufferedReader(java.io.Reader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * @see        java.io.InputStreamReader#InputStreamReader(java.io.InputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * @deprecated As of JDK&nbsp;1.1, the preferred way to translate a byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * stream in the local encoding into a character stream in Unicode is via
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   895
     * the {@code InputStreamReader} and {@code BufferedReader}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    public InputStream getLocalizedInputStream(InputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        return in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * Creates a localized version of an output stream. This method
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   905
     * takes an {@code OutputStream} and returns an
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   906
     * {@code OutputStream} equivalent to the argument in all respects
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * except that it is localized: as Unicode characters are written to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * the stream, they are automatically converted to the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * character set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * If the argument is already a localized stream, it may be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * as the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * @deprecated As of JDK&nbsp;1.1, the preferred way to translate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * Unicode character stream into a byte stream in the local encoding is via
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   916
     * the {@code OutputStreamWriter}, {@code BufferedWriter}, and
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 28872
diff changeset
   917
     * {@code PrintWriter} classes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @param      out OutputStream to localize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @return     a localized output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @see        java.io.OutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @see        java.io.BufferedWriter#BufferedWriter(java.io.Writer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * @see        java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * @see        java.io.PrintWriter#PrintWriter(java.io.OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    public OutputStream getLocalizedOutputStream(OutputStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        return out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
}