`
poethelasi
  • 浏览: 6065 次
文章分类
社区版块
存档分类
最新评论

VM 堆和非堆

阅读更多

 

Heap and Non-Heap Memory
 
The Java VM manages two kinds of memory: heap and non-heap memory, both of which are created when the Java VM starts.
Java VM 管理两种类型的内存:堆和非堆,两者都在JVM启动时创建。
 
  • Heap memory is the runtime data area from which the Java VM allocates memory for all class instances and arrays. The heap may be of a fixed or variable size. The garbage collector is an automatic memory management system that reclaims heap memory for objects. 

  • Non-heap memory includes a method area shared among all threads and memory required for the internal processing or optimization for the Java VM. It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors. The method area is logically part of the heap but, depending on the implementation, a Java VM may not garbage collect or compact it. Like the heap memory, the method area may be of a fixed or variable size. The memory for the method area does not need to be contiguous.

      堆内存是一片运行时数据区域,JVM使用该块内存为所有的类实例和数组分配内存。堆大小可以是固定的或者可变的。GC是一个自动内存管理系统,它将从(不可达)对象上收回堆内存。
 
      非堆内存包括一个被所有线程共享的方法区和一块用于内部处理需要的或用于JVM优化的内存。它存储了每个类的结构,如运行时常量池,字段和方法数据,方法和构造器代码。方法区是堆的逻辑部分,但是,取决于具体的实现,JVM可以不对其进行垃圾回收或者压缩整理。类似堆内存一样,方法区大小可以是固定的或者可变的。方法区内存不需要是连续的。
 
In addition to the method area, a Java VM may require memory for internal processing or optimization which also belongs to non-heap memory. For example, the Just-In-Time (JIT) compiler requires memory for storing the native machine code translated from the Java VM code for high performance.
       除了方法区外,JVM需要内存作为内部处理或者优化,该内存属于非堆内存。比如,JIT编译器为了更好的性能,需要内存存储从JVM代码编译的成本地机器码。
 
Memory Pools and Memory Managers

Memory pools and memory managers are key aspects of the Java VM's memory system.

  • A memory pool represents a memory area that the Java VM manages. The Java VM has at least one memory pool and it may create or remove memory pools during execution. A memory pool can belong either to heap or to non-heap memory.

  • A memory manager manages one or more memory pools. The garbage collector is a type of memory manager responsible for reclaiming memory used by unreachable objects. A Java VM may have one or more memory managers. It may add or remove memory managers during execution. A memory pool can be managed by more than one memory manager.

内存池内存管理器是JVM内存系统的关键组成部分。
     
     一个内存池代表一块JVM管理的内存区域。 JVM至少有一个内存池,它在运行期间可以创建或移除内存池。一个内存池可以属于堆,也可以属于非堆。
     
     一个内存管理器管理一个或多个内存池。GC是一种内存管理器,它负责收回被不可达对象的使用的内存。JVM可能有一个或多个内存管理器。它可以在执行期间可以增加或者移除内存管理器。一个内存池可以
     被一个以上的内存管理进行管理。

Garbage Collection

Garbage collection (GC) is how the Java VM frees memory occupied by objects that are no longer referenced. It is common to think of objects that have active references as being "alive" and non-referenced (or unreachable) objects as "dead." Garbage collection is the process of releasing memory used by the dead objects. The algorithms and parameters used by GC can have dramatic effects on performance.

The Java HotSpot VM garbage collector uses generational GC. Generational GC takes advantage of the observation that most programs conform to the following generalizations.

  • They create many objects that have short lives, for example, iterators and local variables.

  • They create some objects that have very long lives, for example, high level persistent objects.

垃圾收集(GC)是Java虚拟机如何释放不再被引用的对象占用的内存。人们通常认为对象有两种:仍然被引用的对象是“活着”的,非引用(或无法访问)对象是“死“的。垃圾收集(GC)是一个释放被已死对象占用的内存。GC的算法和参数对性能有非常大的影响。
 
Java HotSpot VM 垃圾收集器使用分代垃圾收集。分代垃圾收集器利用了大多数程序遵循以下分代的观察结果:
 
大多数对象只有短暂的生命周期,比如,循环器和变量。
 
少数对象拥有较长的生命周期,比如,高级的持久化对象。
 
Generational GC divides memory into several generations, and assigns one or more memory pools to each. When a generation uses up its allotted memory, the VM performs a partial GC (also called a minor collection) on that memory pool to reclaim memory used by dead objects. This partial GC is usually much faster than a full GC.
 

The Java HotSpot VM defines two generations: the young generation (sometimes called the "nursery") and the old generation. The young generation consists of an "Eden space" and two "survivor spaces." The VM initially assigns all objects to the Eden space, and most objects die there. When it performs a minor GC, the VM moves any remaining objects from the Eden space to one of the survivor spaces. The VM moves objects that live long enough in the survivor spaces to the "tenured" space in the old generation. When the tenured generation fills up, there is a full GC that is often much slower because it involves all live objects. The permanent generation holds all the reflective data of the virtual machine itself, such as class and method objects.

The default arrangement of generations looks something like Figure 3-7.

分代垃圾收集器将内存分为多个代,并为每个代分配一个或多个内存池。当一个代用完了分配给它的内存,VM将在内存池中执行部分垃圾收集(也称为minor 收集),收回被已死对象占用的内存。这个局部垃圾收集通常比full GC要快很多。
 
Java HotSpot VM 定义了两个代:年轻代(有时也称作"护士")和老年代。年轻代有一个”Eden space“和两个“survivor space" 组成。VM将所有初始化对象分配至Eden space,大多数对象在此死去。当执行一次minor GC时,VM将所有活着的对象从Eden space 移到其中的一个Survivor space中。VM将那些在survivor space存活的较长的对象转移到老年代的”tenured“ space.当 tenured 代填满时,一次full GC通常较慢,因为它涉及到所有存活的对象。永久代持有所有的虚拟机本身的反射数据,比如类和方法对象。
 
代的默认安排看起来像如图3-7

Figure 3-7 Generations of Data in Garbage Collection
The different generations of data defined by the Garbage Collector

If the garbage collector has become a bottleneck, you can improve performance by customizing the generation sizes. Using JConsole, you can investigate the sensitivity of your performance metric by experimenting with the garbage collector parameters. For more information, see Tuning Garbage Collection with the 5.0 HotSpot VM.

如果垃圾收集器成为瓶颈,可以调整各个代的大小来改善性能。使用JConsole,你可以尝试通过垃圾收集器参数调查你的性能指标的灵敏度。更多信息,请参见Tuning Garbage Collection with the 5.0 HotSpot VM.

 

分享到:
评论

相关推荐

    Java VM Heap 堆分析(节选)

    ### Java VM Heap 堆分析知识点详解 #### JVM内的内存管理 Java虚拟机(JVM)在执行Java程序的过程中,会负责内存的分配与回收。内存管理主要包括对象的创建、存储以及垃圾回收等过程。 - **Root Set 和对象的...

    运行jar程序时添加vm参数的方法

    总结来说,通过在运行JAR程序时添加VM参数,我们可以定制JVM的行为,包括内存管理策略和远程监控设置。这对于优化程序性能、监控系统状态以及解决内存泄漏等问题非常有帮助。确保正确理解和使用这些参数,可以更好地...

    用在MyEclipse的VM插件

    1. **配置与启动**:VM插件允许用户自定义Java虚拟机参数,如设置JVM内存大小(-Xms, -Xmx)、堆分配策略、类加载器行为等。在项目启动时,这些参数会被应用到运行或调试的Java进程,确保应用按照预期配置运行。 2. *...

    JavaVM运作原理

    Maxine VM是一种高度可配置的实验性虚拟机,它的设计目标是为了方便研究人员理解和改进JVM的内部机制。 ##### 特点 - **灵活性**:允许对JVM内部进行更多的定制和扩展。 - **可研究性**:提供了丰富的工具和文档,...

    Visual VM1.3.6

    Visual VM是一款强大的Java性能分析工具,它为开发者提供了一种可视化的方式来监控和分析JVM(Java虚拟机)上的应用程序。1.3.6是Visual VM的一个版本,它包含了许多改进和增强,使得开发者能够更有效地理解和优化...

    JDK自带VM分析工具

    - **内存**:展示堆和非堆内存使用情况。 - **线程**:提供详细的线程活动和阻塞信息。 - **类**:显示已加载类的数量和详细信息。 - **JVM**:显示 JVM 的配置和运行时参数。 - **MBeans**:查看和管理 MBeans...

    Visual VM 1.3.8 中文版

    1. **内存分析**:Visual VM可以实时监控Java应用的内存分配和使用情况,包括堆内存、 PermGen(在Java 8中已移除)、Metaspace等区域。通过内存视图,开发者可以定位内存泄漏,了解对象生命周期,并分析对象存活集...

    visual vm虚拟机相关分析。

    2. **内存分析**:通过查看堆内存和对象详细信息,Visual VM可以帮助开发者找到内存占用过高的类或者对象,从而优化内存使用。它支持堆转储分析,可以导出堆快照进行深度分析。 3. **线程分析**:Visual VM提供线程...

    IBM 堆内存分析工具

    此外,理解IBM J9 VM的内存模型和垃圾回收机制也非常重要,这有助于更好地利用IBM堆内存分析工具。 总的来说,IBM堆内存分析工具ha456.jar是Java开发和运维人员不可或缺的工具之一,它可以帮助我们有效地管理和优化...

    Java vm.pptx

    内存区域主要分为方法区(存储类信息)、Java堆(所有对象实例都在此分配内存)、栈(每个线程有一个独立的栈,用于存储栈帧)、PC寄存器(记录当前线程执行的指令地址)、本地方法区(为Java的本地方法接口提供内存...

    Java VM 规范

    每个线程都有自己独立的程序计数器和虚拟机栈,而堆和方法区则是所有线程共享的数据区域。 - **程序计数器**:记录当前线程正在执行的字节码指令地址。 - **虚拟机栈**:用于存储局部变量表、操作数栈、动态链接...

    Visual VM的GC插件

    2. **堆内存使用情况**:显示堆内存的总体使用情况,包括新生代、老年代和持久代的大小、已分配空间和剩余空间。这对于识别潜在的内存溢出问题非常有帮助。 3. **对象生存周期**:通过图表展示对象从新生代到老年代...

    tomcat jdk堆大小配置及eclipse中设置

    4. 在"Java Settings"页签中,你可以看到"VM arguments"输入框,这里就是用来输入JVM参数的地方,如`-Xms`和`-Xmx`。 5. 输入你的内存配置,例如`-Xms1024m -Xmx2048m`,然后点击"OK"保存设置。 注意,过大的堆大小...

    优化Java堆大小的5个技巧

    - **Native Heap (C-Heap)**:所有JVM厂商都会使用的一种内存区域,主要用于存储非Java代码的内存需求。 ##### **1.2 学习JVM内存管理的重要性** 深入理解JVM内存管理的重要性不言而喻。一方面,这有助于开发者更...

    eclipse.ini

    可以看出JVM主要管理两种类型的内存:堆和非堆 简单来说:堆就是Java代码可及的内存,是留给开发人员使用的;非堆就是JVM留给自己用的,所以方法区、JVM内部处理或优化所需的内存(如JIT编译后的代码缓存)、每个类...

    linuxvm.pdf

    - 包含起始和结束虚拟地址、标志(如只读标志)、虚拟内存操作集(`vm_ops`)和对应的文件(如果该区域由文件支持的话)等信息。 - 当发生缺页异常时,`nopage()`函数会被调用来处理。 #### 七、分页结构 Linux...

    优化java堆大小的5个技巧.docx

    开发者应详细阅读各个JVM厂商的文档,如Sun HotSpot VM、IBM VM和Oracle JRockit VM,以便更好地了解内存管理机制。 2. **评估应用程序需求**: 应用程序的静态内存占用需求,包括部署的应用数量、加载的类、数据...

    webstorm-vmoptions:JetBrains WebStorm vmoptions 针对性能进行了优化

    `vmoptions`文件是Java虚拟机(JVM)的配置文件,用于设置内存分配、垃圾回收策略等关键参数,直接影响到WebStorm的启动速度和运行性能。针对不同的系统环境,特别是内存大小,我们需要对其进行适当的优化。 对于32...

Global site tag (gtag.js) - Google Analytics