`
liu0107613
  • 浏览: 74599 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

java虚拟机规范 3.5 运行期数据区

    博客分类:
  • java
阅读更多

http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html

3.5 Runtime Data Areas

  The Java virtual machine defines various runtime data areas that are used during execution of a program. Some of these data areas are created on Java virtual machine start-up and are destroyed only when the Java virtual machine exits. Other data areas are per thread. Per-thread data areas are created when a thread is created and destroyed when the thread exits.

 

 java 虚拟机定义好几种运行期数据结构,用于程序的执行。一些数据结构是由java虚拟机启动时创建,退出时销毁。

 

也有一些数据结构用于线程 。用于线程的数据结构是由线程启动时创建,退出时销毁。

 

 

 

3.5.1 The pc Register

The Java virtual machine can support many threads of execution at once (§2.19). Each Java virtual machine thread has its own pc (program counter) register. At any point, each Java virtual machine thread is executing the code of a single method, the current method (§3.6) for that thread. If that method is not native, the pc register contains the address of the Java virtual machine instruction currently being executed. If the method currently being executed by the thread is native, the value of the Java virtual machine's pc register is undefined. The Java virtual machine's pc register is wide enough to hold a returnAddress or a native pointer on the specific platform.

 

3.5.1 PC 寄存器

虚拟机支持多线程并行。每个java线程都有自己的PC寄存器。不管怎样,java线程只是自执行单个方法,线程的当前方法的代码。 方法不是native的话,PC寄存器就包含一个地址,指向虚拟机当前指令。 如果方法是native的话,PC寄存器的值就是undefined.因为java虚拟机的pc寄存器是足够大,所以能够保持一个returnAddress 或一个特定平台的native指针。

 

 

3.5.2 Java Virtual Machine Stacks

Each Java virtual machine thread has a private Java virtual machine stack, created at the same time as the thread.3 A Java virtual machine stack stores frames (§3.6). A Java virtual machine stack is analogous to the stack of a conventional language such as C: it holds local variables and partial results, and plays a part in method invocation and return. Because the Java virtual machine stack is never manipulated directly except to push and pop frames, frames may be heap allocated. The memory for a Java virtual machine stack does not need to be contiguous.

The Java virtual machine specification permits Java virtual machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation. If the Java virtual machine stacks are of a fixed size, the size of each Java virtual machine stack may be chosen independently when that stack is created. A Java virtual machine implementation may provide the programmer or the user control over the initial size of Java virtual machine stacks, as well as, in the case of dynamically expanding or contracting Java virtual machine stacks, control over the maximum and minimum sizes.4

The following exceptional conditions are associated with Java virtual machine stacks:

 

  • If the computation in a thread requires a larger Java virtual machine stack than is permitted, the Java virtual machine throws a StackOverflowError.

     

  • If Java virtual machine stacks can be dynamically expanded, and expansion is attempted but insufficient memory can be made available to effect the expansion, or if insufficient memory can be made available to create the initial Java virtual machine stack for a new thread, the Java virtual machine throws an OutOfMemoryError.

 

3.5.2 虚拟机栈

虚拟机线程拥有一个私有的虚拟机栈,创建线程的时候也同时创建线程栈。

栈存储frames,栈类似于其他语言,如c语言中的栈。存储local 变量和中间结果。同时方法的调用和返回的操作也用到了栈。对Java 虚拟机的栈操作,只能是push和pop frames.  栈内存不需要连续。虚拟机规范栈内存可以固定大小也可以由计算程序自动扩展和缩小。

 

如果栈大小固定的话,当栈创建的时候,虚拟机栈的大小是有虚拟机自由选择的。没有约束。

但是,如果栈的大小是动态的扩展和缩小的话,则虚拟机可以在栈的初始化,控制栈的最大和最小值。

 

虚拟机栈的异常条件如下:

  线程的计算请求的栈大小超过了虚拟机提供的最大值,则抛出StackOverflowError

 当没有足够多的内存来创建一个新线程请求的初始化栈,则抛出OutOfMemoryError

 

  

 

 

虚拟机栈的异常条件如下:

 

如果计算程序请求的内存超过了自动存储系统能够提供的内存的话,就抛出OutOfMemoryError

 

 

3.5.4 Method Area

The Java virtual machine has a method area that is shared among all Java virtual machine threads. The method area is analogous to the storage area for compiled code of a conventional language or analogous to the "text" segment in a UNIX process. It stores per-class structures such as the runtime constant pool, field and method data, and the code for methods and constructors, including the special methods (§3.9) used in class and instance initialization and interface type initialization.

The method area is created on virtual machine start-up. Although the method area is logically part of the heap, simple implementations may choose not to either garbage collect or compact it. This version of the Java virtual machine specification does not mandate the location of the method area or the policies used to manage compiled code. The method area may be of a fixed size or may be expanded as required by the computation and may be contracted if a larger method area becomes unnecessary. The memory for the method area does not need to be contiguous.

A Java virtual machine implementation may provide the programmer or the user control over the initial size of the method area, as well as, in the case of a varying-size method area, control over the maximum and minimum method area size.6

The following exceptional condition is associated with the method area:

 

  • If memory in the method area cannot be made available to satisfy an allocation request, the Java virtual machine throws an OutOfMemoryError.

3.5.4 方法区

虚拟器有一个所有线程共享的方法区. 方法区类似于普通语言编译后代码的存储区,也类似于unix进程的Text segment。存储类结构,像运行期类常量池,字段,方法数据,方法代码,构造方法代码。类中特殊代码,实例的初始化,接口的初始化。

方法区是由虚拟机启动时候创建的,虽然方法区于Java堆内存的一部分,本版虚拟机规范没有制定方法区的位置和方法区如何管理编译后的代码的策略。可以固定,也可以动态增长。内存空间可以不连续。

 

虚拟机栈的异常条件如下:

方法区的内存不能满足请求的内存大小时,则抛出OutOfMemoryError

 

 

 

3.5.3 Heap

The Java virtual machine has a heap that is shared among all Java virtual machine threads. The heap is the runtime data area from which memory for all class instances and arrays is allocated.

The heap is created on virtual machine start-up. Heap storage for objects is reclaimed by an automatic storage management system (known as a garbage collector); objects are never explicitly deallocated. The Java virtual machine assumes no particular type of automatic storage management system, and the storage management technique may be chosen according to the implementor's system requirements. The heap may be of a fixed size or may be expanded as required by the computation and may be contracted if a larger heap becomes unnecessary. The memory for the heap does not need to be contiguous.

A Java virtual machine implementation may provide the programmer or the user control over the initial size of the heap, as well as, if the heap can be dynamically expanded or contracted, control over the maximum and minimum heap size.5

The following exceptional condition is associated with the heap:

 

  • If a computation requires more heap than can be made available by the automatic storage management system, the Java virtual machine throws an OutOfMemoryError.

 

3.5.3 堆区

Java的堆是所有虚拟机线程共享的。也是一个running data area. 是为类实例和array 实例分配内存的数据区。虚拟机启动创建。堆为Object分配的存储区域是由自动存储管理系统(也就是垃圾回收系统)回收的。对象自己不能显式的释放。虚拟机没有指定特定类型的垃圾回收系统,而是由实现者根据系统的需要自行制定垃圾回收技术。堆内存可以固定大小也可以动态的扩展和缩小。堆内存可以不连续。

虚拟机的实现者可以提供程序员或者使用者控制堆内存的初始化大小,如果堆内存是动态增长的话,则要控制堆内存的最大和最小值。

 

分享到:
评论

相关推荐

    Java虚拟机规范.Java SE 8版.zip

    第2章概述Java虚拟机的整体架构,包括class文件格式、数据类型、原始类型、引用类型、运行时数据区、栈帧、浮点算法、异常等,这对理解本书后面的内容有重要帮助;第3章详述如何将Java语言编写的程序转换为Java...

    Java虚拟机规范中文版(JavaSE7).pdf

    阅读和理解Java虚拟机规范对于Java开发者来说至关重要,因为它提供了对Java运行时环境的深入洞察。这对于优化代码、调试问题、理解垃圾收集机制、内存管理以及JVM调优等方面都非常有用。虽然规范描述的是虚拟机的...

    Java虚拟机规范 Java SE 8版-带目录-pdf

    Java虚拟机规范 Java SE 8版-带目录-pdf,本书完整而准确地阐释了Java虚拟机各方面的细节,围绕Java虚拟机整体架构、编译器、class文件格式、加载、链接与初始化、指令集等核心主题对Java虚拟机进行全面而深入的分析...

    Java虚拟机规范中文版.pdf

    JVM规范定义了JVM的结构、执行模型、内存模型以及与平台无关的规范,使得任何遵守这个规范的虚拟机都能运行Java程序。 在JVM中,最核心的概念之一是堆(Heap),它是运行时数据区的一部分,用来存储对象的实例。...

    Java虚拟机规范(中文版).pdf

    ### Java虚拟机规范(JVM)概览 #### 核心概念与重要性 《Java虚拟机规范(JavaSE7版)》是理解Java虚拟机(JVM)运作机制的基石,由Tim Lindholm、Frank Yellin、Gilad Bracha和Alex Buckley等人撰写,后由周志明、...

    Java虚拟机规范 JavaSE7

    JVM规范定义了JVM的结构、指令集和运行时数据区,以及如何执行指令和处理异常。自1999年以来,JVM规范经历了多次更新,而在2011年发布的JavaSE7版则带来了新的变化。 《Java虚拟机规范(JavaSE7版)》为想要了解...

    java虚拟机规范(java SE7)

    java虚拟机规范,高清PDF版本,含有目录结构:第一章:引言; 第二章:java虚拟结构(运行时区域内存:寄存器,java虚拟机栈,java堆,方法去,运行时常量池,本地方法栈); 第三章:为java虚拟机编译; 第四章:...

    java虚拟机规范高清中文版本(java SE 8版本)

    第1章 :简单地介绍了Java虚拟机的历史并吹捧了←_← 一下Java的平台无关性(一次编译,到处运行); 第2章:概览Java虚拟机整体架构; 第3章:介绍如何将Java语言编写的程序转换为虚拟机指令集; 第4章:定义...

    Java虚拟机规范.Java SE 8版

    第2章概述Java虚拟机的整体架构,包括class文件格式、数据类型、原始类型、引用类型、运行时数据区、栈帧、浮点算法、异常等,这对理解本书后面的内容有重要帮助;第3章详述如何将Java语言编写的程序转换为Java...

    Java虚拟机规范中文版

    《Java虚拟机规范》是Java技术的核心文档之一,它详细描述了Java虚拟机(JVM)的行为,包括其内部结构、数据类型、执行模型、指令集、运行时数据区、垃圾回收机制和安全管理等内容。该规范是Java平台实现的基石,对...

    Java虚拟机规范(中文版) Java SE 7

    《Java虚拟机规范》不仅仅是一份技术文档,它是所有Java虚拟机实现的基础,确保了Java程序能够在不同的平台上以一致的方式运行。尽管随着时间的推移,高性能虚拟机的实际实现细节可能与规范有所差异,但这些差异通常...

    Java虚拟机规范SE8英文

    ### Java虚拟机规范SE8知识点概述 #### 一、引言 - **历史背景**:Java虚拟机(JVM)自1995年首次发布以来,已经发展成为支持多种编程语言的重要平台。 - **Java虚拟机定义**:Java虚拟机(JVM)是一种能够执行Java...

    Java虚拟机规范(Java SE 7)中文版

    第2章概览了Java虚拟机整体架构,包括class文件格式、数据类型、原始类型、引用类型、运行时数据区、栈帧、浮点算法、异常等,这对理解本书后面的内容有重要帮助。第3章详述如何将Java语言编写的程序转换为Java...

    Java虚拟机规范(英文)

    6. 规范的作用:JVM规范作为Java平台的基础性文档,规定了JVM的内部架构、数据类型、指令集、运行时数据区、垃圾收集机制等核心内容,是Java开发者和虚拟机实现者必须遵循的标准。 综合以上内容,我们可以看到...

    Java虚拟机规范PDF

    Java虚拟机是运行所有Java程序的抽象计算机,它遵循一定的规范,这样相同的Java字节码就可以在任何遵循此规范的机器上运行。JVM的主要职责是加载字节码、执行字节码指令以及管理内存。 #### 2. 类加载器 JVM中的类...

Global site tag (gtag.js) - Google Analytics