Java GC Series (1): Introduction to Java Garbage collection

Source: Internet
Author: User

This article consists ofimportnew - nice translator from Javapapers.

Java's memory allocations and recoveries are all automatically completed by the JVM garbage collection process. Unlike the C language, Java developers do not need to write their own code to implement garbage collection. This is one of the many popular features of Java that can help programmers to write Java programs better.

The following four tutorials are the basis for understanding Java garbage Collection (GC):

    1. Introduction to Garbage collection
    2. How does rubbish recycling work?
    3. Categories of garbage collection
    4. Garbage collection Monitoring and analysis

This tutorial is the first part of the series. The basic terminology, such as JDK, JVM, JRE, and HOTSPOTVM, is explained first. The JVM structure and the Java heap memory structure are then introduced. Understanding these fundamentals is important for understanding the garbage collection knowledge behind.

Java Key terminology
    • JAVAAPI: A series of packaged libraries that help developers create Java applications.
    • Java Development Kit (JDK): A series of tools to help developers create Java applications. The JDK contains tools to compile, run, package, distribute, and monitor Java applications.
    • Java virtual Machine (JVM): The JVM is an abstract computer structure. Java programs are written according to the characteristics of the JVM. The JVM executes instructions that are specific to the operating system and can translate Java instructions into the underlying system. The JVM ensures the platform independence of Java.
    • Java Runtime Environment (JRE): The JRE contains the JVM implementation and Java APIs.
Java HotSpot Virtual Machine

Each JVM implementation may implement a garbage collection mechanism in different ways. Prior to the acquisition of Sun, Oracle used the JRockit JVM, which was acquired after the acquisition using the Hotspot JVM. Oracle now has two JVM implementations and two JVM implementations are merged over time.

The HotSpot JVM is part of the current Oracle SE Platform standard core component. In this garbage collection tutorial, we'll look at the garbage collection principles based on hotspot virtual machines.

JVM Architecture

The following picture summarizes the key components of the JVM. In the JVM architecture, the two main components associated with garbage collection are heap memory and garbage collector. Heap memory is an in-memory data area used to hold object instances at runtime. The garbage collector will also operate here. Now we know how these components work in the framework.

Java Heap Memory

It is necessary to understand the role of the JVM memory model that exists within the heap. At run time, instances of Java are stored in the heap memory area. When an object is no longer referenced, the satisfied condition is removed from the heap memory. During the garbage collection process, these objects are removed from the heap memory and the memory space is reclaimed. Heap memory The following three main areas:

    1. New Generation (young Generation)
      • Eden Space (Eden Space, where any instance enters the run-time memory area through Eden spaces)
      • S0 Survivor spaces (S0 Survivor space, instances with long periods of time will be moved from Eden Space to S0 Survivor space)
      • S1 survivor Space (longer instances will move from S0 survivor space to S1 survivor space)
    2. Old Generation instance will be promoted from S1 to tenured (lifetime generation)
    3. Permanent generation (Permanent Generation) contains meta-information about the details of classes, methods, and so on

The permanent generation space has been removed from the Java SE8 feature.

The second article in this series will show you how Java garbage collection works.

Original link: javapapers translation: importnew.com - Nice
Link: http://www.importnew.com/13504.html

Java GC Series (1): Introduction to Java Garbage collection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.