Java virtual machine memory model

  JVM is an abbreviation JavaVirtualMachine (Java virtual machine), JVM is a specification for A computing device, which is a fictional computer, is passed over the actual computer simulation of various computer-implemented functions. A very important feature of the Java language is platform-independent. The use of Java Virtual Machine is the key to achieving this characteristic. General high-level language if you want to run on different platforms, at least needs to be compiled into a different object code. And after the introduction of Java virtual machine language, Java language does not need to be recompiled to run on different platforms when. Java Virtual Machine using Java language information associated with a particular shielding platform, so that only Java language compiler to generate object code (bytecode) running in the Java virtual machine can run without modification on multiple platforms . Java Virtual Machine byte code, when executed, the bytecode interpreter into machine instructions executed on a particular platform. This is Java's ability to "compile once, run anywhere" reasons.

  stack:

  Heap when the virtual machine is created startup, is used to store objects of memory space, almost all of the objects are placed on the heap, which is an area shared by the threads.

  Such a description in the specification:

  All object instances and arrays to be allocated on the heap, but with the development of the JIT compiler technology matures and escape analysis, the stack distribution / scalar for

  In other optimization techniques will lead to some subtle happens, all objects are allocated on the heap gradually becomes less categorical.

  java heap garbage collection mechanism is the main place, so the stack can also be subdivided into the new generation, the old era, the Cenozoic is divided into segments, then Eden space / From Survivor space / To Survivor space.

  The java virtual machine specification, Java heap, but may be in a logically contiguous memory space is not physically connected, either in achieving a predetermined size may be extensible, the current mainstream virtual machine is extensible according to the space achieved (and controlled by -Xmx -Xms). If there is no memory in the heap memory allocation completion instance, and the heap can not be extended, it will throw out of memory exception.

  Virtual machine stack:

  Java memory model is the method of execution of the virtual machine stack described, the depth of thread private, no larger than a stack of virtual machines allowed depth StackOverflowError will throw an exception. If the virtual machine stack is dynamically extensible, at the time of application will be extended memory, if you can not apply enough memory, an OutOfMemoryError will be reported.

  Stack frame:

  Support for virtual machine data structures, method calls and method of execution. He is the stack element virtual machine is running a virtual machine in the data area of ​​the stack. Stack frame holds the local variable table, the operand stack, dynamic link, the method returns the address and other information.

  Each method call from start to finish operation is called method is pushed and the process stack.

  Code during compilation, the stack frame to determine how much of the local variable table and how deep the operand stack, so when a data affect how much memory will not be running variable stack frame needs to be allocated, but only depending on the specific virtual machine implementation.

  Local variable table: space for storing local variables defined in the method parameters and method of storage, all the basic data types may be stored during compilation understood, reference type and the return address (address pointing to a byte code instruction). It is the smallest unit of the table 32, a variable called slots, if the memory 32 is greater than two contiguous space slots will be assigned.

  Operand stack: the stack is also known as artificial, it is a last in, first out stack. jvm underlying bytecode is stack-based instruction set type, all opcodes are data on the operand stack operates, for each method call, will create a jvm operand stack, to use for the calculation. Operand stack size is also known compile time. Operand stack operations is arbitrary Java data types.

  When a method has just started, its operand stack is empty, and a method of performing with the implementation of the byte code instructions, copied constant or variable fields from local variable table or object instance written into the operand stack, with the re-calculated elements pop stack into local variables or the table is returned to the caller method, i.e. the pull / push operation. During one complete often contain a plurality of such method of performing a push / push process.

  Dynamic Link: symbol resolution phase will be in the class loading phase reference into direct reference, is called static resolution, the other part will be transformed in every run is a direct reference period ah, known as dynamic linking. Each stack frame contains the method belongs to the stack frame a reference to the runtime constant pool, which is to support dynamic link call process method.

  Methods District: Zhengzhou gynecological examination price http://www.zzkdfk.com/

  , Such as virtual machine loading class information, compiled code, etc. The method of the main storage area of ​​the class metadata. 1.8 jdk implemented before the method is referred to as area A permanent generation region, this part of the region using the JVM memory, but after it is removed permanently jdk8 generation element used to achieve space, except that space is not used jvm memory element , but the use of system memory.

  After removal of the permanent generation string constant pool is placed heap, it may be convenient to collect garbage collector, the runtime constant pool is placed dimensional space, placed runtime constant pool static variables, bytecode and other important information, we can put it where he called the method area.

  Native method stacks:

  Native method stacks and stacks similar to the virtual machine, the object difference is that native method stacks services are performed by native methods jvm, virtual machine and method java jvm service is performed. As for the losers native method, the simple explanation is that non-java java method call.

  Program Counter:

  This is a small memory space, only a java virtual machine specification does not require a memory area overflow abnormality, is to mark the line number of the currently executing thread is executed, when executing native method, program counter value is null. In the virtual machine that works by changing the value of the counter to determine the next instruction to be executed. We know JVM implementation is multi-threaded by the CPU round-robin (i.e., alternately switching the thread and allocated processor execution time) algorithm is implemented. In other words, because a thread might run out of time slice is suspended in the implementation process, while another thread time slice to get started. When the suspended thread to reacquire the time slice when it is suspended in order to continue from where it is necessary to know the location to which it was last executed in the JVM, to record a thread through the program counter bytecode execution position. Therefore, the program counter is characteristic with thread isolated, that is, each thread has its own independent work counter.

Guess you like

Origin www.cnblogs.com/gnz49/p/12059489.html