Code changes required after JDK-8291473
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Aug 4 21:23:46 UTC 2022
Hi Filip,
coming back to your original questions:
> I am unsure about changing the C_POINTER layout to be unbounded.
I think this is how we intended the API to be used. Currently, with JDK
19 jextract, you get back a MemoryAddress and you can dereference that.
So it seems logical to preserve same behavior (using the unbounded
address layout).
>
> I will have to find where jextract decides whether to add a
> SegmentAllocator to the signature or not, as in case of pointers as
> the return type, it should not be there.
Yes, I recall having to fight with same issue - in a much of places we
do some "instanceof MemorySegment" and then assume that, if true, we
need an allocator. All those places need to be updated to test on the
return _layout_. Example:
https://github.com/openjdk/jextract/blob/master/src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java#L122
Cheers
Maurizio
>
> Best regards,
> Filip
>
> [1] - https://github.com/krakowski/jextract/tree/jdk20
>
> On 04.08.22 15:47, Filip Krakowski wrote:
>> Hi,
>>
>> since jextract does not work with the latest changes introduced in
>> https://git.openjdk.org/panama-foreign/pull/694, I started to work on
>> adjusting the sources in [1]. I took the following steps so far:
>>
>> 1. Find & replace all occurrences and imports of "Addressable" and
>> "MemoryAddress" and replace it with "MemorySegment"
>> 2. Change all occurences of "Linker.downcallType" and
>> "Linker.upcallType" with "Linker.methodType"
>> 3. Remove duplicate if-statements resulting from Step 1
>> 4. Make C_POINTER$LAYOUT unbounded (in
>> org.openjdk.jextract.impl.ToplevelBuilder#primitiveLayoutString)
>> 5. Use MemorySegment#equals instead of reference comparison inside
>> org.openjdk.jextract.clang.org.openjdk.jextract.clang#getLocation
>> 6. Tweak build.gradle so that the user does not have to specify the
>> jdk home directory. Gradle will automatically search for the
>> specified JDK version. It can also be instructed to search inside
>> custom locations using the org.gradle.java.installations.paths
>> property, which can be set inside ${HOME}/.gradle/gradle.properties.
>>
>> Since my approach is relatively naive ("find & replace" + fixing
>> compiler and runtime errors), important parts of the code may be
>> incorrect at the moment. I tested it with my Gradle plugin's demo
>> project [2], which works. But again, this is only a simple program
>> just calling printf and doing nothing fancy. In the next step I will
>> try to rewrite some jtreg tests and see if they pass. Hopefully, this
>> should point out all incorrect parts.
>>
>> If you want to try it out, you need to compile [1] and add the
>> resulting "bin"-Folder ("$PROJECT_DIR/build/jextract/bin") to your
>> PATH. Afterwards [2] should just work by executing "./gradlew run".
>> If successful, the program should print "Hello World" (using the
>> native printf function).
>>
>> I would greatly appreciate feedback regarding my general approach to
>> code changes. In particular, I am unsure about changing the C_POINTER
>> layout to be unbounded.
>>
>> Best regards,
>> Filip
>>
>> [1] - https://github.com/krakowski/jextract/tree/jdk20
>> [2] - https://github.com/krakowski/jextract-demo
>
More information about the jextract-dev
mailing list