Where are the local variables of an Android app stored?

180 views Asked by At

The Dalvik Virtual Machine (DVM) has a register-based architecture, as opposed to the Java Virtual Machine (JVM) which is stack-based. So I assume that the local variables of an Android app are stored in the registers. Am I correct? If not, please correct me. If yes, what kind of memory is used for the registers? Are the registers part of a CPU (Central Processing Unit) on the smart phone? Where are these registers located in the phone's hardware?

1

There are 1 answers

1
Dave Newton On BEST ANSWER

From https://source.android.com/devices/tech/dalvik/dalvik-bytecode.html:

Because, in practice, it is uncommon for a method to need more than 16 registers, and because needing more than eight registers is reasonably common, many instructions are limited to only addressing the first 16 registers. When reasonably possible, instructions allow references to up to the first 256 registers. In addition, some instructions have variants that allow for much larger register counts, including a pair of catch-all move instructions that can address registers in the range v0 – v65535. In cases where an instruction variant isn't available to address a desired register, it is expected that the register contents get moved from the original register to a low register (before the operation) and/or moved from a low result register to a high register (after the operation).

The registers are in the Dalvik VM--non-native Android code doesn't run directly on the CPU but in the VM. Native code, obviously, is very different.