- 
        Couldn't load subscription status. 
- Fork 6.1k
8336768: Allow captureCallState and critical linker options to be combined #22327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -161,8 +161,14 @@ private static Object doDowncall(SegmentAllocator returnAllocator, Object[] args | |
| acquiredSessions.add(targetImpl); | ||
|  | ||
| MemorySegment capturedState = null; | ||
| Object captureStateHeapBase = null; | ||
| if (invData.capturedStateMask() != 0) { | ||
| capturedState = SharedUtils.checkCaptureSegment((MemorySegment) args[argStart++]); | ||
| if (!invData.allowsHeapAccess) { | ||
| SharedUtils.checkNative(capturedState); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that this check was missing in the fallback linker, and we were actually crashing when a heap segment was passed as the capture state segment. I've added a new test case that checks that this works as well. | ||
| } else { | ||
| captureStateHeapBase = capturedState.heapBase().orElse(null); | ||
| } | ||
| MemorySessionImpl capturedStateImpl = ((AbstractMemorySegmentImpl) capturedState).sessionImpl(); | ||
| capturedStateImpl.acquire0(); | ||
| acquiredSessions.add(capturedStateImpl); | ||
|  | @@ -197,7 +203,8 @@ private static Object doDowncall(SegmentAllocator returnAllocator, Object[] args | |
| retSeg = (invData.returnLayout() instanceof GroupLayout ? returnAllocator : arena).allocate(invData.returnLayout); | ||
| } | ||
|  | ||
| LibFallback.doDowncall(invData.cif, target, retSeg, argPtrs, capturedState, invData.capturedStateMask(), | ||
| LibFallback.doDowncall(invData.cif, target, retSeg, argPtrs, | ||
| captureStateHeapBase, capturedState, invData.capturedStateMask(), | ||
| heapBases, args.length); | ||
|  | ||
| Reference.reachabilityFence(invData.cif()); | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -90,10 +90,11 @@ private static boolean tryLoadLibrary() { | |
| * @see jdk.internal.foreign.abi.CapturableState | ||
| */ | ||
| static void doDowncall(MemorySegment cif, MemorySegment target, MemorySegment retPtr, MemorySegment argPtrs, | ||
| MemorySegment capturedState, int capturedStateMask, | ||
| Object captureStateHeapBase, MemorySegment capturedState, int capturedStateMask, | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it a bit weird that this method is receiving both the captured segment base and the segment itself. It almost seems as if the checks we do in  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you mean, and I agree it looks a bit strange. but we also pass the array of heap bases separately here (which is more or less a forced move due to how the libffi API works). So, I think the current code is more inline with that. The  | ||
| Object[] heapBases, int numArgs) { | ||
| doDowncall(cif.address(), target.address(), | ||
| retPtr == null ? 0 : retPtr.address(), argPtrs.address(), | ||
| captureStateHeapBase, | ||
| capturedState == null ? 0 : capturedState.address(), capturedStateMask, | ||
| heapBases, numArgs); | ||
| } | ||
|  | @@ -212,7 +213,7 @@ private static void checkStatus(int code) { | |
| private static native int createClosure(long cif, Object userData, long[] ptrs); | ||
| private static native void freeClosure(long closureAddress, long globalTarget); | ||
| private static native void doDowncall(long cif, long fn, long rvalue, long avalues, | ||
| long capturedState, int capturedStateMask, | ||
| Object captureStateHeapBase, long capturedState, int capturedStateMask, | ||
| Object[] heapBases, int numArgs); | ||
|  | ||
| private static native int ffi_prep_cif(long cif, int abi, int nargs, long rtype, long atypes); | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Copyright years