[foreign-preview] RFR: 8282061: Improve support for deterministic closure of shared scopes

Maurizio Cimadamore mcimadamore at openjdk.java.net
Thu Feb 17 16:32:02 UTC 2022


This patch improves the logic for closing shared resource scopes, by using the following algorithm:

1. move the scope from ALIVE to CLOSED - no new thread can access segments associated with the scope
2. do an initial handshake, to collect all threads that are accessing the scope concurrently
3. if no thread is found, finish
4. if some threads T1, T2 ... Tn are found, keep doing handshakes (only against these threads) then go back to (3). 

Note that the logic no longer require *three* states for shared segment, and also this logic always succeeds - that is the close operation can never fail because of a spurious access found during an handshake.

Note that the logic converges quickly, because handshaked threads are deoptimized - meaning that they will have to re-load the liveness state of the resource they are accessing (at which point they will just throw an exception).

Implementation-wise, when looking over the code with @fisk , we realized that it is possible for multiple threads to run the handhshake closure concurrently. To collect all the problematic thread, we used a lock free stack (which was already implemented in the hotspot code). Also, to keep problematic threads alive during multiple rounds of handshaking, we use a ThreadHandleList (this is also required to be able to handshake on a specific thread).

-------------

Commit messages:
 - Fix whitespaces
 - Tweak ResourceScope javadoc
 - More cleanup: make close_scope return type be `void`
 - Add more code comments
 - Add comments, fix test
 - Initial push

Changes: https://git.openjdk.java.net/panama-foreign/pull/643/files
 Webrev: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=643&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8282061
  Stats: 90 lines in 5 files changed: 46 ins; 16 del; 28 mod
  Patch: https://git.openjdk.java.net/panama-foreign/pull/643.diff
  Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/643/head:pull/643

PR: https://git.openjdk.java.net/panama-foreign/pull/643


More information about the panama-dev mailing list