tags:

views:

120

answers:

1

What are some fundamental Feature/Architectural difference between the BEAM and JVM?

  1. Yes I know: one was originally built around java and the other built around erlang
  2. I understand the JVM (somewhat) and want to compare their structures
  3. For example I know that the JVM has one Global GC and BEAM has one per process
+4  A: 

First of all, Beam is a register machine, not a stack machine. Like the WAM for Prolog, it uses "X-registers" which are normal registers (implemented as an array in C), and "Y-registers" which are names for slots in the local function activation record (the "call frame") on the stack. There are no stack manipulation instructions.

Second, there are instructions for quickly allocating a few more words of heap memory, for initializing tuples and other data structures on the heap, for selecting elements of tuples, etc. JVM is focused on objects, and has a 'new' operation that hides the details of memory allocation and basic initialization.

The BEAM has an instruction for decrementing the "reduction counter" for the process and deciding whether it is time to yield to let another process run. JVM on the other hand has synchronization instructions for threads.

One important difference is that BEAM has tail call instructions, which JVM lacks.

Finally, for both the BEAM and JVM, the instruction set used in object files are really only a transport format. The BEAM emulator rewrites the instructions from the file into an internal version with many optimized special-case instructions (that can change from one release to another). Alternatively, you can compile to native code. Most JVMs do the same thing.

RichardC