9 ms·
wait til they hear that Linux has a stack-based architecture. that all C-based software has a stack based architecture. threads with stacks everywhere: surprisi
by mkramlich 11y ago
wait til they hear that Linux has a stack-based architecture. that all C-based software has a stack based architecture. threads with stacks everywhere: surprisingly fast. it's usually things like higher-level architectural patterns and algorithm choices which make a MUCH bigger impact on latency and throughput, than whether you have stacks or not.
- pcwalton 11y agoThe thread is talking more about stack versus register-based VMs than call stacks. The great stack vs. register-based debate is, in my mind, somewhat like the CISC vs. RISC debate—a fun water cooler conversation, but not too relevant in practice. All performance-focused language VMs lower into a (usually SSA-based) IR soon anyway, so the difference only ends up mattering for VMs that are deliberately kept simple for code size, simplicity, or legacy reasons (like Lua, or CPython).
- mkramlich 11y agofair points
- mikeash 11y agoThat's not what that means. In the context of bytecode, a stack-based architecture is one where instructions directly manipulate stack entries. For example, the Java bytecode instruction iadd takes the top two entries from the stack, adds them together, and pushes the result onto the stack. This is in contrast to a register architecture, where you might have an instruction of the form `add x, y, z`, which takes the values in two registers, adds them, and stores the result in another register. To say that Linux or C is stack-based is nonsensical, as it applies to an instruction set architecture. Virtually all hardware ISAs you're likely to encounter are register-based these days.
- pron 11y agoC compiles down to register-based machine instructions, just as Java bytecode does. Bytecode is merely an intermediate represenation.
- abc_lisper 11y agoBut in doing so, Java runs by simulating a stack machine, hence the name virtual machine.
- pron 11y agoJava bytecode is instructions for a stack machine -- but that's an abstraction. Then the bytecode compiles down to (register) machine instructions, and that compiled implementation is highly efficient and highly optimized. The virtual machine itself is a complete abstraction. Modern JVMs do not run a simulation of a stack machine at runtime (after compilation, that is).