4 ms·
HotSpot VM is only using a stack for storing local variables when executing byte code. As soon as it needs to optimize a hot path it turns the byte code into re
by bjourne 4y ago
HotSpot VM is only using a stack for storing local variables when executing byte code. As soon as it needs to optimize a hot path it turns the byte code into register-based cpu-specific assembly.
- shagie 4y agoVery true... but its still a virtual stack machine. This gets into the "when you write the implementation or JIT" it is much easier to write something that doesn't use any registers and then target it to a machine that uses some number of registers than to write the VM for something that is register based, but then has different conventions for how to use those registers than the VM has... This is something that had to work on a 386, Sun Sparc, MIPS, Motorola 68030, Alpha, Vax (the CISCest instruction set you'll ever find https://documentation.help/VAX11/op_POLY.htm https://documentation.help/VAX11/op_POLY.htm )... and even its own Java Processor ( https://en.wikipedia.org/wiki/Java_processor https://en.wikipedia.org/wiki/Java_processor - https://www.usenix.org/legacy/publications/library/proceedings/jvm01/full_papers/aoki/aoki_html/index.html https://www.usenix.org/legacy/publications/library/proceedin... ). The difficulty would be if you made a... 32 register system and then you had to do the JIT from that to MIPS, but the frame pointer was foreign to the VM and $s0-$s7 where not ones you could touch without extra work... and then x86 had different conventions based on who wrote the compiler ( https://en.wikipedia.org/wiki/X86_calling_conventions#List_of_x86_calling_conventions https://en.wikipedia.org/wiki/X86_calling_conventions#List_o... )... It becomes much easier to work with a system with no registers and then make it "easier" to do the JIT than to do registers and then go from "too many" to trying to redo them for that system. And while it's not something I follow at all, apparently the EVM is also stack based. https://medium.com/mycrypto/the-ethereum-virtual-machine-how-does-it-work-9abac2b7c9e https://medium.com/mycrypto/the-ethereum-virtual-machine-how... > The EVM uses a 256-bit register stack from which the most recent 16 items can be accessed or manipulated at once. In total, the stack can only hold 1024 items. Which is... kind of interesting. Reminds me somewhat of dc - https://en.wikipedia.org/wiki/Dc_(computer_program) https://en.wikipedia.org/wiki/Dc_(computer_program) where its stack based, but has "registers" too (though you tend to use registers for storing macros which can then be loaded onto the stack and executed).