Do-it-yourself Java virtual machine notes

1. java = jvm + library

2. jvm = data type + memory management and GC + instruction parsing + function call + multithreading + JIT

3. Data type = atomic type + reference + array

4. Dynamic operation: stack = PC + thread stack

Each frame = one call depth = local variable table + operand stack

5. An example of an instruction execution:

public static float circumference(float r)

{

float pi = 3.14f;

float area = 2 * pi * r;

return area;

}

The bytecode is as follows:

00 ldc #4 top of stack 3.14

02 fstore_1 local data area pi

03 fconst_2 top of stack 

04 fload_1 local data area -- "stack top

05 fmul pops 2 data from the stack, and pushes the result onto the stack

06 The variable fload_00 (the incoming parameter r) is pushed onto the stack

07 fmul pops and operates

08 fstore_2 is stored in area

09 fload_2 local -- "stack top

10 return popup passed to the caller

 

6. Class and Object

1》Class= constant pool + (static) domain, method, instance or class variable occupies space

2"Method=operand stack and local variable table size, method bytecode array

3" constant pool: literals, string references

4" command new putstatic and getstatic; putfield and getfield; instanceof and checkcast; ldc

5" runtime needs to maintain all Classes and all Objects

 

7. Method call

invokestatic invokespecial includes constructors, private methods and via super

The superclass method invoked by the keyword.

invokeinterface invokevirtual

invokedynamic 

XXreturn

The core is to find the method area corresponding to the string, and then interpret and execute

8, the realization of the array

1" The array class is generated by the Java virtual machine at runtime. The class name of an array is the left square bracket ([) + the type descriptor of the array element; the type descriptor of an array is the class name itself. For example, the class name of int[] is [I, the class name of int[][] is [[I, the class name of Object[] is [Ljava/lang/Object; and the class name of String[][] is [ [java/lang/String etc.

2" command

newarray

anewarray

multianewarray

XXaload and XXastore

arraylength

9. Library

1" JNI: Register and call local functions 

2" Exception: It is necessary to record the information of the java call stack by native

3" Initialization before Main (native initialization of the System class)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326379078&siteId=291194637