JVM-graphics display bytecode execution engine execution process, jvm-bytecode

Source: Internet
Author: User

JVM-graphics display bytecode execution engine execution process, jvm-bytecode

In my previous blog JVM-String comparison-bytecode analysis, I introduced the reasons for String comparison. By analyzing bytecode, this blog will show the internal bytecode execution process of the method.

Not to mention, paste the Java method code we will analyze:

public static void bb(){     String s1="a"+"b";     String s2 = "ab";     p(s1==s2);//true}

Paste the bytecode of the Java method to be analyzed:

Public static void bb (); flags: ACC_PUBLIC, ACC_STATIC Code: stack = 2, locals = 2, args_size = 0
0: ldc #5 // String AB pushes the String "AB" from the constant pool to the top of the stack. 2: astore_0 pushes the reference type of the top stack (String "AB ") store the first local variable 3: ldc #5 // String AB to push the String "AB" from the constant pool to the top 5: astore_1 of the stack (String "AB ") store the first local variable 6: aload_0, push the first local variable ("AB") to the top of the stack 7: aload_1, and then the second local variable ("AB ") push to the top of the stack 8: if_acmpne 15 compare the top two reference type values, the results are different jump (the same here) 11: iconst_1 push int type 1 to the top of the stack 12: goto 16 jump to 16 bytecode offset unconditionally 15: iconst_0 16: invokestatic #10 // Method java/lang/Boolean. valueO calls the static method Boolean. valueOf (); and press true of the returned Boolean type to the top of the stack f :( Z) Ljava/lang/Boolean; 19: invokestatic #11 // Method p :( Ljava/lang/Object;) V calls the static Method p (true); outputs true 22: return returns void from the current Method

From Code: the first line below, we know that the depth of the operand stack is 2, the local variable space is 2 slots, and the number of parameters is 0.

 

If you copy all the images, you will see the results of dynamic execution.

----------------------------------------------------------

 

 

 

 

If something is wrong, please correct it.

If you agree with my blog post, it is not easy for the blogger to write this blog.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.