JVM Byte code

2022-07-04  本文已影响0人  Tinyspot

JVM

Concept

Java 字节码描述符

term Type Interpretation
B byte signed byte
C char Unicode character code,encoded with UTF-16
D double double-precision floating-point value
F float single-precision floating-point value
I int integer
J long long integer
LClassName ; reference an instance of class ClassName
S short signed short
Z boolean true or false
[ reference one array dimension
由于long类型的L被引用类型占了,所以long类型用J
LClassName; 引用类型,“L” + 对象类型的全限定名 + “;”
[ 一维数组
Ljava/lang/String;  String
Ljava/util/List;    List<Order> orderList;
[Ljava/lang/Object; Object[]
[Z                  boolean[]   
[Lcom/pojo/Order;   Order[] orders;

// Method Descriptors:  ( {ParameterDescriptor} ) ReturnDescriptor
若返回类型为 void,则以 ‘V’ 结尾
注意方法名称和参数名称本身并非方法描述符的一部分,所以在表中使用了占位符
(Ljava/lang/String;)I       int method(String x)
(ILjava/lang/String;)V      void method(int x, String y)
(I)Ljava/lang/String;       String method(int x)
(Ljava/lang/String;)[C      char[] method(String x)
(ILjava/lang/String;[[Lcom/demo/FileInfo;)V     void method(int x, String y, FileInfo[][] z)

// (ILcom/pojo/Order;J)Lcom/pojo/Order;
public Order getOrder(int anInt, Order order, long aLong) {
    return order;
}
// (ILcom/pojo/Order;J)[[Lcom/pojo/Order;
public Order[][] getOrders(int anInt, Order order, long aLong) {
    return new Order[1][1];
}
// ()Ljava/util/List;
public List<Order> getOrderList() {
    return orderList;
}

Java Byte Code

jclasslib

看到Constant Pool也就是常量池中有22项内容,其中带”Utf8″的就是符号引用。
比如#2,它的值是”com/xrq/test6/TestMain”,表示的是这个类的全限定名;又比如#5为i,#6为I,它们是一对的,表示变量时Integer(int)类型的,名字叫做i;#6为D、#7为d也是一样,表示一个Double(double)类型的变量,名字为d;#18、#19表示的都是方法的名字。

javap-v.jpg

cinit vs init

init is the (or one of the) constructor(s) for the instance, and non-static field initialization.
clinit are the static initialization blocks for the class, and static field initialization.

    public void test(int x) {
        int y = 20;
        int z = x + y;
        System.out.println(z);
    }
image.png

局部变量表:Index 0 表示 this, Index 1 表示 x

command

整型入栈指令

上一篇 下一篇

猜你喜欢

热点阅读