Getting started with the JVM's GC mechanism

Introduction

It mentions the GC algorithm and the role of each area in the heap area.

There are various types of GC algorithms themselves. The following two are the most basic.

Basic algorithm

-Reference Counter

Mark & Sweep is the standard in Java. However, this alone has the following problems, and it is actually extended and implemented.

Challenges of Mark & Sweep

  1. Memory area fragmentation
  2. Stop the world while doing GC
  3. The processing load is high when GC is applied to all the target memory areas (Full GC).

1. Measures against heap area fragmentation => Copying

If the unnecessary area is released repeatedly, the empty area becomes uneven and inflexible. In other words, the processing cost for creating a new object increases.

Therefore, the following algorithms are combined.

** This is why the heap area has a From area and a To area. ** **

2. Countermeasures against downtime => Concurrent marking

--Mark & Sweep Mark is added in parallel in threads without stopping the Java program. --The problem is that if the state is changed before Sweep runs, there is a possibility of leakage and dust. To solve this, mark the object when it is changed (it seems to be a write barrier), stop the Java program before the mark ends and Sweep starts, and fix the marking from the marked place. do. (Serial marking)

It's called a concurrent marker sweep because it adds up this algorithm.

3. Measures against processing load

It uses a generational GC algorithm. Simply put, a new object is placed in the New area, GC is applied to the New area frequently, and the objects that survived after several GCs are considered to continue to survive and are placed in the Old area. An algorithm called FullGC when moving and old are accumulated. Instead of doing Full GC every time, limit the target range of GC and distribute the load of GC.

Reference: GC by generation

** This is why there are New and Old in the JVM heap area. ** **

There are different types of JVM memory areas based on the GC algorithm.

From the contents so far, the following can be understood.

--The reason why From and To are separated in the New and Old areas is to perform copying to prevent fragmentation of the heap area.

--The reason why there are New and Old in the heap area is to limit the area targeted for GC and distribute the processing load. (The Eden area in New also exists because I want to remove the newly created object from the GC target and separate it.)

reference

Java heap memory management mechanism

JVM tuning

Digression

An algorithm called Garbage First Garbage Collection is coming ...? Garbage-First Garbage Collection

Recommended Posts

Getting started with the JVM's GC mechanism
Getting Started with DBUnit
Getting Started with Ruby
Getting Started with Swift
Getting Started with Docker
Getting Started with Doma-Transactions
Getting Started with Doma-Using Projection with the Criteira API
Getting Started with Doma-Using Subqueries with the Criteria API
Getting Started with Doma-Using Joins with the Criteira API
Getting Started with Doma-Introduction to the Criteria API
Getting Started with Doma-Annotation Processing
Getting Started with Java Collection
Getting Started with JSP & Servlet
Getting Started with Java Basics
Getting Started with Spring Boot
Getting Started with Ruby Modules
Getting Started with Doma-Dynamicly construct WHERE clauses with the Criteria API
Getting Started with Reactive Streams and the JDK 9 Flow API
Getting Started with Java_Chapter 5_Practice Exercises 5_4
[Google Cloud] Getting Started with Docker
Getting started with Java lambda expressions
Getting Started with Docker with VS Code
Returning to the beginning, getting started with Java ② Control statements, loop statements
Summarize the main points of getting started with JPA learned with Hibernate
Getting Started with Doma-Criteria API Cheat Sheet
Getting Started with Ruby for Java Engineers
Getting Started with Docker for Mac (Installation)
Getting Started with Parameterization Testing in JUnit
Getting Started with Java Starting from 0 Part 1
Getting Started with Ratpack (4)-Routing & Static Content
Getting Started with Language Server Protocol with LSP4J
Getting Started with Creating Resource Bundles with ListResoueceBundle
Getting Started with Java_Chapter 8_About Instances and Classes
Links & memos for getting started with Java (for myself)
[Deprecated] Getting started with JVM GC and memory management that I didn't understand
Getting Started with Java 1 Putting together similar things
Getting started with Kotlin to send to Java developers
About the mechanism when displaying the GUI with Docker
I tried Getting Started with Gradle on Heroku
Getting started with Java programs using Visual Studio Code
Getting Started with Legacy Java Engineers (Stream + Lambda Expression)
Get started with serverless Java with the lightweight framework Micronaut!
Organize Java GC mechanism
Raise GC with jcmd
Get started with Gradle
Proceed with Rust official documentation on Docker container (1. Getting started)
Getting started with Java and creating an AsciiDoc editor with JavaFX
[Java] [Play Framework] Until the project is started with Gradle
Now is the time to get started with the Stream API
Getting Started with GitHub Container Registry instead of Docker Hub