8204243: remove Thread.destroy() and Thread.stop(Throwable)
authorsmarks
Tue, 12 Jun 2018 13:24:37 -0700
changeset 50530 7e3aa681a484
parent 50529 efd199ab8322
child 50531 aeb7fb702890
8204243: remove Thread.destroy() and Thread.stop(Throwable) Reviewed-by: dholmes, alanb, sspitsyn, iris
make/data/jdwp/jdwp.spec
src/hotspot/share/prims/jvmti.xml
src/java.base/share/classes/java/lang/Thread.java
src/java.base/share/classes/java/lang/doc-files/threadPrimitiveDeprecation.html
src/jdk.jdi/share/classes/com/sun/jdi/ThreadReference.java
test/jdk/java/lang/Thread/StopThrowable.java
--- a/make/data/jdwp/jdwp.spec	Tue Jun 12 11:34:48 2018 -0700
+++ b/make/data/jdwp/jdwp.spec	Tue Jun 12 13:24:37 2018 -0700
@@ -1997,8 +1997,7 @@
         )
     )
     (Command Stop=10
-        "Stops the thread with an asynchronous exception, as if done by "
-        "java.lang.Thread.stop "
+        "Stops the thread with an asynchronous exception. "
         (Out
             (threadObject thread "The thread object ID. ")
             (object throwable "Asynchronous exception. This object must "
--- a/src/hotspot/share/prims/jvmti.xml	Tue Jun 12 11:34:48 2018 -0700
+++ b/src/hotspot/share/prims/jvmti.xml	Tue Jun 12 13:24:37 2018 -0700
@@ -1799,10 +1799,10 @@
     <function id="StopThread" num="7">
       <synopsis>Stop Thread</synopsis>
       <description>
-	Send the specified asynchronous exception to the specified thread
-	(similar to <code>java.lang.Thread.stop</code>).
+	Send the specified asynchronous exception to the specified thread.
 	Normally, this function is used to kill the specified thread with an
-	instance of the exception <code>ThreadDeath</code>.
+	instance of the exception <code>ThreadDeath</code>, similar to
+        <code>java.lang.Thread.stop</code>.
       </description>
       <origin>jvmdi</origin>
       <capabilities>
--- a/src/java.base/share/classes/java/lang/Thread.java	Tue Jun 12 11:34:48 2018 -0700
+++ b/src/java.base/share/classes/java/lang/Thread.java	Tue Jun 12 13:24:37 2018 -0700
@@ -938,26 +938,6 @@
     }
 
     /**
-     * Throws {@code UnsupportedOperationException}.
-     *
-     * @param obj ignored
-     *
-     * @deprecated This method was originally designed to force a thread to stop
-     *        and throw a given {@code Throwable} as an exception. It was
-     *        inherently unsafe (see {@link #stop()} for details), and furthermore
-     *        could be used to generate exceptions that the target thread was
-     *        not prepared to handle.
-     *        For more information, see
-     *        <a href="{@docRoot}/java.base/java/lang/doc-files/threadPrimitiveDeprecation.html">Why
-     *        are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>.
-     *        This method is subject to removal in a future version of Java SE.
-     */
-    @Deprecated(since="1.2", forRemoval=true)
-    public final synchronized void stop(Throwable obj) {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
      * Interrupts this thread.
      *
      * <p> Unless the current thread is interrupting itself, which is
@@ -1062,29 +1042,6 @@
     private native boolean isInterrupted(boolean ClearInterrupted);
 
     /**
-     * Throws {@link NoSuchMethodError}.
-     *
-     * @deprecated This method was originally designed to destroy this
-     *     thread without any cleanup. Any monitors it held would have
-     *     remained locked. However, the method was never implemented.
-     *     If it were to be implemented, it would be deadlock-prone in
-     *     much the manner of {@link #suspend}. If the target thread held
-     *     a lock protecting a critical system resource when it was
-     *     destroyed, no thread could ever access this resource again.
-     *     If another thread ever attempted to lock this resource, deadlock
-     *     would result. Such deadlocks typically manifest themselves as
-     *     "frozen" processes. For more information, see
-     *     <a href="{@docRoot}/java.base/java/lang/doc-files/threadPrimitiveDeprecation.html">
-     *     Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>.
-     *     This method is subject to removal in a future version of Java SE.
-     * @throws NoSuchMethodError always
-     */
-    @Deprecated(since="1.5", forRemoval=true)
-    public void destroy() {
-        throw new NoSuchMethodError();
-    }
-
-    /**
      * Tests if this thread is alive. A thread is alive if it has
      * been started and has not yet died.
      *
--- a/src/java.base/share/classes/java/lang/doc-files/threadPrimitiveDeprecation.html	Tue Jun 12 11:34:48 2018 -0700
+++ b/src/java.base/share/classes/java/lang/doc-files/threadPrimitiveDeprecation.html	Tue Jun 12 13:24:37 2018 -0700
@@ -62,21 +62,6 @@
 </ol>
 In sum, it just isn't practical.
 <hr>
-<h3>What about <code>Thread.stop(Throwable)</code>?</h3>
-<p>In addition to all of the problems noted above, this method may
-be used to generate exceptions that its target thread is unprepared
-to handle (including checked exceptions that the thread could not
-possibly throw, were it not for this method). For example, the
-following method is behaviorally identical to Java's
-<code>throw</code> operation, but circumvents the compiler's
-attempts to guarantee that the calling method has declared all of
-the checked exceptions that it may throw:</p>
-<pre>
-    static void sneakyThrow(Throwable t) {
-        Thread.currentThread().stop(t);
-    }
-</pre>
-<hr>
 <h3>What should I use instead of <code>Thread.stop</code>?</h3>
 <p>Most uses of <code>stop</code> should be replaced by code that
 simply modifies some variable to indicate that the target thread
@@ -339,13 +324,6 @@
 described above, it needn't call <code>notify</code> as well, but it
 still must be synchronized. This ensures that the target thread
 won't miss an interrupt due to a race condition.
-<hr>
-<h3>What about <code>Thread.destroy</code>?</h3>
-<code>Thread.destroy</code> was never implemented and has been
-deprecated. If it were implemented, it would be deadlock-prone in
-the manner of <code>Thread.suspend</code>. (In fact, it is roughly
-equivalent to <code>Thread.suspend</code> without the possibility
-of a subsequent <code>Thread.resume</code>.)
 <p><!-- Body text ends here --></p>
 </body>
 </html>
--- a/src/jdk.jdi/share/classes/com/sun/jdi/ThreadReference.java	Tue Jun 12 11:34:48 2018 -0700
+++ b/src/jdk.jdi/share/classes/com/sun/jdi/ThreadReference.java	Tue Jun 12 13:24:37 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, 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
@@ -118,7 +118,6 @@
      * @throws InvalidTypeException if <code>throwable</code> is not
      * an instance of java.lang.Throwable in the target VM.
      * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
-     * @see java.lang.Thread#stop(Throwable)
      */
     @SuppressWarnings("javadoc")
     void stop(ObjectReference throwable) throws InvalidTypeException;
--- a/test/jdk/java/lang/Thread/StopThrowable.java	Tue Jun 12 11:34:48 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2013, 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.
- *
- * 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.
- */
-
-/**
- * @test
- * @bug 7059085
- * @summary Check that Thread.stop(Throwable) throws UOE
- * @run testng StopThrowable
- */
-
-import org.testng.annotations.Test;
-
-import java.util.concurrent.CountDownLatch;
-
-public class StopThrowable {
-
-    @Test(expectedExceptions=UnsupportedOperationException.class)
-    public void testStopSelf() {
-        Thread.currentThread().stop(new ThreadDeath());
-    }
-
-    private static void awaitUnchecked(CountDownLatch latch) {
-        try {
-            latch.await();
-        } catch (InterruptedException e) {
-            // should not happen
-            throw new RuntimeException(e);
-        }
-    }
-
-    @Test(expectedExceptions=UnsupportedOperationException.class)
-    public void testStopOther() throws Throwable {
-        CountDownLatch ready = new CountDownLatch(1);
-        CountDownLatch done = new CountDownLatch(1);
-        Thread t = new Thread( () ->  { ready.countDown(); awaitUnchecked(done); } );
-        t.start();
-        try {
-            ready.await();
-            t.stop(new ThreadDeath());
-        } finally {
-            done.countDown();
-        }
-    }
-
-    @Test(expectedExceptions=UnsupportedOperationException.class)
-    public void testNull() {
-        Thread.currentThread().stop(null);
-    }
-}