Skip to content
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

Windows native: JLINE(JANSI), ForeignAPISupport, JDK 23+ #43777

Open
Karm opened this issue Oct 8, 2024 · 7 comments
Open

Windows native: JLINE(JANSI), ForeignAPISupport, JDK 23+ #43777

Karm opened this issue Oct 8, 2024 · 7 comments
Assignees
Labels
area/native-image env/windows Impacts Windows machines kind/bug Something isn't working

Comments

@Karm
Copy link
Member

Karm commented Oct 8, 2024

EDIT:

The cause is JBoss logging manager. Isolated reproducer: #43777 (comment)

Workaround

Based on the investigation in oracle/graal#9884 the workaround is to opt-out of the new JLine JDK support that enables Java runtime to talk to Windows native Kernel32 API to control "dumb" terminals that don't understand ESC symbols. You can do it like so:

mvnw package -Dnative -Dquarkus.native.additional-build-args=-J-Djdk.console=jdk.base

Describe the bug

The library used to highlight and color terminal output on Windows, jline needs FFM. Hopefully, it doesn't do any upcalls...no idea why it should though.

Specifically, downcalls are supported on x64 Linux, Windows and MacOS, while upcalls are supported only on x64 Linux.

We need to take a look at how we handle the library in Quarkus and to make it work on Windows.
This issue slipped CI, because the logic detects it is not running in a proper terminal and does not execute. You need a real terminal, like the vanilla cmd or https://cmder.app/ like I use to trigger it. Actually any terminal the JANSI (JLINE) can work with triggers the issue on Windows.

Expected behavior

It works.

Actual behavior

It crashes during build.

Workaround

See EDIT at the beginning.

Remove quarkus-junit5 from the project.

How to Reproduce?

C:\tmp
λ curl -O -J -L https://github.com/graalvm/mandrel/releases/download/mandrel-24.1.0.0-Final/mandrel-java23-windows-amd64-24.1.0.0-Final.zip
λ powershell -c "Expand-Archive -Path mandrel-java23-windows-amd64-24.1.0.0-Final.zip -DestinationPath . -Force
λ SET JAVA_HOME=C:\tmp\mandrel-java23-24.1.0.0-Final\
λ SET GRAALVM_HOME=%JAVA_HOME%
λ SET PATH=%JAVA_HOME%\bin;%PATH%

λ curl -O -J -L "https://code.quarkus.io/d?e=rest&cn=code.quarkus.io"
λ powershell -c "Expand-Archive -Path code-with-quarkus.zip -DestinationPath . -Force
λ cd code-with-quarkus\
C:\tmp\code-with-quarkus
λ vcvars64
λ mvnw package -Dnative

Log

Note that just simply adding the option doesn't help:

C:\tmp\code-with-quarkus
λ mvnw package -Dnative -Dquarkus.native.additional-build-args=-H:+ForeignAPISupport
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] C:\tmp\mandrel-java23-24.1.0.1-devadbc8bdf69d\bin\native-image.cmd -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dlogging.initial-configurator.min-level=500 -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=3 -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Duser.language=en -J-Duser.country=US -J-Dfile.encoding=UTF-8 --features=io.quarkus.runner.Feature,io.quarkus.runtime.graal.DisableLoggingFeature -J--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED -J--add-exports=java.security.jgss/sun.security.jgss=ALL-UNNAMED -J--add-opens=java.base/java.text=ALL-UNNAMED -J--add-opens=java.base/java.io=ALL-UNNAMED -J--add-opens=java.base/java.lang.invoke=ALL-UNNAMED -J--add-opens=java.base/java.util=ALL-UNNAMED -H:+UnlockExperimentalVMOptions -H:BuildOutputJSONFile=code-with-quarkus-1.0.0-SNAPSHOT-runner-build-output-stats.json -H:-UnlockExperimentalVMOptions -H:+UnlockExperimentalVMOptions -H:+GenerateBuildArtifactsFile -H:-UnlockExperimentalVMOptions -H:+ForeignAPISupport -H:+UnlockExperimentalVMOptions -H:+AllowFoldMethods -H:-UnlockExperimentalVMOptions -J-Djava.awt.headless=true --no-fallback --link-at-build-time -H:+UnlockExperimentalVMOptions -H:+ReportExceptionStackTraces -H:-UnlockExperimentalVMOptions -H:-AddAllCharsets --enable-url-protocols=http --enable-monitoring=heapdump -H:+UnlockExperimentalVMOptions -H:-UseServiceLoaderFeature -H:-UnlockExperimentalVMOptions -J--add-exports=org.graalvm.nativeimage/org.graalvm.nativeimage.impl=ALL-UNNAMED --exclude-config io\.netty\.netty-codec /META-INF/native-image/io\.netty/netty-codec/generated/handlers/reflect-config\.json --exclude-config io\.netty\.netty-handler /META-INF/native-image/io\.netty/netty-handler/generated/handlers/reflect-config\.json code-with-quarkus-1.0.0-SNAPSHOT-runner -jar code-with-quarkus-1.0.0-SNAPSHOT-runner.jar
Warning: The option '-H:+ForeignAPISupport' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: Please re-evaluate whether any experimental option is required, and either remove or unlock it. The build output lists all active experimental options, including where they come from and possible alternatives. If you think an experimental option should be considered as stable, please file an issue.
Warning: Option 'DynamicProxyConfigurationResources' is deprecated and might be removed in a future release: This can be caused by a proxy-config.json file in your META-INF directory. Consider including proxy configuration in the reflection section of reachability-metadata.md instead.. Please refer to the GraalVM release notes.
========================================================================================================================
GraalVM Native Image: Generating 'code-with-quarkus-1.0.0-SNAPSHOT-runner' (executable)...
========================================================================================================================
For detailed information and explanations on the build output, visit:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
------------------------------------------------------------------------------------------------------------------------
[1/8] Initializing...                                                                                   (21.2s @ 0.13GB)
 Java version: 23+37, vendor version: Mandrel-24.1.0.1-devadbc8bdf69d
 Graal compiler: optimization level: 2, target machine: x86-64-v3
 C compiler: cl.exe (microsoft, x64, 19.36.32535)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 3 user-specific feature(s):
 - com.oracle.svm.thirdparty.gson.GsonFeature
 - io.quarkus.runner.Feature: Auto-generated class by Quarkus from the existing extensions
 - io.quarkus.runtime.graal.DisableLoggingFeature: Disables INFO logging during the analysis phase
------------------------------------------------------------------------------------------------------------------------
 5 experimental option(s) unlocked:
 - '-H:+AllowFoldMethods' (origin(s): command line)
 - '-H:+ForeignAPISupport' (origin(s): command line)
 - '-H:BuildOutputJSONFile' (origin(s): command line)
 - '-H:-UseServiceLoaderFeature' (origin(s): command line)
 - '-H:+GenerateBuildArtifactsFile' (origin(s): command line)
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 11.05GB of memory (69.1% of 16.00GB system memory, determined at start)
 - 8 thread(s) (100.0% of 8 available processor(s), determined at start)
[2/8] Performing analysis...  []                                                                        (12.7s @ 0.60GB)
    5,445 reachable types   (72.0% of    7,567 total)
    6,345 reachable fields  (38.7% of   16,386 total)
   23,148 reachable methods (41.6% of   55,682 total)
    1,824 types,    18 fields, and   402 methods registered for reflection
        0 downcalls and 0 upcalls registered for foreign access
        4 native libraries: crypt32, ncrypt, psapi, winhttp

Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing jdk.internal.foreign.abi.DowncallStub/0x00000000ae02ac00.invoke(Unknown Source)
Parsing context:
   at jdk.internal.org.jline.terminal.impl.ffm.Kernel32.GetConsoleScreenBufferInfo(Kernel32.java:224)
   at jdk.internal.org.jline.terminal.impl.ffm.WindowsAnsiWriter.getConsoleInfo(WindowsAnsiWriter.java:95)
   at jdk.internal.org.jline.terminal.impl.ffm.WindowsAnsiWriter.processCursorDown(WindowsAnsiWriter.java:239)
   at jdk.internal.org.jline.utils.AnsiWriter.processEscapeCommand(AnsiWriter.java:269)
   at jdk.internal.org.jline.utils.AnsiWriter.write(AnsiWriter.java:134)
   at jdk.internal.org.jline.utils.AnsiWriter.write(AnsiWriter.java:781)
   at java.io.PrintWriter.implWrite(PrintWriter.java:621)
   at java.io.PrintWriter.write(PrintWriter.java:613)
   at java.io.PrintWriter.write(PrintWriter.java:635)
   at java.io.PrintWriter.print(PrintWriter.java:782)
   at java.io.PrintWriter.println(PrintWriter.java:1033)
   at java.lang.Throwable$WrappedPrintWriter.println(Throwable.java:829)
   at java.lang.Throwable.lockedPrintStackTrace(Throwable.java:712)
   at java.lang.Throwable.printStackTrace(Throwable.java:701)
   at java.lang.Throwable.printStackTrace(Throwable.java:688)
   at java.lang.Throwable.printStackTrace(Throwable.java:679)
   at org.slf4j.helpers.Util.report(Util.java:123)
   at org.slf4j.helpers.MessageFormatter.safeObjectAppend(MessageFormatter.java:294)
   at org.slf4j.helpers.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:263)
   at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:225)
   at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:160)
   at io.netty.util.internal.logging.LocationAwareSlf4JLogger.warn(LocationAwareSlf4JLogger.java:195)
   at io.netty.util.internal.SystemPropertyUtil.getInt(SystemPropertyUtil.java:144)
   at io.netty.buffer.ByteBufUtil.<clinit>(ByteBufUtil.java:103)
   at static root method.(Unknown Source)

        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:165)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:184)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureFlowsGraphCreated(MethodTypeFlow.java:152)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.getOrCreateMethodFlowsGraphInfo(MethodTypeFlow.java:110)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow.lambda$update$0(DefaultStaticInvokeTypeFlow.java:75)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.LightImmutableCollection.forEach(LightImmutableCollection.java:90)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow.update(DefaultStaticInvokeTypeFlow.java:74)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis$1.run(PointsToAnalysis.java:575)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:166)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:152)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1726)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1717)
        at java.base/java.util.concurrent.ForkJoinTask$InterruptibleTask.exec(ForkJoinTask.java:1641)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1458)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2034)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:189)
Caused by: com.oracle.svm.core.util.VMError$HostedError: should not reach here: unexpected input could not be handled: linkToNative
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.shouldNotReachHereUnexpectedInput(VMError.java:97)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.PolymorphicSignatureWrapperMethod.buildGraph(PolymorphicSignatureWrapperMethod.java:170)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.SubstitutionMethod.buildGraph(SubstitutionMethod.java:122)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.buildGraph(AnalysisMethod.java:657)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.AnalysisParsedGraph.parseBytecode(AnalysisParsedGraph.java:108)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.parseGraph(AnalysisMethod.java:916)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsedHelper(AnalysisMethod.java:881)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsed(AnalysisMethod.java:864)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.lookupEncodedGraph(InlineBeforeAnalysisGraphDecoder.java:181)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.doInline(PEGraphDecoder.java:1215)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.tryInline(PEGraphDecoder.java:1198)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.trySimplifyInvoke(PEGraphDecoder.java:1053)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.handleInvokeWithCallTarget(PEGraphDecoder.java:1005)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.handleInvoke(PEGraphDecoder.java:991)
        at jdk.graal.compiler/jdk.graal.compiler.nodes.GraphDecoder.processNextNode(GraphDecoder.java:926)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.processNextNode(InlineBeforeAnalysisGraphDecoder.java:269)
        at jdk.graal.compiler/jdk.graal.compiler.nodes.GraphDecoder.decode(GraphDecoder.java:654)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.decode(PEGraphDecoder.java:895)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysis.decodeGraph(InlineBeforeAnalysis.java:73)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:200)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:652)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:167)
        ... 15 more

Output of uname -a or ver

Windows 2019

Output of java -version

23.0.0 23+37

Mandrel or GraalVM version (if different from Java)

OpenJDK 64-Bit Server VM Mandrel-24.1.0.0-Final (build 23+37, mixed mode)

Quarkus version or git rev

3.14.4, 3.15.0, 3.15.1

Build tool (ie. output of mvnw --version or gradlew --version)

mvnw

Additional information

No response

@Karm Karm added area/native-image kind/bug Something isn't working labels Oct 8, 2024
@quarkus-bot quarkus-bot bot added the env/windows Impacts Windows machines label Oct 8, 2024
Copy link

quarkus-bot bot commented Oct 8, 2024

/cc @galderz (mandrel), @zakkak (mandrel,native-image)

@Karm Karm self-assigned this Oct 8, 2024
@Karm Karm changed the title Windows native: JLINE a.k.a. JANSI needs proper ForeignAPISupport on JDK 23+ Windows native: JLINE(JANSI) needs proper ForeignAPISupport on JDK 23+ Oct 8, 2024
@Karm Karm changed the title Windows native: JLINE(JANSI) needs proper ForeignAPISupport on JDK 23+ Windows native: JLINE(JANSI) needs ForeignAPISupport on JDK 23+ Oct 8, 2024
@Karm Karm changed the title Windows native: JLINE(JANSI) needs ForeignAPISupport on JDK 23+ Windows native: JLINE(JANSI) needs ForeignAPISupport, JDK 23+ Oct 8, 2024
@Karm Karm changed the title Windows native: JLINE(JANSI) needs ForeignAPISupport, JDK 23+ Windows native: JLINE(JANSI) , ForeignAPISupport, JDK 23+ Oct 8, 2024
@Karm Karm changed the title Windows native: JLINE(JANSI) , ForeignAPISupport, JDK 23+ Windows native: JLINE(JANSI), ForeignAPISupport, JDK 23+ Oct 8, 2024
@Karm
Copy link
Member Author

Karm commented Oct 9, 2024

Workaround is to remove dependency on quarkus-junit5 and tests as that brings in the readline/jansi...

Merely disabling tests like so is not enough:

C:\tmp\code-with-quarkus
λ mvnw clean package -Dnative -DskipTests -Dquarkus.profile=prod

and that is concerning on its own :(

@Karm
Copy link
Member Author

Karm commented Oct 11, 2024

Update, the actual culprit is jboss-logmanager and what it does internally that allows e.g. color print via JDK's internal jline terminal control devices. It needs additional config

...
    {
      "module": "jdk.internal.le",
      "glob": "jdk/internal/org/jline/utils/capabilities.txt"
    }
  ],

WIP...

@Karm
Copy link
Member Author

Karm commented Oct 14, 2024

This reproduces the issue in isolation, without Quarkus in the picture:

https://github.com/Karm/dev-null/tree/main/jbosslogmanager

Linux: OK
Windows exactly the same error as Quarkus:

C:\tmp\dev-null\jbosslogmanager(main -> origin)
λ native-image --no-fallback --link-at-build-time --initialize-at-build-time=org.jboss,io.smallrye -march=native -H:ConfigurationFileDirectories=./AGENT -jar target/jbosslogmanager.jar
========================================================================================================================
GraalVM Native Image: Generating 'jbosslogmanager' (executable)...
========================================================================================================================
For detailed information and explanations on the build output, visit:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
------------------------------------------------------------------------------------------------------------------------
[1/8] Initializing...                                                                                   (14.2s @ 0.08GB)
 Java version: 23+37, vendor version: Mandrel-24.1.0.0-Final
 Graal compiler: optimization level: 2, target machine: native
 C compiler: cl.exe (microsoft, x64, 19.36.32535)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 1 user-specific feature(s):
 - com.oracle.svm.thirdparty.gson.GsonFeature
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 11.27GB of memory (70.4% of 16.00GB system memory, determined at start)
 - 8 thread(s) (100.0% of 8 available processor(s), determined at start)
[2/8] Performing analysis...  []                                                                         (6.5s @ 0.18GB)
    1,998 reachable types   (56.9% of    3,512 total)
    1,648 reachable fields  (29.8% of    5,521 total)
    7,202 reachable methods (29.1% of   24,729 total)
      698 types,    20 fields, and    98 methods registered for reflection

Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing jdk.internal.foreign.abi.DowncallStub/0x000000003ca1d400.invoke(Unknown Source)
Parsing context:
   at jdk.internal.org.jline.terminal.impl.ffm.Kernel32.GetConsoleScreenBufferInfo(Kernel32.java:224)
   at jdk.internal.org.jline.terminal.impl.ffm.WindowsAnsiWriter.getConsoleInfo(WindowsAnsiWriter.java:95)
   at jdk.internal.org.jline.terminal.impl.ffm.WindowsAnsiWriter.processCursorLeft(WindowsAnsiWriter.java:225)
   at jdk.internal.org.jline.utils.AnsiWriter.processEscapeCommand(AnsiWriter.java:275)
   at jdk.internal.org.jline.utils.AnsiWriter.write(AnsiWriter.java:150)
   at jdk.internal.org.jline.utils.AnsiWriter.write(AnsiWriter.java:773)
   at java.io.PrintWriter.implWrite(PrintWriter.java:574)
   at java.io.PrintWriter.write(PrintWriter.java:560)
   at java.io.ProxyingConsole$WrappingWriter.write(ProxyingConsole.java:270)
   at org.jboss.logmanager.handlers.UncloseableWriter.write(UncloseableWriter.java:44)
   at java.io.BufferedWriter.implFlushBuffer(BufferedWriter.java:178)
   at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:169)
   at java.io.BufferedWriter.implWrite(BufferedWriter.java:334)
   at java.io.BufferedWriter.write(BufferedWriter.java:319)
   at java.io.Writer.write(Writer.java:278)
   at org.jboss.logmanager.handlers.WriterHandler.writeHead(WriterHandler.java:185)
   at org.jboss.logmanager.handlers.WriterHandler.setWriter(WriterHandler.java:113)
   at org.jboss.logmanager.handlers.OutputStreamHandler.setOutputStream(OutputStreamHandler.java:127)
   at org.jboss.logmanager.handlers.ConsoleHandler.setOutputStream(ConsoleHandler.java:252)
   at org.jboss.logmanager.handlers.ConsoleHandler.<init>(ConsoleHandler.java:111)
   at com.oracle.svm.core.code.FactoryMethodHolder.ConsoleHandler_TV4kuafI8Z2OhhB7qtydtK(generated:0)
   at static root method.(Unknown Source)

        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:165)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:184)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureFlowsGraphCreated(MethodTypeFlow.java:152)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.getOrCreateMethodFlowsGraphInfo(MethodTypeFlow.java:110)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow.lambda$update$0(DefaultStaticInvokeTypeFlow.java:75)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.LightImmutableCollection.forEach(LightImmutableCollection.java:90)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow.update(DefaultStaticInvokeTypeFlow.java:74)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis$1.run(PointsToAnalysis.java:575)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:166)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:152)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1726)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1717)
        at java.base/java.util.concurrent.ForkJoinTask$InterruptibleTask.exec(ForkJoinTask.java:1641)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1458)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2034)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:189)
Caused by: com.oracle.svm.core.util.VMError$HostedError: should not reach here: unexpected input could not be handled: linkToNative
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.shouldNotReachHereUnexpectedInput(VMError.java:97)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.PolymorphicSignatureWrapperMethod.buildGraph(PolymorphicSignatureWrapperMethod.java:170)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.SubstitutionMethod.buildGraph(SubstitutionMethod.java:122)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.buildGraph(AnalysisMethod.java:657)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.AnalysisParsedGraph.parseBytecode(AnalysisParsedGraph.java:108)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.parseGraph(AnalysisMethod.java:916)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsedHelper(AnalysisMethod.java:881)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsed(AnalysisMethod.java:864)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.lookupEncodedGraph(InlineBeforeAnalysisGraphDecoder.java:181)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.doInline(PEGraphDecoder.java:1215)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.tryInline(PEGraphDecoder.java:1198)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.trySimplifyInvoke(PEGraphDecoder.java:1053)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.handleInvokeWithCallTarget(PEGraphDecoder.java:1005)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.handleInvoke(PEGraphDecoder.java:991)
        at jdk.graal.compiler/jdk.graal.compiler.nodes.GraphDecoder.processNextNode(GraphDecoder.java:926)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.processNextNode(InlineBeforeAnalysisGraphDecoder.java:269)
        at jdk.graal.compiler/jdk.graal.compiler.nodes.GraphDecoder.decode(GraphDecoder.java:654)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.decode(PEGraphDecoder.java:895)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysis.decodeGraph(InlineBeforeAnalysis.java:73)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:200)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:652)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:167)
        ... 15 more
------------------------------------------------------------------------------------------------------------------------
                        0.6s (2.6% of total time) in 42 GCs | Peak RSS: 0.50GB | CPU load: 3.61
========================================================================================================================
Failed generating 'jbosslogmanager' after 21.9s.

Adding Foreign Function support doesn't help:

λ native-image --no-fallback --link-at-build-time --initialize-at-build-time=org.jboss,io.smallrye \
  -march=native -H:ConfigurationFileDirectories=./AGENT -H:+ForeignAPISupport -jar target/jbosslogmanager.jar

@Karm
Copy link
Member Author

Karm commented Oct 15, 2024

The trace with a different terminal, plain cmd, looks diferently. It's not about color after all. In this case, jbosslogmanager bails out and

  • doesn't attempt to insert any color setting bytes
  • doesn't try to reach out to jansi to talk to terminal natively and set colors

It fails all the same, just by plain trying to write:

Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing jdk.internal.foreign.abi.DowncallStub/0x00000000aca1d800.invoke(Unknown Source)
Parsing context:
   at jdk.internal.org.jline.terminal.impl.ffm.Kernel32.GetConsoleScreenBufferInfo(Kernel32.java:224)
   at jdk.internal.org.jline.terminal.impl.ffm.WindowsAnsiWriter.getConsoleInfo(WindowsAnsiWriter.java:95)
   at jdk.internal.org.jline.terminal.impl.ffm.WindowsAnsiWriter.processCursorUp(WindowsAnsiWriter.java:260)
   at jdk.internal.org.jline.utils.AnsiWriter.processEscapeCommand(AnsiWriter.java:266)
   at jdk.internal.org.jline.utils.AnsiWriter.write(AnsiWriter.java:114)
   at jdk.internal.org.jline.utils.AnsiWriter.write(AnsiWriter.java:773)
   at java.io.Writer.write(Writer.java:242)
   at jdk.internal.org.jline.utils.AnsiWriter.close(AnsiWriter.java:787)
   at java.io.PrintWriter.implClose(PrintWriter.java:457)
   at java.io.PrintWriter.close(PrintWriter.java:443)
   at java.io.FileDescriptor.closeAll(FileDescriptor.java:352)
   at java.io.FileInputStream.close(FileInputStream.java:540)
   at sun.nio.cs.StreamDecoder.implClose(StreamDecoder.java:445)
   at sun.nio.cs.StreamDecoder.lockedClose(StreamDecoder.java:266)
   at sun.nio.cs.StreamDecoder.close(StreamDecoder.java:251)
   at java.io.InputStreamReader.close(InputStreamReader.java:205)
   at java.io.BufferedReader.implClose(BufferedReader.java:636)
   at java.io.BufferedReader.close(BufferedReader.java:621)
   at java.util.ServiceLoader$LazyClassPathLookupIterator.parse(ServiceLoader.java:1174)
   at java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1209)
   at java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1224)
   at java.util.ServiceLoader$LazyClassPathLookupIterator.nextService(ServiceLoader.java:1250)
   at java.util.ServiceLoader$LazyClassPathLookupIterator.next(ServiceLoader.java:1282)
   at java.util.ServiceLoader$LazyClassPathLookupIterator.next(ServiceLoader.java:1112)
   at java.util.AbstractCollection.containsAll(AbstractCollection.java:310)
   at java.util.AbstractSet.equals(AbstractSet.java:95)
   at java.util.HashMap.putVal(HashMap.java:655)
   at java.util.HashMap.put(HashMap.java:619)
   at java.util.HashSet.add(HashSet.java:230)
   at java.util.AbstractCollection.addAll(AbstractCollection.java:338)
   at sun.util.locale.provider.FallbackLocaleProviderAdapter.createLanguageTagSet(FallbackLocaleProviderAdapter.java:70)
   at sun.util.locale.provider.JRELocaleProviderAdapter.getLanguageTagSet(JRELocaleProviderAdapter.java:443)
   at sun.util.locale.provider.JRELocaleProviderAdapter.lambda$getDecimalFormatSymbolsProvider$4(JRELocaleProviderAdapter.java:223)
   at sun.util.locale.provider.JRELocaleProviderAdapter$$Lambda/0x00000000acaeae00.run(Unknown Source)
   at com.oracle.svm.core.jdk.Target_java_security_AccessController.executePrivileged(SecuritySubstitutions.java:132)
   at sun.util.locale.provider.JRELocaleProviderAdapter.getDecimalFormatSymbolsProvider(JRELocaleProviderAdapter.java:219)
   at java.text.DecimalFormatSymbols.getInstance(DecimalFormatSymbols.java:185)
   at java.util.Formatter.getDecimalFormatSymbols(Formatter.java:2031)
   at java.util.Formatter$FormatSpecifier.localizedMagnitude(Formatter.java:4768)
   at java.util.Formatter$FormatSpecifier.localizedMagnitude(Formatter.java:4715)
   at java.util.Formatter$FormatSpecifier.print(Formatter.java:4322)
   at java.util.Formatter$FormatSpecifier.print(Formatter.java:4259)
   at java.util.Formatter$FormatSpecifier.printDateTime(Formatter.java:3294)
   at java.util.Formatter$FormatSpecifier.print(Formatter.java:3196)
   at java.util.Formatter.format(Formatter.java:2790)
   at java.util.Formatter.format(Formatter.java:2738)
   at java.lang.String.format(String.java:4481)
   at jdk.internal.util.Preconditions.outOfBoundsMessage(Preconditions.java:242)
   at jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
   at jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
   at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
   at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
   at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
   at java.lang.StringUTF16.checkIndex(StringUTF16.java:1777)
   at java.lang.StringUTF16.charAt(StringUTF16.java:1575)
   at java.lang.String.charAt(String.java:1631)
   at com.oracle.svm.core.log.RealLog.charAt(RealLog.java:176)
   at com.oracle.svm.core.log.RealLog.rawBytes(RealLog.java:159)
   at com.oracle.svm.core.log.RealLog.string(RealLog.java:124)
   at com.oracle.svm.core.log.RealLog.string(RealLog.java:132)
   at com.oracle.svm.core.log.RealLog.newline(RealLog.java:216)
   at com.oracle.svm.core.SubstrateDiagnostics.printFatalError(SubstrateDiagnostics.java:267)
   at com.oracle.svm.core.jdk.VMErrorSubstitutions.doShutdown(VMErrorSubstitutions.java:168)
   at com.oracle.svm.core.jdk.VMErrorSubstitutions.shutdown(VMErrorSubstitutions.java:146)
   at com.oracle.svm.core.jdk.VMErrorSubstitutions.shouldNotReachHere(VMErrorSubstitutions.java:139)
   at com.oracle.svm.core.jdk.Target_com_oracle_svm_core_util_VMError.shouldNotReachHere(VMErrorSubstitutions.java:90)
   at com.oracle.svm.core.jdk.BacktraceVisitor.visitAOTFrame(StackTraceUtils.java:420)
   at com.oracle.svm.core.jdk.BacktraceVisitor.visitRegularFrame(StackTraceUtils.java:391)
   at com.oracle.svm.core.stack.StackFrameVisitor.visitRegularFrame(StackFrameVisitor.java:54)
   at com.oracle.svm.core.stack.JavaStackWalker.visitRegularFrame(JavaStackWalker.java:490)
   at com.oracle.svm.core.stack.JavaStackWalker.doWalk(JavaStackWalker.java:470)
   at com.oracle.svm.core.stack.JavaStackWalker.walkCurrentThread(JavaStackWalker.java:422)
   at com.oracle.svm.core.stack.JavaStackWalker.walkCurrentThread(JavaStackWalker.java:404)
   at com.oracle.svm.core.thread.JavaThreads.visitCurrentVirtualThreadStackFrames(JavaThreads.java:275)
   at com.oracle.svm.core.thread.JavaThreads.visitCurrentStackFrames(JavaThreads.java:264)
   at com.oracle.svm.core.jdk.Target_java_lang_Throwable.fillInStackTrace(JavaLangSubstitutions.java:292)
   at com.oracle.svm.core.jdk.Target_java_lang_Throwable.fillInStackTrace(JavaLangSubstitutions.java:250)
   at java.lang.Throwable.<init>(Throwable.java:338)
   at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:68)
   at com.oracle.svm.core.code.FactoryThrowMethodHolder.InvocationTargetException_A2xd37nsKO5IPIIfILcxNH(generated:0)
   at com.oracle.svm.core.reflect.ReflectionAccessorHolder.invoke_bUHM2U8LqB1SjpZrGE4lTK(generated:0)
   at static root method.(Unknown Source)

        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:165)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:184)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureFlowsGraphCreated(MethodTypeFlow.java:152)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.getOrCreateMethodFlowsGraphInfo(MethodTypeFlow.java:110)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow.lambda$update$0(DefaultStaticInvokeTypeFlow.java:75)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.LightImmutableCollection.forEach(LightImmutableCollection.java:90)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultStaticInvokeTypeFlow.update(DefaultStaticInvokeTypeFlow.java:74)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis$1.run(PointsToAnalysis.java:575)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:166)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:152)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1726)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1717)
        at java.base/java.util.concurrent.ForkJoinTask$InterruptibleTask.exec(ForkJoinTask.java:1641)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
        at java.base/java.util.concurrent.ForkJoinPool.externalHelpQuiesce(ForkJoinPool.java:2535)
        at java.base/java.util.concurrent.ForkJoinPool.helpQuiescePool(ForkJoinPool.java:2569)
        at java.base/java.util.concurrent.ForkJoinPool.awaitQuiescence(ForkJoinPool.java:3808)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.complete(CompletionExecutor.java:208)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis.doTypeflow(PointsToAnalysis.java:613)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis.finish(PointsToAnalysis.java:601)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.AbstractAnalysisEngine.runAnalysis(AbstractAnalysisEngine.java:157)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:832)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:592)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:554)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:528)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:711)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.start(NativeImageGeneratorRunner.java:139)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:94)
Caused by: com.oracle.svm.core.util.VMError$HostedError: should not reach here: unexpected input could not be handled: linkToNative
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.shouldNotReachHereUnexpectedInput(VMError.java:97)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.PolymorphicSignatureWrapperMethod.buildGraph(PolymorphicSignatureWrapperMethod.java:170)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.substitute.SubstitutionMethod.buildGraph(SubstitutionMethod.java:122)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.buildGraph(AnalysisMethod.java:657)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.AnalysisParsedGraph.parseBytecode(AnalysisParsedGraph.java:108)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.parseGraph(AnalysisMethod.java:916)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsedHelper(AnalysisMethod.java:881)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsed(AnalysisMethod.java:864)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.lookupEncodedGraph(InlineBeforeAnalysisGraphDecoder.java:181)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.doInline(PEGraphDecoder.java:1215)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.tryInline(PEGraphDecoder.java:1198)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.trySimplifyInvoke(PEGraphDecoder.java:1053)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.handleInvokeWithCallTarget(PEGraphDecoder.java:1005)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.handleInvoke(PEGraphDecoder.java:991)
        at jdk.graal.compiler/jdk.graal.compiler.nodes.GraphDecoder.processNextNode(GraphDecoder.java:926)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.processNextNode(InlineBeforeAnalysisGraphDecoder.java:269)
        at jdk.graal.compiler/jdk.graal.compiler.nodes.GraphDecoder.decode(GraphDecoder.java:654)
        at jdk.graal.compiler/jdk.graal.compiler.replacements.PEGraphDecoder.decode(PEGraphDecoder.java:895)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysis.decodeGraph(InlineBeforeAnalysis.java:73)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:200)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:652)
        at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:167)
        ... 26 more

@Karm
Copy link
Member Author

Karm commented Oct 15, 2024

I have narrowed it down to the switch between jline internal to JDK being opt-in up to JDK 21 and default later, e.g. in JDK 23+ where I am reproducing it. I'll open a GraalVM bug. I hit the issue at runtime without JBoss Log manager, and at build-time with it. WIP...

@Karm
Copy link
Member Author

Karm commented Oct 16, 2024

Updated with workaround:

mvnw package -Dnative -Dquarkus.native.additional-build-args=-J-Djdk.console=jdk.base

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/native-image env/windows Impacts Windows machines kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant