Skip to content

Add FileDescriptorId abstraction for serializable file descriptors#136

Merged
dlunch merged 3 commits intomainfrom
fd-abstraction
Apr 5, 2026
Merged

Add FileDescriptorId abstraction for serializable file descriptors#136
dlunch merged 3 commits intomainfrom
fd-abstraction

Conversation

@dlunch
Copy link
Copy Markdown
Owner

@dlunch dlunch commented Apr 4, 2026

Summary

  • Introduce FileDescriptorId newtype wrapping usize to replace raw Rust object pointer storage in FileDescriptor, making it serializable
  • Update Runtime trait so stdin/stdout/stderr/open return FileDescriptorId instead of Box<dyn File>, with a new get_file(fd) method for retrieval
  • Add fd table (Arc<Mutex<BTreeMap>>) to RuntimeImpl and TestRuntime for fd → file mapping management

Copilot AI review requested due to automatic review settings April 4, 2026 23:52
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: faac185209

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces storing raw Rust object pointers in java.io.FileDescriptor with a FileDescriptorId newtype, enabling file descriptor values to be represented as plain integers (and thus more amenable to serialization) while allowing runtimes to map IDs back to File objects.

Changes:

  • Introduces FileDescriptorId(usize) and re-exports it from java_runtime.
  • Updates the Runtime trait: stdin/stdout/stderr/open now return FileDescriptorId, plus a new get_file(fd) method for lookup.
  • Adds fd tables (Arc<Mutex<BTreeMap<..>>>) to RuntimeImpl and TestRuntime, and updates Java I/O classes to use the new fd-based flow.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
java_runtime/src/runtime/io.rs Adds the FileDescriptorId newtype used as the runtime-facing FD handle.
java_runtime/src/runtime.rs Updates the Runtime trait to return FileDescriptorId and adds get_file.
java_runtime/src/lib.rs Re-exports FileDescriptorId from the java_runtime crate API.
src/runtime.rs Implements an fd table in RuntimeImpl and adapts stdio/open to return ids and support lookup.
test_utils/src/lib.rs Updates TestRuntime to use an fd table and the new Runtime interface.
java_runtime/src/classes/java/io/file_descriptor.rs Changes Java FileDescriptor storage from raw pointer bytes to an int fd and resolves via Runtime::get_file.
java_runtime/src/classes/java/io/random_access_file.rs Switches to creating FileDescriptor from a FileDescriptorId and passes runtime context for lookup.
java_runtime/src/classes/java/io/file_input_stream.rs Switches open/init and read paths to fd-based lookup via Runtime::get_file.
java_runtime/src/classes/java/io/file_output_stream.rs Switches open/init and write paths to fd-based lookup via Runtime::get_file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dlunch dlunch merged commit 34ebc38 into main Apr 5, 2026
8 of 10 checks passed
@dlunch dlunch deleted the fd-abstraction branch April 5, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants