`
netcome
  • 浏览: 482220 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

IBM JVM垃圾回收原理——1

    博客分类:
  • JAVA
阅读更多

原文下载:IBM Garbage Collection and Storage Allocation Techniques 

 

1 Introduction 

 

This document describes the functions of the Storage (ST) component from release 1.2.2 

to 1.4.1, Service Refresh 1. (IBM JDK5.0/6.0没有发布最新文档)

 

The ST component allocates areas of storage in the heap.  These areas of storage define 

objects, arrays, and classes.  When an area of storage has been allocated, an object 

continues to be live while a reference (pointer) to it exists somewhere in the active state 

of the JVM; thus the object is reachable.  When an object ceases to be referenced from 

the active state, it becomes garbage and can be reclaimed for reuse.  When this 

reclamation occurs, the Garbage Collector must process a possible finalizer and also 

ensure that any monitor that is associated with the object is returned to the pool of 

available monitors (sometimes called the monitor cache).  Not all objects are treated 

equally by the ST component.  Some (ClassClass and Thread) are allocated into special 

regions of the heap (pinned clusters)(类和线程被分配到堆的特定区域); others (Reference and its derivatives) are treated 

specially during tracing of the heap.  More details on these special cases are given in 

section 4.4 “Reference Objects”. 

 

1.1 Object allocation 

 

Object allocation is driven by calls to one of the allocation interfaces; for example,  

stCacheAlloc, stAllocObject, stAllocArray, stAllocClass(这些函数没见过。。。). These interfaces all allocate a given amount of storage from the heap, but have different parameters and semantics.  The 

stCacheAlloc(用于小对象) routine is specifically designed to deliver optimal allocation performance 

for small objects. Objects are allocated directly from a thread local allocation buffer that 

the thread has previously allocated from the heap.(对象从线程之前对分配来的本地缓存中获取空间) A new object is allocated from the end 

of this cache without the need to grab the heap lock(新对象无需获取堆的锁即可分配空间,效率很高); therefore, it is very efficient. Objects 

that are allocated through the stAllocObject and stAllocArray interfaces are, if small 

enough (currently 512 bytes), also allocated from the cache.  

 

1.2 Reachable Objects 

 

The active state of the JVM is made up of the set of stacks that represents the threads, the 

static’s that are inside Java classes, and the set of local and global JNI references(堆包含线程所用栈、类的静态变量和本地、全局JNI引用集合). All 

functions that are invoked inside the JVM itself cause a frame on the C stack. This 

information is used to find the roots. These roots are then used to find references to other 

objects. This process is repeated until all reachable objects are found. 

 

1.3 Garbage Collection 

 

When the JVM cannot allocate an object from the current heap because of lack of space, 

the first task is to collect all the garbage that is in the heap. This process starts when any 

thread calls stGC either as a result of allocation failure, or by a specific call to 

System.gc()(引起完整GC?). The first step is to get all the locks that the garbage collection process needs. (第一步是获取垃圾回收所需的全部锁)

This step ensures that other threads are not suspended while they are holding critical 

locks. All the other threads are then suspended through an execution manager (XM) 

interface, which guarantees to make the suspended state of the thread accessible to the 

calling thread. This state is the top and bottom of the stack and the contents of the 

registers at the suspension point. It represents the state that is required to trace for object 

references. Garbage collection can then begin. It occurs in three phases: 

y  Mark 

y  Sweep 

y  Compaction (optional) 

 

1.3.1 Mark Phase 

 

In the mark phase, all the objects that are referenced from the thread stacks, static’s, 

interned strings, and JNI references are identified. This action creates the root set of 

objects that the JVM references. Each of those objects might, in turn, reference others. 

Therefore, the second part of the process is to scan each object for other references that it 

makes. These two processes together generate a vector that defines live objects. 

 

Each bit in the vector (allocbits) corresponds to an 8-byte section of the heap.(矢量中的每个bit代表了堆的一个8字节区域)  The 

appropriate bit is set when an object is allocated.  When the Garbage Collector traces the 

stacks, it first compares the pointer against the low and high limits of the heap. It then 

ensures that the pointer is pointing to an object that is on an 8-byte boundary (GRAIN) 

and that the appropriate allocbit is set to indicate that the pointer is actually pointing at an 

object. The Garbage Collector now sets a bit in the markbits vector to indicate that the 

object has been referenced. 

 

Finally, the Garbage Collector scans the fields of the object to search for other object 

references that the object makes.  This scan of the objects is done accurately because the 

method pointer that is stored in its first word enables the Garbage Collector to know the 

class of the object. The Garbage Collector therefore has access to a vector of offsets that 

the classloader builds at class linking time (before the creation of the first instance).  The 

offsets vector gives the offset of fields that are in the object that contains object 

references. (垃圾回收器可以通过类的定义找到对象字段引用)

 

1.3.2 Sweep Phase 

 

After the mark phase, the markbits vector contains a bit for every reachable object that is 

in the heap. The markbits vector must be a subset of the allocbits vector. The task of the 

sweep phase is to identify the intersection(交集) of these vectors; that is, objects that have been 

allocated but are no longer referenced. 

 

The original technique for this sweep phase was to start a scan at the bottom of the heap, 

and visit each object in turn. The length of each object was held in the word that 

immediately preceded it on the heap. At each object, the appropriate allocbit and markbit 

was tested to locate the garbage. 

 

Now, the bitsweep technique avoids the need to scan the objects that are in the heap and 

therefore avoids the associated overhead cost for paging(换页). In the bitsweep technique, the 

markbits vector is examined directly to look for long sequences of zeros (not marked), 

which probably identify free space. When such a long sequence is found, the length of 

the object that is at the start of the sequence is examined to determine the amount of free 

space that is to be released. 

 

1.3.3 Compaction Phase 

 

After the garbage has been removed from the heap, the Garbage Collector can compact 

the resulting set of objects to remove the spaces that are between them. Because 

compaction can take a long time, it is avoided if possible(压缩耗时). Compaction, therefore, is a rare 

event. Compaction avoidance is explained in more detail later in section “4.3.1 

Compaction Avoidance”.  

 

The process of compaction is complicated because handles are no longer in the JVM. If 

any object is moved, the Garbage Collector must change all the references that exist to it. 

If one of those references was from a stack, and therefore the Garbage Collector is not 

sure that it was an object reference (it might have been a float, for example), the Garbage 

Collector cannot move the object. (如果引用来自于栈,垃圾回收器不敢确定它是否是对象引用,也可能是浮点数比如,所以垃圾回收器不能移动对象)Such objects that are temporarily fixed in position are 

referred to as dosed in the code and have the dosed bit set in the header word to indicate 

this fact. Similarly, objects can be pinned during some JNI operations. Pinning has the 

same effect, but is permanent until the object is explicitly unpinned by JNI. Objects that 

remain mobile are compacted in two phases by taking advantage of the fact that the mptr 

is known to have the low three bits set to zero. One of these bits can therefore be used to 

denote the fact that it has been swapped. Note that this swapped bit is applied in two 

places: the link field (where it is known as OLINK_IsSwapped), and also the mptr (where 

it is known as GC_FirstSwapped). In both cases, the least significant bit (x01) is being 

set. 

 

At the end of the compaction phase, the threads are restarted through an XM interface. 

 

分享到:
评论

相关推荐

    ibm-java-堆内存分析工具-heapanalyzer

    - **垃圾回收(GC)原理**:了解如何自动回收不再使用的对象,以及不同垃圾收集器的工作机制。 - **内存泄漏**:理解内存泄漏的原因,如全局变量、静态集合、线程池未关闭等。 - **对象引用**:强引用、软引用、...

    JVMClass文件结构学习.docx

    JVM通过解析特定的二进制文件格式——Class文件来执行Java字节码。Class文件包含了JVM指令集、符号表以及辅助信息。 Class文件的结构基于两种数据类型:无符号数和表。无符号数是基本的数据类型,使用u1、u2、u3、...

    IBM WebSphere Performance Tool / ISA / jca457.jar / ha456.jar / ga439.jar

    通过分析这个日志,开发者和运维人员可以了解垃圾收集器的行为,包括何时启动、耗时多久、回收了多少内存等,这对于调整JVM参数以优化WebSphere性能至关重要。例如,如果频繁的垃圾收集导致应用暂停时间过长,可能...

    GCCollector

    **GCCollector——深入理解垃圾回收与性能优化** 在Java编程语言中,内存管理是一个关键的概念,特别是垃圾收集(Garbage Collection, GC)机制。GC是自动进行内存清理的一种技术,它负责识别并释放不再使用的对象...

    Tomcat性能优化

    ### Tomcat性能优化 ...综上所述,通过合理配置JVM参数和垃圾回收策略,可以在很大程度上避免Tomcat中的内存溢出问题,进而提升其整体性能。此外,选择合适的虚拟机版本也是提高性能的重要步骤之一。

    Plumbr Handbook Java Garbage Collection

    手册针对的是Oracle Hotspot和OpenJDK的行为,对于其他如jRockit或IBM J9等JVM的运行时环境,本手册中涉及的内容可能有所不同。 垃圾收集是自动内存管理的一个过程,其主要目的是找到并清理不再使用的对象,释放...

    Java虚拟机(第二版)1

    《Java虚拟机(第二版)》一书涵盖了Java开发与运行环境的核心部分——Java虚拟机(JVM)的深入解析。这本书旨在帮助读者理解JVM的工作原理,优化Java应用程序的性能,并解决运行时可能出现的问题。 Java自1995年...

    Tomcat优化-Tomcat 的性能调优的原理和方法

    - 对于IBM虚拟机,建议将`-Xms`设置为应用所需的最小值,以提高垃圾回收效率。 ##### 2.1.2 操作系统性能优化 - **HP-UX示例**:在HP-UX系统中,以下参数对Tomcat的影响较大: - `max_thread_proc`:一个进程所...

    IBM面试题目(特别绝对有作用的)

    5. **JVM**:理解内存模型,包括堆、栈、方法区、本地方法栈等,以及垃圾回收机制。 6. **设计模式**:熟悉常见的设计模式,如单例、工厂、装饰器、观察者等,并能结合实际问题应用。 7. **Spring框架**:了解依赖...

    公司内部培训的高性能应用设计与开发技术(绝版)

    - JVM中的引用类型包括强引用、软引用、弱引用和虚引用,其中软引用可以帮助加速垃圾回收过程。 - **GC分代回收机制**: - 堆被分为Young(年轻代)、Tenured(年老代)和Perm(持久代)。 - 不同类型的垃圾收集...

    websphere系统部署

    为了优化垃圾回收,勾选“详细垃圾回收”,并添加通用JVM参数:-XX:+UseParallelGC -Dfile.encoding=UTF-8 -XX:PermSize=256M -DenvironmenTypeCode=DevEnvironment -Dfile.encoding=GBK。这些参数有助于提高性能和...

    ibm教育学院Java2课件

    它可能包括Java的平台独立性(Java虚拟机JVM)、面向对象特性、垃圾回收机制等内容。 2. **第四章 软件开发周期简介**:这部分内容可能讲解了软件开发的基本流程,包括需求分析、设计、编码、测试和维护等阶段,...

    J2EE企业级项目开发-3期(KC007) 3.4 消息中间件考试.doc

    【J2EE企业级项目开发-3期(KC007) 3.4 消息中间件】是针对企业级应用开发中的一个重要组件——消息中间件进行深度探讨的课程内容。消息中间件在现代软件架构中扮演着关键角色,它负责在分布式系统中的不同组件之间...

    Hadoop实战

    第一部分 Hadoop——一种分布式...23612.4 搭建面向企业查询的分析系统——IBM的ES2项目 23812.4.1 ES2系统结构 24012.4.2 ES2爬虫 24112.4.3 ES2分析 24212.4.4 小结 24912.4.5 参考文献 250附录A HDFS文件命令 251

    计算机二级JAVA重点知识点积累.pdf

    - 其他特点包括面向对象、安全性、高性能、可移植性、解释执行和自动垃圾回收等,这些将在进一步的学习中深入理解。 4. **Java标准组织——JCP(Java Community Process)**: JCP是一个开放的国际组织,负责Java...

    perf tools jre2

    3. `J9TraceFormat.dat`:可能与IBM J9 JVM的追踪格式相关,perf可以捕获并分析这些追踪数据,以理解JVM的内部行为。 4. `ir.idl` 和 `orb.idl`:这些可能是接口定义语言(IDL)文件,用于跨进程通信。perf可能用于...

    Java入门教程

    1. **跨平台性**:Java的这一特性源于其“字节码”概念,即Java源代码被编译成一种中间格式——字节码,然后由Java虚拟机(JVM)解释执行,从而实现了平台独立性。 2. **安全性**:Java提供了严格的访问控制机制和...

    java的入门教程

    Java的平台独立性得益于其独特的运行时环境——Java虚拟机(JVM),它能够解释字节码,让Java程序能够跨平台运行。面向对象的特性让Java的程序设计更加模块化和可复用。Java支持多线程,这使得可以同时执行多个任务...

    MemoryAnalyzer 使用中文

    - **打开heap dump**:MAT支持多种格式的heap dump文件,如标准的JVM dump或IBM J9 dump。用户只需通过"File" -> "Open Heap Dump"菜单导入文件。 - **概览视图**:在主界面,可以看到一个概览图,显示堆内存的...

Global site tag (gtag.js) - Google Analytics