当前位置:网站首页>JVM memory structure

JVM memory structure

2022-06-25 16:44:00 Zhangzhiming (autumn recruit version)

 1. Which parts of the memory will overflow
     ① No memory overflow area - Program counter
     ② There are two types of memory overflows
       Ⅰ appear OutOfMemoryError The situation of
           1️⃣ Heap memory exhausted - More and more objects , Has been using , Can't be recycled
           2️⃣ Method area out of memory - More and more classes are loaded , Many frameworks dynamically generate new classes during runtime
           3️⃣ Virtual machine stack accumulation - Each thread will occupy up to 1M Memory , When there are more and more threads running for a long time without destroying
       Ⅱ appear StackOverflowError Region
           1️⃣ Inside the virtual machine stack - Too many method calls ( Recursion has no proper exit )
    

since Java The garbage collection mechanism can automatically reclaim memory , How can there be a memory leak ?
                 This problem , We need to know GC When to recycle memory objects , What kind of memory object will be GC Think it's “ No longer use ” Of .
                Java Access to memory objects in , It's a way of quoting . stay Java In the code, we maintain a reference variable of the memory object , Through this reference variable's value , We can access the memory object space in the corresponding memory address . stay Java In the program , The reference variable itself can be stored in heap memory , It can also be placed in the memory of the code stack ( Same as basic data type ). GC The thread will start tracking from the reference variable in the code stack , To determine which memory is in use . If GC In this way, threads , Unable to trace to a certain heap memory , that GC I think this memory will no longer be used ( Because the code can no longer access this memory ).
                 Through this directed graph memory management , When a memory object loses all references ,GC You can recycle it . On the other hand , If there is a reference to this object , Then it will not be GC Recycling , Even if it is Java Virtual machine throw OutOfMemoryError .
java Since it exists gc Threads , Why is there a memory leak ? - THISISPAN - Blog Garden 1. since Java The garbage collection mechanism can automatically reclaim memory , How can there be a memory leak ? This problem , We need to know GC When to recycle memory objects , What kind of memory object will be GC Think it's “ No longer use ” Of . Java in https://www.cnblogs.com/panxuejun/p/5888817.html

Method area and permanent generation 、 The relationship between meta spaces
        ① The method area is JVM A block in the memory specification , Used to store class metadata 、 Method bytecode
Even if the compiler
        ② Permanent generation is Hotspot Virtual machines are right JVM Specification implementation (1.8 Before )
        ③ Metaspace is Hotspot Virtual machines are right JVM Specification implementation (1.8 after ), Use local memory
As a storage space for this information

JVM Memory parameters
        about JVM Memory configuration parameters : -Xmx10240m -Xms10240m -Xmn5120m -XX:SurvivorRatio=3
Where the minimum memory value and Survivor The total size is
             
   -Xmx:jvm Maximum number of memory 1024m:10g
        ​​​​​​​        -Xms:jvm Minimum memory for  ​​​​​​​ 1024m:10g
                -Xms:jvm The number of new generation memory  ​​​​​​​  5120m:5g
                -XX:SurvivorRatio=3      eden:from=3 So the Cenozoic is divided into 5 Share eden3 from1 to1
        therefore Survivor:2g               

 

 

原网站

版权声明
本文为[Zhangzhiming (autumn recruit version)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251612485971.html