Skip to content
This repository

Welcome to Erjang!

Erjang is a virtual machine for Erlang, which runs on Java(tm).

From 0 to Erjang in 30 seconds

If you just want to try it out, do this:

curl -O https://dl.dropboxusercontent.com/u/1360473/erjang-R16B01.jar && java -jar erjang-R16B01.jar
Eshell V5.7.5  (abort with ^G)
1> 

That's a minimal install that includes just stdlib, kernel, compiler, erts and sasl. Should be able to let you compile and run basic erlang programs.

How does it work?

It loads Erlang's binary .beam file format, converts it into Java's .class file format, and loads it into the JVM. It will eventually have it's own implementation of all Erlang's BIFs (built-in-functions) written in Java. Erjang also has a BEAM interpreter; if you launch erjang with a +i argument it will run interpreted (slower, but using much less memory).

Does it work?

Yes! It does actually work.

  • It can boot Erlang/OTP to the Eshell (jerl command).
  • Run Erlang distribution, tcp/ip, port commands (stdio to external processes).
  • You can run the compiler (c(foo) command in the prompt)
  • It runs mnesia with distribution across Erjang/BEAM nodes.
  • The HTTP packet parsers are in the tcp/ip stack, so mochiweb and webmachine can run (without crypto for now).
  • Larger systems like rabbitmq and riak can boot; and works for basic cases ... but it's not ready for prime time yet.
  • Etc. etc. Lot's of stuff work.
krab$ ./jerl 
Eshell V5.8  (abort with ^G)
1> erlang:display("hello world!").
"hello world!"
true
2> q().
krab$ 

There are still things that doesn't work: a few BEAM instruction are missing some runtime support. There are also BIFs missing, or only partially implemented; we're quite careful to throw @erjang.NotImplemented@ in BIFs (or branches thereof) which are not complete. Many OTP modules need NIFs or linked-in drivers that are entirely missing or only partly implemented.

Why are you doing this?

Good question. Well, I just wanted to learn Erlang, and so this felt like a good way to get through all the details. Seems to be working -- I am learning erlang!

What will it feel like to be running Erlang on the JVM?

Here is what to expect:

  • In Erjang, every node runs on a single heap, and so global GC will sometimes happen.
  • On the other hand, Erjang does not copy messages between processes -- they are simply shared, so sending large messages is significantly cheaper.
  • Over all, you will lose the predictability in behavior that Erlang has with regard to GC pauses, because Erlang can GC each process individually. Java GC continues to improve, so this might become less of an issue over time; but it will likely never go away.
  • My current tests indicate, that you can get better throughput in Erjang than BEAM, see this blog post
  • Erjang can run the "ring problem" at-par with BEAM, the Erlang virtual machine. If you let the JIT warm up, Erjang looks like it is faster than beam.
  • The big win is that Erjang is running on a VM that does dynamic compilation, selective inlining, and all the performance that comes from that.

How do you implement Erlang's feature X?

Something went wrong with that request. Please try again.