Java class post-compilation class file overview (bottom)

Source: Internet
Author: User

Specific examples of

Java files

Package Com.weixuan.test;public class MyTest {private int age;private String name;public int getage () {return age;} Public String GetName () {return name;} public void Setage (int.) {this.age = age;} public void SetName (String name) {this.name = name;} public static void Main (string[] args) {}}

Compile with Javac-g:vars Mytest.java, display localvariable

C:\users\weixu_000\desktop>javac-g:vars Mytest.javac:\users\weixu_000\desktop>javap-verbose Mytest.classclassfile/c:/users/weixu_000/desktop/mytest.class last modified 2015-7-5;  Size 708 bytes MD5 checksum 2d2527c48aba8637fbf99840391879aapublic class Com.weixuan.test.MyTest minor version:0 major version:52 flags:acc_public, acc_superconstant pool: #1 = methodref #5. #28//Java/lang/object. " <init>:() V #2 = Fieldref #4. #29//Com/weixuan/test/mytest.age:i #3 = Fieldref #4. #   //com/weixuan/test/mytest.name:ljava/lang/string; #4 = Class #31//Com/weixuan/test/mytest #5 = Class #32//Java/lang/ob Ject #6 = Utf8 Age #7 = Utf8 I #8 = Utf8 name #9 = Utf8 Lj  ava/lang/string;             #10 = Utf8 <init> #11 = Utf8 () V #12 = Utf8 Code #13 = Utf8  Localvariabletable #14 = Utf8 this #15 = Utf8 lcom/weixuan/test/mytest;               #16 = Utf8 Getage #17 = Utf8 () I #18 = Utf8 getName #19 = Utf8  () ljava/lang/string;               #20 = Utf8 Setage #21 = Utf8 (I) V #22 = Utf8 setName #23 = Utf8               (ljava/lang/string;) v #24 = Utf8 main #25 = Utf8 ([ljava/lang/string;) v #26 = Utf8  args #27 = Utf8 [ljava/lang/string; #28 = Nameandtype #10: #11//"<init>":() V #29 = Nameandtype #6: #7//age:i #30 = Nam  Eandtype #8: #9//name:ljava/lang/string; #31 = Utf8 com/weixuan/test/mytest #32 = Utf8 java/lang/object{public com.weixuan.test.MyTe    St (); Descriptor: () V flags:acc_public code:stack=1, Locals=1, args_size=1 0:aload_0 1:invokespec        Ial #1          Method java/lang/object. "       <init> ":() V 4:return localvariabletable:start Length Slot Name Signature 0  5 0 This lcom/weixuan/test/mytest;    public int getage ();      Descriptor: () I flags:acc_public code:stack=1, Locals=1, args_size=1 0:aload_0 1:getfield         #2//Field age:i 4:ireturn localvariabletable:start Length Slot Name Signature 0 5 0 This lcom/w  Eixuan/test/mytest;    Public java.lang.String getName ();    Descriptor: () ljava/lang/string;                  Flags:acc_public code:stack=1, Locals=1, args_size=1 0:aload_0 1:getfield #3         Field name:ljava/lang/string; 4:areturn localvariabletable:start Length Slot Name Signature 0 5 0 This lcom/w  Eixuan/test/mytest;    public void setage (int); Descriptor: (I) V flags:acc_public Code: stack=2, locals=2, args_size=2 0:aload_0 1:iload_1 2:putfield #2/         /Field Age:i 5:return localvariabletable:start Length Slot Name Signature 0 6 0 This lcom/we            Ixuan/test/mytest;    0 6 1 Age I public void SetName (java.lang.String);         Descriptor: (ljava/lang/string;) V flags:acc_public code:stack=2, locals=2, args_size=2 0:aload_0         1:aload_1 2:putfield #3//Field name:ljava/lang/string; 5:return localvariabletable:start Length Slot Name Signature 0 6 0 This lcom/we            Ixuan/test/mytest;  0 6 1 name ljava/lang/string;    public static void Main (java.lang.string[]); Descriptor: ([ljava/lang/string;) V flags:acc_public, Acc_static code:stack=0, Locals=1, args_size=1 0 : Return Localvariabletable:starT Length Slot Name Signature 0 1 0 args [ljava/lang/string;} 

The corresponding byte code

Cafe babe 0000 0034 001f 0a00 0500 1a090004 001b 0900 0400 1c07 001d 0700 1e010003 6167 6501 0001 4901 0004 6e61 6d650100 124c 6a61 7661 2f6c 616e 672f 53747269 6e67 3b01 0006 3c69 6e69 743e 01000328 2956 0100 0443 6f64 6501 000f 4c696e65 4e75 6d62 6572 5461 626c 6501 00066765 7441 6765 0100 0328 2949 0100 07676574 4e61 6d65 0100 1428 294c 6a61 76612f6c 616e 672f 5374 7269 6e67 3b01 00067365 7441 6765 0100 0428 4929 5601 00077365 744e 616d 6501 0015 284c 6a61 76612f6c 616e 672f 5374 7269 6e67 3b29 56010004 6d61 696e 0100 1628 5b4c 6a61 76612f6c 616e 672f 5374 7269 6e67 3b29 5601000a 536f 7572 6365 4669 6c65 0100 0b4d7954 6573 742e 6a61 7661 0c00 0a00 0b0c0006 0007 0c00 0800 0901 0017 636f 6d2f7765 6978 7561 6e2f 7465 7374 2F4D 79546573 7401 0010 6a61 7661 2f6c 616e 672f4f62 6a65 6374 0021 0004 0005 0000 00020002 0006 0007 0000 0002 0008 0009 00000006 0001 000a 000b 0001 000c 0000 001d0001 0001 0000 0005 2ab7 0001 b100 00000100 0d00 0000 0600 0100 0000 0300 01000 e00 0f00 0100 0c00 00001d00 0100 01000000 052a b400 02ac 0000 0001 000d 00000006 0001 0000 0009 0001 0010 0011 0001000c 0000 001d 0001 0001 0000 0005 2ab40003 b000 0000 0100 0d00 0000 0600 01000000 0d00 0100 1200 1300 0100 0c00 00002200 0200 0200 0000 062a 1bb5 0002 b1000000 0100 0d00 0000 0a00 0200 0000 11000500 1200 0100 1400 1500 0100 0c00 00002200 0200 0200 0000 062a 2bb5 0003 b1000 000 0100 0d00 0000 0a00 0200 0000 15000500 1600 0900 1600 1700 0100 0c00 00001900 0000 0100 0000 01b1 0000 0001 000d0000 0  006 0001 0000 001a 0001 0018 00000002 0019

A specific explanation

1. Magic number: First four bytes cafe babe, coffee baby

2, Secondary major version: next four bytes 0000 0034

3, Chang

The first two bytes are constant pool capacity counters, followed by constant pools

001F: Constant Pool capacity Counter decimal 31 that is, there are 30 constants, and the index is 1 to 30

4. Access Mark

After the Chang is over, it is the access flag.

0021: Only Acc_public and Acc_super are true. That is, the class is a normal class of public, with no other modifiers

5. Class index, parent class index and interface index collection

After the access flag, it is the class index, the parent class index, and the interface index collection.

0004 0005 00000004: Class index is 4, look up table, #4 = Class #29//Com/weixuan/test/mytestindex is, #29 = Utf8 com/weixuan/test/mytest Full class name 0005: The parent class index is 5, look up the table, #5 = Class #30//Java/lang/objectindex is a, #30 = Utf8 Java/lang/object The parent class is Object0000: interface information is 0, no interface information.

6. Field table Collection

0002 0002 0006 0007 0000 0002 0008 0009 0000

After the interface index collection is the two-byte field capacity counter for the field table

0002:2 Properties. In the source code is, age and name, we verify:

0002 0002 0006 00070002: Access flag, check field access flag table, 0002--->0x0002--->acc_private0006:name_index, value is 6, check table, first property is age#6 = Utf8 AGE0007: The descriptor index of the first property, the value is 7, the table, the property type is I--->int#7 = Utf8 I0000: attribute information, no 0002: The second attribute of the access flag, Acc_private0008:name_index, the value is 8, Look up the table, the second property is name#8 = Utf8 name0009: Descriptor index value is 9, look up table, L object type, that is, String object type # = Utf8 ljava/lang/string;0000: attribute information, none

7. Collection of method tables

The end of the field table is the method capacity counter at the beginning of the method table collection, followed by the contents of the method table

0006 0001 000a 000b 0001 000c

6 Methods of 0006:methods_count

The source code is getname (), Getage (), SetName (), Setage (), main (), and the <init> method added by the compiler

0001: Access flag 0001---> Acc_public,public 000a:name_index, value 10, check table # # = Utf8 <init>000b: Descriptor index, 11, table, method is public void () type, no parameter #11 = Utf8 () V0001: Number of properties 1 000c: The attribute index value is 12 table, the corresponding constant is code#12 = Utf8 Code

8, compile, Javac-g:vars Mytest.java, can display localvariable

Analyze the Code property of the <init> method

Public com.weixuan.test.MyTest ();d escriptor: () vflags:acc_publiccode:stack=1, Locals=1, args_size=10:aload_01: Invokespecial #1//Method java/lang/object. " <init> ":() V4:returnLocalVariableTable:Start Length Slot Name Signature0 5 0 this lcom/weixuan/test/mytest;

As you can see, statck:1,local:1,codelength:5

Find the appropriate byte code

0001 0001 0000 0005 2AB7 0001 b1

0001 0001 0000 0005 corresponds to Stack,local,codelength

2AB7 0001 B1 is the content of code

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java class post-compilation class file overview (bottom)

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.