Merge "Remove dead code related to shutdown hooks."
diff --git a/ojluni/src/main/java/java/io/DeleteOnExitHook.java b/ojluni/src/main/java/java/io/DeleteOnExitHook.java
index 0376456..447f038 100755
--- a/ojluni/src/main/java/java/io/DeleteOnExitHook.java
+++ b/ojluni/src/main/java/java/io/DeleteOnExitHook.java
@@ -36,14 +36,11 @@
class DeleteOnExitHook {
private static LinkedHashSet<String> files = new LinkedHashSet<>();
static {
- // Android-changed: Access java.lang.Shutdown directly.
- java.lang.Shutdown.add(2, true,
- new Runnable() {
- public void run() {
- runHooks();
- }
- }
- );
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ runHooks();
+ }
+ });
}
private DeleteOnExitHook() {}
diff --git a/ojluni/src/main/java/java/lang/ApplicationShutdownHooks.java b/ojluni/src/main/java/java/lang/ApplicationShutdownHooks.java
deleted file mode 100755
index 512cfc1..0000000
--- a/ojluni/src/main/java/java/lang/ApplicationShutdownHooks.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package java.lang;
-
-import java.util.*;
-
-/*
- * Class to track and run user level shutdown hooks registered through
- * <tt>{@link Runtime#addShutdownHook Runtime.addShutdownHook}</tt>.
- *
- * @see java.lang.Runtime#addShutdownHook
- * @see java.lang.Runtime#removeShutdownHook
- */
-
-class ApplicationShutdownHooks {
- /* The set of registered hooks */
- private static IdentityHashMap<Thread, Thread> hooks;
- static {
- try {
- Shutdown.add(1 /* shutdown hook invocation order */,
- false /* not registered if shutdown in progress */,
- new Runnable() {
- public void run() {
- runHooks();
- }
- }
- );
- hooks = new IdentityHashMap<>();
- } catch (IllegalStateException e) {
- // application shutdown hooks cannot be added if
- // shutdown is in progress.
- hooks = null;
- }
- }
-
-
- private ApplicationShutdownHooks() {}
-
- /* Add a new shutdown hook. Checks the shutdown state and the hook itself,
- * but does not do any security checks.
- */
- static synchronized void add(Thread hook) {
- if(hooks == null)
- throw new IllegalStateException("Shutdown in progress");
-
- if (hook.isAlive())
- throw new IllegalArgumentException("Hook already running");
-
- if (hooks.containsKey(hook))
- throw new IllegalArgumentException("Hook previously registered");
-
- hooks.put(hook, hook);
- }
-
- /* Remove a previously-registered hook. Like the add method, this method
- * does not do any security checks.
- */
- static synchronized boolean remove(Thread hook) {
- if(hooks == null)
- throw new IllegalStateException("Shutdown in progress");
-
- if (hook == null)
- throw new NullPointerException();
-
- return hooks.remove(hook) != null;
- }
-
- /* Iterates over all application hooks creating a new thread for each
- * to run in. Hooks are run concurrently and this method waits for
- * them to finish.
- */
- static void runHooks() {
- Collection<Thread> threads;
- synchronized(ApplicationShutdownHooks.class) {
- threads = hooks.keySet();
- hooks = null;
- }
-
- for (Thread hook : threads) {
- hook.start();
- }
- for (Thread hook : threads) {
- try {
- hook.join();
- } catch (InterruptedException x) { }
- }
- }
-}
diff --git a/ojluni/src/main/java/java/lang/Shutdown.java b/ojluni/src/main/java/java/lang/Shutdown.java
deleted file mode 100755
index afda074..0000000
--- a/ojluni/src/main/java/java/lang/Shutdown.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.lang;
-
-
-/**
- * Package-private utility class containing data structures and logic
- * governing the virtual-machine shutdown sequence.
- *
- * @author Mark Reinhold
- * @since 1.3
- * @hide
- */
-// Android-changed: Make class public.
-public class Shutdown {
-
- /* Shutdown state */
- private static final int RUNNING = 0;
- private static final int HOOKS = 1;
- private static final int FINALIZERS = 2;
- private static int state = RUNNING;
-
- /* Should we run all finalizers upon exit? */
- private static boolean runFinalizersOnExit = false;
-
- // The system shutdown hooks are registered with a predefined slot.
- // The list of shutdown hooks is as follows:
- // (0) Console restore hook
- // (1) Application hooks
- // (2) DeleteOnExit hook
- private static final int MAX_SYSTEM_HOOKS = 10;
- private static final Runnable[] hooks = new Runnable[MAX_SYSTEM_HOOKS];
-
- // the index of the currently running shutdown hook to the hooks array
- private static int currentRunningHook = 0;
-
- /* The preceding static fields are protected by this lock */
- private static class Lock { };
- private static Object lock = new Lock();
-
- /* Lock object for the native halt method */
- private static Object haltLock = new Lock();
-
- /* Invoked by Runtime.runFinalizersOnExit */
- static void setRunFinalizersOnExit(boolean run) {
- synchronized (lock) {
- runFinalizersOnExit = run;
- }
- }
-
-
- /**
- * Add a new shutdown hook. Checks the shutdown state and the hook itself,
- * but does not do any security checks.
- *
- * The registerShutdownInProgress parameter should be false except
- * registering the DeleteOnExitHook since the first file may
- * be added to the delete on exit list by the application shutdown
- * hooks.
- *
- * @param slot the slot in the shutdown hook array, whose element
- * will be invoked in order during shutdown
- * @param registerShutdownInProgress true to allow the hook
- * to be registered even if the shutdown is in progress.
- * @param hook the hook to be registered
- *
- * @throws IllegalStateException
- * if registerShutdownInProgress is false and shutdown is in progress; or
- * if registerShutdownInProgress is true and the shutdown process
- * already passes the given slot
- */
- // Android changed s/@params/@param
- public static void add(int slot, boolean registerShutdownInProgress, Runnable hook) {
- synchronized (lock) {
- if (hooks[slot] != null)
- throw new InternalError("Shutdown hook at slot " + slot + " already registered");
-
- if (!registerShutdownInProgress) {
- if (state > RUNNING)
- throw new IllegalStateException("Shutdown in progress");
- } else {
- if (state > HOOKS || (state == HOOKS && slot <= currentRunningHook))
- throw new IllegalStateException("Shutdown in progress");
- }
-
- hooks[slot] = hook;
- }
- }
-
- /* Run all registered shutdown hooks
- */
- private static void runHooks() {
- for (int i=0; i < MAX_SYSTEM_HOOKS; i++) {
- try {
- Runnable hook;
- synchronized (lock) {
- // acquire the lock to make sure the hook registered during
- // shutdown is visible here.
- currentRunningHook = i;
- hook = hooks[i];
- }
- if (hook != null) hook.run();
- } catch(Throwable t) {
- if (t instanceof ThreadDeath) {
- ThreadDeath td = (ThreadDeath)t;
- throw td;
- }
- }
- }
- }
-
- /* The halt method is synchronized on the halt lock
- * to avoid corruption of the delete-on-shutdown file list.
- * It invokes the true native halt method.
- */
- static void halt(int status) {
- synchronized (haltLock) {
- halt0(status);
- }
- }
-
- static native void halt0(int status);
-
- /* Wormhole for invoking java.lang.ref.Finalizer.runAllFinalizers */
- private static native void runAllFinalizers();
-
-
- /* The actual shutdown sequence is defined here.
- *
- * If it weren't for runFinalizersOnExit, this would be simple -- we'd just
- * run the hooks and then halt. Instead we need to keep track of whether
- * we're running hooks or finalizers. In the latter case a finalizer could
- * invoke exit(1) to cause immediate termination, while in the former case
- * any further invocations of exit(n), for any n, simply stall. Note that
- * if on-exit finalizers are enabled they're run iff the shutdown is
- * initiated by an exit(0); they're never run on exit(n) for n != 0 or in
- * response to SIGINT, SIGTERM, etc.
- */
- private static void sequence() {
- synchronized (lock) {
- /* Guard against the possibility of a daemon thread invoking exit
- * after DestroyJavaVM initiates the shutdown sequence
- */
- if (state != HOOKS) return;
- }
- runHooks();
- boolean rfoe;
- synchronized (lock) {
- state = FINALIZERS;
- rfoe = runFinalizersOnExit;
- }
- if (rfoe) runAllFinalizers();
- }
-
-
- /* Invoked by Runtime.exit, which does all the security checks.
- * Also invoked by handlers for system-provided termination events,
- * which should pass a nonzero status code.
- */
- static void exit(int status) {
- boolean runMoreFinalizers = false;
- synchronized (lock) {
- if (status != 0) runFinalizersOnExit = false;
- switch (state) {
- case RUNNING: /* Initiate shutdown */
- state = HOOKS;
- break;
- case HOOKS: /* Stall and halt */
- break;
- case FINALIZERS:
- if (status != 0) {
- /* Halt immediately on nonzero status */
- halt(status);
- } else {
- /* Compatibility with old behavior:
- * Run more finalizers and then halt
- */
- runMoreFinalizers = runFinalizersOnExit;
- }
- break;
- }
- }
- if (runMoreFinalizers) {
- runAllFinalizers();
- halt(status);
- }
- synchronized (Shutdown.class) {
- /* Synchronize on the class object, causing any other thread
- * that attempts to initiate shutdown to stall indefinitely
- */
- sequence();
- halt(status);
- }
- }
-
-
- /* Invoked by the JNI DestroyJavaVM procedure when the last non-daemon
- * thread has finished. Unlike the exit method, this method does not
- * actually halt the VM.
- */
- static void shutdown() {
- synchronized (lock) {
- switch (state) {
- case RUNNING: /* Initiate shutdown */
- state = HOOKS;
- break;
- case HOOKS: /* Stall and then return */
- case FINALIZERS:
- break;
- }
- }
- synchronized (Shutdown.class) {
- sequence();
- }
- }
-
-}
diff --git a/ojluni/src/main/native/Register.cpp b/ojluni/src/main/native/Register.cpp
index 89dca05..cced144 100644
--- a/ojluni/src/main/native/Register.cpp
+++ b/ojluni/src/main/native/Register.cpp
@@ -46,7 +46,6 @@
extern void register_java_lang_Float(JNIEnv*);
extern void register_java_lang_ProcessEnvironment(JNIEnv*);
extern void register_java_lang_Runtime(JNIEnv*);
-extern void register_java_lang_Shutdown(JNIEnv*);
extern void register_java_lang_StrictMath(JNIEnv*);
extern void register_java_lang_Math(JNIEnv*);
extern void register_java_lang_System(JNIEnv*);
@@ -126,7 +125,6 @@
register_java_lang_ProcessEnvironment(env);
register_java_lang_Runtime(env);
register_java_lang_System(env);
- register_java_lang_Shutdown(env);
register_java_lang_UNIXProcess(env);
// register_java_net_InetAddress depends on java_lang_Float & Math being
// fully registered (getMethodId on InetAddress class triggers its
diff --git a/ojluni/src/main/native/Shutdown.c b/ojluni/src/main/native/Shutdown.c
deleted file mode 100755
index f765a83..0000000
--- a/ojluni/src/main/native/Shutdown.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#include "jni.h"
-#include "jni_util.h"
-#include "jvm.h"
-
-#include "JNIHelp.h"
-
-#define NATIVE_METHOD(className, functionName, signature) \
-{ #functionName, signature, (void*)(className ## _ ## functionName) }
-
-
-JNIEXPORT void JNICALL
-Shutdown_halt0(JNIEnv *env, jclass ignored, jint code)
-{
- JVM_Halt(code);
-}
-
-
-JNIEXPORT void JNICALL
-Shutdown_runAllFinalizers(JNIEnv *env, jclass ignored)
-{
- jclass cl;
- jmethodID mid;
-
- if ((cl = (*env)->FindClass(env, "java/lang/ref/Finalizer"))
- && (mid = (*env)->GetStaticMethodID(env, cl,
- "runAllFinalizers", "()V"))) {
- (*env)->CallStaticVoidMethod(env, cl, mid);
- }
-}
-
-static JNINativeMethod gMethods[] = {
- NATIVE_METHOD(Shutdown, halt0, "(I)V"),
- NATIVE_METHOD(Shutdown, runAllFinalizers, "()V"),
-};
-
-void register_java_lang_Shutdown(JNIEnv* env) {
- jniRegisterNativeMethods(env, "java/lang/Shutdown", gMethods, NELEM(gMethods));
-}
diff --git a/ojluni/src/main/native/openjdksub.mk b/ojluni/src/main/native/openjdksub.mk
index e861230..6767354 100644
--- a/ojluni/src/main/native/openjdksub.mk
+++ b/ojluni/src/main/native/openjdksub.mk
@@ -69,7 +69,6 @@
ProcessEnvironment_md.c \
System.c \
Runtime.c \
- Shutdown.c \
UNIXProcess_md.c \
Bits.c \
Character.cpp \
diff --git a/openjdk_java_files.mk b/openjdk_java_files.mk
index a0ba44f..37c010c 100644
--- a/openjdk_java_files.mk
+++ b/openjdk_java_files.mk
@@ -107,7 +107,6 @@
ojluni/src/main/java/java/lang/annotation/Target.java \
ojluni/src/main/java/java/lang/annotation/package-info.java \
ojluni/src/main/java/java/lang/Appendable.java \
- ojluni/src/main/java/java/lang/ApplicationShutdownHooks.java \
ojluni/src/main/java/java/lang/ArithmeticException.java \
ojluni/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java \
ojluni/src/main/java/java/lang/ArrayStoreException.java \
@@ -1143,7 +1142,6 @@
ojluni/src/main/java/com/sun/nio/file/ExtendedWatchEventModifier.java \
ojluni/src/main/java/com/sun/nio/file/SensitivityWatchEventModifier.java \
ojluni/src/main/java/java/beans/ChangeListenerMap.java \
- ojluni/src/main/java/java/lang/Shutdown.java \
ojluni/src/main/java/sun/misc/FDBigInteger.java \
ojluni/src/main/java/sun/misc/FloatingDecimal.java \
ojluni/src/main/java/java/text/spi/BreakIteratorProvider.java \