Use i = i ++ + + + to get you get started JAVAP

zhaozj2021-02-16  63

Keywords: java javap and author contact: xiaozuidaizhi@sina.com ==================================== ============================================================================================================================================================================================================= ====== Abstract: Javap is a good tool for the internal operation mechanism in the program, but it has a statement different from the compiled. This article analyzes the special language phenomenon of i = i i with Java, takes you into the micro world of Java. ============================================================================================================================================================================================================= ========================================== first let's take a look at the javap command and Its basic usage. Javap is the use of the Class files, JavaP, and Java, Java, etc., the SUN is the same, and Java is similar. When you configure the environment variable, Java is similar to JAVAC, Java and other commands. Java's most common usage is also the utmost usage: javap - [parameter] Test, Test is the class file name generated by the Test.java file after Javac compile, that is, before Java, you must compile with Javac. This file, you need to pay attention to it, when using Javap to compile the .class file, do not bring its compact name, otherwise it will be reported. Our most commonly used parameters for Javap is C, which is like Javap -c test usage. If you want to know more about Java's parameters, I recommend you a article "Javap Introduction to the JavaP" You can get this article by querying the title on the home page of the website. Below we enter the topic:

The first example INT i = 0; i = i i; code: 0: iconst_0 Push 0 into the stack / / corresponding assignment statement int i = 0; IConst_0 0 is the initial value 1: iStore_1 from the stack Pop-up this value and store it to the index of the local variable table. / / The corresponding assignment statement, the sentence is assignment, this sentence is stored, index 1 is i, because there is no other variable, so local variables in this example Index constant 2: iLoad_1 Push the value of the local variable table index 1 to the stack // Push the calculation result at the local variable index 1 into the stack temporary storage, the index of the local variable starts, according to this type, this The sentence means that the variable I = 0 first pushes the stack temporary storage 3: IINC 1, 1 local variable table index 1 variable plus 1 // Self-adding variable I 1, then the variable I is 1 6: IINC 1 1 The variables at the local variable table index 1 adds the variable I from 1, then the variable I is 2 9: iLoad_1 Push the value of the local variable table index 1 to the stack // Put the variable I = 2 Push the stack temporary storage 10: IADD pops up two integers from the operand stack and adds them. The resulting integer pushback stack is added to the two temporary integers, namely 0 2 = 2 11: iStore_1 pops up from the stack and stores it to the index of the local variable table. Popping the result of the step plus the result pops up the stack 12: return pops the value from the stack and push it into the operator count of the calling method. Exit method // Return i = 2, calculate the second example I = 0; i = i i ; code: 0: IConst_0 Push 0 into the stack / / corresponding assignment statement int i = 0; iconst_0 0 is the initial value 1: iStore_1 pops up from the stack, and stores it to the index of the local variable table 1 / / Corresponding assignment statement, the above sentence is assignment, this sentence is store 2: IINC 1, 1 Local Variables in the variable table index 1 adds the variable I to 1, then the variable I is 1 5: iLoad_1 Push the value at the local variable table index 1 to the stack // Push the variable I = 1 Stack Temporary Storage 6: ILOAD_1 Push the value at the local variable table index 1 to the stack // Push the variable I = 1 into the stack temporary storage 7: IINC 1, 1 Local variable table index 1 variable plus 1 // The variable i is self-added, then the variable I is 2 10: IADD pops up two integers from the operast stack and adds them.

Push the resulting integer pushback stack // add two temporary integers, namely 0 2 = 2 Note: Although the step is to make i = 2, but not push into the stack storage 11: iStore_1 from the stack This value is popped, and stores it to the index of the local variable table. Pop up the result plugging the result plugging up the stack 12: return from the stack and push it to the call method. Exit method // Return i = 2, the calculation end ========================================= ============================================================== below It is a more complicated example for readers to analyze it.

INT i = 0; i = i i; int J = 0; j = J J; code: 0: iconst_0 1: iStore_1 2: iLoad_1 3: IINC 1, 1 6: IINC 1, 1 9: ILOAD_1 10: Iadd 11: iStore_1 12: Iconst_0 13: IStore_2 14: IINC 2, 1 17: ILOAD_2 18: IINC 2, 1 21: ILOAD_2 22: IADD 23: IStore_2 24: Return

转载请注明原文地址:https://www.9cbs.com/read-16598.html

New Post(0)