If you don’t know anything about JVM, it is recommended not to talk about performance, and performance is not measured this way.
The parameters and local variables of the method correspond to the local variable table 3 in the virtual machine stack 1stack frame2. The reference type occupies one slot SLOT, so the difference in your second way of writing is that the stack frame has one more slot. Create After the String object, the reference of the object is on the operand stack String对象后,对象的引用在操作数栈4上,通过aload指令保存到本地变量表,调用testString方法的时候通过aload4
and is saved to the local variable table through the aload instruction. When calling the testString method, pass aload instruction is pushed to the top of the operand stack.
Summary: There is one more SLOT in the stack frame and two more instructions in the method call. The redundant instructions will be eliminated after JIT warm-up. There is no actual difference.
If you don’t know anything about JVM, it is recommended not to talk about performance, and performance is not measured this way.
The parameters and local variables of the method correspond to the local variable table 3 in the virtual machine stack 1stack frame2. The reference type occupies one slot SLOT, so the difference in your second way of writing is that the stack frame has one more slot. Create After the
and is saved to the local variable table through theString
object, the reference of the object is on the operand stackString
对象后,对象的引用在操作数栈4上,通过aload
指令保存到本地变量表,调用testString方法的时候通过aload
4aload
instruction. When calling the testString method, passaload instruction is pushed to the top of the operand stack.
Summary: There is one more SLOT in the stack frame and two more instructions in the method call. The redundant instructions will be eliminated after JIT warm-up. There is no actual difference.
-
2.5.2. Java Virtual Machine Stacks ↩
-
2.6. Frames ↩
-
2.6.1. Local Variables ↩
-
2.6.2. Operand Stacks ↩
🎜