JDK-8335480 : Only deoptimize threads if needed when closing shared arena
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang.foreign
  • Affected Version: 22.0.1,23
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-07-01
  • Updated: 2024-07-29
  • Resolved: 2024-07-18
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.
JDK 24
24 b08Fixed
Related Reports
Relates :  
Relates :  
Description
Currently, when we close a shared arena, we deoptimize to top frame of all other thread. This is needed because there are cases in JIT compiled code where a thread is stopped at a safepoint in between the arena liveness check, and a subsequent memory access, such as:

liveness check (from @Scoped method)
for (...) {
    for (...) { // strip-mining inner loop
        memory access (from @Scoped method)
    }
    safepoint <-- STOPPED HERE
}

Deoptimizing then returns us to a situation where we will do a liveness check before the next memory access:

for (...) {
    call to ScopedMemoryAccess
    safepoint <-- STOPPED HERE
}

However, we might be able to reduce the number of cases where we deoptimize. For instance, we don't need to deoptimize when:
1.) we are already throwing an async exception (although, in that case we will likely deopt as a result of the exception being thrown any way)
2.) we are inside code from an @Scoped method, but we did not find our session oop (we can detect this accurately in this case)
3.) the oop of the memory session (which holds the liveness state field), is not found anywhere in the physical frame (including all inlined code). We may not be able to determine this accurately due to JDK-8290892 though

Avoiding deoptimization in these cases may improve performance in situations where a large number of threads is frequently closing unrelated shared arenas.
Comments
Changeset: 7bf53132 Branch: master Author: Jorn Vernee <jvernee@openjdk.org> Date: 2024-07-18 11:00:39 +0000 URL: https://git.openjdk.org/jdk/commit/7bf531324404419e7de3e83e245d351e1a4e4499
18-07-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/20158 Date: 2024-07-12 13:57:23 +0000
12-07-2024

I've attached an assembly dump that illustrates the loop safepoint issue. Look for "{poll}", that is the loop safepoint, after which we don't check the liveness bit again.
12-07-2024