IBM JVM 1.4.1 GC and Memory Management

xiaoxiao2021-03-06  50

(This article, main translation

http://www-106.ibm.com/developerWorks/java/jdk/diagnosis/gcandmemory.pdf

1 Overview

This document describes the function and working principle of ST (storage components) in IBM JavaVM 1.4.1.

The ST component is responsible for allocating memory in HEAP, which can be used to define objects, arrays, and classes. After the memory is allocated, if there is a reference to it in the JVM, then this object is considered to be survived, that is, this object is up. When an object is not directly or indirect, it becomes garbage, which can be recovered, and the corresponding memory can be reused. When recycling objects, the garbage collector (GC) must terminate the object to ensure that all of the associated Monitor is reclaimed (this pool is generally called Monitor Cache). In ST, not all object processing is the same, some objects (such as ClassClass and Thread) objects always allocate (PinnedClusters), all Reference objects (including sub-objects) in HEAP. The GC is also specially processed. The detailed situation will be explained below.

1.1 Object Allocation

When calling these interface methods, objects are assigned: StCachealloc, StallocObject, Stallocarray, Stallocclass. These methods allocate a given size area from the heap, but there are different call parameters and semantics. Stcachealloc is always used to assign small objects. It is optimized to have good performance, the object is allocated directly from the thread, and a new object is always in this stack. The tail is allocated, and there is no need to occupy a global lock, so the efficiency is very high. Use StallocObject / Stallocarray assigned objects, if there is enough (<512 bytes), it will also be assigned from this partial heap.

1.2 REACHABLE OBJECTS

A JVM activity status consists of several parts: all active threads, stack, Java classes Static member, partial or global JNI reference. All calling methods have a corresponding C stack that is a collection of all root objects that make up the JVM. In the root refer to the objects in the heap, the object will reference other objects, which repeats to determine all accessible objects.

1.3 GARBAGE COLLECTION

When JVM can't assign an object in the current stack, it is: garbage recycling for the heap. This process starts when any thread calls STGC (probably because memory allocation fails, or calls to system.gc ()).

First, JVM should obtain all lock resources required for garbage collection to ensure that when other thread holds a key lock, it will not be suspended. All other threads will be paused through the XM interface, ensuring that the state of these threads can be used correctly by the current thread. These states include a thread stack, a register that performs a time, which is used to track object references.

Then, the GC can begin, it contains 3 phases:

Mark Sweep Compression (optional)

1.3.1 Tag (Mark) Stage In the tag phase, all objects that can be referenced from the thread stack, INTERNEDSTRING, JNI references. First, you need to create a JVM root object collection. Objects in this collection may reference to other objects, so the next step is to scan these objects to find all references to objects. This process generates all one containing all survived objects. Each binary bit in the AllocBits vector corresponds to an 8-byte memory in the heap, when the position 1 indicates that the corresponding memory object is assigned to an object. When the GC traces the stack, it first compares whether a pointer is within the scope of the heap, and then determines whether this pointer is pointing to an 8 aligned address, and the corresponding Allocbit is already set. If these conditions are met, the GC will put this The pointer is used as an object pointer, and the corresponding bit is set in the MarkBits vector to indicate that the object is accessed. (The so-called conservative algorithm, actually this may not be a pointer, for example an integer, floating point number) Finally, the GC scans all fields in this object to determine the object it referenced. This scanning process is precise because the meta information is stored in the object, which fields can be provided for the GC is a reference field (this information is initialized when the ClassLoader is loaded).

1.3.2 Sweep Phase

After the marking phase is completed, each bit in the Markbits vector represents the corresponding object is survived, and the bit in the markbits must be a subset of allocbits. The main goal of the cleaning stage is to find the difference between the two, find all the objects that exist but not living. In the conventional sweeping technology, in the heash, access each object, the inspection team won allocbit and markbit to detect whether the object is garbage. Now, due to the use of a bitwise cleaning, it is no longer necessary to scan the objects in the heap, which avoids the risk of the shortage. When the bitwise cleaning, the MarkBits vector is checked for those of those of the plurality of 0 (these areas may be free), when such a zone is found, the length of the object before this area is checked to confirm that it can be released. Memory space.

1.3.3 Compaction Phase

转载请注明原文地址:https://www.9cbs.com/read-81290.html

New Post(0)