百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rjvm

> 编程语言
开源

一个用 Rust 编写的小型 JVM。学习项目

1.6K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个用 Rust 编写的小型 JVM。学习项目

RJVM

This project is an attempt to write a minimal JVM 7 using Rust.

Important note: this is a hobby project, built for fun and for learning purposes. In particular, it is my first real program in Rust and I've used to learn the language - thus, I'm sure some parts of the code are not very "idiomatic" Rust since I'm just learning the language.

The code quality is definitely not production ready - there are not enough tests, there isn't enough documentation and some of the initial decision should be revisited. (I.e.: this is not representative of the code I write for work .)

The code is licensed under the Apache v2 license.

The architecture is discussed in a series of posts on my blog, https://andreabergia.com.

What has been implemented and what hasn't

The current code can execute various simple programs, but it has a lot of limitations.

Here is a list of the implemented features:

  • parsing .class files
  • resolving classes from a jar file, or from a folder
  • execution of real code:
    • primitive types, arrays, strings
    • control flow statements
    • classes, subclasses, interfaces
    • methods (virtual, static, natives)
    • exception throwing and catching
    • stack traces
    • garbage collection

However, there are a lot of important things not implemented (and not planned to):

  • threading
  • multi dimensional arrays
  • reflection
  • annotations
  • class file verification
  • I/O
  • just in time code execution (JIT)
  • proper class loaders

The JVM uses the real classes from OpenJDK 7 - meaning the classes such as java.lang.Object, java.lang.String or java.lang.Exception are real production classes, without any modifications. The JVM is "good enough" to parse and execute their code, something which makes me very happy indeed.

The VM is limited to 64 bits platforms, as there are quite a few places where I assume that the size of a pointer is exactly 8 bytes.

Implementations that should be modified

One poor implementation detail is that for things like stack overflow, accessing an array out of bounds, divisions by zero, etc. I should be throwing real java exceptions, rather than internal errors that will abort executions. In general, the error handling is not great - there are no details when you get an internal error, something that made debugging more painful than it should have been.

There's also quite a few things whose implementation is quite poor, or not really coherent with the JVM specs, but it is "good enough" to execute some simple code; for example I do not have a class for arrays. If you're curious, look for the TODO in the code.

I'm also quite sure there's a million bugs in the code.

Code structure

The code is currently structured in three crates:

  • reader, which is able to read a .class file and contains various data structures for modelling their content;
  • vm, which contains the virtual machine that can execute the code as a library;
  • vm_cli, which contains a very simple command-line launcher to run the vm, in the spirit of the java executable.

There are some unit test and some integration tests - definitely not enough, but since this is not production code but just a learning exercise, I'm not that worried about it. Still, IntelliJ tells me I have a bit above 80% of coverage, which is not bad. The error paths aren't really tested, though.

I use just as a command runner, but most tasks are just cargo commands.

Project status and further works

I consider the project complete. It was super instructive, but I do not plan to keep working on it.

The only thing I'm considering is to extract the reader crate in a separate repository, and publish it on crates.io, since it could actually be useful to someone else.

GitHub Issues· 0 开放

在 GitHub 查看全部

暂无开放 Issues,或尚未同步最近议题。

核心特点

  • •parsing .class files
  • •resolving classes from a jar file, or from a folder
  • •execution of real code:
  • •primitive types, arrays, strings
  • •control flow statements
  • •classes, subclasses, interfaces
  • •methods (virtual, static, natives)
  • •exception throwing and catching
  • •stack traces
  • •garbage collection

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言