Depth understanding of java virtual machine (11): stack-based bytecode interpreter execution engine

1, interpreted

Compilation process is as follows

 

 2, the stack-based instruction set and register-based instruction set

Java compiler output instruction stream, is based on the basic stack instruction set architecture, most of the instruction stream instructions are zero address, depending on the operation hours of work. As opposed to a register based instruction set, i.e. the current pc instruction set supported. Difference between the two, for example as follows:

1 + 1 stack-based instruction set iconst_1, iconst_1, iadd, istore_0, set based on an instruction register mov eax 1, add eax 1. The main advantage of the current instruction is a stack-based portability, provided directly by the hardware registers, a program dependent on the hardware directly. Stack based instruction set can decide whether to register frequently accessed data into better performance, compact code, compiler implements easier. Since the number of instructions in the stack implementation and the memory, the stack-based instruction set to be slower.

 

3, stack-based interpretation of the implementation process

public int calc(){
int a=100;
int b=200;
int c=300;
return (a+b)*c;
}

public int calc():
Code:
Stack=2,Locals=4,Args_size=1
0:bipush 100
2:istore_1
3:sipush 200
6:istore_2
7:sipush 300
10:istore_3
11:iload_1
12:iload_2
13:iadd
14:iload_3
15:imul
16:ireturn

This instruction process to perform the

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/xiaofeiyang/p/11933388.html