How to understand iTunes + and + + I from the java byte code layer
Today, I will talk to you about how to understand iTunes + and + + I from the java byte code layer, which may not be understood by many people. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something from this article.
Program purpose
From the java bytecode layer, why after I = iByte +, the result is the value before + 1. The result is the value after + 1 after iDiversioni.
Key instruction
Iload_: takes values from the local variables table and pushes them into the Operand stack.
Istore_: is taken out of the stack and then stored in the local variable table.
Public class TestIPulsPlus {public static void main (String [] args) {int I = 8; I = I = + + I; System.out.println (I);}}
ITunes + execution result:
eight
Use jclasslib to view iBytecode
Find the Code area of the main method:
Figure: iSuppli + bytecode
Bytecode interpretation
0 bipush 8
Press the number 8 into the Operand stack and change it to int before pressing the stack.
2 istore_1
8 out of the stack and saved to the local variable table numbered 1.
Figure: the local variable numbered 1 is 1
The above two lines of instructions complete the int I = 8; line of code.
3 iload_1
An int value of 8 is obtained from the local variable table. Then press it to the Operand stack.
4 iinc 1 by 1
The I in the local variable table is operated by + 1. At this time, the value in the stack is 8, and the I in the local variable table is 9.
7 istore_1
8 out of the stack and saved to the local variable table numbered 1. That is, assign a value to the I variable. The I value of the local variable scale changed from 9 to 8.
Next, interpret the bytecode of iBytecode
Figure: iBytecode (bytecode)
+ + I sample source code public class TestIPulsPlus {public static void main (String [] args) {int I = 8 X / I = I = I; System.out.println (I);}}
The execution result is:
nine
The interpretation of the bytecode of iBytecode
0 bipush 8
Press the number 8 into the Operand stack and change it to int before pressing the stack.
2 istore_1
8 out of the stack and saved to the local variable table numbered 1.
Figure: the local variable numbered 1 is 1
The above two lines of instructions complete the int I = 8; line of code.
3 iinc 1 by 1
The I in the local variable table is operated by + 1. At this time, the I in the local variable scale is 9.
6 iload_1
An int value of 9 is obtained from the local variable scale. Then press it to the Operand stack.
7 istore_1
9 out of the stack and saved to the local variable table numbered 1. That is, assign a value to the I variable.
Referenc
Chapter 6. The Java Virtual Machine Instruction Set
Summary
Lines 3 and 4 are opposite to each other.
ITunes + executes iload_1 before iinc 1 by 1.
Iload_1: get an int value of 8 from the local variable table. Then press it to the Operand stack.
Iinc 1 by 1: perform + 1 operation on the I in the local variable scale. At this time, the value in the stack is 8, and the I in the local variable table is 9.
Istore_ 1, you get 8 in the stack, so the final result is 8.
For + + I, iinc 1 by 1 is executed first, followed by iload_1.
Iinc 1 by 1: perform + 1 operation on the I in the local variable scale. At this time, the I in the local variable scale is 9.
Iload_1: get the int value 9 from the local variable table. Then press it to the Operand stack.
Istore_ 1, you get 9 in the stack, so the final result is 9.
After reading the above, do you have any further understanding of how to understand iByte + and + + I from the java bytecode layer? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.