Repository navigation
Harden the generated FFM runtime and copy value types verbatim - #32
Merged
Merged
Conversation
The macOS implementation encodes the capture as PNG while Linux and Windows produce BMP; the test only accepted the BMP header.
Value types - Enums and data classes are emitted on the JVM as verbatim copies of the native declarations (defaults, body members, companions, KDoc), with native-only imports dropped. Runtime fixes found by torture and seeded monkey tests - Exceptions thrown by JVM callbacks no longer kill the VM: they unwind the native caller and are rethrown with their original type. - Native error state is thread-local (errors leaked across threads). - Collections, strings, byte arrays and data class string fields of any size: oversized results are parked natively and read back instead of overflowing fixed buffers or calling the function twice. - Flows use credit-based backpressure (slow collectors lost elements). - Suspend calls always signal completion (ATOMIC start); job handles are owned by the JVM to avoid use-after-free on cancellation. - Object lifecycle uses a lease: calls after close() throw, close() is safe concurrently and from callbacks, arguments stay alive during calls, and the Cleaner no longer captures the proxy (unclosed objects leaked). - Coroutine completion uses static upcall stubs dispatched by call id and callback stubs are released per call (unbounded memory growth). - List<Short>/List<Byte> and non-String map keys are encoded consistently. - Strings containing NUL are rejected instead of silently truncated. Callbacks are now valid for the duration of the call only; event streams should be exposed as Flow.
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.
Summary
Enums and data classes are now generated on the JVM as verbatim copies of their native declarations. While verifying this end to end, torture tests and seeded monkey tests uncovered a series of runtime bugs in the generated FFM layer, all fixed here.
Value types
enum class/data classkeep default values, body members, entry bodies, companion objects, KDoc and annotations (e.g. a customequals/hashCodeon a data class with aByteArrayfield was previously dropped).kotlinx.cinterop,platform.*,kotlin.native) and of module packages are removed.Runtime bugs fixed
IndexOutOfBoundsExceptionor crash (returns, sets, maps, suspend, DC fields)String/ByteArray> 8 KBStringfield > 8 KBStableRefread backclose()spins foreverCoroutineStart.ATOMIC, completion always signalledStableRefclose(), concurrentclose(), closed object as argumentIllegalStateException, deferred disposalCleaneraction captured the proxyOutOfMemoryErrorStableRefdisposalList<Short>/List<Byte>, non-Stringmap keysClassCastExceptionStringargumentsIllegalArgumentException(returns decoded by length)Behavior changes
Flow<T>(assysteminfoalready does). README updated.IllegalStateException.Stringarguments containing\u0000throwIllegalArgumentException.Tests
ValueTypeParityTest,ValueTypeTortureTest: value types across FFM, overflow parity, class-init races in fresh classloaders, re-entrant callbacks.RuntimeTortureTest,BufferTortureTest: every buffer past its limit, error isolation across threads, lifecycle races, cleaner reclamation, flows and cancellations.MonkeyTest: seeded model-based monkey (each native result checked against a JVM model) and concurrent chaos monkey (8 threads, random closes, throwing callbacks, cancellations, GC). Replay withMONKEY_SEED=<seed>, widen withMONKEY_SEEDS=<n>(add--rerun).systeminfo: screen capture test accepts the PNG produced on macOS.Results on macOS arm64:
calculator1785 tests green, monkeys green on 500 seeds each;benchmarkandsysteminfogreen; plugin unit tests green.