Repository navigation
chasm-jit: compile to JVM classes on the JVM - #132
Open
Wavesonics wants to merge 2 commits into
Open
Wavesonics wants to merge 2 commits into
Wavesonics wants to merge 2 commits into
Conversation
runtime-jit gains a jvm target: the shared frontend compiles in parallel, backend-jvm lowers into memory, and the classes are defined in a loader of the module's own and installed as the DEX path does. The DEX-specific compile, loader and package naming move to androidMain. chasm-jit gains a jvm target, so its spec suite runs on the JVM too.
The frontend step, loading, and the error handling around them are shared by the DEX and JVM paths. chasm-aot and the JVM JIT load generated classes through one parallel-capable MemoryClassLoader in compiled-api, which lets go of each class's bytes once defined. JVM lowering runs on at most the JIT's compile workers and stops when the compile is cancelled, the JVM path checks memory 0 is ByteBuffer-backed and keeps chunk starts for trap diagnostics, and a stack overflow while compiling becomes a generation failure. Adds the JVM ABI dumps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
chasm-jit only targets Android, so a JVM host (a desktop app, say) has to interpret modules it loads at runtime, or compile them ahead of time with chasm-aot, which needs the module at build time. This gives chasm-jit a
jvm()target that compiles at instantiation with the JVM backend chasm-aot already uses.How
runtime-jitgainsjvm(). The DEX-specific lowering and loading move toandroidMain(DexCompile.kt,DexLoader.kt,PackageNames.kt);jvmMain(JvmCompile.kt) lowers withbackend-jvminto memory.commonMain: the parallel frontend step, the loading step, and the error handling (compile/expect compileUnchecked).MemoryClassLoader, initialized up front withCodeClassInitializer, and installed through the generated module'sCompiledCode.install, the same path DEX takes. The loader is now shared with chasm-aot'sCompileOutput.Memory.load(moved tocompiled-api'sjvmMain); it is parallel-capable and lets go of each class's bytes once defined.backend-jvm:ModuleLowerertakesparallelismand acheckCancelledcallback (defaults keep chasm-aot unchanged);JvmModulereportsinlineMemoryandchunkStarts, so the JIT checks memory 0 isByteBuffer-backed at install and keeps chunk starts for trap diagnostics.StackOverflowErrorwhile compiling now becomes a generation failure on both targets.chasm-jitgainsjvm(), so its spec suite and corpus test also run on the JVM. JVM ABI dumps added.Testing
:chasm-jit:jvmTest: 267 pass, including the core spec suite throughchasm.jit.instance, plus a cancellation test.:chasm-jit:corpusTest,:compiler:backend-jvm:test,:chasm-aot:jvmTest,:runtime:compiled-api:jvmTest,:runtime-aot:jvmTestpass.:chasm-jit:connectedAndroidDeviceTest(InstanceTest) passes on an API 34 emulator.checkLegacyAbi,lintKotlin,fmtclean.Numbers
Harper grammar checker (8 MB module), desktop, 32 cores, 300-paragraph check:
Caveats and follow-ups
backend-jvmlowering: about 50 s of CPU for Harper (276 classes, 12.8 MB of bytecode), spread over the worker threads. Profiling points at ASM serialization (includingcodeLength, which writes methods to measure them), slot liveness and dead-store removal. I plan to look at that next.backend-jvmstill runs its own thread pool per compile; making it lower on aParallelTaskExecutorlikebackend-dexwould share the JIT's permits across concurrent compiles. That touches chasm-aot, so it seemed better as a follow-up.