Objective
After Java is started as a process running in the operating system, the process has to allocate the following memory:
1. Java Heap:
Stores the Java memory area, where the heap size is when the JVM starts up as if the operating system request is complete, where-xmx and-xms represent the maximum and initial sizes, respectively. GC management that is fixed and belongs to Java after the heap size allocation is complete.
2. Threads:
The entity of the actual program that the JVM runs is a thread, and the JVM allocates a stack size for it when it creates the thread. If the number of threads is greater than the number of cores in the CPU, it can result in high memory and inefficiency.
3. Class and ClassLoader: The class and ClassLoader are saved in the heap's permanent generation, and they themselves need to occupy memory. 4. NIO:
The NIO class library appears behind java1.4, a new way to execute IO based on channels and buffers, mainly using the Java.io.ByteFuffer Allocatedirect () method to allocate memory. Unlike traditional IO, this way the data interaction of the network or disk directly occurs directly in the kernel space of the operating system, eliminating the time-consuming of copying to JVM space and switching on the Java heap.
5. JNI:
Java native language invocation, in fact, the Java runtime, such as file, network, IO or other hardware calls need to use JNI, so JNI also need to occupy memory.
JVM Memory Structure
- Line number indicator for PC register (thread private) thread execution
- Memory model of Java Virtual machine stack (thread private) Java method execution
- Java heap (thread sharing) garbage heap
- Method area (thread sharing, permanent generation), class information, constants, static variables, compiled code and other data, the logical part of the heap in the virtual machine specification, alias Non-heap (non-heap) to differentiate
- The local method area (native method) executes the native method service for the JVM
- Run a constant pool (literal symbol) PS: Understand the next String.inter () method
allocation, layout, and access of objects above the Java heap 1, creation of objects (in the case of ordinary Java objects)
Java Web in-depth analysis (one-by-one) JVM (1)