Java virtual machine knowledge____ should be enough for interviews

JVM directory

  1. Overview of JVM Architecture
    1.1 Class Loading Mechanism
    1.2 Types of Class Loaders
    1.3 Parental Delegation Mechanism
    1.4 Sandbox Security Mechanism
  2. Heap Architecture Overview
  3. Getting Started with Heap Parameter Tuning
1. Overview of JVM architecture

2. Class loader
  • There are three types of class loaders: BootStrapClassLoader, ExtensionClassLoader, and AppClassLoader. The loading order is as follows

  • BootStrapClassLoader loads the dependent packages under the following path

C:\Program Files (x86)\Java\jdk1.8.0_191\jre\lib\rt.jar

  • ExtensionClassLoader loads dependent packages under the following paths

C:\Program Files (x86)\Java\jdk1.8.0_191\jre\lib\ext

  • AppClassLoader

加载用户自定的类

  • 面试题: Parent delegation mechanism When a class is to be loaded, it is usually loaded from the top to the bottom area. First, check BootStrapClassLoader, ExtensionClassLoader, and AppClassLoader. If they exist, they will be loaded from the parent class area. This ensures the uniqueness of the object. This uniqueness is the sandbox security mechanism.
3. Native method stack
  • The local method stack is responsible for loading dependent packages written in other languages, such as business logic written in C or C++. The scene will use the scene in the scene of interacting with the hardware
4. JAVA stack
  • The Java stack is complex to load the program to run, the life cycle of the stack is synchronized with the thread, and the algorithm logic is first-in-last-out. Stored as basic data types + object reference variables + instance methods, etc.

  • The stack frame represents that every time a method in the class is executed, a stack frame will be generated. Including input, output variables, local variables. Relevant operations of pushing and popping the stack.

5. Program Counter
  • All threads are private and take up little space. What is recorded is the execution sequence of the program.
6. Method area
  • Stores the structure information of the file

7. Overview of the heap architecture

Knowledge point one
堆内 存包括如下三个部分 新生代 、老年代、元空间。三者占比为  1 :  2 : 0  
 
备注 jdk1.8 以后 元空间替代永久代 ,并且元空间占用的是物理内存而不是虚拟机内存, 占用的物理内存比例为 0.25 . 
Knowledge point two
在新生代中  伊甸园: 幸存者0 区:幸存者1 区 占比为 8 : 1 : 1
Knowledge point three

In jdk 1.8, the heap memory only includes two parts: new generation + old generation. By default, the maximum memory is 1/4 of the total memory, and the initial memory is 1/64

参数含义   
                 1.    -- Xms    堆当中初始化内存 
                 2.   -- Xmm   堆当中最大内存   
                 3.   -- Xmn    新生代占用内存
 
在参数调优目标:     减小GC程序的回收次数、提高GC程序的执行效率、因为GC程序的执行会影响程序的运行效率。
方法1   将堆的初始内存 设置为 堆的最大内存
Knowledge point 4 Execution process of garbage collection mechanism
 
在新生代     1.   伊甸园区做gc操作将存活的         对象拷贝到 幸存者0区 
            2.   当幸存者0满了 以后做GC操作将  对象拷贝到  幸存者1 区
 
在老年代     3.  当幸存者1区满了 以后做GC 操作   将存货的对象拷贝到 老年代区
            4.  当老年代 满了以后 会做 FULL GC 操作 
            5.  Full GC 操作以后发现 由于空间原因 无法将对象进行保存 就会出行 OOM 错误,因此发送异常区域在老年代
Knowledge point five
在老年代执行FULL GC的效率是 小于  在新生代 执行GC 效率的。 原因是因为老年代空间是新生代的2倍。但是老年代执行的效率却比新生代慢了大约8-10倍
Knowledge point 6 GC recovery algorithm

In the heap, different algorithms are executed for different areas, and the efficiency of the algorithm is not good or bad. Only if it fits.

GC回收算法 
 
(1 ) 引用计数发 :对象被引用一次就是会 +1 、引用第二次 +1 +1 。如果不在引用就会 -1 。
缺点 维护计数器本身也会消耗资源 、对于循环引用复杂度高。已经废弃了
 
(2) 复制算法 : 作用在新生代、对象在做GC操作的时候对象 对象会被复制。
 
优点: 对象在内存是连续、不会产生碎片化
缺点: 占用空间 、因为被复制两次
 
(3) 标记算法 :作用在老年、执行逻辑 第一次标记要清除的对象、第二次清楚对象
优点: 无空间的占用
缺点:  对象在内存中不是连续的、产生碎片化
 
(4) 标记压缩算法 : 作用在老年代  执行逻辑 第一次标记要清除的对象、第二次清楚对象 、第三步压缩对象
 
优点: 无碎片化
缺点: 时间复杂度高

Pay attention to WeChat official account Programmer Ruirui

Reply to the java virtual machine after paying attention
to get "In-depth understanding of Java virtual machine JVM advanced features and best practices"

insert image description here

Guess you like

Origin blog.csdn.net/a18302465887/article/details/106025281