clikt icon indicating copy to clipboard operation
clikt copied to clipboard

Runtime error when enabling vector API and native access at the same time

Open andriesfc opened this issue 1 year ago • 3 comments

Do not know if this a JDK bug, or not, but I get this nasty native memory access error when enabling these two JVM options in the mordant classes:

  • --add-modules=jdk.incubator.vector
  • --enable-native-access=ALL-UNNAMED

I'm using:

  • Kotlin 2.1.10

  • Clikt 5.0.2

  • JDK 21 (on MacOS Intel):

    openjdk version "21.0.5" 2024-10-15 LTS
    OpenJDK Runtime Environment Temurin-21.0.5+11 (build 21.0.5+11-LTS)
    OpenJDK 64-Bit Server VM Temurin-21.0.5+11 (build 21.0.5+11-LTS, mixed mode)
    

Stack trace

WARNING: Using incubator modules: jdk.incubator.vector
Exception in thread "main" java.lang.ClassCastException: Cannot cast java.lang.Integer to java.lang.foreign.MemorySegment
	at java.base/java.lang.Class.cast(Class.java:4067)
	at java.base/java.lang.invoke.VarHandles.insertCoordinates(VarHandles.java:501)
	at java.base/java.lang.invoke.MethodHandles.insertCoordinates(MethodHandles.java:8144)
	at com.github.ajalt.mordant.terminal.terminalinterface.ffm.FfmLayoutsKt.varHandle(FfmLayouts.kt:133)
	at com.github.ajalt.mordant.terminal.terminalinterface.ffm.FfmLayoutsKt$shortField$$inlined$scalarField$default$1$1.invoke(FfmLayouts.kt:84)
	at com.github.ajalt.mordant.terminal.terminalinterface.ffm.FfmLayoutsKt$shortField$$inlined$scalarField$default$1$1.invoke(FfmLayouts.kt:81)
	at com.github.ajalt.mordant.terminal.terminalinterface.ffm.StructAccessor$DefaultImpls.getValue(FfmLayouts.kt:117)
	at com.github.ajalt.mordant.terminal.terminalinterface.ffm.MacosCLibrary$winsize.getValue(TerminalInterface.ffm.macos.kt:11)
	at com.github.ajalt.mordant.terminal.terminalinterface.ffm.MacosCLibrary$winsize.getWs_col(TerminalInterface.ffm.macos.kt:22)
	at com.github.ajalt.mordant.terminal.terminalinterface.ffm.TerminalInterfaceFfmMacos.getTerminalSize(TerminalInterface.ffm.macos.kt:89)
	at com.github.ajalt.mordant.terminal.TerminalDetectionKt.detectSize(TerminalDetection.kt:217)
	at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:81)
	at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:60)
	at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:49)
	at com.github.ajalt.clikt.core.MordantContextKt.getTerminal(MordantContext.kt:13)
	at luceneinaction.AppKt$main$1$special$$inlined$findOrSetObject$default$1.getValue(Context.kt:563)
	at luceneinaction.AppKt$main$1$special$$inlined$findOrSetObject$default$1.getValue(Context.kt:510)
	at luceneinaction.AppKt$main$1.getContext(App.kt:35)
	at luceneinaction.AppKt$main$1.run(App.kt:59)
	at com.github.ajalt.clikt.core.CoreCliktCommandKt.parse(CoreCliktCommand.kt:107)
	at com.github.ajalt.clikt.core.CoreCliktCommandKt.main(CoreCliktCommand.kt:78)
	at com.github.ajalt.clikt.core.CoreCliktCommandKt.main(CoreCliktCommand.kt:90)
	at luceneinaction.AppKt.main(App.kt:62)

andriesfc avatar Feb 08 '25 19:02 andriesfc

I'm not familiar with the vector incubator. Does it change the function signatures of the FFM module?

ajalt avatar Feb 09 '25 16:02 ajalt

Hi @ajalt. I really do not know. I'm busy re-learning Lucene. And it seems they have enabled this experimental module by default in the latest version 😠. I will my share my project.

andriesfc avatar Feb 09 '25 18:02 andriesfc

Here is the part of the setup which breaks it: andriesfc/lucene-in-action.

andriesfc avatar Feb 09 '25 19:02 andriesfc