JVM
- Java SE Specifications
- The Java Virtual Machine Specification - Hotspot VM
- 4.The
class
File Format - 6.The Java Virtual Machine Instruction Set
- 7.Opcode Mnemonics by Opcode
- 4.The
- The Java Language Specification
- https://www.cnblogs.com/mengchunchen/p/7819051.html
Concept
- JVM 指令由一个字节长度的操作码和零至多个操作数构成
Java 字节码描述符
- Table 4.3-A. Interpretation of field descriptors
- 字段描述符 Field Descriptors
- 方法描述符 Method Descriptors,语法:(参数类型字段描述符)返回类型描述符
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
- javap -verbose Demo // 不用带后缀.class
- 局部变量表
看到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表示的都是方法的名字。

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);
}

局部变量表:Index 0 表示 this, Index 1 表示 x
command
整型入栈指令
-
iconst_<i>
Push the int constant <i> (-1, 0, 1, 2, 3, 4 or 5) onto the operand stack. -
bipush byte
取值 -128~127 -
sipush byte
取值 -32768~32767 -
ldc index
取值 -2147483648~2147483647
网友评论