jdk/src/java.base/share/classes/java/lang/Shutdown.java
author avstepan
Tue, 18 Aug 2015 18:04:17 +0300
changeset 32227 34721a47bc92
parent 25859 3317bb8137f4
permissions -rw-r--r--
8132478: [tidy] three new warnings from java docs (java.net, javax.annotation) Summary: minor docs cleanup (jdk part) Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2703
diff changeset
     2
 * Copyright (c) 1999, 2005, 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: 2703
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: 2703
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: 2703
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2703
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2703
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * Package-private utility class containing data structures and logic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * governing the virtual-machine shutdown sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author   Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @since    1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
class Shutdown {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /* Shutdown state */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static final int RUNNING = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final int HOOKS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final int FINALIZERS = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static int state = RUNNING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /* Should we run all finalizers upon exit? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static boolean runFinalizersOnExit = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
2277
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    48
    // The system shutdown hooks are registered with a predefined slot.
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    49
    // The list of shutdown hooks is as follows:
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    50
    // (0) Console restore hook
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    51
    // (1) Application hooks
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    52
    // (2) DeleteOnExit hook
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    53
    private static final int MAX_SYSTEM_HOOKS = 10;
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    54
    private static final Runnable[] hooks = new Runnable[MAX_SYSTEM_HOOKS];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    56
    // the index of the currently running shutdown hook to the hooks array
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    57
    private static int currentRunningHook = 0;
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    58
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /* The preceding static fields are protected by this lock */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static class Lock { };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static Object lock = new Lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /* Lock object for the native halt method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static Object haltLock = new Lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /* Invoked by Runtime.runFinalizersOnExit */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static void setRunFinalizersOnExit(boolean run) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            runFinalizersOnExit = run;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    74
    /**
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    75
     * Add a new shutdown hook.  Checks the shutdown state and the hook itself,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * but does not do any security checks.
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    77
     *
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    78
     * The registerShutdownInProgress parameter should be false except
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    79
     * registering the DeleteOnExitHook since the first file may
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    80
     * be added to the delete on exit list by the application shutdown
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    81
     * hooks.
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    82
     *
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    83
     * @params slot  the slot in the shutdown hook array, whose element
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    84
     *               will be invoked in order during shutdown
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    85
     * @params registerShutdownInProgress true to allow the hook
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    86
     *               to be registered even if the shutdown is in progress.
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    87
     * @params hook  the hook to be registered
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    88
     *
32227
34721a47bc92 8132478: [tidy] three new warnings from java docs (java.net, javax.annotation)
avstepan
parents: 25859
diff changeset
    89
     * @throws IllegalStateException
34721a47bc92 8132478: [tidy] three new warnings from java docs (java.net, javax.annotation)
avstepan
parents: 25859
diff changeset
    90
     *         if registerShutdownInProgress is false and shutdown is in progress; or
34721a47bc92 8132478: [tidy] three new warnings from java docs (java.net, javax.annotation)
avstepan
parents: 25859
diff changeset
    91
     *         if registerShutdownInProgress is true and the shutdown process
34721a47bc92 8132478: [tidy] three new warnings from java docs (java.net, javax.annotation)
avstepan
parents: 25859
diff changeset
    92
     *         already passes the given slot
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    94
    static void add(int slot, boolean registerShutdownInProgress, Runnable hook) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        synchronized (lock) {
2277
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    96
            if (hooks[slot] != null)
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    97
                throw new InternalError("Shutdown hook at slot " + slot + " already registered");
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    98
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    99
            if (!registerShutdownInProgress) {
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   100
                if (state > RUNNING)
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   101
                    throw new IllegalStateException("Shutdown in progress");
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   102
            } else {
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   103
                if (state > HOOKS || (state == HOOKS && slot <= currentRunningHook))
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   104
                    throw new IllegalStateException("Shutdown in progress");
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   105
            }
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   106
2277
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
   107
            hooks[slot] = hook;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /* Run all registered shutdown hooks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static void runHooks() {
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   114
        for (int i=0; i < MAX_SYSTEM_HOOKS; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            try {
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   116
                Runnable hook;
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   117
                synchronized (lock) {
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   118
                    // acquire the lock to make sure the hook registered during
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   119
                    // shutdown is visible here.
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   120
                    currentRunningHook = i;
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   121
                    hook = hooks[i];
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   122
                }
2277
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
   123
                if (hook != null) hook.run();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            } catch(Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                if (t instanceof ThreadDeath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    ThreadDeath td = (ThreadDeath)t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    throw td;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /* The halt method is synchronized on the halt lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * to avoid corruption of the delete-on-shutdown file list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * It invokes the true native halt method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    static void halt(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        synchronized (haltLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            halt0(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    static native void halt0(int status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /* Wormhole for invoking java.lang.ref.Finalizer.runAllFinalizers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private static native void runAllFinalizers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /* The actual shutdown sequence is defined here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * If it weren't for runFinalizersOnExit, this would be simple -- we'd just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * run the hooks and then halt.  Instead we need to keep track of whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * we're running hooks or finalizers.  In the latter case a finalizer could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * invoke exit(1) to cause immediate termination, while in the former case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * any further invocations of exit(n), for any n, simply stall.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * if on-exit finalizers are enabled they're run iff the shutdown is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * initiated by an exit(0); they're never run on exit(n) for n != 0 or in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * response to SIGINT, SIGTERM, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private static void sequence() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            /* Guard against the possibility of a daemon thread invoking exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
             * after DestroyJavaVM initiates the shutdown sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            if (state != HOOKS) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        runHooks();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        boolean rfoe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            state = FINALIZERS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            rfoe = runFinalizersOnExit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (rfoe) runAllFinalizers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /* Invoked by Runtime.exit, which does all the security checks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Also invoked by handlers for system-provided termination events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * which should pass a nonzero status code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    static void exit(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        boolean runMoreFinalizers = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (status != 0) runFinalizersOnExit = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            case RUNNING:       /* Initiate shutdown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                state = HOOKS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            case HOOKS:         /* Stall and halt */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            case FINALIZERS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                if (status != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    /* Halt immediately on nonzero status */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    halt(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    /* Compatibility with old behavior:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                     * Run more finalizers and then halt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    runMoreFinalizers = runFinalizersOnExit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (runMoreFinalizers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            runAllFinalizers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            halt(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        synchronized (Shutdown.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            /* Synchronize on the class object, causing any other thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
             * that attempts to initiate shutdown to stall indefinitely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            sequence();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            halt(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /* Invoked by the JNI DestroyJavaVM procedure when the last non-daemon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * thread has finished.  Unlike the exit method, this method does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * actually halt the VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    static void shutdown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            case RUNNING:       /* Initiate shutdown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                state = HOOKS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            case HOOKS:         /* Stall and then return */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            case FINALIZERS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        synchronized (Shutdown.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            sequence();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
}