Question

How do register-based virtual machines implement registers.

I've been reading a lot of online information about register-based virtual machines and I've seen int r[16]; used as the method to implement the registers. This brings up a few questions like how is a machine like this able to handle a long or a float?

Both Parrot and Dalvik are register-based virtual machines. Parrot states that it has a register window which allows an unlimited number of registers and dalvik supports up to 65,536 registers. I want to know how the registers are implemented on these virtual machines

I'd like to see the actual implemented code because I'm interested in how they are able to store values that different and as to if they are created on call of the opcode or are they always there?

Thank you

Was it helpful?

Solution

In dalvik, each register is 32 bits wide. A long/double value is stored using 2 registers. The actual register values are "persisted" in the call stack, but may temporarily live in an actual physical machine register.

The 64k limit on the number of registers is due to the size of the field in the dex file that holds the number of registers, which is 16 bits. Practically speaking, methods just don't need that many registers.

If you want to get a deeper understanding of how dalvik works, the best resource is the source itself. For example, here is the portable C implementation of the "const" opcode, which stores an immediate value into a register.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top