Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, in this pull request I propose migrating the project to jdk22 support.
I also managed to track down the reason the upcall test failed.
After adding tests for other upcalls i noticed, it only failed for jvm functions that return strings.
I eventually inserted a few debug prints into the generated bytecode of upcall-class and downcall-class and saw this:
Turns out the downcall function that is wrapped by downcall-class correctly handles the function argument as a MemorySegment (thus not necessitating any to-prim-asm conversion), but the function wrapped by upcall-class returns a Long for the ret-type
::mem/c-string
. I'm not entirely sure if that's the case for any value that hasprimitive-type
of::mem/pointer
but I suspect that's the case.Because of that a simple change to
to-prim-asm
didn't work since it would have to behave differently for upcall-class and downcall-class.The solution I've settled on in this pull request is to still let upcall-class/upcall use the
to-prim-asm
instructions but also for specifically pointer types callMemorySegment.ofAddress
. There is a downside to doing that though. Since this is a default static method of an Interface, calling it from bytecode necessitates a higher bytecode version than is default. Version 8 is fine, but it needs to be specified on the generated class. I've also bumped the insn version to 0.5.4 which allows emitting more recent jvm bytecode versions should that be necessary. In any case, with that change we caninvokestatic
with the extra argumenttrue
, which sets ASMsitf
flag so we can specify that we're talking about an InterfaceMethodref and successfully call the interface method directly from bytecode.I'm not exactly sure if the function wrapped by upcall-class shouldn't just return a MemorySegment in the first place instead of a Long, but i wasn't sure how to robustly integrate this.
The reason it does so, is because of how
serialize
is implemented forc-string
. In migrating to the jdk22 API, I kept the old behavior, which simply returns the address of the string as a Long. I'm not sure if other parts of the library depend on that specific behavior, so the additional call toMemorySegment.ofAddress
seemed like the pragmatic choice to me.Any feedback on this?