Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

JVM Series IV: types of HotSpot VM GC

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Types of HotSpotVMGC

Collector species

There are four types of GC in HotSpotVM5.0:

Incremental (sometimescalledtrain) lowpausecollector has been discarded and is not introduced.

Category serialcollector (Serial) parallelcollector (parallel)

(throughputcollector)-(focus on throughput) concurrentcollector (concurrency)

(concurrentlowpausecollector)-(focus on response time) introduction

Single-threaded collector

Using a single thread to complete all gc work, without communication between threads, is relatively efficient

Parallel collector

Using multi-thread and multi-CUP to improve the efficiency of GC.

The main goal is to achieve a certain throughput.

Concurrent collector

Using multi-thread and multi-CUP to improve the efficiency of GC.

Do most of the work concurrently, making the gcpause short

Trial scenario single processor machine with no pausetime requirements

Suitable for science and technology and background processing

Have applications of medium / large dataset size and run on multiprocessors, focusing on throughput (throughput)

Suitable for medium / large dataset size applications, application servers, telecommunications

Focus on responsetime, not throughput

Use the default in Client mode

Can be used

Available-mandatory use by XX:+UseSerialGC

Advantages: no advantages for server applications

Disadvantages: slow, unable to make full use of hardware resources

Default in Server mode

-- YGC:PSFGC:ParallelMSC

Mandatory assignment is available with-XX:+UseParallelGC or-XX:+UseParallelOldGC

-- ParallelGC stands for FGC and ParallelMSC

-- ParallelOldGC stands for FGC and ParallelCompacting

Advantages: high efficiency

Disadvantages: when the heap becomes larger, the resulting pause time becomes longer

Available-XX:+UseConcMarkSweepGC force assignment

Advantages:

When reclaiming old, the pause time caused by the application is very short, so it is suitable for applications with high response time.

Disadvantages:

1. Memory fragmentation and floating garbage

The memory allocation efficiency of 2.old is low.

3. The whole time of recycling is longer.

4. Contend with App for CPU memory Reclamation trigger YGC

Insufficient eden space

FGC

Insufficient old space

Insufficient perm space

Displays timing triggers for calls to System.gc (), including RMI, etc.

Pessimistic Strategy in YGC

Memory information of dumplive (jmap-dump:live)

YGC

Insufficient eden space

FGC

Insufficient old space

Insufficient perm space

Displays timing triggers for calls to System.gc (), including RMI, etc.

Pessimistic Strategy in YGC-- before YGC & after YGC

Memory information of dumplive (jmap-dump:live)

YGC

Insufficient eden space

CMSGC

The utilization rate of 1.oldGen reaches a certain rate, which is 92% by default.

two。 CMSClassUnloadingEnabled is configured, and the use of PermGen reaches a certain rate, which is 92% by default.

3.Hotspot decides whether to break the law or not based on the estimate.

4. When ExplictGCInvokesConcurrent is configured, it shows that System.gc. XML is called.

FullGC (SerialMSC)

Promotionfailed or concurrentModeFailure; what happens when memory collection is triggered? YGC

Clear the memory occupied by all noref objects in eden+from

Copy all living objects in eden+from to to

In the process, some objects will be promoted to old:

-- to can't let go.

-- those who have survived more than tenuringthreshold

Recalculate TenuringThreshold

Do the above actions with a single thread

Suspend the application in the whole process

FGC

If CollectGen0First is configured, YGC is triggered first

Clear the object of noref in heap and the information of class loaded in classloader that has been unloaded in permgen

Do the above actions with a single thread

Suspend the application of YGC in the whole process

The action is basically the same as that of serial, but different:

1. Multithreaded processing

In the end, 2.YGC not only recalculates TenuringThreshold, but also resizes Eden and From

FGC

1. If ScavengeBeforeFullGC is configured (default), YGC (?) will be triggered first.

2.MSC: clear the noref object in heap, load the class information in classloader that has been unloaded in permgen, and compress it

3.Compacting: clear some noref objects in heap, load class information in classloader that has been unloaded in permgen, and compress partially

Multithreading to do the above actions.

YGC

The action is basically the same as that of serial, but different:

1. Multithreaded processing

CMSGC:

When 1.oldgen arrives at the ratio, only the space occupied by noref objects in oldgen is cleared.

When 2.permgen arrives, it clears only the class information loaded by classloader that has been cleared.

FGC

The detailed parameters with serial are available-XX:+UseSerialGC is mandatory.

-XX:SurvivorRatio=x, controls the size of the eden/s0/s1

-XX:MaxTenuringThreshold, which is used to control the maximum number of times an object can survive in the new generation.

-XX:PretenureSizeThreshold=x, which controls how many bytes the objects exceed are allocated in old.-XX:SurvivorRatio=x, controls the size of eden/s0/s1.

-XX:MaxTenuringThreshold, which is used to control the maximum number of times an object can survive in the new generation.

-XX:UseAdaptiveSizePolicy dynamically adjusts the actions of edenfrom and tenuringthreshold after removing YGC

-XX:ParallelGCThreads sets the number of parallel threads

Triggered when XX:CMSInitiatingOccupancyFraction sets the ratio that oldgen uses to reach

-XX:CMSInitiatingPermOccupancyFraction, which is triggered when the ratio of PermGen usage reaches is set.

-XX:+UseCMSInitiatingOccupancyOnly forbids hostspot to trigger CMSGC by itself

Note:

The difference between throughputcollector and concurrentlowpausecollector is that throughputcollector uses multithreading only in youngarea, while concurrentlowpausecollector also uses multithreading in tenuredgeneration.

According to official documents, the two of them need to be multi-CPU in order to work. In the case of a CPU, it is not as good as the default serialcollector, because thread management consumes CPU resources. In the case of two CPU, the improvement is not great. It will only improve in the case of more CPU. Of course, concurrentlowpausecollector has a mode that provides as few pauses as possible on machines with less CPU, see CMSGCIncrementalmode.

When you want to use throughputcollector, add-XX:+UseParallelGC to javaopt to start throughputcollector collection. You can also add-XX:ParallelGCThreads= to change the number of threads. There are also two parameters-XX:MaxGCPauseMillis= and-XX:GCTimeRatio=,MaxGCPauseMillis= used to control the maximum pause time, while-XX:GCTimeRatio can increase the ratio of GC to CPU and reduce heap by maximum speech.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 268

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report