Java Virtual Machine architecture

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Sophisticated_/article/details/89364418

Java Virtual Machine specification describes an abstract of the virtual machine behavior, rather than a widely used any kind of virtual machines. To achieve a java virtual machine, only one instruction per class bytecode files require read correctly, and the operating instructions can execute properly implied. Virtual machine specification does not explicitly described in detail, the virtual machine should not be the designer creativity to tie him down, designer interior absolute discretion details Virtual Machine Specification never described. Such as: memory layout runtime data area, which GC algorithm selection, whether bytecode instructions optimized internal (e.g., using time compiler to compile the bytecode into machine code).

class file format

Code compiled after the implementation of the java virtual machine uses a platform-neutral binary format, this format is called class文件格式. class file format representation precisely defines classes and interfaces, including a target platform dependent file format in practice, such as the byte order and the like.

type of data

Data types Java virtual machine can operate can be divided into two categories: primitive types and reference types . Corresponding thereto, there are the original value and the reference value , they can be used for variable assignment, transmission parameters, the method returns, arithmetic operation.
Java virtual machine is directly supported by the object, the object here can be an instance of a class dynamically allocated, it can be an array. Using the virtual machine referencetype is a reference to an object, the type of reference is a pointer to the object is conceivable, each object may be multiple references to it, the object of the operation, transmitting and checking by reference in its reference the type of data

Original type and value

Java virtual machine supports primitive data types including numeric types , boolean type , returnAddress type

  • 数值类型:byte、short、int、long、char、float、double
  • boolean类型: Boolean values ​​true and false, there is no bytecode instructions dedicated boolean value java virtual machine, boolean values ​​are replaced with a java virtual machine type data compiled int
  • returnAddress类型: Pointer to an operation code, this code and virtual machine operation corresponding to the command, the virtual machine supports primitive types, only the data type returnAddress not correspond directly to the Java language

Reference types and value

Java Virtual Machine There are three reference types: class types , array types , interface types . These types of reference values, respectively, refers to the instance dynamically created array instance, implements an instance of a class instance or an array interface.

There is also a special reference type of value: nulla reference when not point to any object, its value is null. Is a null reference, does not have any actual run-time type, but can be transformed into any type of reference. The default value is a reference type is nul

Run-time data area

Here Insert Picture Description

pc register

Java virtual machine supports multiple execution threads, each thread has its own pc register, at any time, a java virtual machine thread will execute the code of a method, this method is being called the thread execution thread currently method . A register storing instructions related to site information, since the CPU time slice limits wheel, during concurrent execution of many threads, any time a determination of a core processor or a multi-core processor, a thread will perform in a instruction. This will inevitably lead to frequent interruptions or resume, how to ensure that there is no difference between the points of it? After each thread created, will have its own program counter and the branch frame, the program counter is used to store the offset and row number designator executing instructions and the like, a thread of execution, or the program counter to be dependent recovery.

If this method is not native, that pc register is saved Java虚拟机正在执行的字节码指令的地址, if the method is native, that pc register is undefined. pc register can hold at least the value of a data type returnAddress or a pointer associated with the local platform

Java Virtual Machine stack

Every java virtual machine thread has its own private Java virtual machine stack, the stack and threads simultaneously create, to store 栈帧, it is to store a local variable with a number of good results not yet been calculated, and it fills in the method calls and returns very important role
Here Insert Picture Description

Java heap

The heap is available to each thread shared runtime memory region, but also for the region all class instances and array objects allocate memory. Heap create, store the virtual machine is started when GCvarious objects managed by these managed objects can not be displayed without having to be destroyed

GC过程: Heap is divided into two blocks of the new generation and the old era. Objects produced in the beginning of the new generation into the old years when entering its twilight years, but it's too old to accept large objects that can not fit in the new generation. Eden new generation region = 1 + 2 Survivor areas. Most of the objects in the Eden area generated when loading area filled Eden, will trigger YoungGarbage Collection, namely YGC. Garbage collection time, achieve clear strategy in the Eden area, the object is not directly referenced recovery. Still alive object will be transferred to Survivor areas, there is really worthy of the name of this area. Survivor Sl divided into two memory space and so, to a piece of space? YGC every time, they will live objects copied to the piece of unused space, then the space currently being used completely removed, using state of the two exchange space. If the upper limit YGC objects to be transferred is greater than the capacity of Survivor areas, shellfish lj directly handed over to the old era. If some of the objects that no enterprise can always go in exchange to exchange Survivor areas of the new generation, it would be wrong. Each object has a counter, each will be added YGC l. -XX:MaxTenuringThresholdConfiguration parameters can explain the value of the counter reaches a certain value, the target was promoted from the old to the new generation's. If this parameter is configured as I, then move directly to the old year from the Eden area of the new generation. The default value is 15, after the exchange Survivor 14 times in the area, was promoted to the old era.

Dimensional space

Perm region predecessor element space has been eliminated, different from the permanent generation element in the local memory space allocation. In JDK8, all contents Perm region move heap memory string constant, other meta information including the class, fields, static properties, methods, and so the constant movement space Yuan
Here Insert Picture Description

  • object class meta-information, static properties System.out, and so there is an integer constant 10 million yuan space
  • String constant pool, which is the actual object is stored in the heap memory
Native method stacks

Achieve java virtual machine might be used to support traditional native method stack, this stack is native method stacks, when the java virtual machine using other language (C) to achieve the command interpreter, you can also use the native method stacks

Stack frame

Stack frames are used to store data structures and the data part of the process results, but also for handling dynamic linking, return values, and methods exception dispatcher. With the method call stack frame is created, with the method ends destruction, storage space stack frame by the thread that created it distributed java virtual machine stacks, each stack frame has its own local variable table, the operand stack and points to the current method belongs to the class the run always quote the amount of pool. Stack frame is a thread-local private data, not possible to refer to another stack frame in a thread stack frame

Local variable table

Local variable table is a method parameters and local variables storage area. With respect to the preparation phase and the properties of the variable class initialization phase, the local variable is not the preparatory phase, it must be explicitly initialized. If a non-static method, the index[0]storage location is an instance method belongs to an object reference, then stores the parameters and local variables.

Operand stack

An operand stack is initially empty bucket structure stack. During execution method, there will be all kinds of people and write commands to extract information stack. JVM is a stack-based execution engine's execution engine, which refers to the operation of the stack stack. The method defined depth bytecode is stack-based instruction set type, stack meta attribute information stack

Dynamic Link

Each stack frame contains a constant pool of the current in the reference method, with the aim to support dynamic linking method invocation.

Methods return address

There are two exits from performing the methods of: a first, normal exit, i.e., any method to perform a normal return bytecode instructions, the second, abnormal exit. Whatever retreat
a case, the position of the current method is called to return to. The method of exit process is equivalent to eject the current stack frame

Representation of an object

Java virtual machine specification does not mandate a predetermined object representing the internal structure of the virtual machine oracle some implementations, a reference to an object is a pointer to the instance handle pointer, the handle also contains two pointers, a pointer to a table in which, various methods of the object table contains also contains a pointer to the class object, the object class used to represent the type of object; object handle pointer to another example of data allocated on the heap

Java threads and memory

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/Sophisticated_/article/details/89364418