Skip to main content

Command Palette

Search for a command to run...

Rust JVM Post 0

Published
6 min read
P

JVM based developer for over 6 years (Scala, Java, Clojure).

Experience with distributed algorithms using Apache Flink and Apache Spark.

Experience with high performance simulation development using C++ and Fortran

Interested in the Rust programming language and programming language design in general.

Contributor to the Foresight Autonomous Driving project for BMW through their joint venture with Critical Software, Critical Techworks.

The project is developed in Scala, using Apache Flink and Apache park to process map data and events. Through this project I am able to further improve my knowledge of Functional Programming and distributed algorithms.

With the support of Critical Techworks I am also a lead on the Community of Practices for the Rust Development language, where interested developers are able to learn and discuss this new programming language.

From the end of 2018 to the end of 2019 I've worked as a Calypso developer for the back office at Natixis Porto.

The first 4 years of my career I worked with the Brazilian Navy, developing simulators for the Mercantile Navy. During this period I was able to learn and develop my skills as a programmer. Over the last two years at the project I was assigned the role of Technical Manager in the project, where I was tasked with the decisions over our technology stack, tools and processes.

There we successfully migrated from SVN to Git using a self hosted GitLab instance, implemented a CI pipeline and moved old support systems (such as file sharing servers and databases) to newer and more modern technologies. The success of these migrations in the project raised the interest of the rest of the development group, and many projects are moving to the same processes we implemented here. In March 2018 my team and I released the first version of our simulator for the Mercantile Navy School in Rio de Janeiro. An article about the inauguration can be found in the following link (in portuguese):

https://www.marinha.mil.br/ciaga/node/425

Technical information about the simulator can be found in the following link (in Portuguese):

https://www.marinha.mil.br/ipqm/node/114

From September 2014 to June 2018 I contributed as a tutor for the CEDERJ foundation, where I helped students on topics such as Programming using Pascal and Python, basic computing using Libre Office tools and mathematics courses for Computer Science courses.

Introduction

While Rust is one of my favorite languages to work on, over the last few years JVM based languages (namely Java and Scala) are my daily work tools. In an effort to better understand the lower level implementation details of the JVM I’ve been researching how to build my own. And to have some extra fun, why not do it in Rust?

Being a part 0 of a N part series, this post won’t have any code, just a short discussion on what our goal is and resources for the future.

This is not necessarily a series for learning Rust, so some knowledge of the language is necessary. Some knowledge of C++ and JVM based languages is a plus, but not strictly necessary.

The JVM Components

Roughly speaking, there are three main components in the JVM architecture:

  • A class loader, which parses .class files into JVMs internal data structures;
  • A bytecode verifier, which validates the data in these data structures;
  • An Execution Engine, which interprets the byte code and executes the instructions;

Other related components are:

  • A compiler, which translate some language into bytecode

  • A Garbage Collector, which manages the memory of the JVM;

  • A JIT compiler, which compiles “hot” portions of the byte code into native code;

  • A Native Interface, which is able to “talk” with linked native code;

What We WON’T Be Building

We won’t be writing the following:

  • A compiler: I’m targeting writing the virtual machine, so we will assume our compiled code comes from the Gods and we just execute it;

  • A JIT compiler: Though this might be a stretch goal, this will take a lot of research time;

  • The new fastest most awesomest JVM to ever be built: Smarter people than me have been writing JVMs for over 25 years, this is just a research project;

What We Will Be Building

Our goal is to have:

  • Class loader;

  • Bytecode verifier;

  • Execution Engine;

  • A Native Interface;

  • Some form of garbage collection;

The target for this toy implementation is the JVM 8 specification.

One of the main points of this implementation is for it to be used for learning, so it should be really well documented. Part of this documentation will be this series of posts, the other part will be code documentation focused on following the specification to the letter.

Research Material

Our main source of truth will be the The Java® Virtual Machine Specification for the Java SE 8 Edition. This document describes all the data structures, bytecodes and functionalities necessary for a complaint JVM.

Another important source I’ll be using is the openJDK8 source code (OpenJDK Mercurial Repositories) which can be downloaded using Mercurial or as a zip. We are particularly interested in the hotspot portion of the repositories (jdk8u hotspot).

Finally, the The Rust Programming Language — The Rust Programming Language and std — Rust will be used as basis for the Rust language itself.

Tools

Besides all the standard Rust tools (Cargo, Rustup, Clippy, etc), I’ll be using CLion + Rust Plugin as an IDE. The point is to be able to use the same IDE for our code and the openJDK implementation. Also, having access to a debugger is directly in the IDE is nice.

Similar Works

There are a few JVMs implemented in Rust already with similar goals to this project. I’d like to call attention to one particular implementation (https://github.com/kittylyst/ocelotter) which was part of a talk at Devoxx this year (https://www.youtube.com/watch?v=7ECbwgkHdAE&t=384s).

I’ve also tried my hand at this before, going as far as implementing a full class loader. The implementation can be found here. I’ll be using mostly the same structure, so you can take a peek at where we are going.

Conclusion

Well, thats it. On the next entry I’ll either go through the project organization or take a peek at the organization of the openJDK project, since it will be one of our main sources of inspiration.

See you then!

More from this blog

Untitled Publication

12 posts