JDK-8293975 : Degrade Thread.suspend and Thread.resume
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 20
  • Submitted: 2022-09-18
  • Updated: 2022-09-27
  • Resolved: 2022-09-27
Related Reports
CSR :  
Relates :  
Description
Summary
-------

Degrade `Thread.suspend()` and `Thread.resume()` to throw `UnsupportedOperationException` (UOE) unconditionally.

Problem
-------

Thread.suspend dates from JDK 1.0 as a user facing API to suspend a victim thread from execution. It is inherently deadlock prone. Thread.suspend and Thread.resume have been deprecated since JDK 1.2 with a link to the "Java Thread Primitive Deprecation" page that explains the reasoning for the deprecation.

The recent steps on degrading and removing the feature are:

- Thread.suspend and Thread.resume were terminally deprecated in Java 14
- ThreadGroup.suspend and ThreadGroup.resume were degraded to throw UOE in Java 19

At this time, Thread.suspend will suspend a platform thread as it always done. Both Thread.suspend and Thread.resume throw UOE if invoked on a virtual Thread.

Solution
--------

- Re-specify Thread.suspend and Thread.resume to throw UOE.
- Update the JVM TI, JDWP and JDI specifications to drop Thread.suspend/resume as possible suspend/resume functions. This change has otherwise no impact on the suspend/resume APIs defined for debuggers.
- Minor adjustments to java.lang.IllegalThreadStateException.
- Minor updates to java.lang.SecurityManager to drop references to Thread.suspend/resume and other degraded methods that no longer call into the security manager.

Specification
-------------

A zip file with the specdiffs is attached to this CSR with changes to the docs of the following API elements:

```
java.lang.Thread.suspend
java.lang.Thread.resume
java.lang.IllegalThreadStateException
java.lang.SecurityManager.checkAccess(Thread)
java.lang.SecurityManager.checkAccess(ThreadGroup)
java.lang.RuntimePermission modifyThread and modifyThreadGroup targets
com.sun.jdi.ThreadReference.suspend()
com.sun.jdi.ThreadReference.resume()
com.sun.jdi.VirtualMachine.suspend()
com.sun.jdi.VirtualMachine.resume()
JDWP ThreadReference/Suspend and ThreadReference/Resume commands
JVMTI ResumeThread / ResumeThreadList functions
JVMTI GetThreadState description of JVMTI_THREAD_STATE_SUSPENDED
```







Comments
Moving to Approved.
27-09-2022

API changes look good.
23-09-2022

The SVC part looks good.
22-09-2022

> Update the JVM TI, JDWP and JDI specifications to drop Thread.suspend as a possible suspend function. Nit: Need to say the same about Thread.resume (see Thread#resume in ThreadReference.java).
21-09-2022