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.