Index ¦ Archives ¦ Atom

JVM vs BEAM Architecture Differences

  • Recently read a study comparing the design of widely used Oracle's implementation of JVM (aka. HotSpot VM) and Erricson's implementation Erlang VM (BEAM) with respect to concurrency and parallelism. This study was published in May 2015.
  • This is not about comparing two languages (i.e java vs erlang/elixir) or programming paradigms (Object Oriented vs Functional). This is more about the design of the virtual machine themselves which ultimately is responsibile for interpreting the bytecode into machine level instructions and runs the applications.

JVM

  • JVM's internal representation has a stack, shared heap and garbage collector.
  • The garbage collector has two sections within it to identify objects that die too young and those live long.
  • There will be a global pause (all world pause) to clean up garbage values.
  • The responsibility of avoiding deadlock for critical sections for concurrency falls to the programmer due to underlying shared heap (shared state).
  • Akka framework brings the Actor model to Java applications, but underlying shared heap means block in one component means entire application thread blocks.
  • VM Threads are one-to-one mapping with os level threads. Therefore scheduling is relied on os level schedulers.
  • JIT Compiliation strategy is a strength.
  • Irrespective of it's implementation, JVM also employs a lot of optimization strategies to garbage collection, scheduling, etc., that counters the design limitations.

BEAM

  • BEAM is implemented with Actor Model. With processos as Actors and Message passing among processes.
  • Each process has it's own stack and heap. No global pause for garbage collecting, since each processes has it's own memory scope isolated from others.
  • Has number of schedulers as per the cpu core and schedulers can load-balance based on strategies.
  • VM threads are many-to-many mapping with os level threads therefore no need to entirely depend on os level schedulers.
  • There are no JIT compilation strategy with BEAM. A project called BEAMJIT was started some years back, but it's not complete.

Now, let us not jump to conclusions of which is better without matching them against the context and problem at hand. Here is a discussion thread in Hacker News on the same topic.

© Prasanna Venkadesh. Creative Commons Attribution ShareAlike. Theme by Giulio Fidente on github.