--- old/src/java.base/share/classes/java/lang/Runtime.java 2018-02-15 14:56:25.000000000 -0800 +++ new/src/java.base/share/classes/java/lang/Runtime.java 2018-02-15 14:56:25.000000000 -0800 @@ -35,6 +35,8 @@ import java.util.List; import java.util.Optional; import java.util.StringTokenizer; + +import jdk.internal.misc.SharedSecrets; import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; @@ -77,19 +79,16 @@ * serves as a status code; by convention, a nonzero status code indicates * abnormal termination. * - *

The virtual machine's shutdown sequence consists of two phases. In - * the first phase all registered {@link #addShutdownHook shutdown hooks}, - * if any, are started in some unspecified order and allowed to run - * concurrently until they finish. In the second phase all uninvoked - * finalizers are run if {@link #runFinalizersOnExit finalization-on-exit} - * has been enabled. Once this is done the virtual machine {@link #halt halts}. + *

The virtual machine first invokes all registered + * {@link #addShutdownHook shutdown hooks}, if any, are started in + * some unspecified order and allowed to run concurrently until they finish. + * Once this is done the virtual machine {@link #halt halts}. * *

If this method is invoked after the virtual machine has begun its * shutdown sequence then if shutdown hooks are being run this method will - * block indefinitely. If shutdown hooks have already been run and on-exit - * finalization has been enabled then this method halts the virtual machine - * with the given status code if the status is nonzero; otherwise, it - * blocks indefinitely. + * block indefinitely. If shutdown hooks have already been run + * then this method halts the virtual machine with the given status code + * if the status is nonzero; otherwise, it blocks indefinitely. * *

The {@link System#exit(int) System.exit} method is the * conventional and convenient means of invoking this method. @@ -107,7 +106,6 @@ * @see java.lang.SecurityManager#checkExit(int) * @see #addShutdownHook * @see #removeShutdownHook - * @see #runFinalizersOnExit * @see #halt(int) */ public void exit(int status) { @@ -140,10 +138,9 @@ * thread. When the virtual machine begins its shutdown sequence it will * start all registered shutdown hooks in some unspecified order and let * them run concurrently. When all the hooks have finished it will then - * run all uninvoked finalizers if finalization-on-exit has been enabled. - * Finally, the virtual machine will halt. Note that daemon threads will - * continue to run during the shutdown sequence, as will non-daemon threads - * if shutdown was initiated by invoking the {@link #exit exit} method. + * halt. Note that daemon threads will continue to run during the shutdown + * sequence, as will non-daemon threads if shutdown was initiated by + * invoking the {@link #exit exit} method. * *

Once the shutdown sequence has begun it can be stopped only by * invoking the {@link #halt halt} method, which forcibly @@ -253,10 +250,9 @@ * *

This method should be used with extreme caution. Unlike the * {@link #exit exit} method, this method does not cause shutdown - * hooks to be started and does not run uninvoked finalizers if - * finalization-on-exit has been enabled. If the shutdown sequence has - * already been initiated then this method does not wait for any running - * shutdown hooks or finalizers to finish their work. + * hooks to be started. If the shutdown sequence has already been + * initiated then this method does not wait for any running + * shutdown hooks to finish their work. * * @param status * Termination status. By convention, a nonzero status code @@ -284,46 +280,6 @@ } /** - * Enable or disable finalization on exit; doing so specifies that the - * finalizers of all objects that have finalizers that have not yet been - * automatically invoked are to be run before the Java runtime exits. - * By default, finalization on exit is disabled. - * - *

If there is a security manager, - * its {@code checkExit} method is first called - * with 0 as its argument to ensure the exit is allowed. - * This could result in a SecurityException. - * - * @param value true to enable finalization on exit, false to disable - * @deprecated This method is inherently unsafe. It may result in - * finalizers being called on live objects while other threads are - * concurrently manipulating those objects, resulting in erratic - * behavior or deadlock. - * This method is subject to removal in a future version of Java SE. - * - * @throws SecurityException - * if a security manager exists and its {@code checkExit} - * method doesn't allow the exit. - * - * @see java.lang.Runtime#exit(int) - * @see java.lang.Runtime#gc() - * @see java.lang.SecurityManager#checkExit(int) - * @since 1.1 - */ - @Deprecated(since="1.2", forRemoval=true) - public static void runFinalizersOnExit(boolean value) { - SecurityManager security = System.getSecurityManager(); - if (security != null) { - try { - security.checkExit(0); - } catch (SecurityException e) { - throw new SecurityException("runFinalizersOnExit"); - } - } - Shutdown.setRunFinalizersOnExit(value); - } - - /** * Executes the specified string command in a separate process. * *

This is a convenience method. An invocation of the form @@ -702,9 +658,6 @@ */ public native void gc(); - /* Wormhole for calling java.lang.ref.Finalizer.runFinalization */ - private static native void runFinalization0(); - /** * Runs the finalization methods of any objects pending finalization. * Calling this method suggests that the Java virtual machine expend @@ -724,7 +677,7 @@ * @see java.lang.Object#finalize() */ public void runFinalization() { - runFinalization0(); + SharedSecrets.getJavaLangRefAccess().runFinalization(); } /**