Skip to content

Commit

Permalink
Merge pull request #16663 from ChengJin01/ffi_remove_restriction_sess…
Browse files Browse the repository at this point in the history
…ions_upcall_stub

[FFI] Remove the restriction on all sessions in downcall
  • Loading branch information
tajila authored Feb 3, 2023
2 parents 16d3598 + 8029839 commit 4701ec8
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ private final void addMemArgSession(MemorySession memArgSessionOrScope)
private final void addMemArgScope(ResourceScope memArgSessionOrScope)
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
{
if ((memArgSessionOrScope.ownerThread() != null)
&& !sessionOrScopeSet.contains(memArgSessionOrScope)
) {
if (!sessionOrScopeSet.contains(memArgSessionOrScope)) {
sessionOrScopeSet.add(memArgSessionOrScope);
}
}
Expand Down Expand Up @@ -645,7 +643,10 @@ private void SetDependency(MemorySession session) {
*/
if (memArgSession.isAlive()) {
Thread owner = memArgSession.ownerThread();
if (owner == Thread.currentThread()) { // For the confined session
/* The check is intended for the confined session or
* the shared session(e.g. implicit/global session).
*/
if ((owner == Thread.currentThread()) || (owner == null)) {
MemorySessionImpl memArgSessionImpl = (MemorySessionImpl)memArgSession;
memArgSessionImpl.acquire0();
session.addCloseAction(memArgSessionImpl::release0);
Expand All @@ -663,7 +664,10 @@ private void SetDependency(ResourceScope scope) {
for (ResourceScope memArgScope : sessionOrScopeSet) {
if (memArgScope.isAlive()) {
Thread owner = memArgScope.ownerThread();
if (owner == Thread.currentThread()) { // For the confined scope
/* The check is intended for the confined scope or
* the shared scope(e.g. implicit/global scope).
*/
if ((owner == Thread.currentThread()) || (owner == null)) {
scope.keepAlive(memArgScope); // keepAlive() is only used in JDK18
}
}
Expand All @@ -676,7 +680,10 @@ private void acquireScope() {
for (ResourceScope memArgScope : sessionOrScopeSet) {
if (memArgScope.isAlive()) {
Thread owner = memArgScope.ownerThread();
if (owner == Thread.currentThread()) { // For the confined scope
/* The check is intended for the confined scope or
* the shared scope(e.g. implicit/global scope).
*/
if ((owner == Thread.currentThread()) || (owner == null)) {
Handle scopeHandle = memArgScope.acquire();
scopeHandleMap.put(memArgScope, scopeHandle);
}
Expand All @@ -689,7 +696,10 @@ private void releaseScope() {
for (ResourceScope memArgScope : sessionOrScopeSet) {
if (memArgScope.isAlive()) {
Thread owner = memArgScope.ownerThread();
if (owner == Thread.currentThread()) { // For the confined scope
/* The check is intended for the confined scope or
* the shared scope(e.g. implicit/global scope).
*/
if ((owner == Thread.currentThread()) || (owner == null)) {
Handle scopeHandle = scopeHandleMap.get(memArgScope);
memArgScope.release(scopeHandle);
}
Expand Down

0 comments on commit 4701ec8

Please sign in to comment.