What other famous virtual/abstract machines are there other than the BEAM and the JVM?

In all my thinking about the Elixir ecosystem all I can do is keep comparing it to Java because in my mind the BEAM is analogous to the JVM (but takes an approach that suits my brain better). I’m wondering if there are other well known virtual machines that I can compare and contrast the BEAM with.

Thanks!

1 Like

Javascript, Perl, Python, Ruby are all compiled languages running on VMs, to name a few.

However if you want to limit the scope to VMs that have more than one well known languages, there is also the .NET vm.

Ok, so I guess a web browser is just a virtual machine for JavaScript. I had never made that connection before.

In what sense does Python/Perl/Ruby run in a virtual machine whereas C does not? And I’m curious how you would categorize Rust and Go.

Can we call the PHP Zend engine a VM?

Perl/Python/Ruby all compile down to byte code. In the case of python, the byte code can be serialized out as .pyc file. In the case of Perl and Ruby the compiled byte code exists only in memory because they do not want to commit to a stable ABI.

Javascript in either browser and node.js are compiled down to byte code prior to execution; not unlike perl or ruby.

On the other hand, Rust and Go use LLVM to compile down to native code prior to execution. I don’t think it is me, but a generally accepted classification of language environments:

Most interpreted languages, except shells, run on some sort of VMs.

1 Like

I guess so as PHP is compiled to bytecode.

Thanks for a good explanation. I suppose one can expect Python or Ruby code that runs on a MacBook to also run on a Windows machine, so in that sense they are hardware-independent and run in a virtual machine. I’m not sure that the abstraction away from the underlying machine is all that powerful when in comes to Ruby/Perl/Python, though. The JVM and the BEAM seem like they are virtual machines for applications, while Ruby/Perl/Python interpreters seem like they are virtual machines for scripts.

The BEAM, for instance, has its own process scheduler – there is nothing comparable in Ruby/Python/Perl.

4 Likes

Another observation I have is that when I am thinking about the BEAM I find myself thinking about “programming a computer”. When I think about the JVM I think about “using an interface to program a computer”.

The BEAM feels like putting my whole arm up inside a puppet, whereas the JVM feels like trying to control a puppet via some strings attached to a stick.

I think that the reason the BEAM feels directly like a computer to me whereas the JVM feels like only an interface to a computer is that the BEAM allows me to reason about processes and threads of execution in a clearer and more powerful way.

There is also a sense in which I think of the BEAM as being “turned on”, sort of like a computer might be turned on or a car might be idling in the driveway. The environments for Python/Ruby/Perl never feel like this to me.

2 Likes

Sheesh, that blew my mind a bit: Lisp had a hardware VM, lol

There were also hardware implementations of JVM.

About question itself - from bigger ecosystems - .NET. Lesser known but also “popular” to some extent ParrotVM, BPF/eBPF, LuaJIT, SCUMM VM.

Additionally technically x86 is also “VM” on top of RISC CPUs that are running microcode and is “compiled” on the fly.

2 Likes

Wow, interesting – I wonder if I can find a hardware JVM on eBay. It might be a nice way to acquire a JVM and then videotape myself beating it to death with a hammer.

HipHop Virtual Machine, formerly for PHP, now for Hack, was a big thing in the PHP circles earlier. It made PHP devs push for more performance in PHP 7.

MoarVM was designed for Raku aka Perl 6. There are also a bunch of toy languages implemented on top of it.

Surprised no one has mentioned the one lurking in millions of pockets all over the world: the Android Runtime (ART): Android Runtime - Wikipedia.

I would love to see a cross-compiler to translate BEAM files into .dex but I’m sure there are lots of technical hurdles to that. But as an Elixir lover who has suffered through trying to get somewhere with building a mobile app using React Native, being able to write at least an Android app in Elixir would be awesome.

3 Likes

Two more interesting examples:

The Warren Abstract Machine is the de facto standard target abstract machine which Prolog-implementations target.

The family of Forths (and threaded interpretive languages in general) also target a very interesting minimal stack-based machine. It’s probably as close as you can get to a minimal virtual machine which still is practical: Bootstrapping Forth on a new target platform takes no more than a weekend.
There are also a couple of FPGAs which can execute Forth-code directly.

1 Like

Ah, forth, quintessential VM for sure. Thanks for the reminder! Still prefer my old HP 12c over any other calculator in part because of stacks, RPN and forth.

2 Likes

Only one correction: Perl doesn’t compile to bytecode, it compiles to AST (abstract syntax trees). Python, Elixir (and other BEAM vm based languages), Javascript, JVM based languages, .NET based languages, they all compile to bytecode.

In Ruby it depends. Erruby (ruby on BEAM), JRuby and Rubinius compile to bytecode. MRI (cruby) and mruby compile to AST. TruffleRuby compiles to native executable code.

1 Like