Skip to content

Commit 5feb762

Browse files
committed
fiat lux
0 parents  commit 5feb762

83 files changed

Lines changed: 7324 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
rust:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: checkout
15+
uses: actions/checkout@v4
16+
17+
- name: setup java
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: '17'
22+
23+
- name: setup rust
24+
uses: dtolnay/rust-toolchain@stable
25+
with:
26+
components: rustfmt, clippy
27+
28+
- name: setup cargo-llvm-cov
29+
uses: taiki-e/install-action@cargo-llvm-cov
30+
31+
- name: cargo fmt
32+
run: cargo fmt --all --check
33+
34+
- name: cargo clippy
35+
run: cargo clippy --workspace --all-targets -- -D warnings
36+
37+
- name: cargo llvm-cov
38+
run: cargo llvm-cov --workspace --all-features --fail-under-lines 80

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
/fixtures/**/build
3+
/mini-rt/out

Cargo.lock

Lines changed: 174 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[workspace]
2+
members = [
3+
"rjvm",
4+
"classfile",
5+
"loader",
6+
"runtime",
7+
"interpreter",
8+
]
9+
resolver = "2"
10+
11+
[workspace.package]
12+
edition = "2021"
13+
license = "MIT"
14+
version = "0.1.0"
15+
16+
[workspace.dependencies]
17+
anyhow = "1"
18+
thiserror = "1"
19+
zip = { version = "0.6", default-features = false, features = ["deflate"] }

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# rjvm
2+
3+
rjvm is a small jvm-in-rust focused on clear structure and correct-enough behavior for trusted java 7 bytecode.
4+
5+
the project is intentionally minimal:
6+
- interpreter only (no jit)
7+
- stable handle-based java references
8+
- compact runtime model for objects, arrays, frames, and exceptions
9+
- tiny intrinsic surface for io and string operations used by fixtures
10+
11+
## workspace overview
12+
13+
- `classfile/`: parses `.class` files (constant pool, methods, code attributes, exception tables)
14+
- `loader/`: loads classes from classpath directories and jar files
15+
- `runtime/`: value model, heap/object/array storage, and field keys
16+
- `interpreter/`: bytecode execution, method invocation, exceptions, class init, intrinsics, and gc
17+
- `rjvm/`: cli entrypoint and argument handling
18+
- `mini-rt/`: tiny java runtime jar experiments and build script
19+
- `fixtures/`: java programs used as integration fixtures
20+
- `tests/run_fixtures.sh`: compiles fixtures and validates rjvm output
21+
22+
## execution model
23+
24+
rjvm starts from a resolved main class and executes:
25+
- `public static void main(String[] args)`
26+
- or `public static int main()`
27+
28+
class loading is classpath/jar based. at startup, rjvm builds a class repository from available class files and resolves method/field references at execution time.
29+
30+
class initialization is tracked per class. active use sites (`new`, `getstatic`, `putstatic`, `invokestatic`) trigger `<clinit>` once for that class.
31+
32+
## command line
33+
34+
```bash
35+
rjvm --cp <paths> <mainclass> [args...]
36+
rjvm --jar <app.jar> [args...]
37+
rjvm --jar <app.jar> --main <mainclass> [args...]
38+
```
39+
40+
notes:
41+
- class names can be passed with dots or slashes; cli normalizes to jvm binary names.
42+
- for `--jar`, `main-class` is read from `meta-inf/manifest.mf` when present.
43+
44+
## build and test
45+
46+
```bash
47+
cargo test
48+
./tests/run_fixtures.sh
49+
```
50+
51+
## manual examples
52+
53+
compile and run the args fixture:
54+
55+
```bash
56+
javac -source 7 -target 7 -d fixtures/entry_args/build fixtures/entry_args/src/*.java
57+
cargo run -p rjvm -- --cp fixtures/entry_args/build Main alpha beta gamma
58+
```
59+
60+
compile and run the json parser stress fixture:
61+
62+
```bash
63+
javac -source 7 -target 7 -d fixtures/stress_json_java/build fixtures/stress_json_java/src/*.java
64+
cargo run -p rjvm -- --cp fixtures/stress_json_java/build Main "$(cat fixtures/stress_json_java/run_args.txt)"
65+
# or your own json
66+
cargo run -p rjvm -- --cp fixtures/stress_json_java/build Main '{"a": {"b": [1,2, [55]]}, "c": null}"
67+
```
68+
69+
## design notes
70+
71+
- java references are represented as stable indices/handles, not rust references.
72+
- gc is non-moving mark-sweep to keep handles stable.
73+
- the fixture set is the compatibility target. this is not a full openjdk-compatible vm. i’m not that far gone :)
74+
- code is organized so semantics are explicit over clever.
75+
76+
<hr/>
77+
78+
have fun!

classfile/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "classfile"
3+
version.workspace = true
4+
edition.workspace = true
5+
license.workspace = true
6+
7+
[dependencies]
8+
thiserror.workspace = true

0 commit comments

Comments
 (0)