Add some GraalVM notes + sample scan of Trace Agent

This commit is contained in:
UnicornFreedom 2024-10-10 13:58:18 +02:00
parent 596939087e
commit 6decd3e51a
2 changed files with 6683 additions and 0 deletions

49
GRAALVM.md Normal file
View File

@ -0,0 +1,49 @@
GraalVM Support
===
This is an experimental support branch for GraalVM.
Running
---
This is easy.
If we are using the recent GraalVM 23, we only need to bump Scala 2.13 and SBT to the latest version.
Ocelot Desktop seem to work out of the box.
Native Image
---
This is tricky.
Ocelot relies on a lot of reflection. So we need to work around it.
### 1. Replace Log4J
It is simply not compatible with native images ([logback seems to work](https://github.com/spring-projects/spring-boot/issues/33470)).
### 2. Run the Trace Agent
Add the following VM option:
```shell
-agentlib:native-image-agent=config-output-dir=/ocelot-desktop-folder/src/main/resources/META-INF/native-image/
```
The `/src/main/resources/META-INF/native-image/` folder is important here -
this is where GraalVM will be looking for a file named `reachability-metadata.json`.
The agent will try to detect all the reflective references happening at runtime.
It may not catch everything from the first try, because the code has to be executed to be detected.
There are options to merge scan results and to dump them at some intervals, etc.
### 3. Build a fat JAR
```sbt
sbt assembly
```
### 4. Run Native Image compiler
For example:
```shell
C:\Users\xxx\.jdks\graalvm-ce-23.0.0\bin\native-image -jar C:\Users\xxx\IdeaProjects\ocelot-desktop\target\scala-2.13\ocelot-desktop.jar
```
We are simply giving it the path to the fat JAR from the previous step.
This command will generate a bunch of `*.dll` and the `ocelot-desktop.exe` file in the current directory.
### 5. Hope for the best

File diff suppressed because it is too large Load Diff