summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rw-r--r--native-image/README.md246
-rwxr-xr-xnative-image/build.sh69
-rw-r--r--native-image/kotlin-2.4.21-native-image.patch522
4 files changed, 845 insertions, 1 deletions
diff --git a/README.md b/README.md
index 7d1e5b6..fb658fc 100644
--- a/README.md
+++ b/README.md
@@ -24,9 +24,16 @@ kotlin-proxy/
│ ├── fallback.txt # other cached KGP versions (definition lookup only)
│ └── .stamp # versions the lists were generated for (drift detection)
├── dist/kotlin-proxy-compiler-stubs.jar # the artifact
+├── native-image/ # how to build the OFA Kotlin compiler native image
+├── tools/collect_metadata.py # collects native image reachability metadata from a compile
+├── tools/ic_check.sh # checks incremental compilation in the OFA build
└── test_project/ # AGP test app that consumes the jar
```
+The stub runs a GraalVM native image of the Kotlin compiler, which
+`kotlin.proxy.nativeImage` points to. `native-image/README.md` describes how to
+build that image with the compiler plugins OFA needs.
+
## Building `dist/kotlin-proxy-compiler-stubs.jar`
```bash
@@ -330,7 +337,7 @@ via `org.gradle.jvmargs` or the daemon's own args):
| property | default | meaning |
|---|---|---|
| `kotlin.proxy.pgoProfileDir` | unset | for an image built with `--pgo-instrument`: each compile writes `<dir>/<uuid>.iprof`. Merge them with `native-image-utils merge-pgo-profiles --input-dir=<dir> --output-file=<file>`. |
-| `kotlin.proxy.nativeImage` | unset | native-image distribution root (it holds `bin/kotlinc-native-image.sh`), for example `~/source/kotlin/prepare/compiler-native-image/build/dist`. If unset, the stub downloads the JetBrains release into `<user.dir>/native-image/`. |
+| `kotlin.proxy.nativeImage` | required | native-image distribution root (it holds `bin/kotlinc-native-image.sh`), for example `~/source/kotlin/prepare/compiler-native-image/build/dist`. Compilation fails if it is not set. See `native-image/README.md`. |
The marker file is what proves the stub ran **inside the out-of-process
daemon** (its thread name is `RMI TCP Connection(N)`), regardless of the
diff --git a/native-image/README.md b/native-image/README.md
new file mode 100644
index 0000000..31ec4dd
--- /dev/null
+++ b/native-image/README.md
@@ -0,0 +1,246 @@
+# Building the Kotlin compiler native image for OFA
+
+The stub jar runs a GraalVM native image of the Kotlin compiler
+(`kotlin.proxy.nativeImage`). The JetBrains release of that image only bundles
+some compiler plugins, and loads no others. OFA uses parcelize and
+kotlin-empty-to-string, so it needs its own image. This document records how the
+`kotlin-2.4.21-native-image-x86_64-ofa-1` image was built.
+
+Files in this directory:
+
+| file | what it is |
+|---|---|
+| `kotlin-2.4.21-native-image.patch` | changes to `prepare/compiler-native-image` in the Kotlin repository at tag `v2.4.21` |
+| `build.sh` | runs the native image build with the options below |
+
+Tools used from `../tools`:
+
+| tool | what it is |
+|---|---|
+| `collect_metadata.py` | replays a compile from a Kotlin daemon log with the GraalVM tracing agent, to collect reachability metadata |
+| `ic_check.sh` | checks that incremental compilation gives correct output |
+
+## Requirements
+
+- Oracle GraalVM for JDK 25, in `/usr/lib/jvm/java-25-graalvm` (or set
+ `GRAALVM_HOME`). GraalVM Community Edition can build the image, but it has
+ no G1 GC and no PGO, which give most of the speed.
+- The Kotlin repository: `git clone https://github.com/JetBrains/kotlin`,
+ then `git checkout v2.4.21`.
+- An OFA checkout with the `kotlinProxyStubJar` / `kotlinProxyNativeImage`
+ support in `KotlinConventionPlugin`, and a Gradle cache that holds
+ `kotlin-empty-to-string-compiler` (any OFA Kotlin build downloads it).
+
+The first build of the Kotlin repository takes a long time.
+
+## Why the image needs changes
+
+In Kotlin 2.4.21, `PluginCliParser` reads `META-INF/services` from each
+`-Xplugin` jar, then creates the registrar and the command line processor with
+`Class.forName(name).newInstance()`. In the native image, `Class.forName`
+finds only classes that are compiled into the image. So each plugin needs two
+things:
+
+1. Its classes on the native image classpath.
+2. Reflection metadata for the no-arg constructors of its registrar and
+ command line processor.
+
+The file `META-INF/org/jetbrains/kotlin/bundled-compiler-plugins.txt` in the
+image is not read at runtime in 2.4.21. Plugin jars are matched by their
+service files, not by name.
+
+## The patch
+
+`kotlin-2.4.21-native-image.patch` changes
+`prepare/compiler-native-image/build.gradle.kts`:
+
+- Bundles parcelize (`:kotlin-parcelize-compiler`).
+- `kotlin.build.native-image.extra-plugins` bundles plugin jars from outside
+ the Kotlin repository, for kotlin-empty-to-string. Format:
+ `pluginId;registrarFqName;commandLineProcessorFqName;jarPrefixes;jarPath`,
+ entries separated by `|`. The jar must be compiled against
+ kotlin-compiler-embeddable.
+- `generateBundledPluginsMetadata` writes the constructor metadata for all
+ bundled plugins onto the image classpath.
+- `kotlin.build.native-image.use-g1`, `pgo-instrument`, `pgo-profile` and
+ `extra-args` add `--gc=G1`, `--pgo-instrument`, `--pgo=<file>` and other
+ native-image options. The names match the Kotlin master branch.
+- `kotlin.build.native-image.graalvm-home` selects GraalVM directly. Oracle
+ GraalVM reports `Oracle Corporation` as vendor, so the `GRAAL_VM` toolchain
+ request in 2.4.21 does not find it.
+
+The patch also changes the reachability metadata in
+`resources/META-INF/native-image/org/jetbrains/kotlin/kotlin-compiler-embeddable/reachability-metadata.json`.
+The JetBrains metadata was collected from Kotlin-only tests. OFA compiles Java
+and Kotlin sources together, which uses IntelliJ PSI code that those tests do
+not reach. The added metadata came from these steps:
+
+1. `collect_metadata.py` runs on modules that use different features:
+
+ | module | why |
+ |---|---|
+ | `coreutils` | Java and Kotlin sources, parcelize |
+ | `live_score` | sources generated by KSP, parcelize, serialization |
+ | `ndc` | serialization, protobuf sources |
+ | `rewards` | compose, parcelize, serialization |
+ | `app` | the largest module |
+
+2. Six IntelliJ resource bundles are added by hand. The tracing agent did not
+ record them, and `:app` failed with `MissingResourceException: Can't find
+ bundle for base name messages.JavaPsiBundle`. The bundles are
+ `messages.CoreBundle`, `messages.CoreDeprecatedMessagesBundle`,
+ `messages.JavaErrorBundle`, `messages.JavaOptionBundle`,
+ `messages.JavaPsiBundle` and `messages.UtilBundle`. They are all the
+ `messages/*.properties` files in `kotlin-compiler-embeddable.jar`.
+
+## Procedure
+
+### 1. Apply the patch
+
+```bash
+cd ~/source/kotlin
+git checkout v2.4.21
+git apply ~/source/kotlin_proxy/native-image/kotlin-2.4.21-native-image.patch
+```
+
+The build with `-PdeployVersion` also changes
+`libraries/stdlib/src/kotlin/util/KotlinVersion.kt`. That change is
+generated, it is not part of the patch.
+
+### 2. Build a plain image
+
+```bash
+~/source/kotlin_proxy/native-image/build.sh plain
+```
+
+The image is in `prepare/compiler-native-image/build/dist`. `build.sh` uses
+`-march=x86-64-v3`, so the image runs on the IQ builders. Do not use
+`-march=native` for an image that leaves the build machine.
+
+### 3. Build OFA with the image, and collect missing metadata
+
+Build the stub jars (`make` in this repository), then set in OFA
+`mobile/mobile/gradle-local.properties`:
+
+```properties
+kotlinProxyStubJar=/home/<user>/source/kotlin_proxy/dist/kotlin-proxy-compiler-stubs.jar
+kotlinProxyNativeImage=/home/<user>/source/kotlin/prepare/compiler-native-image/build/dist
+```
+
+Stop old Kotlin daemons, then build all Kotlin modules:
+
+```bash
+pkill -f 'KotlinCompile[D]aemon'
+./gradlew compileDebugKotlin --continue
+```
+
+A module that fails with one of these errors needs more reachability metadata:
+
+- `PicoInitializationException: Either do the specified parameters not match
+ any of the following constructors:[]`
+- `ClassNotFoundException` or `NoSuchMethodException` from compiler code.
+
+The failed compile is in `/tmp/kotlin-daemon.*.log`, with its arguments. Run:
+
+```bash
+~/source/kotlin_proxy/tools/collect_metadata.py <module> [<module> ...]
+```
+
+`<module>` is the `-module-name` of the compile, for example `coreutils`.
+The script merges the metadata into the Kotlin checkout. Then repeat steps 2
+and 3 until all modules build.
+
+A `MissingResourceException` for a resource bundle needs a hand-made entry in
+the `resources` list of `reachability-metadata.json`:
+`{"bundle": "messages.<Name>"}`.
+
+### 4. Check incremental compilation
+
+```bash
+~/source/kotlin_proxy/tools/ic_check.sh jvm # must pass, else the test is wrong
+~/source/kotlin_proxy/tools/ic_check.sh proxy
+```
+
+The native image compiler runs in a subprocess. The Kotlin daemon gets no
+output or lookup data from it, so incremental builds leave stale class files.
+`KotlinConventionPlugin` disables incremental compilation when the proxy is
+used. All four checks must pass in proxy mode.
+
+### 5. Collect PGO profiles
+
+```bash
+~/source/kotlin_proxy/native-image/build.sh instrument
+```
+
+Add a profile directory to `gradle-local.properties`. Each compile writes one
+`.iprof` file there.
+
+```properties
+kotlinProxyPgoProfileDir=/home/<user>/kotlin-pgo
+```
+
+Stop old Kotlin daemons, then compile all modules:
+
+```bash
+pkill -f 'KotlinCompile[D]aemon'
+./gradlew compileDebugKotlin --rerun-tasks
+```
+
+Merge the profiles:
+
+```bash
+/usr/lib/jvm/java-25-graalvm/lib/svm/bin/native-image-utils merge-pgo-profiles \
+ --input-dir=/home/<user>/kotlin-pgo --output-file=/home/<user>/kotlin.iprof
+```
+
+Then remove `kotlinProxyPgoProfileDir` from `gradle-local.properties`.
+
+### 6. Build the final image
+
+```bash
+~/source/kotlin_proxy/native-image/build.sh pgo /home/<user>/kotlin.iprof
+```
+
+### 7. Package and upload
+
+`bin/` must be at the root of the archive. OFA passes the extracted directory
+as `kotlinProxyNativeImage`.
+
+```bash
+cd ~/source/kotlin/prepare/compiler-native-image/build/dist
+tar -cJf ~/kotlin-2.4.21-native-image-x86_64-ofa-1.tar.xz .
+sha256sum ~/kotlin-2.4.21-native-image-x86_64-ofa-1.tar.xz
+```
+
+Upload the archive and `dist/kotlin-proxy-compiler-stubs-nolog.jar` (as
+`kotlin-proxy-compiler-stubs-<version>.jar`) to
+`https://build.android.service.osa/storage/`. Update the file names and the
+SHA-256 checksums in OFA `mobile/mobile/build/iq/kotlin_proxy.py`. Use a new
+`ofa-N` suffix for a new image of the same Kotlin version.
+
+## Results
+
+`./gradlew compileDebugKotlin --rerun-tasks`, OFA, 2026-11-23:
+
+| compiler | build time | sum of Kotlin compile tasks | `:app` compile |
+|---|---|---|---|
+| JVM daemon | 2m00s | 151.4s | 50.8s |
+| native image, G1, no PGO | about 2m00s | | |
+| native image, G1, PGO | 1m48s | 131.6s | 39.2s |
+
+Each compile starts a new process with cold caches. Modules that compile in
+less than 3s are not faster than with the JVM daemon. The large modules give
+the gain. Without incremental compilation, the image is not useful for
+developer builds, only for clean builds on IQ.
+
+## When Kotlin is updated
+
+The patch, the metadata and the checksums are for Kotlin 2.4.21. For a new
+Kotlin version:
+
+1. Check out the new tag, and apply the patch. Fix conflicts in
+ `build.gradle.kts`.
+2. Set `KOTLIN_VERSION` in `build.sh`, and the kotlin-empty-to-string version
+ for the new Kotlin version.
+3. Do steps 2 to 7. Keep the hand-made bundle entries in the metadata.
+4. Regenerate the stub jars for the new Kotlin version (see `../README.md`).
diff --git a/native-image/build.sh b/native-image/build.sh
new file mode 100755
index 0000000..fa114d7
--- /dev/null
+++ b/native-image/build.sh
@@ -0,0 +1,69 @@
+#!/usr/bin/env bash
+# Builds the Kotlin compiler native image for OFA in a patched Kotlin checkout.
+# See native-image/README.md for the full procedure.
+#
+# Usage: build.sh plain|instrument|pgo <profile.iprof> [Kotlin checkout]
+# plain G1 and -O3, no PGO. Use it to collect reachability metadata.
+# instrument Image that writes PGO profiles (kotlin.proxy.pgoProfileDir).
+# pgo Final image, optimized with the merged profile.
+#
+# The result is in <Kotlin checkout>/prepare/compiler-native-image/build/dist.
+
+set -eu
+
+KOTLIN_VERSION=2.4.21
+GRAALVM_HOME=${GRAALVM_HOME:-/usr/lib/jvm/java-25-graalvm}
+# Builders need a portable target. -march=native gives an image that only runs on this CPU.
+MARCH=${MARCH:-x86-64-v3}
+EMPTY_TO_STRING_VERSION=2.4.0-0.1.5
+
+MODE=${1:-}
+case "$MODE" in
+plain)
+ OPTIMIZATION=(-Pkotlin.build.native-image.extra-args="-O3 -march=$MARCH")
+ shift
+ ;;
+instrument)
+ OPTIMIZATION=(-Pkotlin.build.native-image.pgo-instrument=true
+ -Pkotlin.build.native-image.extra-args="-march=$MARCH")
+ shift
+ ;;
+pgo)
+ if [ $# -lt 2 ]; then
+ echo "Usage: $0 pgo <profile.iprof> [Kotlin checkout]" >&2
+ exit 2
+ fi
+ # PGO enables -O3.
+ OPTIMIZATION=(-Pkotlin.build.native-image.pgo-profile="$(realpath "$2")"
+ -Pkotlin.build.native-image.extra-args="-march=$MARCH")
+ shift 2
+ ;;
+*)
+ echo "Usage: $0 plain|instrument|pgo <profile.iprof> [Kotlin checkout]" >&2
+ exit 2
+ ;;
+esac
+
+KOTLIN_DIR=${1:-$HOME/source/kotlin}
+
+EMPTY_TO_STRING_JAR=$(find ~/.gradle/caches/modules-2 \
+ -name "kotlin-empty-to-string-compiler-$EMPTY_TO_STRING_VERSION.jar" | head -1)
+if [ -z "$EMPTY_TO_STRING_JAR" ]; then
+ echo "No kotlin-empty-to-string-compiler-$EMPTY_TO_STRING_VERSION.jar in the Gradle cache." >&2
+ echo "Build any OFA Kotlin module once to download it." >&2
+ exit 1
+fi
+
+EXTRA_PLUGINS="com.opera.gradle.kotlin-empty-to-string-compiler"
+EXTRA_PLUGINS+=";com.opera.EmptyToStringCompilePluginRegistrar"
+EXTRA_PLUGINS+=";com.opera.EmptyToStringCommandLineProcessor"
+EXTRA_PLUGINS+=";kotlin-empty-to-string-compiler"
+EXTRA_PLUGINS+=";$EMPTY_TO_STRING_JAR"
+
+cd "$KOTLIN_DIR"
+./gradlew :kotlin-compiler-native-image:kotlincNativeImageDist \
+ -PdeployVersion="$KOTLIN_VERSION" -Pbuild.number="$KOTLIN_VERSION" \
+ -Pkotlin.build.native-image.graalvm-home="$GRAALVM_HOME" \
+ -Pkotlin.build.native-image.use-g1=true \
+ "${OPTIMIZATION[@]}" \
+ -Pkotlin.build.native-image.extra-plugins="$EXTRA_PLUGINS"
diff --git a/native-image/kotlin-2.4.21-native-image.patch b/native-image/kotlin-2.4.21-native-image.patch
new file mode 100644
index 0000000..1708bcd
--- /dev/null
+++ b/native-image/kotlin-2.4.21-native-image.patch
@@ -0,0 +1,522 @@
+diff --git i/prepare/compiler-native-image/build.gradle.kts w/prepare/compiler-native-image/build.gradle.kts
+index 705e4e379..16648abae 100644
+--- i/prepare/compiler-native-image/build.gradle.kts
++++ w/prepare/compiler-native-image/build.gradle.kts
+@@ -31,6 +31,48 @@ val pluginsRuntime by configurations.creating {
+
+ val bundledCompilerPlugins = mutableListOf<BundledCompilerPluginInfo>()
+
++// Each entry: pluginId;registrarFqName;commandLineProcessorFqName;jarPrefixes(comma-separated);jarPath
++// Entries are separated by '|'. The plugin jar must be compiled against kotlin-compiler-embeddable.
++val extraCompilerPlugins = kotlinBuildProperties
++ .stringProperty("kotlin.build.native-image.extra-plugins")
++ .orNull
++ .orEmpty()
++ .split("|")
++ .map { it.trim() }
++ .filter { it.isNotEmpty() }
++ .map { entry ->
++ val fields = entry.split(";").map { it.trim() }
++ require(fields.size == 5) { "Malformed kotlin.build.native-image.extra-plugins entry: $entry" }
++ ExtraCompilerPluginInfo(
++ pluginId = fields[0],
++ registrarFqName = fields[1],
++ commandLineProcessorFqName = fields[2].ifEmpty { null },
++ jarPrefixes = fields[3].split(",").map { it.trim() }.filter { it.isNotEmpty() },
++ jar = file(fields[4]),
++ )
++ }
++
++val useG1Gc = kotlinBuildProperties
++ .booleanProperty("kotlin.build.native-image.use-g1", false)
++ .get()
++val pgoProfile = kotlinBuildProperties
++ .stringProperty("kotlin.build.native-image.pgo-profile")
++ .orNull
++val pgoInstrument = kotlinBuildProperties
++ .booleanProperty("kotlin.build.native-image.pgo-instrument", false)
++ .get()
++// For example -O3, or -march=x86-64-v3. Separated by spaces.
++val extraNativeImageArgs = kotlinBuildProperties
++ .stringProperty("kotlin.build.native-image.extra-args")
++ .orNull
++ .orEmpty()
++ .split(" ")
++ .filter { it.isNotBlank() }
++// Oracle GraalVM reports "Oracle Corporation" as vendor, so the GRAAL_VM toolchain spec does not match it.
++val graalVmHome = kotlinBuildProperties
++ .stringProperty("kotlin.build.native-image.graalvm-home")
++ .orNull
++
+ dependencies {
+ nativeImageClasspath(project(":kotlin-compiler-embeddable", configuration = "runtimeElements"))
+
+@@ -106,6 +148,27 @@ dependencies {
+ nativeImageClasspath(project(":plugins:compose-compiler-plugin:compiler"))
+ }
+
++ bundledCompilerPlugin(
++ pluginId = "org.jetbrains.kotlin.parcelize",
++ registrarFqName = "org.jetbrains.kotlin.parcelize.ParcelizeComponentRegistrar",
++ commandLineProcessorFqName = "org.jetbrains.kotlin.parcelize.ParcelizeCommandLineProcessor",
++ jarPrefixes = listOf("parcelize-compiler", "kotlin-parcelize-compiler"),
++ ) {
++ nativeImageClasspath(project(":kotlin-parcelize-compiler"))
++ }
++
++ // Plugins built outside of this repository, from -Pkotlin.build.native-image.extra-plugins.
++ for (extraPlugin in extraCompilerPlugins) {
++ bundledCompilerPlugin(
++ pluginId = extraPlugin.pluginId,
++ registrarFqName = extraPlugin.registrarFqName,
++ commandLineProcessorFqName = extraPlugin.commandLineProcessorFqName,
++ jarPrefixes = extraPlugin.jarPrefixes,
++ ) {
++ nativeImageClasspath(files(extraPlugin.jar))
++ }
++ }
++
+ // Tests
+ pluginsRuntime(libs.kotlinx.serialization.core)
+ pluginsRuntime(composeRuntime())
+@@ -129,7 +192,9 @@ sourceSets {
+
+ val graalLauncher = javaToolchains.launcherFor {
+ languageVersion.set(JavaLanguageVersion.of(JdkMajorVersion.JDK_25_0.targetName))
+- vendor.set(JvmVendorSpec.GRAAL_VM)
++ if (graalVmHome == null) {
++ vendor.set(JvmVendorSpec.GRAAL_VM)
++ }
+ }
+
+ projectTests {
+@@ -218,15 +283,46 @@ val generateBundledPluginsInfo = tasks.register("generateBundledPluginsInfo") {
+ }
+ }
+
++// PluginCliParser creates the registrar and the command line processor with Class.forName().newInstance().
++val generateBundledPluginsMetadata = tasks.register("generateBundledPluginsMetadata") {
++ description = "Generates reflection metadata for the constructors of the bundled compiler plugins"
++
++ val outputDir = layout.buildDirectory.dir("bundled-plugins-metadata")
++ val pluginClasses = bundledCompilerPlugins.flatMap { listOfNotNull(it.registrarFqName, it.commandLineProcessorFqName) }
++ inputs.property("pluginClasses", pluginClasses)
++ outputs.dir(outputDir)
++ doLast {
++ val file = outputDir.get().file("META-INF/native-image/bundled-compiler-plugins/reachability-metadata.json").asFile
++ file.parentFile.mkdirs()
++ val entries = pluginClasses.joinToString(",\n") { className ->
++ """ {"type": "$className", "methods": [{"name": "<init>", "parameterTypes": []}]}"""
++ }
++ file.writeText("{\n \"reflection\": [\n$entries\n ]\n}\n")
++ }
++}
++
+ val kotlincNativeImageTask = tasks.register<Exec>("kotlincNativeImage") {
+ description = "Build a native image of the kotlin-compiler-embeddable"
+
+ val launcher = graalLauncher
+ val resources = layout.projectDirectory.dir("resources")
+- val classpathFiles = files(nativeImageClasspath, resources)
+- inputs.files(nativeImageClasspath, resources, launcher.map { it.metadata.installationPath.asFile })
++ val classpathFiles = files(nativeImageClasspath, resources, generateBundledPluginsMetadata)
++ val graalVmHomeDir = graalVmHome?.let { file(it) }
++ inputs.files(nativeImageClasspath, resources, generateBundledPluginsMetadata)
+ .withNormalizer(ClasspathNormalizer::class)
+ .withPropertyName("nativeImageClasspath")
++ val graalVmRelease: Any = graalVmHomeDir?.resolve("release")
++ ?: launcher.map { it.metadata.installationPath.file("release") }
++ inputs.file(graalVmRelease).withPropertyName("graalVmRelease")
++ inputs.files(listOfNotNull(pgoProfile)).withPropertyName("pgoProfile")
++
++ val optimizationArgs = buildList {
++ if (useG1Gc) add("--gc=G1")
++ if (pgoProfile != null) add("--pgo=$pgoProfile")
++ if (pgoInstrument) add("--pgo-instrument")
++ addAll(extraNativeImageArgs)
++ }
++ inputs.property("optimizationArgs", optimizationArgs)
+
+ val isWindows = currentOs.isWindows
+ val mainClass = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"
+@@ -238,7 +334,7 @@ val kotlincNativeImageTask = tasks.register<Exec>("kotlincNativeImage") {
+ outputs.file(executableFile)
+
+ doFirst {
+- val javaHome = launcher.get().executablePath.asFile.toPath().parent.parent
++ val javaHome = graalVmHomeDir?.toPath() ?: launcher.get().executablePath.asFile.toPath().parent.parent
+
+ val nativeImageName = if (isWindows) "native-image.exe" else "native-image"
+ val nativeImageBin = javaHome.resolve("lib/svm/bin/$nativeImageName")
+@@ -256,6 +352,7 @@ val kotlincNativeImageTask = tasks.register<Exec>("kotlincNativeImage") {
+ "-H:+AddAllCharsets",
+ "-H:+UnlockExperimentalVMOptions",
+ "-H:+AllowJRTFileSystem",
++ *optimizationArgs.toTypedArray(),
+ "-cp", fullClasspath,
+ "-o", outputFile.get().asFile.absolutePath,
+ mainClass,
+@@ -389,6 +486,14 @@ fun Test.useReachabilityMetadataResources() {
+ )
+ }
+
++data class ExtraCompilerPluginInfo(
++ val pluginId: String,
++ val registrarFqName: String,
++ val commandLineProcessorFqName: String?,
++ val jarPrefixes: List<String>,
++ val jar: File,
++)
++
+ data class BundledCompilerPluginInfo(
+ val pluginId: String,
+ val registrarFqName: String,
+diff --git i/prepare/compiler-native-image/resources/META-INF/native-image/org/jetbrains/kotlin/kotlin-compiler-embeddable/reachability-metadata.json w/prepare/compiler-native-image/resources/META-INF/native-image/org/jetbrains/kotlin/kotlin-compiler-embeddable/reachability-metadata.json
+index 55c4017a8..17bfbb292 100644
+--- i/prepare/compiler-native-image/resources/META-INF/native-image/org/jetbrains/kotlin/kotlin-compiler-embeddable/reachability-metadata.json
++++ w/prepare/compiler-native-image/resources/META-INF/native-image/org/jetbrains/kotlin/kotlin-compiler-embeddable/reachability-metadata.json
+@@ -18,6 +18,24 @@
+ }
+ ]
+ },
++ {
++ "type": "com.opera.EmptyToStringCommandLineProcessor",
++ "methods": [
++ {
++ "name": "<init>",
++ "parameterTypes": []
++ }
++ ]
++ },
++ {
++ "type": "com.opera.EmptyToStringCompilePluginRegistrar",
++ "methods": [
++ {
++ "name": "<init>",
++ "parameterTypes": []
++ }
++ ]
++ },
+ {
+ "type": "gnu.trove.TObjectHashingStrategy"
+ },
+@@ -91,6 +109,9 @@
+ {
+ "type": "java.lang.Object"
+ },
++ {
++ "type": "java.lang.Object[]"
++ },
+ {
+ "type": "java.lang.Runtime",
+ "methods": [
+@@ -173,6 +194,9 @@
+ }
+ ]
+ },
++ {
++ "type": "java.util.ResourceBundle"
++ },
+ {
+ "type": "java.util.Set"
+ },
+@@ -382,6 +406,9 @@
+ {
+ "type": "kotlinx.coroutines.scheduling.CoroutineScheduler"
+ },
++ {
++ "type": "org.jetbrains.kotlin.KtPsiSourceElement"
++ },
+ {
+ "type": "org.jetbrains.kotlin.allopen.AllOpenCommandLineProcessor",
+ "methods": [
+@@ -448,6 +475,9 @@
+ "type": "org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments",
+ "allDeclaredMethods": true
+ },
++ {
++ "type": "org.jetbrains.kotlin.cli.common.arguments.RemovedCompilerArguments"
++ },
+ {
+ "type": "org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings",
+ "fields": [
+@@ -485,6 +515,9 @@
+ }
+ ]
+ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.openapi.editor.event.DocumentListener[]"
++ },
+ {
+ "type": "org.jetbrains.kotlin.com.intellij.openapi.extensions.impl.ExtensionPointImpl"
+ },
+@@ -503,9 +536,45 @@
+ }
+ ]
+ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.openapi.vfs.transformer.TextPresentationTransformers",
++ "methods": [
++ {
++ "name": "<init>",
++ "parameterTypes": []
++ }
++ ]
++ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.JavaModuleSystem"
++ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.JavaResolveResult[]"
++ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.LanguageSubstitutors",
++ "methods": [
++ {
++ "name": "<init>",
++ "parameterTypes": []
++ }
++ ]
++ },
+ {
+ "type": "org.jetbrains.kotlin.com.intellij.psi.PsiElementFinder"
+ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.PsiMethod[]"
++ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.PsiRecordComponent[]"
++ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.SingleRootFileViewProvider"
++ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.augment.PsiAugmentProvider"
++ },
+ {
+ "type": "org.jetbrains.kotlin.com.intellij.psi.compiled.ClassFileDecompilers",
+ "methods": [
+@@ -518,15 +587,39 @@
+ {
+ "type": "org.jetbrains.kotlin.com.intellij.psi.compiled.ClassFileDecompilers$Decompiler"
+ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.impl.JavaClassSupersImpl",
++ "methods": [
++ {
++ "name": "<init>",
++ "parameterTypes": []
++ }
++ ]
++ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.impl.cache.TypeInfo[]"
++ },
+ {
+ "type": "org.jetbrains.kotlin.com.intellij.psi.impl.source.JavaFileElementType"
+ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.CompositeElement"
++ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.psi.stubs.StubBase"
++ },
+ {
+ "type": "org.jetbrains.kotlin.com.intellij.util.KeyedLazyInstanceEP"
+ },
+ {
+ "type": "org.jetbrains.kotlin.com.intellij.util.QueryExecutor"
+ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.util.containers.ConcurrentIntObjectHashMap"
++ },
++ {
++ "type": "org.jetbrains.kotlin.com.intellij.util.containers.ConcurrentIntObjectHashMap$CounterCell"
++ },
+ {
+ "type": "org.jetbrains.kotlin.com.intellij.util.containers.ConcurrentLongObjectHashMap",
+ "fields": [
+@@ -603,6 +696,9 @@
+ {
+ "type": "org.jetbrains.kotlin.load.java.JavaIncompatibilityRulesOverridabilityCondition"
+ },
++ {
++ "type": "org.jetbrains.kotlin.load.java.structure.impl.JavaClassifierTypeImpl"
++ },
+ {
+ "type": "org.jetbrains.kotlin.load.java.structure.impl.source.JavaFixedElementSourceFactory",
+ "methods": [
+@@ -648,6 +744,24 @@
+ }
+ ]
+ },
++ {
++ "type": "org.jetbrains.kotlin.parcelize.ParcelizeCommandLineProcessor",
++ "methods": [
++ {
++ "name": "<init>",
++ "parameterTypes": []
++ }
++ ]
++ },
++ {
++ "type": "org.jetbrains.kotlin.parcelize.ParcelizeComponentRegistrar",
++ "methods": [
++ {
++ "name": "<init>",
++ "parameterTypes": []
++ }
++ ]
++ },
+ {
+ "type": "org.jetbrains.kotlin.powerassert.PowerAssertCommandLineProcessor",
+ "methods": [
+@@ -1515,11 +1629,98 @@
+ }
+ ],
+ "methods": [
++ {
++ "name": "arrayBaseOffset",
++ "parameterTypes": [
++ "java.lang.Class"
++ ]
++ },
++ {
++ "name": "arrayIndexScale",
++ "parameterTypes": [
++ "java.lang.Class"
++ ]
++ },
++ {
++ "name": "compareAndSwapInt",
++ "parameterTypes": [
++ "java.lang.Object",
++ "long",
++ "int",
++ "int"
++ ]
++ },
++ {
++ "name": "compareAndSwapLong",
++ "parameterTypes": [
++ "java.lang.Object",
++ "long",
++ "long",
++ "long"
++ ]
++ },
++ {
++ "name": "compareAndSwapObject",
++ "parameterTypes": [
++ "java.lang.Object",
++ "long",
++ "java.lang.Object",
++ "java.lang.Object"
++ ]
++ },
++ {
++ "name": "copyMemory",
++ "parameterTypes": [
++ "java.lang.Object",
++ "long",
++ "java.lang.Object",
++ "long",
++ "long"
++ ]
++ },
++ {
++ "name": "getAndAddInt",
++ "parameterTypes": [
++ "java.lang.Object",
++ "long",
++ "int"
++ ]
++ },
++ {
++ "name": "getObjectVolatile",
++ "parameterTypes": [
++ "java.lang.Object",
++ "long"
++ ]
++ },
+ {
+ "name": "invokeCleaner",
+ "parameterTypes": [
+ "java.nio.ByteBuffer"
+ ]
++ },
++ {
++ "name": "objectFieldOffset",
++ "parameterTypes": [
++ "java.lang.reflect.Field"
++ ]
++ },
++ {
++ "name": "putObjectVolatile",
++ "parameterTypes": [
++ "java.lang.Object",
++ "long",
++ "java.lang.Object"
++ ]
++ }
++ ]
++ },
++ {
++ "type": "sun.net.www.protocol.jar.Handler",
++ "methods": [
++ {
++ "name": "<init>",
++ "parameterTypes": []
+ }
+ ]
+ },
+@@ -1603,11 +1804,47 @@
+ {
+ "glob": "kotlin/reflect/reflect.kotlin_builtins"
+ },
++ {
++ "glob": "localization/messages/JavaPsiBundle.properties"
++ },
++ {
++ "glob": "localization/messages/JavaPsiBundle_en.properties"
++ },
++ {
++ "glob": "localization/messages/JavaPsiBundle_en_US.properties"
++ },
++ {
++ "glob": "messages/JavaPsiBundle.properties"
++ },
++ {
++ "glob": "org/jetbrains/kotlin/org/fusesource/jansi/internal/native/Linux/x86_64/libjansi.so"
++ },
+ {
+ "glob": "org/jetbrains/kotlin/org/fusesource/jansi/internal/native/Mac/arm64/libjansi.jnilib"
+ },
+ {
+ "glob": "org/jetbrains/kotlin/org/fusesource/jansi/jansi.properties"
++ },
++ {
++ "bundle": "localization//messages/JavaPsiBundle"
++ },
++ {
++ "bundle": "messages.CoreBundle"
++ },
++ {
++ "bundle": "messages.CoreDeprecatedMessagesBundle"
++ },
++ {
++ "bundle": "messages.JavaErrorBundle"
++ },
++ {
++ "bundle": "messages.JavaOptionBundle"
++ },
++ {
++ "bundle": "messages.JavaPsiBundle"
++ },
++ {
++ "bundle": "messages.UtilBundle"
+ }
+ ]
+-}
++}
+\ No newline at end of file