Live data from Hacker News

Building a Minimalistic Virtual Machine

pointersgonewild.com

51–60 of 72 posts

Re: Building a Minimalistic Virtual Machine

#51

Earlier quoted context omitted.

I go into some of the design decisions I made to make JIT optimizations easier here: https://github.com/maximecb/uvm/blob/main/doc/design.md

You mention parallel computation and being open for discussion. My favourite area of computing is parallel computing and multithreading. My toy multithreaded interpreter in Java can communicate integers between threads with message passing. I never got around to communicating complicated objects because I'm not sure how to solve the garbage collection problem with compound data structures/object graphs AND sending ob…

I was thinking something like actors, or independent processes sending messages would be nice. Just because it's very safe and predictable. Less error-prone than threads.

The thing that kind of gets me is it seems difficult to have safe shared memory with actors? You ideally want to be able to share memory if you want things to be efficient, but if you have shared memory, then you get into issues with atomic writes and things being observed in different orders, etc.

Re: Building a Minimalistic Virtual Machine

#52
Nice idea! Some of the goals remind me of CHIP-8 [0] ("the hello world of emulators" [1]) but presumably not constrained to 8 bits and with a bit more than just the ISA and graphics support?

[0] http://www.cs.columbia.edu/~sedwards/classes/2016/4840-sprin...

[1] https://www.reddit.com/r/EmuDev/comments/9ezrvt/easiest_emul...

Re: Building a Minimalistic Virtual Machine

#54
post #29

Earlier quoted context omitted.

> Implementing a good GC is incredibly hard If you are interpreting instructions a simple one will be more than enough. Classes are its primitives, you just create a basic runtime representation for them with name, superclass, implemented interfaces and the methods’ bytecodes. Then an object can be as simple as a header containing a pointer to the class’s representation and then a listing of its fields, which can all…

> With all due respect, you ain’t going to beat the JVM with your UVM’s JIT compiler, not even close. I think I may be able to get very close to native performance. I don't want to sound like an asshole by appealing to authority, but you aren't talking to a teenager writing an interpreter from their parent's basement. I have 21 years of programming experience, a PhD in compiler design and multiple published papers. I…

You say this stuff is incredibly hard. Kaba says it's impossible and don't try. I say it's easy. I whipped up a JIT to make my virtual machine go 50x faster. I never expected Blinkenlights to go faster than Bochs. Now all the sudden it's outperforming Qemu for many of my use cases. People are doing stuff with it I never expected, like booting the Linux Kernel and running Alpine Linux on Cygwin. Garbage Collection is easy too. I wrote a GC using the NSA POPCNT instruction for an experimental LISP dialect I wrote last Winter called Plinko. It ran faster than any other LISP interpreter I've seen, as measured by the GC-intensive binary trees benchmark game. The only thing faster was SBCL with JIT which was only a hair faster than Plinko using just an interpreter. NIH is awesome because the truth is, when you're focused on your own needs, outperforming the big official things is like shooting fish in a barrel. Technologies like the JVM aren't great because they're better. They're great because they've carefully crafted the long tail of edge cases and compromises that enables it to be good enough for the largest group of people. Generalized software is at a huge disadvantage because bloat fills caches and it can't use special case algorithms. For example, people publish papers all the time bragging about how they beat the performance of the C++ STL at some given thing and that impresses the people who never tried, but it honestly isn't that hard if you consider the burdens that the STL is required to carry.

Re: Building a Minimalistic Virtual Machine

#55

Arguably more interesting is UXN: https://100r.co/site/uxn.html A small personal computing stack, with a plethora of examples ready to go. Built by two they/them hackers who live on a boat and basically have bootstrapped everything about their vessel, their computing, their engineering, etc. It's very, VERY old-school hacker-y. They would've made excellent phreaks back in the good ol' days.

Author here. The creator of UXN is a friend of mine and we chat semi-regularly about our VMs. I have a lot of respect for uxn and credit it as an inspiration, but the goals of each project are different. UXN is a 16-bit system with 64KB of RAM accessible. It will also probably always remain interpreted. These design restrictions are seen as tools to foster creativity. UVM is a 32/64-bit VM. It's currently interpreted…

It might be worth linking the instruction set in the sources (there doesn't seem to be a doc yet?) - it gives a fairly decent picture of what kind of VM we're talking about:

https://github.com/maximecb/uvm/blob/main/vm/src/vm.rs

One thing I didn't quite grok there. It seems that the operand stack is also used directly for locals and hence is indexable, with what looks like an implicit frame base register? But the stack is not addressable. Is the language runtime expected to manage a separate in-memory stack for addressable locals and dynamically allocated arrays, like wasm?

Re: Building a Minimalistic Virtual Machine

#56
post #7

Earlier quoted context omitted.

LLVM is more heavyweight. Has a lot of analysis and optimization passes for static compilation. UVM is currently very lightweight, will be JIT compiled. Crucially UVM will provide graphics, audio and networking primitives.

That's what LLVM is today, but IIRC their goals were the same. It might be worth it to look at what made it turn away from the minimal idea and into the heavyweight that it is now.

LLVM also has a strong emphasis on performance and interoperability with existing code and is willing to introduce arch- and platform-specific features for that purpose.

Re: Building a Minimalistic Virtual Machine

#57
I don't think it's a bad idea, but having looked into this sort of thing pretty deeply, I do think it's a "now you have two problems" idea when started by centering an ideal VM.

Foundational software is very slippery stuff - it's analogous to having a yeast culture. Before the software was there we had machine language and the specific hardware, but gradually we built a stack of compiler tech, common protocols, etc. And from there we went and started targeting the end of further abstracting it, making it perfectly portable and so forth, but that's like trying to engineer a perfect yeast: while some might get a better benchmark on some metric, the overall metric is a pass/fail: "Can I bake bread with this?"

Of course, a lot of people give up along the way and buy something off the shelf, because they want bread now. And that's fine - they're eating off it, and the world keeps turning.

But if you do try, you can "do more with less" by carefully limiting the kinds of computation and I/O you're doing and describing that as a protocol, then developing software around the protocol. At that point, the software's specification has an insulation barrier from its dependencies, and you don't necessarily care about the whole of the dependency because you've selected a subset whose specific features and codepaths can be vetted in more depth.

And the odd thing about this is that it's the kind of thing that, at its outset, doesn't lead towards complexity, because you intentionally started with a system that does less than its dependent parts: but once you have that, you can knock out and replace the dependencies to "do one thing well," ship of Theseus style. At that point it can become larger again, and evolve. And that's roughly how we ended up with the giant soup of stuff that is "Web tech". At every point along the way, it did bake bread. But when it was first specified, it hardly did anything at all: it bundled "download remote files, present files as documents".

Re: Building a Minimalistic Virtual Machine

#58
post #42

the jvm already exists and you can run ancient compiled class files with it.

The level of cynicism on HN is sometimes really depressing. > the jvm already exists and you can run [some] ancient compiled class files with it [but many won't work correctly]. FTFY.

I’ve been toying with the idea of taking an ancient bootstrapping JVM implementation, forget which now dead project it was written for, dusting it off and doing something similar to your project. None of these new millennium fancified features — compute like it’s 1996.

Though I’m mostly interested in compiler tech, as an amateur, and don’t really want to delve too deeply into VM theory.

Time is the main factor holding me back though…sigh.

Re: Building a Minimalistic Virtual Machine

#59

Earlier quoted context omitted.

The level of cynicism on HN is sometimes really depressing. > the jvm already exists and you can run [some] ancient compiled class files with it [but many won't work correctly]. FTFY.

I’ve been toying with the idea of taking an ancient bootstrapping JVM implementation, forget which now dead project it was written for, dusting it off and doing something similar to your project. None of these new millennium fancified features — compute like it’s 1996. Though I’m mostly interested in compiler tech, as an amateur, and don’t really want to delve too deeply into VM theory. Time is the main factor holdin…

If you want to compute like it's 1986, I think it would be fun to build a BASIC interpreter for UVM. Bonus points if you do your own text rendering on a blue background and you add simple primitives for 2D graphics.

https://github.com/maximecb/uvm/issues/7

Post reply on HN