当前位置:网站首页>Introduction to JVM basic concepts
Introduction to JVM basic concepts
2022-06-11 15:23:00 【Evader1997】
JVM What is it?
JVM also called Java virtual machine , yes Java The runtime environment of the program . It is to use C Write a software , Like other software, it runs on the operating system (LInux,win,mac etc. ) Of . Where does the operating system run ?
Before the birth of computer software , Our computer can only execute certain programs , To run a program by splicing circuits . If you need to run the second program, you need to splice a new set of circuits and run , This is the early computer hardware . Later, von Neumann led to the wave of computer software , It wants to **‘ preservation ’** get up , This is the beginning of computer software . So the operating system is running on the hardware .JVM, operating system , The relationship among computer hardware is :
JVM Architecture of
JVM The most common thing in is tuning , In fact, JVM Of the five areas of , The basic thing that involves tuning is heap memory tuning , This is determined by the mechanism of heap memory . For local method interfaces , Namely native Related methods of modification , These methods are C language-written . The local method information is stored in the local method interface , When called, the local method in the local method library will be called .
Class loader
species
Start class loader :Bootstrap ClassLoader
Extend the classloader :Extension ClassLoader
Application class loader :Application ClassLoader
Do not discuss custom class loaders
A simple loading process of a class

Test code , You can understand at a glance
 {
String str = new String("abc");
System.out.println(str.getClass().getClassLoader());
// System.out.println(classLoader.getParent());
System.out.println("====== I'm the divider ======");
Person person = new Person();
System.out.println(person.getClass().getClassLoader());
System.out.println(person.getClass().getClassLoader().getParent());
System.out.println(person.getClass().getClassLoader().getParent().getParent());
}
}


Ladies and gentlemen, just look at two moving pictures , We know String Class is JDK A self-contained class in , Is loaded by the boot class loader , Start class loader at Java You can't get it in . Therefore, the second dynamic graph generates a null pointer exception . Compare... In the first graph Peron Class is custom , So the loading is finally completed by the application loader . Why print three class loaders , Leave a suspense .
The role of the three class loaders
1. Start class loader : load <JAVA_HOME>\lib In the directory , Or be -Xbootclasspath The class of the path specified by the , And is JVM Identified class libraries , Users can't get .
2. Extend the classloader : load <JAVA_HOME>\lib\ext In the directory , Or be java.ext.dirs Class libraries in the path specified by the system variable . Users can get .
3. Application class loader : This loader is also known as the system loader (System), yes ClassLoader in getSystemClassLoader() Return value of method . Load user path (ClassPath) The specified class library . Users can use . Users can get
Parent delegate mechanism
There is a need for class loading
The subclass loader passes the request for class loading to the parent class , Layer by layer to start the class loader
If the parent class loader fails to load, it will feed back to the child class to load itself
The so-called parents , Is to extend the class loader and start the class loader . The advantage of parental delegation is that it doesn't make a class reload twice , For example, you can customize java.lang.String It's illegal .
Sandbox security mechanism
A sandbox can be understood as a closed box , Our program can only run in this box . We develop locally , The development is completed and deployed to the remote server , stay Java Local code in is trusted by default , It's safe . But remote code is not trusted , So we need to add some security mechanisms to ensure the operation of the program , For example, when the remote code operates the operating system and local resources, the credit granting steps should be added ,jdk6 Then the domain is proposed (domain) The concept of , Make sandbox safer .
Native

native The delegate is a local method , take Thread Class, for example , First Thread Not an abstract class, not an interface , Why is there a way to realize without writing methods ? The reason is that this method is native Modify the . stay Java in , All are native The modification is the local method .Java Only its mark is stored , Use it to call the local method library .
PC register
PC The register area is also called the program counter , We know that in the case of multithreading ,CPU It's a high-speed wheel , Each thread is allocated a time slice , There is ** Half the program is executed to execute other threads , Next time, go back to this thread ,CPU How to know where the program has been executed ?** The answer is the program counter , This can be understood as a pointer , It will point to the memory address of the next instruction .PC Registers are thread private , Every thread has a PC register , This ensures that threads are independent of each other .
Stack
Stack also known as Java Virtual machine stack , It is characterized by first in and last out , This is related to its data structure . Inside the stack are stack frames , Each stack frame actually corresponds to a method to be executed . After each method is executed, it will pop up and disappear , The sign that a program has finished executing is that there is no stack frame in the stack . Usually, what is stored in the stack is some references , So the program is finished , There is basically no garbage left in the stack , So it basically won't appear OOM. The possible exception is that the stack frame loaded into the stack exceeds the maximum stack frame that the stack can hold , A stack overflow exception will be reported , Another case is that the memory requested by the current stack frame exceeds the maximum memory , Will appear OOM The problem of .
Pile up
Java in new All objects are stored in the heap , The so-called garbage collection is the collection object . So most of the tuning we talk about is actually heap tuning . The following is the structure diagram of heap memory .

边栏推荐
- Interview shock 26: how to stop threads correctly?
- 04 _ In simple terms index (I)
- 深度解读:分布式系统韧性架构压舱石OpenChaos
- Let me tell you the benefits of code refactoring
- 2021 go developer survey
- How about art plus online school? Is it a new online organization?
- 浅析分布式系统之体系结构-事务与隔离级别(多对象、多操作)下篇
- 容易让单片机程序跑飞的原因
- Flutter 3.0 was officially released: it stably supports 6 platforms, and byte jitter is the main user
- Devil cold rice # 037 devil shares the ways to become a big enterprise; Female anchor reward routine; Self discipline means freedom; Interpretation of simple interest and compound interest
猜你喜欢

IDEA2021.1版本安装教程

Don't you understand the design and principle of thread pool? Break it up and crush it. I'll teach you how to design the thread pool

老虎国际季报图解:营收5263万美元 持续国际化布局

【创建型模式】工厂方法模式

LoveLive! Published an AI paper: generating models to write music scores automatically

19. 二叉搜索树的插入删除修剪

简单的C语言版本通讯录

05 _ 深入浅出索引(下)

回溯法/解空间树 排列树

Qcustomplot 1.0.1 learning (3) - plotting quadratic functions
随机推荐
英伟达研发主管:AI 是如何改进芯片设计的?
Nomad application layout scheme 04 of hashicopy (scaling and updating a job)
Analyse approfondie de la conception du système relationnel du Groupe de cercles
汤峥嵘:CTO 是商业思维和技术思维交汇的那个点
Uniapp développe des applets Wechat, de la construction à la mise en ligne
2022.02.28
How about art plus online school? Is it a new online organization?
【创建型模式】单例模式
Why can redis be so fast?
Hamad application layout scheme 03 of hashicopy (run a job)
Number system conversion (function)
深度解读:分布式系统韧性架构压舱石OpenChaos
Talk about the principle of QR code scanning login
Did you break the rules?
Hamad application layout scheme 02 of hashicopy
06 _ 全局锁和表锁 :给表加个字段怎么有这么多阻碍?
Tencent interviewers share their interview experience, how to evaluate the interviewers' technical and personal comprehensive quality, and give you some suggestions on the interview
03 _ Transaction isolation: why can't I see it after you change it?
Leetcode daily question - Search insertion position
06 _ Global lock and table lock: Why are there so many obstacles to adding a field to a table?