Data sharing between stack frames of virtual machine memory optimization technology

In the general model. Two different stack frames generally exist independently, but most JVMs will perform some optimizations during the implementation process, so that the two stack frames overlap. (Mainly reflected in the case of parameter passing in the method), so that the operand stack of the lower stack frame and some local variables of the upper stack frame overlap.

Take the following program as an example:

image.png

image.png

Here, the formal parameter x of the caller is put into the operand stack, and at the same time, the local variable table of the callee also shares this area. This not only saves some space, but more importantly, you can directly share part of the data when the method is called. No additional parameter assistance is required.

Guess you like

Origin blog.csdn.net/weixin_47184173/article/details/113576740