0 /*
1 * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation. Oracle designates this
7 * particular file as subject to the "Classpath" exception as provided
8 * by Oracle in the LICENSE file that accompanied this code.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
0 /*
1 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation. Oracle designates this
7 * particular file as subject to the "Classpath" exception as provided
8 * by Oracle in the LICENSE file that accompanied this code.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
112 private static void runHooks() {
113 for (int i=0; i < MAX_SYSTEM_HOOKS; i++) {
114 try {
115 Runnable hook;
116 synchronized (lock) {
117 // acquire the lock to make sure the hook registered during
118 // shutdown is visible here.
119 currentRunningHook = i;
120 hook = hooks[i];
121 }
122 if (hook != null) hook.run();
123 } catch(Throwable t) {
124 if (t instanceof ThreadDeath) {
125 ThreadDeath td = (ThreadDeath)t;
126 throw td;
127 }
128 }
129 }
130 }
131
132 /* The halt method is synchronized on the halt lock
133 * to avoid corruption of the delete-on-shutdown file list.
134 * It invokes the true native halt method.
135 */
136 static void halt(int status) {
137 synchronized (haltLock) {
138 halt0(status);
139 }
140 }
141
142 static native void halt0(int status);
143
144 /* Wormhole for invoking java.lang.ref.Finalizer.runAllFinalizers */
145 private static native void runAllFinalizers();
146
147
148 /* The actual shutdown sequence is defined here.
149 *
150 * If it weren't for runFinalizersOnExit, this would be simple -- we'd just
|
112 private static void runHooks() {
113 for (int i=0; i < MAX_SYSTEM_HOOKS; i++) {
114 try {
115 Runnable hook;
116 synchronized (lock) {
117 // acquire the lock to make sure the hook registered during
118 // shutdown is visible here.
119 currentRunningHook = i;
120 hook = hooks[i];
121 }
122 if (hook != null) hook.run();
123 } catch(Throwable t) {
124 if (t instanceof ThreadDeath) {
125 ThreadDeath td = (ThreadDeath)t;
126 throw td;
127 }
128 }
129 }
130 }
131
132 /* Notify the VM that it's time to halt. */
133 static native void beforeHalt();
134
135 /* The halt method is synchronized on the halt lock
136 * to avoid corruption of the delete-on-shutdown file list.
137 * It invokes the true native halt method.
138 */
139 static void halt(int status) {
140 synchronized (haltLock) {
141 halt0(status);
142 }
143 }
144
145 static native void halt0(int status);
146
147 /* Wormhole for invoking java.lang.ref.Finalizer.runAllFinalizers */
148 private static native void runAllFinalizers();
149
150
151 /* The actual shutdown sequence is defined here.
152 *
153 * If it weren't for runFinalizersOnExit, this would be simple -- we'd just
|
191 if (status != 0) {
192 /* Halt immediately on nonzero status */
193 halt(status);
194 } else {
195 /* Compatibility with old behavior:
196 * Run more finalizers and then halt
197 */
198 runMoreFinalizers = runFinalizersOnExit;
199 }
200 break;
201 }
202 }
203 if (runMoreFinalizers) {
204 runAllFinalizers();
205 halt(status);
206 }
207 synchronized (Shutdown.class) {
208 /* Synchronize on the class object, causing any other thread
209 * that attempts to initiate shutdown to stall indefinitely
210 */
211 sequence();
212 halt(status);
213 }
214 }
215
216
217 /* Invoked by the JNI DestroyJavaVM procedure when the last non-daemon
218 * thread has finished. Unlike the exit method, this method does not
219 * actually halt the VM.
220 */
221 static void shutdown() {
222 synchronized (lock) {
223 switch (state) {
224 case RUNNING: /* Initiate shutdown */
225 state = HOOKS;
226 break;
227 case HOOKS: /* Stall and then return */
228 case FINALIZERS:
229 break;
|
194 if (status != 0) {
195 /* Halt immediately on nonzero status */
196 halt(status);
197 } else {
198 /* Compatibility with old behavior:
199 * Run more finalizers and then halt
200 */
201 runMoreFinalizers = runFinalizersOnExit;
202 }
203 break;
204 }
205 }
206 if (runMoreFinalizers) {
207 runAllFinalizers();
208 halt(status);
209 }
210 synchronized (Shutdown.class) {
211 /* Synchronize on the class object, causing any other thread
212 * that attempts to initiate shutdown to stall indefinitely
213 */
214 beforeHalt();
215 sequence();
216 halt(status);
217 }
218 }
219
220
221 /* Invoked by the JNI DestroyJavaVM procedure when the last non-daemon
222 * thread has finished. Unlike the exit method, this method does not
223 * actually halt the VM.
224 */
225 static void shutdown() {
226 synchronized (lock) {
227 switch (state) {
228 case RUNNING: /* Initiate shutdown */
229 state = HOOKS;
230 break;
231 case HOOKS: /* Stall and then return */
232 case FINALIZERS:
233 break;
|