jdk/src/share/classes/java/lang/Runtime.java
author martin
Mon, 10 Mar 2008 14:32:51 -0700
changeset 48 dc5744ca15ea
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
4960438: (process) Need IO redirection API for subprocesses Reviewed-by: alanb, iris
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1995-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Every Java application has a single instance of class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <code>Runtime</code> that allows the application to interface with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * the environment in which the application is running. The current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * runtime can be obtained from the <code>getRuntime</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * An application cannot create its own instance of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author  unascribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @see     java.lang.Runtime#getRuntime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @since   JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class Runtime {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static Runtime currentRuntime = new Runtime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Returns the runtime object associated with the current Java application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Most of the methods of class <code>Runtime</code> are instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * methods and must be invoked with respect to the current runtime object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * @return  the <code>Runtime</code> object associated with the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *          Java application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static Runtime getRuntime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return currentRuntime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /** Don't let anyone else instantiate this class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private Runtime() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Terminates the currently running Java virtual machine by initiating its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * shutdown sequence.  This method never returns normally.  The argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * serves as a status code; by convention, a nonzero status code indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * abnormal termination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * <p> The virtual machine's shutdown sequence consists of two phases.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * the first phase all registered {@link #addShutdownHook shutdown hooks},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * if any, are started in some unspecified order and allowed to run
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * concurrently until they finish.  In the second phase all uninvoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * finalizers are run if {@link #runFinalizersOnExit finalization-on-exit}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * has been enabled.  Once this is done the virtual machine {@link #halt
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * halts}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <p> If this method is invoked after the virtual machine has begun its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * shutdown sequence then if shutdown hooks are being run this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * block indefinitely.  If shutdown hooks have already been run and on-exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * finalization has been enabled then this method halts the virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * with the given status code if the status is nonzero; otherwise, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * blocks indefinitely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * <p> The <tt>{@link System#exit(int) System.exit}</tt> method is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * conventional and convenient means of invoking this method. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param  status
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *         Termination status.  By convention, a nonzero status code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *         indicates abnormal termination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *         If a security manager is present and its <tt>{@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *         SecurityManager#checkExit checkExit}</tt> method does not permit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *         exiting with the specified status
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @see java.lang.SecurityManager#checkExit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @see #addShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @see #removeShutdownHook
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see #runFinalizersOnExit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see #halt(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public void exit(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            security.checkExit(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        Shutdown.exit(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Registers a new virtual-machine shutdown hook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * <p> The Java virtual machine <i>shuts down</i> in response to two kinds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * of events:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *   <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *   <p> <li> The program <i>exits</i> normally, when the last non-daemon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *   thread exits or when the <tt>{@link #exit exit}</tt> (equivalently,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *   <tt>{@link System#exit(int) System.exit}</tt>) method is invoked, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *   <p> <li> The virtual machine is <i>terminated</i> in response to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *   user interrupt, such as typing <tt>^C</tt>, or a system-wide event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *   such as user logoff or system shutdown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *   </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * <p> A <i>shutdown hook</i> is simply an initialized but unstarted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * thread.  When the virtual machine begins its shutdown sequence it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * start all registered shutdown hooks in some unspecified order and let
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * them run concurrently.  When all the hooks have finished it will then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * run all uninvoked finalizers if finalization-on-exit has been enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Finally, the virtual machine will halt.  Note that daemon threads will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * continue to run during the shutdown sequence, as will non-daemon threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * if shutdown was initiated by invoking the <tt>{@link #exit exit}</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * method.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * invoking the <tt>{@link #halt halt}</tt> method, which forcibly
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * <tt>{@link IllegalStateException}</tt> to be thrown.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * program invokes <tt>{@link #exit exit}</tt> the expectation is
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * other thread, by invoking the <tt>{@link ThreadGroup#uncaughtException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * uncaughtException}</tt> method of the thread's <tt>{@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * ThreadGroup}</tt> object.  The default implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * prints the exception's stack trace to <tt>{@link System#err}</tt> and
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * <tt>SIGKILL</tt> signal on Unix or the <tt>TerminateProcess</tt> call on
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * will be run. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param   hook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *          An initialized but unstarted <tt>{@link Thread}</tt> object
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *          <tt>{@link RuntimePermission}("shutdownHooks")</tt>
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * De-registers a previously-registered virtual-machine shutdown hook. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param hook the hook to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @return <tt>true</tt> if the specified hook had previously been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * registered and was successfully de-registered, <tt>false</tt>
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *          <tt>{@link RuntimePermission}("shutdownHooks")</tt>
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <tt>{@link #exit exit}</tt> method, this method does not cause shutdown
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * shutdown hooks or finalizers to finish their work. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param  status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *         Termination status.  By convention, a nonzero status code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *         indicates abnormal termination.  If the <tt>{@link Runtime#exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *         exit}</tt> (equivalently, <tt>{@link System#exit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *         System.exit}</tt>) method has already been invoked then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *         status code will override the status code passed to that method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *         If a security manager is present and its <tt>{@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *         SecurityManager#checkExit checkExit}</tt> method does not permit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *         an exit with the specified status
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,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * its <code>checkExit</code> method is first called
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *        if a security manager exists and its <code>checkExit</code>
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)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @since   JDK1.1
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <tt>exec(command)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <tt>{@link #exec(String, String[], File) exec}(command, null, null)</tt>.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *          If <code>command</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *          If <code>command</code> is empty
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * <tt>exec(command, envp)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <tt>{@link #exec(String, String[], File) exec}(command, envp, null)</tt>.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *                    <tt>null</tt> if the subprocess should inherit
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *          If <code>command</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *          or one of the elements of <code>envp</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *          If <code>command</code> is empty
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * <tt>exec(command, envp, dir)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * <tt>{@link #exec(String[], String[], File) exec}(cmdarray, envp, dir)</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * where <code>cmdarray</code> is an array of all the tokens in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * <code>command</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * <p>More precisely, the <code>command</code> string is broken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * into tokens using a {@link StringTokenizer} created by the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * <code>new {@link StringTokenizer}(command)</code> with no
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * array <code>cmdarray</code>, in the same order.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *                    <tt>null</tt> if the subprocess should inherit
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *                    <tt>null</tt> if the subprocess should inherit
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *          If <code>command</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *          or one of the elements of <code>envp</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *          If <code>command</code> is empty
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * <tt>exec(cmdarray)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * <tt>{@link #exec(String[], String[], File) exec}(cmdarray, null, null)</tt>.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *          If <code>cmdarray</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *          or one of the elements of <code>cmdarray</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *          If <code>cmdarray</code> is an empty array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *          (has length <code>0</code>)
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <tt>exec(cmdarray, envp)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <tt>{@link #exec(String[], String[], File) exec}(cmdarray, envp, null)</tt>.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *                    <tt>null</tt> if the subprocess should inherit
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *          If <code>cmdarray</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *          or one of the elements of <code>cmdarray</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *          or one of the elements of <code>envp</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *          If <code>cmdarray</code> is an empty array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *          (has length <code>0</code>)
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
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <p>Given an array of strings <code>cmdarray</code>, representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * tokens of a command line, and an array of strings <code>envp</code>,
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
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * <p>This method checks that <code>cmdarray</code> is a valid operating
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
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * <p>If <tt>envp</tt> is <tt>null</tt>, the subprocess inherits the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * environment settings of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * <p>{@link ProcessBuilder#start()} is now the preferred way to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * start a process with a modified environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * <p>The working directory of the new subprocess is specified by <tt>dir</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * If <tt>dir</tt> is <tt>null</tt>, the subprocess inherits the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * current working directory of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * <p>If a security manager exists, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * method is invoked with the first component of the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * <code>cmdarray</code> as its argument. This may result in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * {@link SecurityException} being thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * <p>Starting an operating system process is highly system-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * Among the many things that can go wrong are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <li>The operating system program file was not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * <li>Access to the program file was denied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * <li>The working directory does not exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * <p>In such cases an exception will be thrown.  The exact nature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * of the exception is system-dependent, but it will always be a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * subclass of {@link IOException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @param   cmdarray  array containing the command to call and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *                    its arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @param   envp      array of strings, each element of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *                    has environment variable settings in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *                    <i>name</i>=<i>value</i>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *                    <tt>null</tt> if the subprocess should inherit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *                    the environment of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @param   dir       the working directory of the subprocess, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *                    <tt>null</tt> if the subprocess should inherit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *                    the working directory of the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @return  A new {@link Process} object for managing the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *          If a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *          {@link SecurityManager#checkExec checkExec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *          method doesn't allow creation of the subprocess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *          If <code>cmdarray</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *          or one of the elements of <code>cmdarray</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *          or one of the elements of <code>envp</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *          If <code>cmdarray</code> is an empty array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     *          (has length <code>0</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @see     ProcessBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    public Process exec(String[] cmdarray, String[] envp, File dir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        return new ProcessBuilder(cmdarray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            .environment(envp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            .directory(dir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            .start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Returns the number of processors available to the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <p> This value may change during a particular invocation of the virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * machine.  Applications that are sensitive to the number of available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * processors should therefore occasionally poll this property and adjust
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * their resource usage appropriately. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @return  the maximum number of processors available to the virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *          machine; never smaller than one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    public native int availableProcessors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * Returns the amount of free memory in the Java Virtual Machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * <code>gc</code> method may result in increasing the value returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * by <code>freeMemory.</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @return  an approximation to the total amount of memory currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *          available for future allocated objects, measured in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    public native long freeMemory();
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 total amount of memory in the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * The value returned by this method may vary over time, depending on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * the host environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * Note that the amount of memory required to hold an object of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * given type may be implementation-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @return  the total amount of memory currently available for current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *          and future objects, measured in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    public native long totalMemory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Returns the maximum amount of memory that the Java virtual machine will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * attempt to use.  If there is no inherent limit then the value {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * java.lang.Long#MAX_VALUE} will be returned. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @return  the maximum amount of memory that the virtual machine will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *          attempt to use, measured in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public native long maxMemory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * Runs the garbage collector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * Calling this method suggests that the Java virtual machine expend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * effort toward recycling unused objects in order to make the memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * they currently occupy available for quick reuse. When control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * returns from the method call, the virtual machine has made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * its best effort to recycle all discarded objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * The name <code>gc</code> stands for "garbage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * collector". The virtual machine performs this recycling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * process automatically as needed, in a separate thread, even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <code>gc</code> method is not invoked explicitly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * The method {@link System#gc()} is the conventional and convenient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * means of invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    public native void gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    /* Wormhole for calling java.lang.ref.Finalizer.runFinalization */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    private static native void runFinalization0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * Runs the finalization methods of any objects pending finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * Calling this method suggests that the Java virtual machine expend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * effort toward running the <code>finalize</code> methods of objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * that have been found to be discarded but whose <code>finalize</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * methods have not yet been run. When control returns from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * method call, the virtual machine has made a best effort to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * complete all outstanding finalizations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * The virtual machine performs the finalization process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * automatically as needed, in a separate thread, if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * <code>runFinalization</code> method is not invoked explicitly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * The method {@link System#runFinalization()} is the conventional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * and convenient means of invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * @see     java.lang.Object#finalize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    public void runFinalization() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        runFinalization0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Enables/Disables tracing of instructions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * If the <code>boolean</code> argument is <code>true</code>, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * method suggests that the Java virtual machine emit debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * information for each instruction in the virtual machine as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * is executed. The format of this information, and the file or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * output stream to which it is emitted, depends on the host environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * The virtual machine may ignore this request if it does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * this feature. The destination of the trace output is system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * If the <code>boolean</code> argument is <code>false</code>, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * method causes the virtual machine to stop performing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * detailed instruction trace it is performing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * @param   on   <code>true</code> to enable instruction tracing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     *               <code>false</code> to disable this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    public native void traceInstructions(boolean on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * Enables/Disables tracing of method calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * If the <code>boolean</code> argument is <code>true</code>, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * method suggests that the Java virtual machine emit debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * information for each method in the virtual machine as it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * called. The format of this information, and the file or other output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * stream to which it is emitted, depends on the host environment. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * virtual machine may ignore this request if it does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Calling this method with argument false suggests that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * virtual machine cease emitting per-call debugging information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * @param   on   <code>true</code> to enable instruction tracing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *               <code>false</code> to disable this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    public native void traceMethodCalls(boolean on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * Loads the specified filename as a dynamic library. The filename
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * argument must be a complete path name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * (for example
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * <code>Runtime.getRuntime().load("/home/avh/lib/libX11.so");</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * First, if there is a security manager, its <code>checkLink</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * method is called with the <code>filename</code> as its argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * This may result in a security exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * This is similar to the method {@link #loadLibrary(String)}, but it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * accepts a general file name as an argument rather than just a library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * name, allowing any file of native code to be loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * The method {@link System#load(String)} is the conventional and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * convenient means of invoking this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * @param      filename   the file to load.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     *             <code>checkLink</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     *             loading of the specified dynamic library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * @exception  UnsatisfiedLinkError  if the file does not exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * @exception  NullPointerException if <code>filename</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     *             <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * @see        java.lang.Runtime#getRuntime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    public void load(String filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        load0(System.getCallerClass(), filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    synchronized void load0(Class fromClass, String filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            security.checkLink(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        if (!(new File(filename).isAbsolute())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            throw new UnsatisfiedLinkError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                "Expecting an absolute path of the library: " + filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        ClassLoader.loadLibrary(fromClass, filename, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * Loads the dynamic library with the specified library name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * A file containing native code is loaded from the local file system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * from a place where library files are conventionally obtained. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * details of this process are implementation-dependent. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * mapping from a library name to a specific filename is done in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * system-specific manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * First, if there is a security manager, its <code>checkLink</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * method is called with the <code>libname</code> as its argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * This may result in a security exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * The method {@link System#loadLibrary(String)} is the conventional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * and convenient means of invoking this method. If native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * methods are to be used in the implementation of a class, a standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * strategy is to put the native code in a library file (call it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * <code>LibFile</code>) and then to put a static initializer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * static { System.loadLibrary("LibFile"); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * within the class declaration. When the class is loaded and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * initialized, the necessary native code implementation for the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * methods will then be loaded as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * If this method is called more than once with the same library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * name, the second and subsequent calls are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @param      libname   the name of the library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *             <code>checkLink</code> method doesn't allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *             loading of the specified dynamic library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @exception  UnsatisfiedLinkError  if the library does not exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @exception  NullPointerException if <code>libname</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     *             <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    public void loadLibrary(String libname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        loadLibrary0(System.getCallerClass(), libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    synchronized void loadLibrary0(Class fromClass, String libname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            security.checkLink(libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        if (libname.indexOf((int)File.separatorChar) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            throw new UnsatisfiedLinkError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    "Directory separator should not appear in library name: " + libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        ClassLoader.loadLibrary(fromClass, libname, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Creates a localized version of an input stream. This method takes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * an <code>InputStream</code> and returns an <code>InputStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * equivalent to the argument in all respects except that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * localized: as characters in the local character set are read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * the stream, they are automatically converted from the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * character set to Unicode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * If the argument is already a localized stream, it may be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * as the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * @param      in InputStream to localize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @return     a localized input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @see        java.io.InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @see        java.io.BufferedReader#BufferedReader(java.io.Reader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @see        java.io.InputStreamReader#InputStreamReader(java.io.InputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @deprecated As of JDK&nbsp;1.1, the preferred way to translate a byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * stream in the local encoding into a character stream in Unicode is via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * the <code>InputStreamReader</code> and <code>BufferedReader</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    public InputStream getLocalizedInputStream(InputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        return in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * Creates a localized version of an output stream. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * takes an <code>OutputStream</code> and returns an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * <code>OutputStream</code> equivalent to the argument in all respects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * except that it is localized: as Unicode characters are written to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * the stream, they are automatically converted to the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * character set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * If the argument is already a localized stream, it may be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * as the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @deprecated As of JDK&nbsp;1.1, the preferred way to translate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * Unicode character stream into a byte stream in the local encoding is via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * the <code>OutputStreamWriter</code>, <code>BufferedWriter</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * <code>PrintWriter</code> classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @param      out OutputStream to localize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @return     a localized output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @see        java.io.OutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @see        java.io.BufferedWriter#BufferedWriter(java.io.Writer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @see        java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * @see        java.io.PrintWriter#PrintWriter(java.io.OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    public OutputStream getLocalizedOutputStream(OutputStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        return out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
}