Code changes required after JDK-8291473

Filip Krakowski filip.krakowski at hhu.de
Thu Aug 4 15:39:58 UTC 2022


Hi,

Small update:

I looked through all jtreg tests and made the same replacements as 
before [1]. On my system 91 out of 97 tests pass, although I made an 
error somewhere during replacing all "MemoryAddress" and "Addressable" 
occurrences, because the signature belonging to the generated method of 
native functions returning a pointer now expects a SegmentAllocator as 
the first parameter, where the underlying MethodHandle does not. Calling 
such methods results in an WrongMethodTypeException since the 
MethodHandle is not expecting a SegmentAllocator.

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.

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