Re-reading "in-depth understanding of Java virtual machines"

Source: Internet
Author: User

First, the Java Virtual Machine memory area How to divide 1, the Java Virtual Machine Memory region Division

Zone Name

function (use)

Type

Characteristics

Virtual machine stipulation Exception condition

Other Notes

1 program counter bytecode instruction address thread private 1, less memory space
2, created and destroyed with user process start and end.
none Each thread has a separate program counter. A null pointer when the native method is executed.
virtual machine stack (stack memory) java method execution of the memory model ( method stack frame in the stack, out of the stack ). Each method executes, creating a stack frame for storing local variable tables, operands, dynamic links, method exits, and so on.
Execute Java Method service for virtual machine to execute Java method
thread private 1, less memory space
2, build and destroy with user process start and end
1, Stackoverflowerror: The thread request stack depth is greater than the stack depth allowed by the virtual machine.
2, Outmemoryerror: If the virtual machine stack can be dynamically extended, if the extension cannot request enough memory to throw an exception
local variable table : Used to hold the types that are known at compile time, including basic types, reference types, and returnaddress types. The memory space required for the local variable table is allocated at compile time, and the run time does not change the local variable table size.
local method stack native method thread private 1, less memory space
2, established and destroyed with user process start and end
1, Stackoverflowerror:
2, Outmemoryerror:
 
Heap (GC heap, heap memory) object instances , where almost all object instances are assigned thread sharing 1, large memory space,
2, created with the virtual machine process started
3, the main management of the garbage collector
4, no need for contiguous memory space, as long as logically continuous can
1, Outmemoryerror: There is no memory in the heap to complete the instance assignment, and the heap can no longer be extended by throwing 2, from memory allocation angle: The heap can be divided into multiple thread-private allocation buffers, in order to better reclaim memory and faster allocation of memory
5 Method Area (non-heap) Used to store class information, constants, static variables, instant compiler-compiled code, and so on, which are loaded by the virtual machine (information such as class name, access modifier, constant pool, field description, method description, etc.) Thread sharing 1. A logical part of heap memory
2, memory recycling mainly for the recovery of constant pool and type of unloading
1, Outmemoryerror: method to fail to meet the memory allocation requirements when thrown, that is, there is not enough memory to allocate Run a constant pool: a variety of literal and symbolic references that are generated during the compilation period, which are stored when the class loads in the run-time constant pool. The run-time constant pool is dynamic, and constants can be generated during the compilation period, and new constants can be added at run time ...

Direct memory is not an area of Java memory.

2, Heap memory Space: object instance creation, memory layout and memory positioning (1) How objects in the heap memory space create allocations

1) locates the symbol reference of the type in the constant pool according to the type constant of the new instruction, and determines whether the class is loaded, parsed, and initialized

2) Load If the type information is determined not to be loaded

3) Allocating heap memory space of a specified size within a heap

How to allocate heap memory space: A, pointer collision: That is, the heap memory space is physically continuously allocated, allocated relatively regular, in used memory to the unused memory direction to allocate

B, Idle list: That is, the heap memory space is not structured allocation, using an idle list to record the current unallocated memory space, the allocation of the free list within the specified size of the memory space to allocate

How to ensure the correctness of memory allocation: the thread private allocation buffer (TLAB), each thread allocates a small area of memory (local thread allocation buffer), each of which allocates instance objects only within its own tlab. Set Tlab:-xx:+/-usetlab

4) Automatic initialization: Initialize the default value of the memory space

5) Set the object header information

6) The Init initialization method is initialized according to the object declaration position.

(2) How objects in the heap memory space are laid out

1) Object Header

2) Instance data

3) Align

(3) How objects in the heap memory space are positioned

1) Handle

2) Direct pointer

3. Oom abnormal debugging and parameter setting

Overflow area

Parameter settings

Exception throw condition

Other Notes

Heap -xms
-xmx
Heap memory cannot be automatically extended, there are not enough memory allocation instance objects Set parameter-xx:+heapdumponoutmemoryerror dump occurs when an exception occurs the current memory heap dump snapshot for post-mortem analysis
Virtual machine stacks and local methods -XSS: Setting the virtual machine stack size
-xoss: Setting Local method size
1. Stackoverflowerror: The thread request stack depth is greater than the stack depth allowed by the virtual machine.
2, Outmemoryerror: If the virtual machine stack can be dynamically extended, if the extension cannot request enough memory to throw an exception
The higher the virtual machine stack capacity allocated per thread, the less number of threads can be established
Method area and run-time constant -xx:permsize minimum capacity of the method area
-xx:maxpermsize: Maximum method area capacity
1, Outmemoryerror: method to fail to meet the memory allocation requirements when thrown, that is, there is not enough memory to allocate
Direct Memory -xx:maxdirectmemorysize: Specifies the direct memory maximum capacity if the default is not specified as the heap size capacity 1, Outmemoryerror: method to fail to meet the memory allocation requirements when thrown, that is, there is not enough memory to allocate Not part of the Java memory area
Direct Memory = physical memory-total memory in each region

Ii. how to implement garbage collection and memory allocation

Third, how to monitor the performance of virtual machine, how to deal with the fault, how to analyze

Iv. How Java programs are stored (class file structure)

V. How Java programs are loaded (class loading mechanism)

Vi. How Java programs execute (virtual machine bytecode execution engine)

Vii. How Java program code is optimized

Viii. Memory models for Java

IX. Java Threads

Re-reading "in-depth understanding of Java virtual machines"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.