How does Dalvik VM save and restore its registers between method calls?

Semantically, VM Dalvik has a new set of registers for each method and has no instructions for accessing the call stack. But from the point of view of its implementation, the registers must be somehow saved when the method is called and restored when the method returns. How does (implementation of Google) Dalvik do it?

+6
source share
2 answers

The registers to which the dalvik bytecode refers are not machine registers at all, but they are actually points in the call stack. Whenever you call a method, dalvik allocates enough memory in the frame of the method stack to store all the registers that this method needs.

Please note that not all calculations will immediately change the value on the stack, vm, obviously, must load the values ​​into the machine register to perform calculations. The results can be stored in a machine register, which will be used later, without immediately writing it back to the appropriate location of the stack at the discretion of the virtual machine. Values ​​will be flushed back to the call stack if and when necessary (i.e. when you call another method, use different synchronization constructs or it needs a register for another calculation, etc.).

+3
source

Here is the source repository for dalvik, you can walk through the search guide. source for android

+1
source

Source: https://habr.com/ru/post/905045/


All Articles