jvm 字节码学习2

关于方法表的查找方法:

  1. 找到访问控制access_flag 00 01==>public

  2. 找到简单名字name_index 00 17==>inc

  3. 找到描述符descriptor_index 00 18==>()I
    翻译过来: public int inc()

  4. 找到attribute_count 00 01==>代表只有一个属性表

  5. 对照属性表 attribute_info (u2,u4,u1*length(length 就是u4的值))

  6. 找到attribute_name_index 00 11==>code

  7. 找到attribete_length 00 00 00 be==>表示190个u1(be等于十进制的190)

max_stacks 方法的栈深
max_locals 方法的本地变量数量
args_size 方法的参数有多少个(默认是this,即为1,如果方法是static,那么就是0)

  1. 找到max_stacks最大栈深 00 01==>1 max_stacks

  2. 找到max_locals 最大变量数 00 05>5
    10.找到code_length代码行数 00 00 00 18
    >24
    11.对应的字节码:

    0x04 ===> iconst_1
    0x3c ===> istore_1
    putstatic #3 ===> b3
    jvm 虚拟机字节码指令表 https://www.cnblogs.com/GarfieldEr007/p/9943528.html

  3. 异常表(都是u2)
    00 00 00 05 00 0a 00 02==>from:0 to:5 target:10
    从LineNumberTable中可以看到0 表示源码中的第13行,5表示第19行,即图中的x=3, target:10 表示有异常就会执行第15行,即catch(Exception e).

 Exception table:                                                                                                                                                                                                                                from    to  target type                                                                                                                                                                                                                          0     5    10   Class java/lang/Exception                                                                                                                                                                                                    0     5    21   any                                                                                                                                                                                                                         10    16    21   any                                                                                                                                                                                                                   LineNumberTable:                                                                                                                                                                                                                               line 13: 0                                                                                                                                                                                                                                   line 14: 2                                                                                                                                                                                                                                   line 19: 5                                                                                                                                                                                                                                   line 14: 7                                                                                                                                                                                                                                   line 15: 10                                                                                                                                                                                                                                  line 16: 11                                                                                                                                                                                                                                  line 17: 13                                                                                                                                                                                                                                  line 19: 16                                                                                                                                                                                                                                  line 17: 18                                                                                                                                                                                                                                  line 18: 21                                                                                                                                                                                                                                  line 19: 22                                                                                                                                                                                                                                  line 20: 24 

13:本地变量表(LocalVariableTable)
start+length:一个本地变量的作用域
slot: 几个槽来存储
name:简单名字

//max_locals 最大变量数
LocalVariableTable:  
 Start  Length  Slot  Name   Signature                                                                                                                                                                                                            0      26     0  this   Lcom/icil/jvm/test2/TestClass;                                                                                                                                                                                       2       8     1     x   I                                                                                                                                                                                                                   13       8     1     x   I                                                                                                                                                                                                                   24       2     1     x   I                                                                                                                                                                                                                   11      10     2     e   Ljava/lang/Exception;   

14: signature: 伪泛型

原文地址:https://www.cnblogs.com/wanthune/p/12830009.html