Live data from Hacker News

Write Your Own Virtual Machine (2022)

jmeiners.com

61–70 of 102 posts

Re: Write Your Own Virtual Machine (2022)

#61

Alas, educational architectures like the Brookshear Machine and Little Computer look nothing like real ones, making them worse than useless: in my experience students who take courses using these often end up with a more distorted understanding of computers than those who take no classes at all. Most people who want to learn a bit about how their machines work would be better served by taking an operating systems cou…

I think of Knuth's old MIX which was a decimal machine which might have gotten built in the 1960s but which nobody has built since the 1970s. A system like that can teach you many fundamentals but not the tricks here https://en.wikipedia.org/wiki/Hacker%27s_Delight which mainly depend on conventional numeric representations.

MIX wasn't decimal, but rather abstract over the choice of base, a decision Knuth changed in later volumes of the series, even before switching to MMIX.

There have been decimal and hybrid computers built since the 01970s (especially for pocket calculators, but new decimal instructions were still being added to Intel's lineup in the 8086 with AAM and AAD, and I think decimal continued to be a consideration for the AS/400 into the 90s), but MIX is really kind of an 01950s design, with:

- word-addressed memory

- five bytes per word (plus a sign bit)

- one word per instruction

- six bits per byte (in binary realizations)

- possible decimal

- a single accumulator

- sign-magnitude

- no stack, and

- a nonrecursive subroutine call convention relying on self-modifying code.

You can find one or another of these characteristics in machines designed since 01960, but the combination looked old-fashioned already when it was introduced.

Re: Write Your Own Virtual Machine (2022)

#62
post #59

Some books that i was pointed to; 1) Virtual Machines: Versatile Platforms for Systems and Processes by Smith and Nair - Seems to be a comprehensive subject overview book. 2) Virtual Machines by Iain Craig - Seems like a more hands-on book with languages and VMs. 3) Virtual Machine Design and Implementation in C/C++ by Bill Blunden - Seems like an hands-on implementation. If somebody who has read any of the above can…

I'm not convinced that the subject is narrow enough to overview in a single book. The considerations involved in writing a Nintendo emulator, a hypervisor using VT-x, a conventional multitasking operating system, an interpreter for a new scripting language, a SQL query optimizer, a regular expression matcher, a security monitor for untrusted player code running on a game server, etc., would seem to have very little o…

You are thinking about "Virtual Machines" in a more philosophical/abstract sense. Here the definition is in a much more narrower and conventional sense. Surprisingly i can't find too many books on this subject. The Iain Craig book looks pretty interesting since it seems to link language to the VM, so maybe one can learn both language design and a VM to run it on.

Other than the above i can only think of studying "QEMU Internals" for more knowledge - https://airbus-seclab.github.io/qemu_blog/

Re: Write Your Own Virtual Machine (2022)

#63
post #26

Earlier quoted context omitted.

I don't think that terminology is "overwhelmingly common", and I'd argue that it isn't even entirely correct. The JVM is widely deployed, the Ethereum VM is called the "EVM", https://www.linuxfoundation.org/hubfs/LF%20Research/The_Stat... describes BPF and eBPF repeatedly as "virtual machines", https://webassembly.org/ begins by saying, "WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based…

Disagree with both of you. JVM was always a misnomer, it just stuck because that's just the name they stuck with. Putting "virtual machine" in its name in defiance of the meaning doesn't suddenly make it a virtual machine any more than calling your dog "my son" makes your dog your son. And virtual machines have used software virtialization for the longest time, they aren't always hardware based. Really, a virtual mac…

The JVM is what is called a "Process Virtual Machine" - https://en.wikipedia.org/wiki/Virtual_machine#Process_virtua...

Re: Write Your Own Virtual Machine (2022)

#64
post #35

Earlier quoted context omitted.

Interesting. How would you advocate actually gaining that knowledge then? It seems like a student would need to know a significant amount of coding in order to learn those abstractions in an interactive manner. And by learn them I mean learn them (not just following a tutorial), organizing the code for a fully working x86 architecture is no joke. But a student with that level of skill probably doesn't need to learn t…

Very good question. My working assumption throughout was that the people in a computer architecture class already had 1 or 2 semesters of other programming courses where they worked in a high-level language, and are looking to learn how computers work "closer to the hardware". And educational architectures create a completely false impression in this domain. If I had to teach assembly programming to people who never…

I appreciate the candid response. I have noticed there is a class of very intelligent, well-educated adult learners who have nevertheless been unexposed to software education until adulthood who are now looking for a career change. I've found that there is a lot of difficulty initially with combining abstractions, i.e., "a variable holds a value, a function is also a value, a function is also a thing that sometimes takes values and sometimes returns values, therefore a variable can hold a function, a function can be passed as an argument to a function, and a function can return a function".

Reasonable adults might have reasonable questions about those facts, such as, "what does any of that have to do with a computer?"

To my embarrassment, I realized they were completely right and my early exposure to software made me overlook some extremely important context.

So for these adults, the expectation of struggling through a few semesters/years of javascript is not an optimal learning route.

My hope was that working from the logic gate level up would at least provide the intuition about the relationship between computers (Turing Machines, really, not modern computers) and software.

However, I think based on your excellent critique I will be sure to include a unit on how "educational architectures are very different from modern architectures and I may have ruined your brain by teaching you this" haha.

Re: Write Your Own Virtual Machine (2022)

#65

Earlier quoted context omitted.

My recommendation is to use an old 8-bit architecture like 6502 or Z80. Apparently a lot of CS courses in India still use the 8086/8088 too.

Back in China my first comp arch class used 8051, it was fun. I remember everyone getting a development board and playing with assembly.

For an excellent (and free) 8051 book with lots of C code see Michael Pont's Patterns for Time-Triggered Embedded Systems - https://www.safetty.net/publications/pttes

Re: Write Your Own Virtual Machine (2022)

#66
post #57

Earlier quoted context omitted.

Disagree with both of you. JVM was always a misnomer, it just stuck because that's just the name they stuck with. Putting "virtual machine" in its name in defiance of the meaning doesn't suddenly make it a virtual machine any more than calling your dog "my son" makes your dog your son. And virtual machines have used software virtialization for the longest time, they aren't always hardware based. Really, a virtual mac…

The JVM is a VM in that sense. It isn't a physical computer, but presents itself as one. It's true that that computer doesn't have a disk or a keyboard, but neither do the vast majority of physical computers, including, specifically, the set-top boxes the JVM was originally designed to run on.

> The JVM is a VM in that sense. It isn't a physical computer, but presents itself as one.

No, it isn't and doesn't. What in the world does it have that makes you think it pretends to be a computer? A bunch of pretend registers and a memory limit?

Re: Write Your Own Virtual Machine (2022)

#67

Earlier quoted context omitted.

Disagree with both of you. JVM was always a misnomer, it just stuck because that's just the name they stuck with. Putting "virtual machine" in its name in defiance of the meaning doesn't suddenly make it a virtual machine any more than calling your dog "my son" makes your dog your son. And virtual machines have used software virtialization for the longest time, they aren't always hardware based. Really, a virtual mac…

The JVM is what is called a "Process Virtual Machine" - https://en.wikipedia.org/wiki/Virtual_machine#Process_virtua...

[flagged]

Re: Write Your Own Virtual Machine (2022)

#68
post #9

Earlier quoted context omitted.

the 80286 has its own problems/inessential complexity if you look at this from the riscv angle, moving from "u-mode only vm that doesn't use paging under the hood" to "u+s-mode vm with sv39" isn't an enormous jump in complexity imo i think i might teach it starting as like, "sv21" (page tables aren't nested), then pose real sv39 and the tree structure as the solution to making a sparse mapping over 512GiB then moving…

Sometimes I dream of a 24-bit generation of computers (in terms of address space and the space of index math) of which https://en.wikipedia.org/wiki/Zilog_eZ80 may be the best realization. You can almost run a real operating system on that chip in the sense of a 24 bit supervisor that could run multiple 16 bit processes (if you could get CP/M to run you have one heck of a userspace) Unfortunately you can't trap the i…

Even better than that was an Z280 which did have a proper user/supervisor mode and simple MMU. Really reminiscent of a PDP-11 in terms of supervisor state, just strapped to a z80 instruction set otherwise. Also added a nice SP relative load to the instruction set.

Re: Write Your Own Virtual Machine (2022)

#69
post #53

Earlier quoted context omitted.

Teachers don't want extra work. My first 360 assembler class our first assignment: add two numbers, fault, print the crashdump and circle the answer to the ADD in the printout. I wrote an RPN calculator, had it do a series of calculations and print the result. Turned that in. The teacher wrote on it "You have 24 hours to turn in the required assignment"

Sounds like you needed to learn to follow basic instructions.

Said like a true teacher.

Re: Write Your Own Virtual Machine (2022)

#70
post #57

Earlier quoted context omitted.

The JVM is a VM in that sense. It isn't a physical computer, but presents itself as one. It's true that that computer doesn't have a disk or a keyboard, but neither do the vast majority of physical computers, including, specifically, the set-top boxes the JVM was originally designed to run on.

> The JVM is a VM in that sense. It isn't a physical computer, but presents itself as one. No, it isn't and doesn't. What in the world does it have that makes you think it pretends to be a computer? A bunch of pretend registers and a memory limit?

It doesn't have registers, pretend or otherwise, or a memory limit. It sounds like you aren't very familiar with the JVM or computers in general. On the JVM in particular, I suggest reading https://docs.oracle.com/javase/specs/jvms/se23/html/index.ht....
Post reply on HN