The basic architecture of resource tuning the JVM tuning the road Spark Learning (xiii) SparkCore of

Discuss QQ: 1586558083

 

text

A, JVM structure of FIG.

1.1 Java Memory Architecture

JVM memory structure has three main blocks: heap, and stack method area .

Heap memory is the JVM largest one of the young generation and Old's composition, and the young generation of memory has been divided into three parts, Eden space, the From Survivor space, the To Survivor space , a case where the young generation according to 8 Default: 1: 1 ratio to allocate;

The method area stores class information, constants, variables and other static data area is shared by the threads, the Java heap is distinguished, there is a method area alias Non-Heap (non-heap);

Stack is divided into the implementation of java virtual machine stacks and stacks local method is mainly used in the method.

1.2 How to control the memory size of each parameter area

1.3 Control parameters

-Xms set minimum heap space.

-Xmx sets the maximum size of the heap space.

-XX: NewSize set up the new generation of the minimum amount of space.

-XX: MaxNewSize set up the new generation of maximum space.

-XX: PermSize substituting permanent settings the minimum of space.

-XX: MaxPermSize set up a permanent space on behalf of maximum size.

-Xss set the stack size for each thread.

Not directly set the parameters of old age, but you can set heap space size and the size of the new generation of space of two parameters controlled indirectly.

  Old's space = heap size - the size of the young generation large space

The relationship between the JVM and system calls 1.4

 

The method area is shared by all threads and heap memory area; and java stack, native method stacks and the programmer is running counter thread private memory area.

Effect two, JVM each region

2.1 Java heap (Heap)

    For most applications, Java heap (Java Heap) is the largest piece of memory in the 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.

     Java heap is the main area managed by the garbage collector, and therefore often also called "GC heap." If you look from the perspective of memory recovery, due to the current collector basically adopted generational collection algorithm, so the Java heap can also be broken down into: the old and the new generation's; and then there is little detailed Eden space, From Survivor space, To Survivor space.

Under the Java Virtual Machine specification, Java heap may be in discontinuous physical memory space, as long as logically contiguous to, just like our disk space. When implemented, may be implemented as a fixed size, it can be expanded, but the current mainstream is an extensible virtual machine implemented (by -Xms -Xmx and control).

If there is no complete examples in the heap memory allocation, and the stack can no longer expand, it will throw an OutOfMemoryError.

2.2 Method Area (Method Area)

  District method (Method Area) and the Java heap, as each thread is a 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. Although Java Virtual Machine Specification as described in the method area is a logical part of the heap, but it has an alias called Non-Heap (non-stack), the Java heap object should be distinguished.

For habit development and deployment for developers to program in the HotSpot virtual machine, a lot of people willing to method area called "permanent Generation" (Permanent Generation), essentially the two are not equivalent, simply because HotSpot Virtual Machine design team chose the GC generational collection extends to the method area, or use the method to achieve permanent generations area only.

Java Virtual Machine Specification limit of this region is very loose, in addition to and do not require continuous as the Java heap memory can be selected and fixed size or may be expanded, but also can choose not to implement garbage collection. In contrast, garbage collection behavior in this area is relatively small appearance, but not the data into the area just as a permanent method of generation of the same name "permanent" exists. Garbage collection target this area is mainly for recycling constant pool and unloading of the type of general recovery in this region, "achievement" relatively unsatisfactory, especially the type of unloading, conditions can be quite harsh, but this part of the region recycling is really necessary.

Under the Java Virtual Machine specification, when the method of memory allocation area can not meet demand, it will throw an OutOfMemoryError. 

2.3 program counter (Program Counter Register)

Program counter (Program Counter Register) is a small memory space, its role can be seen as the row number designator bytecode executed by the current thread. 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 bytecode instructions, branching, looping, branching, exception handling, and other basic functions thread recovery relies on the counter to complete. Since the multi-threaded 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 one thread the instructions. Therefore, in order to restore the thread switch to the correct execution position, each thread requires a separate program counter, between the threads independently of each other, independent store, we call this type of memory area is "thread-private "memory. If the thread is executing a Java method, the counter records the address of the virtual machine bytecode instruction being executed; if the method is being performed Natvie, this counter value is null (Undefined).

This memory area is the only one not provide for any situation in the region OutOfMemoryError Java Virtual Machine Specification.

2.4 JVM stack (JVM Stacks)

Like the program counter, Java Virtual Machine stack (Java Virtual Machine Stacks) is also a thread private, its life cycle and the same thread. Is a virtual machine stack Java memory model described method of execution: when each method will be executed at the same time create a stack frame (Stack Frame) for storing local variable table, operation information stack, dynamic linking, method exports. Each method is called until the completion of the execution procedure, a stack frame corresponds to a virtual machine from the stack to the stack of a process stack. 

The local variable table stored compile various known basic data types (boolean, byte, char, short, int, float, long, double), object reference (reference type, it is not equivalent to the object itself, depending on the virtual machine implement, it may be a reference to the start address pointer to the object may also be a handle to the object representing the object associated with this or other location) and returnAddress type (address pointing to a byte code instruction).

Wherein the long and double-length 64-bit data occupies two local variable space (Slot), the remaining data occupies only one type. Desired local variable table created during compilation memory space allocated, when entering a method, this method requires much space for local variables allocated in the frame is completely determined during operation of the method does not change the size of the local variable table.

In the Java Virtual Machine Specification, this area provides two anomalies: If the stack is greater than the depth of the thread requested virtual machine allowable depth, StackOverflowError will throw an exception; if the virtual machine can dynamically expand the stack (most of the current Java virtual machines can be dynamically expanding, but the Java virtual machine specification also allows virtual machine stack fixed length), when the expansion can not apply enough memory will throw OutOfMemoryError exception.

2.5 native method stacks (Native Method Stacks)

Native method stacks (Native Method Stacks) and the role played by the virtual machine stack is very similar, but the difference is the virtual machine execution stack for the Java Virtual Machine method (ie bytecode) service, and is for the native method stacks virtual machine to use a method of Native service. Virtual Machine Specification language native method stack method used, use a data structure is not mandatory, so the specific virtual machine it can be freely realized. Even some virtual machines (such as Sun HotSpot VM) directly put into one native method stacks and stacks virtual machine. Like the virtual machine stack, the stack area native method can also throw StackOverflowError and an OutOfMemoryError.

 

 

text

A, JVM structure of FIG.

1.1 Java Memory Architecture

JVM memory structure has three main blocks: heap, and stack method area .

Heap memory is the JVM largest one of the young generation and Old's composition, and the young generation of memory has been divided into three parts, Eden space, the From Survivor space, the To Survivor space , a case where the young generation according to 8 Default: 1: 1 ratio to allocate;

The method area stores class information, constants, variables and other static data area is shared by the threads, the Java heap is distinguished, there is a method area alias Non-Heap (non-heap);

Stack is divided into the implementation of java virtual machine stacks and stacks local method is mainly used in the method.

1.2 How to control the memory size of each parameter area

1.3 Control parameters

-Xms set minimum heap space.

-Xmx sets the maximum size of the heap space.

-XX: NewSize set up the new generation of the minimum amount of space.

-XX: MaxNewSize set up the new generation of maximum space.

-XX: PermSize substituting permanent settings the minimum of space.

-XX: MaxPermSize set up a permanent space on behalf of maximum size.

-Xss set the stack size for each thread.

Not directly set the parameters of old age, but you can set heap space size and the size of the new generation of space of two parameters controlled indirectly.

  Old's space = heap size - the size of the young generation large space

The relationship between the JVM and system calls 1.4

 

The method area is shared by all threads and heap memory area; and java stack, native method stacks and the programmer is running counter thread private memory area.

Effect two, JVM each region

2.1 Java heap (Heap)

    For most applications, Java heap (Java Heap) is the largest piece of memory in the 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.

     Java heap is the main area managed by the garbage collector, and therefore often also called "GC heap." If you look from the perspective of memory recovery, due to the current collector basically adopted generational collection algorithm, so the Java heap can also be broken down into: the old and the new generation's; and then there is little detailed Eden space, From Survivor space, To Survivor space.

Under the Java Virtual Machine specification, Java heap may be in discontinuous physical memory space, as long as logically contiguous to, just like our disk space. When implemented, may be implemented as a fixed size, it can be expanded, but the current mainstream is an extensible virtual machine implemented (by -Xms -Xmx and control).

If there is no complete examples in the heap memory allocation, and the stack can no longer expand, it will throw an OutOfMemoryError.

2.2 Method Area (Method Area)

  District method (Method Area) and the Java heap, as each thread is a 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. Although Java Virtual Machine Specification as described in the method area is a logical part of the heap, but it has an alias called Non-Heap (non-stack), the Java heap object should be distinguished.

For habit development and deployment for developers to program in the HotSpot virtual machine, a lot of people willing to method area called "permanent Generation" (Permanent Generation), essentially the two are not equivalent, simply because HotSpot Virtual Machine design team chose the GC generational collection extends to the method area, or use the method to achieve permanent generations area only.

Java Virtual Machine Specification limit of this region is very loose, in addition to and do not require continuous as the Java heap memory can be selected and fixed size or may be expanded, but also can choose not to implement garbage collection. In contrast, garbage collection behavior in this area is relatively small appearance, but not the data into the area just as a permanent method of generation of the same name "permanent" exists. Garbage collection target this area is mainly for recycling constant pool and unloading of the type of general recovery in this region, "achievement" relatively unsatisfactory, especially the type of unloading, conditions can be quite harsh, but this part of the region recycling is really necessary.

Under the Java Virtual Machine specification, when the method of memory allocation area can not meet demand, it will throw an OutOfMemoryError. 

2.3 program counter (Program Counter Register)

Program counter (Program Counter Register) is a small memory space, its role can be seen as the row number designator bytecode executed by the current thread. 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 bytecode instructions, branching, looping, branching, exception handling, and other basic functions thread recovery relies on the counter to complete. Since the multi-threaded 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 one thread the instructions. Therefore, in order to restore the thread switch to the correct execution position, each thread requires a separate program counter, between the threads independently of each other, independent store, we call this type of memory area is "thread-private "memory. If the thread is executing a Java method, the counter records the address of the virtual machine bytecode instruction being executed; if the method is being performed Natvie, this counter value is null (Undefined).

This memory area is the only one not provide for any situation in the region OutOfMemoryError Java Virtual Machine Specification.

2.4 JVM stack (JVM Stacks)

Like the program counter, Java Virtual Machine stack (Java Virtual Machine Stacks) is also a thread private, its life cycle and the same thread. Is a virtual machine stack Java memory model described method of execution: when each method will be executed at the same time create a stack frame (Stack Frame) for storing local variable table, operation information stack, dynamic linking, method exports. Each method is called until the completion of the execution procedure, a stack frame corresponds to a virtual machine from the stack to the stack of a process stack. 

The local variable table stored compile various known basic data types (boolean, byte, char, short, int, float, long, double), object reference (reference type, it is not equivalent to the object itself, depending on the virtual machine implement, it may be a reference to the start address pointer to the object may also be a handle to the object representing the object associated with this or other location) and returnAddress type (address pointing to a byte code instruction).

Wherein the long and double-length 64-bit data occupies two local variable space (Slot), the remaining data occupies only one type. Desired local variable table created during compilation memory space allocated, when entering a method, this method requires much space for local variables allocated in the frame is completely determined during operation of the method does not change the size of the local variable table.

In the Java Virtual Machine Specification, this area provides two anomalies: If the stack is greater than the depth of the thread requested virtual machine allowable depth, StackOverflowError will throw an exception; if the virtual machine can dynamically expand the stack (most of the current Java virtual machines can be dynamically expanding, but the Java virtual machine specification also allows virtual machine stack fixed length), when the expansion can not apply enough memory will throw OutOfMemoryError exception.

2.5 native method stacks (Native Method Stacks)

Native method stacks (Native Method Stacks) and the role played by the virtual machine stack is very similar, but the difference is the virtual machine execution stack for the Java Virtual Machine method (ie bytecode) service, and is for the native method stacks virtual machine to use a method of Native service. Virtual Machine Specification language native method stack method used, use a data structure is not mandatory, so the specific virtual machine it can be freely realized. Even some virtual machines (such as Sun HotSpot VM) directly put into one native method stacks and stacks virtual machine. Like the virtual machine stack, the stack area native method can also throw StackOverflowError and an OutOfMemoryError.

 

Guess you like

Origin www.cnblogs.com/liuys635/p/11002738.html