4 ms·
This x1000. I started implementing a JVM for shits and giggles a while ago, and once I had laid out ~220 panics for each opcode, it was incredibly satisfying to
by tiddles 5y ago
This x1000. I started implementing a JVM for shits and giggles a while ago, and once I had laid out ~220 panics for each opcode, it was incredibly satisfying to implement them one at a time to work towards bootstrapping the standard library.
Granted, most opcodes are implemented incorrectly as minor things like method and field resolution aren’t quite there yet.. as soon as I’ve implemented enough opcodes to actually run something and return/exit/throw, the correctness will be a bugger to fix :^)
- binji 5y agoJVM is a great choice! You might also want to check out WebAssembly too (full disclosure: I used to work on wasm). There aren't too many opcodes, and a lot of them are relatively simple math operations. Once you get it working, you could run things like JSLinux! https://bellard.org/jslinux/vm.html?url=win2k.cfg&mem=192&graphic=1&w=1024&h=768 https://bellard.org/jslinux/vm.html?url=win2k.cfg&mem=192&gr...
- tiddles 5y agoThat’s a great idea, I’m not that familiar with wasm and the best way to learn is of course to implement a VM :) Cheers for the link to the meeting notes in the other comment chain, sounds like a great rabbit hole
- kfrane 5y agoYou're right about wasm not being too complicated, I've learned this when watching David Beazley coding a WebAssembly interpreter in under an hour. And it doesn't require any knowledge about it beforehand. https://www.youtube.com/watch?v=r-A78RgMhZU https://www.youtube.com/watch?v=r-A78RgMhZU
- javajosh 5y agoGiven your experience at this level of abstraction, do you have any thoughts on what an ideal set of opcodes look like? E.g. something like Knuth's MMIX. Do you prefer RISC or CISC? What about RISC-V? How much do the designers of real-world micro-architectures talk to folks like you? A bit of a tangent, I know, but it feels important.
- binji 5y agoI'm probably the wrong person to ask, to be honest. I was around for a lot of the design of Wasm, but wasn't really involved at that level. That said, in my opinion the ideal set of opcodes really depends on your goal. There were many goals For Wasm, but I think there was a focus on keeping it small and simple. Originally it was AST-based, but it was changed to a stack machine to reduce size. It was also designed to be AoT or JIT compiled, so the opcode layout is not particularly friendly to hardware decoding or interpreters (although people have made some very high quality Wasm interpreters). And of course there were a lot of discussions and disagreements about the best way forward: AST vs. register VM vs. stack machine. Structured control flow vs. goto. How to handle unreachable code. How to store integer literals (LEB vs. prefix byte). What the text format should look like (sexprs vs. ...?) etc.
- ywei3410 5y agoAre there any meeting notes/chat logs for those discussions? It would be fascinating to get some insight into the design process for a modern VM.
- binji 5y agoYes, you can find all the meeting notes here: https://github.com/webassembly/meetings https://github.com/webassembly/meetings However there were a lot of discussions that were not in those meetings and were in smaller groups or held in GitHub issues or PRs. Most of these were in https://github.com/webassembly/design https://github.com/webassembly/design.
- skitter 5y agoI've just started the same, it's definitely fun. One thing that surprised me about field resolution is that a class can have multiple fields with the same name (if they have different types).
- tiddles 5y agoThe gigantic spec has so many surprises hidden in it - the use of a bespoke “modified utf8” for native strings was a fun discovery. Good luck with the mammoth project! I think the fun will really start when it comes to running mini programs to test against a reference implementation and finding out we implemented core parts like method/field/(super)interface resolution totally wrong. Oh, and optimisation too. It’d be cool to implement a JIT but that’s a long way away