当前位置:网站首页>JVM easy start-02
JVM easy start-02
2022-06-23 10:25:00 【cfcoolya】
One .JVM Architecture diagram
Throughout JVM Learning process , This picture should be remembered deeply , So that you won't lose your way

Two .Native Method
In a multithreaded Thread Of start Method source code , There's a way 【private native void start0()】, There is a keyword native.
- I've brought native Keywords , explain Java It doesn't reach the scope of , Go back and call the underlying C The library of languages .
- It goes to the local method stack , Call the local method interface JNI(Java native interface)

Historical reasons :Java It was born C、C++ When you're walking around , Want to have a foothold , Must call C、C++ The program , So a special area is opened in the memory and marked as native Code for , Its specific approach is to Navitive Method Stack Registered in navtive Method , Load when executing the engine Native Libraries.
3、 ... and . Method area
Method area (Method Area) Is shared by all threads , Information about all defined methods is stored in this area .
Static variables 、 Constant 、 Class information ( Construction method 、 Interface definition )、 The runtime constant pool exists in the method , But instance variables exist in heap memory and are independent of the method area (static、final、class、 Constant pool )
Four . Stack
- To explain it in a popular language is : If you drink too much, you will vomit , If you eat too much, you will be in line .
- Stack storage is faster than heap , Next to registers , Stack data can be shared .
- There is no garbage collection problem in the stack , As soon as the thread ends , The stack is Over, The life cycle is consistent with the thread , Threads are private .
5、 ... and . Pile up (sun-hotspot)
One JVM There's only one heap memory , The size of heap memory can be adjusted ; After the class loader reads the class file , Need to put class 、 Method 、 Constant variables in heap memory , Save real information for all reference types .
5.1 Pile up
- New Area Young/New
- Retirement area Tenure/Old
- The permanent zone Perm

GC Garbage recycling is mainly carried out in new areas and old-age areas , It is also divided into light GC And heavy GC, If there's not enough memory , Or there is an endless cycle , It will lead to java.lang.OutOfMemoryError:Java heap space.
5.2 New Area
The new area is divided into two parts : Eden (Eden) And the survival zone (Survivor Space), All classes are in Eden Quilt new Coming out .
When Eden When you run out of space , The program has to create objects ,JVM Your garbage collector will be on Eden Zone for garbage collection (Minor GC), Similar operation 0 The district is full , Move to 1 District , Retirement area . If the elderly care area has implemented Full GC The object cannot be saved after , It will produce OOM abnormal “Out of MemoryError”.
If it appears OOM, explain Java There is not enough heap memory for the virtual machine , Here's why :
- Java The heap memory setting of the virtual machine is not enough , You can use the parameter -Xms( Initial value size ),-Xmx( Maximum size ) To adjust
- A lot of objects are created in the code , And it can not be collected by garbage collector or dead loop for a long time
5.3 The permanent zone
- To hold JDK What you carry Class,Interface Metadata , It stores the class information necessary for the running environment
- The data in this area will not be collected by the garbage collector , close JVM The memory occupied by this area will be released
- Java.lang.OutOfMemoryError:PerGen space explain Java Virtual machine to permanent generation Perm Not enough memory settings
- JDK1.8 And there is no permanent generation after , Constant pool 1.8 In meta space
5.4 Heap memory tuning
-Xms: Set the initial allocation size , Default physical memory 1/64
-Xmx: Maximum allocated memory , Default physical memory 1/4
-XX:PrintGCDetails: Output detailed GC Processing logs
6、 ... and . Method area + Pile up + Stack interaction

The illustration :https://blog.csdn.net/thera_qing/article/details/110544168
Learning comes from :B standing - Madness theory
边栏推荐
- Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award
- [software and system security] heap overflow
- IPv6 的速度比 IPv4 更快?
- 2021-05-07封装 继承 super this
- How does thymeleaf get the value of the request parameter in the URL?
- Golang 快速上手 (2)
- [day 23] given an array of length N, insert element x into the position specified by the array | array insertion operation 4
- Successful experience of postgraduate entrance examination in materials and Chemical Engineering (metal) of Beijing University of Aeronautics and Astronautics in 2023
- mysql中innodb下的redo log什么时候开始执行check point落盘的?
- Tencent tangdaosheng: practice "science and technology for the good" and promote sustainable social value innovation
猜你喜欢

数学分析_笔记_第2章:实数与复数

开发者,你对云计算可能有些误解

Build a security video monitoring platform using Huawei cloud ECS server

Go language JSON processing

Cloud native database Amazon RDS

数值计算方法

JVM简单入门-01

Liujinhai, architect of zhongang Mining: lithium battery opens up a Xintiandi for fluorine chemical industry

Golang 快速上手 (3)

Data structures and differences between MySQL InnoDB engine and MyISAM
随机推荐
NOI OJ 1.3 11:计算浮点数相除的余数 C语言
2021-04-16 recursion
Developer, you may have some misunderstandings about cloud computing
Too helpless! Microsoft stopped selling AI emotion recognition and other technologies, saying frankly: "the law can not keep up with the development of AI"
How to pass values to onclick events in thymeleaf
文献综述怎么写 ,一直没头绪写不出来怎么办?
beanstalk 常用方法、说明
谷贱伤农,薪贱伤码农!
Numerical calculation method
Pycharm installation tutorial, super detailed
用贪吃蛇小游戏表白(附源码)
Three implementation methods of distributed lock
2021-05-12内部类
NiO example
2021-04-12 the first implementation of linked list!!!
What is a good quick development framework like?
Golang quick start (1)
Nuxt.js spa与ssr的区别
SQL create a new field based on the comparison date
2021-05-07 constructor