src/java.base/share/classes/java/lang/Shutdown.java
author darcy
Wed, 15 Aug 2018 10:44:56 -0700
changeset 51413 43e41800d579
parent 49186 b8bfadfacded
permissions -rw-r--r--
5075463: (enum) Serialized Form javadoc for java.lang.Enum is misleading Reviewed-by: lancea, rriggs, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49176
f413e471a6ab 8041626: Shutdown tracing event
rwestberg
parents: 47216
diff changeset
     2
 * Copyright (c) 1999, 2018, 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
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    29
import jdk.internal.misc.VM;
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    30
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Package-private utility class containing data structures and logic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * governing the virtual-machine shutdown sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @author   Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @since    1.3
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    37
 *
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    38
 * @see java.io.Console
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    39
 * @see ApplicationShutdownHooks
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    40
 * @see java.io.DeleteOnExitHook
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class Shutdown {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
2277
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    45
    // The system shutdown hooks are registered with a predefined slot.
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    46
    // The list of shutdown hooks is as follows:
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    47
    // (0) Console restore hook
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    48
    // (1) ApplicationShutdownHooks that invokes all registered application
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    49
    //     shutdown hooks and waits until they finish
2277
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    50
    // (2) DeleteOnExit hook
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    51
    private static final int MAX_SYSTEM_HOOKS = 10;
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    52
    private static final Runnable[] hooks = new Runnable[MAX_SYSTEM_HOOKS];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    54
    // the index of the currently running shutdown hook to the hooks array
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    55
    private static int currentRunningHook = -1;
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    56
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /* The preceding static fields are protected by this lock */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static class Lock { };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static Object lock = new Lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /* Lock object for the native halt method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static Object haltLock = new Lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    64
    /**
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    65
     * Add a new system shutdown hook.  Checks the shutdown state and
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    66
     * the hook itself, but does not do any security checks.
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    67
     *
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    68
     * The registerShutdownInProgress parameter should be false except
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    69
     * registering the DeleteOnExitHook since the first file may
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    70
     * 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
    71
     * hooks.
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    72
     *
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    73
     * @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
    74
     *               will be invoked in order during shutdown
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    75
     * @params registerShutdownInProgress true to allow the hook
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    76
     *               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
    77
     * @params hook  the hook to be registered
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    78
     *
32227
34721a47bc92 8132478: [tidy] three new warnings from java docs (java.net, javax.annotation)
avstepan
parents: 25859
diff changeset
    79
     * @throws IllegalStateException
34721a47bc92 8132478: [tidy] three new warnings from java docs (java.net, javax.annotation)
avstepan
parents: 25859
diff changeset
    80
     *         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
    81
     *         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
    82
     *         already passes the given slot
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    84
    static void add(int slot, boolean registerShutdownInProgress, Runnable hook) {
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    85
        if (slot < 0 || slot >= MAX_SYSTEM_HOOKS) {
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    86
            throw new IllegalArgumentException("Invalid slot: " + slot);
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    87
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        synchronized (lock) {
2277
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    89
            if (hooks[slot] != null)
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    90
                throw new InternalError("Shutdown hook at slot " + slot + " already registered");
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
    91
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    92
            if (!registerShutdownInProgress) {
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    93
                if (currentRunningHook >= 0)
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    94
                    throw new IllegalStateException("Shutdown in progress");
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    95
            } else {
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    96
                if (VM.isShutdown() || slot <= currentRunningHook)
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    97
                    throw new IllegalStateException("Shutdown in progress");
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    98
            }
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
    99
2277
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
   100
            hooks[slot] = hook;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   104
    /* Run all system shutdown hooks.
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   105
     *
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   106
     * The system shutdown hooks are run in the thread synchronized on
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   107
     * Shutdown.class.  Other threads calling Runtime::exit, Runtime::halt
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   108
     * or JNI DestroyJavaVM will block indefinitely.
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   109
     *
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   110
     * ApplicationShutdownHooks is registered as one single hook that starts
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   111
     * all application shutdown hooks and waits until they finish.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static void runHooks() {
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   114
        synchronized (lock) {
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   115
            /* Guard against the possibility of a daemon thread invoking exit
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   116
             * after DestroyJavaVM initiates the shutdown sequence
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   117
             */
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   118
            if (VM.isShutdown()) return;
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   119
        }
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   120
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   121
        for (int i=0; i < MAX_SYSTEM_HOOKS; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            try {
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   123
                Runnable hook;
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   124
                synchronized (lock) {
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   125
                    // 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
   126
                    // shutdown is visible here.
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   127
                    currentRunningHook = i;
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   128
                    hook = hooks[i];
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2277
diff changeset
   129
                }
2277
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
   130
                if (hook != null) hook.run();
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   131
            } catch (Throwable t) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                if (t instanceof ThreadDeath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    ThreadDeath td = (ThreadDeath)t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    throw td;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   138
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   139
        // set shutdown state
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   140
        VM.shutdown();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
49176
f413e471a6ab 8041626: Shutdown tracing event
rwestberg
parents: 47216
diff changeset
   143
    /* Notify the VM that it's time to halt. */
f413e471a6ab 8041626: Shutdown tracing event
rwestberg
parents: 47216
diff changeset
   144
    static native void beforeHalt();
f413e471a6ab 8041626: Shutdown tracing event
rwestberg
parents: 47216
diff changeset
   145
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /* The halt method is synchronized on the halt lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * to avoid corruption of the delete-on-shutdown file list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * It invokes the true native halt method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    static void halt(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        synchronized (haltLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            halt0(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    static native void halt0(int status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /* Invoked by Runtime.exit, which does all the security checks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Also invoked by handlers for system-provided termination events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * which should pass a nonzero status code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    static void exit(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        synchronized (lock) {
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   164
            if (status != 0 && VM.isShutdown()) {
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   165
                /* Halt immediately on nonzero status */
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   166
                halt(status);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        synchronized (Shutdown.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            /* Synchronize on the class object, causing any other thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
             * that attempts to initiate shutdown to stall indefinitely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
             */
49176
f413e471a6ab 8041626: Shutdown tracing event
rwestberg
parents: 47216
diff changeset
   173
            beforeHalt();
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   174
            runHooks();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            halt(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /* Invoked by the JNI DestroyJavaVM procedure when the last non-daemon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * thread has finished.  Unlike the exit method, this method does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * actually halt the VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    static void shutdown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        synchronized (Shutdown.class) {
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   186
            runHooks();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
}