Skip to content

feat!: split Vm & Env, add callbacks, arrays & ByteBuffers (etc) - #20

Merged
tachy0nnn merged 16 commits into
mainfrom
feat/exceptions
Dec 3, 2026
Merged

tachy0nnn merged 16 commits into
mainfrom
feat/exceptions

Conversation

@tachy0nnn

@tachy0nnn tachy0nnn commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

summary

  • add AI policy (so we have now rules for using AI in repositories)
  • document supported linux archs in README
  • big change: split of C++ bridge
  • register static method for Rust callbacks with primitive and reference types
  • add JavaArray, Type::parse, and direct ByteBuffer helpers on Env

breaking changes

  • Vm::env and Vm::attach_current_thread replace Vm::get_jni_env and Vm::detach_current_thread
  • AttachGuard
    detaches on drop only when attach_current_thread attached the thread
  • find_class, define_class, and new_string now live on Env instead of Vm
  • Class, Object, JavaString, and Output now use the 'env lifetime, and Method and Value now take lifetime
    parameters
  • matches on Value need the new Object, String, Class, and Array variants, and matches on Output need
    Class and Array
  • usagi_vm_attach_current_thread, usagi_class_register_method, and UsagiMethodCallback changed sigs in
    include/usagi.h, and usagi_test_register_add and usagi_test_register_fail no longer exist

assisted with:

  • model: Gemini 4 Hydrogen (gemini-4-hydrogen)
  • harness: Pi
  • kinda got busy with studying.. didn't really want to stall on progress and wanna do something, so yeah!

@tachy0nnn tachy0nnn self-assigned this Nov 28, 2026
@tachy0nnn tachy0nnn added type: documentation Improvements or additions to documentation type: enhancement New feature or request type: refactor ai: assisted labels Nov 28, 2026
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

The pull request splits the C++ JNI bridge and expands its C and Rust APIs. It adds environment and reference types, array and direct-buffer operations, and callback-backed Java method registration and invocation. It also updates repository policy, platform documentation, and CI configuration.

Changes: JNI bridge and Rust API

Layer / File(s) Summary
Native API and runtime
include/usagi.h, src/ffi.rs, cpp/internal.hpp, cpp/error.cpp, cpp/vm.cpp, cpp/object.cpp, cpp/bridge.cpp, CMakeLists.txt, build.rs
The C++ bridge implementation is removed and its functionality is split across focused source files. The C API and Rust FFI declarations add VM, object, error, and JNI reference operations. Build configuration lists the new sources and recursively tracks files under the JNI source and include trees.
Java arrays and direct buffers
cpp/array.cpp, cpp/bytebuffer.cpp, src/array.rs, src/env.rs, tests/phase2.rs
The APIs create and access primitive and object arrays, transfer array regions, and pin primitive elements. They also create and query direct byte buffers. Integration tests cover array behavior, thread sharing, and buffer access.
Rust environments and shared references
src/vm.rs, src/env.rs, src/object.rs, src/string.rs, src/lib.rs, src/ffi.rs, src/error.rs
Vm::env returns an Env, and thread attachment returns an AttachGuard. Objects and strings use environment lifetimes and support conversion to GlobalRef; global references can be rebound through an environment from the same VM. Error::new is public, and FFI tests use the environment API.
Java method calls and Rust callbacks
cpp/call.cpp, cpp/registry.cpp, src/callback.rs, src/class.rs, src/method.rs, src/value.rs, src/sig.rs, tests/registration.rs, tests/phase2.rs
Java method calls support object, class, string, and array values. Classes can register Rust callbacks as static methods. The callback bridge converts arguments and results and reports errors. Signature parsing validates field descriptors and class names. Tests cover conversions, callback replacement, exceptions, and multithreaded calls.

Repository guidance

Layer / File(s) Summary
Contribution policy and platform status
AI_POLICY.md, README.md
AI_POLICY.md adds requirements for AI-assisted bug reports and contributions. The README states that Linux on x86_64 and aarch64 are supported and other platforms are unsupported.

CI and advisory configuration

Layer / File(s) Summary
Workflow and advisory settings
.github/workflows/audit.yml, .github/workflows/ci.yml, deny.toml
The workflows update pinned versions of cargo-deny-action and cachix/install-nix-action. The advisory configuration sets unmaintained to "all".

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant JavaCaller
  participant NativeMethodHandle
  participant RustTrampoline
  participant RustCallback
  JavaCaller->>NativeMethodHandle: invoke registered method
  NativeMethodHandle->>RustTrampoline: dispatch JNI arguments
  RustTrampoline->>RustCallback: convert arguments and invoke handler
  RustCallback-->>RustTrampoline: return value or error
  RustTrampoline-->>NativeMethodHandle: convert result or report error
  NativeMethodHandle-->>JavaCaller: return value or Java exception
Loading

Possibly related PRs

  • rurikoo/usagi#14: Both changes address Java exception conversion in the method-call path.
Merge Risk: Low · previous review 38e27 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat!: split Vm & Env, add callbacks, arrays & ByteBuffers (etc)" matches the main changes in the changeset. The diff splits the VM and environment APIs into Vm and Env (src/vm.rs, src/env.…
Description check Passed The description is related to the changeset. It lists the AI policy, the README Linux architecture note, the C++ bridge split, static method registration for Rust callbacks, JavaArray, Type::parse, an…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat!: split Vm & Env, add callbacks, arrays & ByteBuffers (etc)" matches the main changes in the changeset. The diff splits the VM and environment APIs into Vm and Env (src/vm.rs, src/env.rs), adds JNI callback registration (src/callback.rs, cpp/registry.cpp), adds primitive and object array support (src/array.rs, cpp/array.cpp), and adds direct ByteBuffer helpers (src/env.rs, cpp/bytebuffer.cpp). The title does not mention the AI policy, README status, or the C++ bridge split, which are smaller parts of the change. The "(etc)" suffix is informal but does not make the title misleading.

Full details: Description check

Explanation

The description is related to the changeset. It lists the AI policy, the README Linux architecture note, the C++ bridge split, static method registration for Rust callbacks, JavaArray, Type::parse, and direct ByteBuffer helpers on Env. Its breaking-changes section matches the Vm/Env split, the lifetime changes, and the removed test functions in the diff.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as outdated.

tachy0nnn and others added 5 commits November 30, 2026 21:17
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: yon <154914363+tachy0nnn@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 80c4fcfb-75e5-47c0-b0b3-2af3bb6bd859
Commits

Reviewing files that changed from the base of the PR and between ea6e48f and 4c97ba7.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 10

  • .github/workflows/audit.yml
  • .github/workflows/ci.yml
  • cpp/object.cpp
  • cpp/registry.cpp
  • include/usagi.h
  • src/array.rs
  • src/ffi.rs
  • src/object.rs
  • tests/phase2.rs
  • tests/registration.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit

Comment thread .github/workflows/audit.yml Resolved
Comment thread cpp/object.cpp Resolved
Comment thread cpp/registry.cpp Resolved
Comment thread src/array.rs Resolved
- keep unmaintained = "all" in deny.toml advisories
- accept Cloneable and Serializable for array elements
- break GlobalRef capture cycle on registered callbacks
- etc

Refs #20

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Major 1
  1. Shutdown can null a method handle while a concurrent dispatch still reads it.
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eefe23db-d151-4be1-aae9-3af03687f4dc
Commits

Reviewing files that changed from the base of the PR and between 4c97ba7 and 6e41ce4.

Files selected for processing: 11

  • cpp/internal.hpp
  • cpp/registry.cpp
  • cpp/vm.cpp
  • deny.toml
  • include/usagi.h
  • src/array.rs
  • src/callback.rs
  • src/ffi.rs
  • src/vm.rs
  • tests/phase2.rs
  • tests/registration.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional comments: 2

src/array.rs: 1

261-262: Functional Correctness

The comment's premise fails for method-returned arrays. Array metadata comes from the runtime array class at the wrapping boundary, not from the declared return type. usagi_call_method uses the same make_object_handle path that stores java/nio/ByteBuffer for a ByteBuffer[] result. The None branch in matches_type is therefore not reached for the described ByteBuffer[] case. A separate, unestablished case where metadata is absent is not the scenario the comment raises.

cpp/registry.cpp: 1

311-311: Stability & Availability

The concern cannot be decided from the available evidence. The repository clears nativehandle during shutdown and leaves the method entry in place, which is the premise the comment relies on. Whether an active callback can then call that method and crash depends on jnivm's dispatch, which is in a dependency that is not available in this checkout. Whether the shutdown contract allows such a nested call is also unresolved.

Comment thread cpp/registry.cpp Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Major 1
  1. Callbacks registered after VM shutdown can leak the VM.
Minor 7
  1. Finish fallible tracking before publishing the method.
  2. Keep the callback alive until the class mutex is released on insertion failure.
  3. Allocate the replacement before taking the existing handle out of the method.
  4. Avoid allocating a handle snapshot in noexcept shutdown.
  5. Report worker setup failures instead of hanging the test.
  6. Assert that the nested ping call sees the cleared callback.
  7. Registration accepts a return kind that does not match the signature.
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2994e487-deae-4bcd-a535-4a513a72aa58
Commits

Reviewing files that changed from the base of the PR and between 6e41ce4 and 38e279a.

Files selected for processing: 2

  • cpp/registry.cpp
  • tests/registration.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional comments: 1

cpp/registry.cpp: 1

369-369: Stability & Availability

The concurrency question cannot be decided from this checkout. The pinned libjnivm submodule is absent, so its method dispatch path, and whether it reads Method::native when nativehandle is set, cannot be inspected. The unlocked write at cpp/registry.cpp:369 is in the reviewed code, but whether it races depends on that dispatch path.

Comment thread cpp/registry.cpp Resolved
Comment thread cpp/registry.cpp Resolved
Comment thread cpp/registry.cpp Resolved
Comment thread cpp/registry.cpp Resolved
Comment thread tests/registration.rs Resolved
Comment thread tests/registration.rs Resolved
@tachy0nnn

Copy link
Copy Markdown
Member Author

im tired i just merge this rq

# Conflicts:
#	cpp/bridge.cpp
#	include/usagi.h
#	src/ffi.rs
#	src/method.rs
@tachy0nnn
tachy0nnn enabled auto-merge (squash) December 3, 2026 18:56
@tachy0nnn
tachy0nnn disabled auto-merge December 3, 2026 19:29
@tachy0nnn
tachy0nnn merged commit 49461a9 into main Dec 3, 2026
14 of 15 checks passed
@tachy0nnn
tachy0nnn deleted the feat/exceptions branch December 3, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant