jvm Study Notes (1) --- runtime data area

Runtime data area

Program Counter

Program Counter (Program Counter Register) is a small memory space, it can be seen as an indicator of the current line number of thread execution. In the conceptual model of a virtual machine's (only a conceptual model, a variety of virtual machine might go through some achieve more efficient way), when the bytecode interpreter at work is to be selected by changing the value of a counter to be executed instruction, branching, looping, branching, exception handling, thread resume and other basic functions need to rely on the counter to complete.
Since multithreaded java virtual machine is in turn switched mode execution time and processor allocation by threads to achieve, at any time a determined, a processor (for multi-core processors is a kernel) will only execute a thread of instructions. Therefore, in order to restore the thread switch to the correct execution position, each thread requires a separate program counter, each threads independently of each other, independent store, we call this type of memory area for the "thread private" memory.
If the thread is executing a java method, the counter records the address of the virtual machine bytecode instructions being executed, if a native method being executed, the counter value is null, this is only one memory area in the java virtual machine specification does not specify any area OutOfMemoryError situation.

java virtual machine stack

Like the program counter, java VM stack (java virtual machine stacks) is also a thread private, its life cycle and the same thread. Virtual machine stack memory model described java method performed; each method creates a stack frame (stack frame) while performing the local variable table for storing information, the operand stack, dynamic link, the method exports. Each method execution until completion of the procedure is called, a corresponding stack frame process in the virtual machine from the stack to the stack.
Local variable table to store various types of data base of known compiler, object references and returnAdress (address pointing to a byte code instruction) in the java virtual machine specification, this abnormal condition specifies two regions: if the thread request stack depth is greater than the depth of the virtual machine allowable StackOverflowError will throw an exception; if the virtual machine can dynamically extend, if not extended to apply enough memory, it will throw an OutOfMemoryError.

Native method stacks

Native method stacks (native method stack) and the virtual machine stack multi-role is very similar, but the difference between them is the implementation of a virtual machine stack java (bytecode) service, and the local stack method was to use a virtual machine the native service. Like the virtual machine stack, native method stacks StackOverflowError and will throw an OutOfMemoryError.

java heap

java heap (java heap) memory is the biggest piece of java virtual machine management, java heap is shared by all threads in a memory area is created when the virtual machine starts. The sole purpose of this memory area is stored object instance, almost all object instances are here to allocate memory. This is described in the java virtual machine specification is: all object instances and arrays to be allocated on the heap, but with the development of JIT compiler technology matures and escape analysis, allocation on the stack, scalar replacement technology will be optimization cause some subtle changes, all objects are allocated on the heap gradually becomes less "absolutely" the.
java heap is the main area managed by the garbage collector, and therefore often also called "GC heap" (garbage collected heap). From the perspective of memory recall, because now collectors have adopted the basic generational collection algorithm, java heap can also be broken down into: the new generation and the old year: there are again more carefully Eden space, from survivor space, to survivor space . From the perspective of memory allocation point of view, shared by the threads java heap may be divided into multiple threads private allocate a buffer (thread local allocation buffer, TLAB) . But in any case divided, has nothing to do with the storage of content, regardless of which area, are still stored object instances, further divided the purpose is to better recovery of memory, or better allocate memory.
Under java virtual machine, java heap may be in discontinuous physical memory space, as long as logically contiguous to, just like our disks. When implementing either can be implemented as a fixed size, and can also be extended, but the current mainstream virtual machine is an extensible, accomplished (by -Xmx and -Xms), if there is no memory in the heap upon completion instance assignment, and the heap can not be extended, it will throw an OutOfMemoryError.

Methods district

Way to go (method area) with java heap, just as each thread shared memory area, which is used to store class information has been loaded in the virtual machine, constants, static variables, the time compiler to compile the code and other data.

Runtime constant pool

Runtime constant pool (runtime constant pool) is part of the zone method. class file in addition to the information class versions, fields, methods, interfaces, etc., there is a constant pool (constant pool table), and for storing various literal reference symbol generated by the compiler, this part will be the method of entering the area after the class loading operation is stored in the constant pool.
java virtual machine (naturally including the constant pool) format there are strict requirements for each class file portions, each for storing a byte of data that must meet the requirements of the specification was only recognized by the virtual machine, the loading and execution. But for the runtime constant pool, Java Virtual Machine Specification details without making any demands.
Runtime constant pool relative to another important feature of the class is to have a constant pool dynamics, JAVA language does not require constant necessarily only compile to produce, that is not preset the contents of the class file constant pool to enter the zone run method time constant pool during operation may be new constant into the pool, this feature was developed intern () method is plenty personnel use a String.

Direct Memory

Direct memory (direct memory) is not part of the data area of the virtual machine is running, not the Java Virtual Machine specification defines the area of memory.
Jdk1.4 newly added in the NIO (new input / output) type, based on the introduction of a channel (channel) and a buffer (buffer) of the I / O mode, it can use native library direct external memory heap allocation, and stored in the heap through a java DirectByteBuffer this referenced object as the operation memory. This can significantly improve performance in some scenarios, it avoids the replicate data in the heap and the heap java native.

Guess you like

Origin www.cnblogs.com/curiousforcode/p/11388896.html