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