JDK-8260376 : Cleanup Thread state transitions
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 17
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2021-01-25
  • Updated: 2022-11-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
There are a couple of simplifications that can be done to the transition/transition wrapper code:

- Consolidate ThreadBlockInVM and ThreadBlockInVMWithDeadlockCheck
- Consolidate ThreadInVMfromJava and ThreadInVMfromJavaNoAsyncException
- With little effort maybe we can also get rid of the transitional states (_thread_in_vm_trans, _thread_blocked_trans, etc) since we either are already in a safepoint unsafe state before checking for safepoints/handshakes or we can transition first to the desired safepoint unsafe state and then check for safepoint/handshakes. 
- Make clear which operations we need to check for when transitioning from one state to another(safepoint/handshake, suspend, async exceptions etc) and adjust wrappers if needed.
- We call make_walkable() before transitioning to a safe state, but stack should always be walkable if we are in the vm and there is a last Java frame (_last_Java_sp != NULL). It seems the only issue could come from the compiler, since it can set _last_Java_sp but not _last_Java_pc, expecting it will be retrieved later from _last_Java_sp if we do need to walk the stack. For x86 and aarch64,  _last_Java_pc is retrieved by doing _last_Java_pc = _last_Java_sp[-1]).