1, program Counter Register is a small amount of memory space, it can be considered as the current thread executes the byte code of the line number indicator. 2. Java Virtual machine stack (stack) threads are private, and each method call creates a stack frame to store information such as local variable tables, operand stacks, dynamic links, method exits, and so on. Local variables hold the various basic data types (boolean,byte,char,short,int,float,long,double), object references (reference types), and returnaddress types that are known at compile time. 3, the local method stack, the local method of the virtual machine provides the stack 4, Java heap (heap) all threads share a piece of memory area, the object instance is Native. May be divided into: The new generation and the old age. A little more detailed is Eden space, from Survivor space, to survivor space and so on. 5. The method area is a pure-blooded shared memory area used to store data such as class information, constants, static variables, and code compiled by the instant compiler that have been loaded by the virtual machine. Often referred to as permanent generation (Permanent Generation) 6, the run-time pool (runtime Constant pools) is part of the method area for storing the various literal and symbolic references generated during the compilation period, This section is stored in the run-time pool of the class load backward into the method area. 7. Direct Memory
2.3 Creation of objects
1, check Load: Encountered the new command, first check whether the parameters of this directive can be positioned in the constant pool to the symbol reference of the class, and check that the symbol refers to the class of the representative has been loaded, parsed and initialized;
2. Partition memory: Allocating space for an object is equivalent to dividing a certain size of memory from the Java heap, which is divided into "pointer collision" and "idle list" according to the storage method in the heap, but it is not thread-safe in the concurrency situation, there are two ways to solve the problem. One is to synchronize the allocated memory space action, and the other is to allocate the memory in different space, each thread allocates a small chunk of memory in the Java heap, called the local thread allocation cache (TLAB);
3, initialization: Memory allocation will be allocated after the memory space is initialized to 0 (excluding the object header);
4, the necessary settings for the object (class metadata information, object hash code, GV generational) stored in the object header
The memory distribution of the object
Object header, instance data, aligned padding
Object header The first part is used to store the object's own run-time data, such as hash code, GC generational age, thread-held locks, etc. (Mark work), the second department is the type pointer, that is, the object pointer to its class metadata, the virtual machine through this pointer to determine which class of the object is the strength
Note If the object is an array, then there must be a piece of data in the object header that records the length of the object array, and the virtual machine can determine the size of the Java object through the metadata information of the ordinary Java object, but the size of the array cannot be determined from the metadata of the array, and here is a description for the for (int i= Arr.length; i>0; i--) and for (int i= 0; i<arr.length;i++) do not have an essential difference.
Instance data: Both inherited from the parent class and defined by the subclass need to be recorded, affected by the order in which the virtual machine allocation policy parameters and fields are defined in the Java source code, for example, fields of the same width are assigned together (Double,long)
Aligned padding does not necessarily exist as a placeholder for the role
Access positioning of objects
The concrete objects on the heap need to be manipulated by reference protectors on the stack. There are two ways to access the mainstream, the handle and the direct pointer access;
Handle Access: The heap will be divided into a block of memory as a handle pool, reference is stored in the object's handle address, the handle also contains the object instance data and the type of data each of the specific address information
Direct pointer access, where the object's address is stored in the Regerence
Pros and cons Analysis: The biggest advantage of the handle is that regerence is stored in a stable handle address, when the object is moved is only changing the handle of the instance data pointer, and the reference itself is not changed, the advantage of the direct pointer is faster,
Memory Overflow Condition:The overflow of the virtual machine stack, the general will prompt Stackoverflowerror, if prompt outmemoryerror may be the result of multithreading, when the Java virtual machine allocates a virtual machine stack for each thread, At this point the stack of each thread does not overflow and will not trigger Stackoverflowerror, but the thread has been assigned to cause outmemoryerror.
Other overflow conditions are relatively simple.
1. Definition
stack frame is a data structure used to support virtual machines for method invocation and method execution, which is the stack element of the virtual machine stack in the data area when the virtual machine is running. The stack frame stores information such as the local variable table of the method, the operand stack, the dynamic connection, and the method return address.
Each method from the start of the call to the completion of the process, corresponding to a stack frame in the virtual machine stack from the stack to the process.
For the execution engine, in the active thread, only the stack frame at the top of the stack is valid, called the current stack frame, and the method associated with the stack frame is called the current method. All bytecode directives run by the execution engine operate on the current stack frame only.
2. Composition
(1) Local Variables table
A local variable table is a set of variable value storage spaces that are used to store method parameters and local variables defined inside the method. When a Java program is compiled into a class file, it is determined in the Max_locals data item of the method's Code property that the method needs to be assigned
the capacity of the maximum local variable table.
the capacity of the local variable table is the smallest unit in the variable slot (slot), where a slot in a 32-bit virtual machine can hold a data type that is less than 32 bits (Boolean, Byte, char, short, int, float, Reference and ReturnAddress eight species).
the reference type Virtual machine specification does not explicitly describe its length, but in general, the virtual machine implementation should at least be able to find, directly or indirectly from this reference, the object type data in the starting address index and the method area of the objects in the Java heap.
The returnaddress type is for bytecode instruction JSR, Jsr_w, and RET, which points to the address of a bytecode directive.
a virtual machine is the process of passing a parameter value to a list of parameter variables using a local variable table, and if it is an instance method (not static), then the slot for the No. 0-bit index of the local variable table defaults to the reference used to pass the object instance to which the method belongs, and is accessed through this in the method.
slots can be reused, and when the variables in the slot are out of scope, the next time the slot is allocated, the original data is overwritten. The slot reference to an object affects the GC (if referenced, it will not be recycled).
The system does not assign the initial value to the local variable (the instance variable and the class variable are given the initial value). That is, there is no preparation stage like a class variable.
(2) stack of operations
The Java Virtual machine's interpretation execution engine is called the "stack-based execution engine", where the stack refers to the-operand stack.
The operand stack is also often referred to as the stack of operations.
as with the local variable area, the operand stack is also organized into an array of word lengths. But unlike the former, it is not accessed through the index, but through the standard stack operation-the stack and the stack. For example, if an instruction presses a value into the operand stack, another command can then eject the value for use.
virtual machines store data in the operand stack in the same way as in local variables: storage such as int, long, float, double, reference, and ReturnType. Values for byte, short, and char types are also converted to int before they are pressed into the operand stack.
The virtual machine takes the operand stack as its working area-most instructions will pop up the data from here, perform the operation, and then press the result back to the operand stack. For example, the iadd instruction is going to pop two integers from the operand stack, perform the addition operation, and press the result back to the operand stack to see the following example, which shows how the virtual machine adds the local variables of the two int types, and then saves the result to the third local variable:
begin
iload_0 // push the int in local variable 0 onto the stack
iload_1 // push the int in local variable 1 onto the stack
iadd // pop two ints, add them, push result
istore_2 // pop int, store into local variable 2
end
in this bytecode sequence, the first two directives iload_0 and Iload_1 will be stored in the local variables indexed to 0 and 1 of the integer pressed into the operand stack, after which the iadd instruction pops the two integers from the operand stack, and then presses the result into the operand stack. The fourth instruction istore_2 pops the result from the operand stack and stores it in the local variable area index of 2. The state changes of local variables and operand stacks in this process are described in detail, and the area of local variables and operand stacks which are not used in the graph are represented in blank.
Chapter II Java memory area and memory overflow exception