当前位置:网站首页>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.

  1. 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 .
  2. 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

  1. 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 .
  2. Stack storage is faster than heap , Next to registers , Stack data can be shared .
  3. 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 :

  1. 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
  2. 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

  1. To hold JDK What you carry Class,Interface Metadata , It stores the class information necessary for the running environment
  2. The data in this area will not be collected by the garbage collector , close JVM The memory occupied by this area will be released
  3. Java.lang.OutOfMemoryError:PerGen space explain Java Virtual machine to permanent generation Perm Not enough memory settings
  4. 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  

 

 

原网站

版权声明
本文为[cfcoolya]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231006570559.html