Repository navigation
runtime-jit: access linear memory through the byte array - #130
Closed
Wavesonics wants to merge 2 commits into
Closed
Wavesonics wants to merge 2 commits into
Wavesonics wants to merge 2 commits into
Conversation
When sun.misc.Unsafe was reachable, compile passed its byte array base offset to the DEX backend, which then lowered inline linear memory accesses to Unsafe.getInt, putInt, getLong and putLong calls. On ART these calls from generated code go through the generic JNI trampoline instead of an intrinsic, so a memory-heavy module spends most of its time in JNI transitions and gains little from compilation. Leave byteArrayBaseOffset unset so the backend emits its existing byte-array loads and stores. The Unsafe lowering stays in the backend and remains reachable through DexOptions. Measured on an x86_64 API 34 emulator with a store that meters fuel and is interruptible. Harper's grammar checker (Rust, 7.6 MB, 3,574 functions) checking 300 paragraphs, steady state over 12 calls in a fresh process: interpreted 7.78 s compiled, Unsafe 7.42 s compiled, byte array 1.66 s With Unsafe, simpleperf attributes about 72% of CPU time to ART's generic JNI machinery. A Rust word count (115 KB) goes from 320 ms to 94 ms and a C word count (4 KB) from 62 ms to 33 ms. Output is byte-identical across all three modes. Fixes CharlieTap#128.
This was referenced Nov 11, 2026
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.
Fixes #128.
runtime-jitno longer passesbyteArrayBaseOffsettoDexOptions, so the DEX backend emits its existing byte-array loads and stores for linear memory instead ofsun.misc.Unsafecalls. On ART those Unsafe calls from generated code go through the generic JNI trampoline rather than an intrinsic, which costs far more than the array accesses that replace them and dominated the run time of memory-heavy modules.The Unsafe lowering is untouched and still reachable through
DexOptions, in case you'd rather gate it than leave it unused.Harper's grammar checker (Rust, 7.6 MB, 3,574 functions), 300 paragraphs, x86_64 API 34 emulator, steady state over 12 calls in a fresh process:
A Rust word count goes from 320 ms to 94 ms, and a C word count from 62 ms to 33 ms. Output is byte-identical across all three modes.
Testing:
:chasm-jit:connectedAndroidDeviceTestpasses on the same emulator (266 tests). Not yet measured on arm64 hardware.