- 浏览: 30729 次
- 性别:
- 来自: 北京
-
最新评论
摘自《Java面向对象编程》
Java虚拟机提供了程序运行时环境,运行时环境中最重要的一个资源是运行时数据区。运行时数据区是操作系统为Java虚拟机进程分配的内存区域,主要包括堆区、方法区和Java栈区等。 l 在方法区中存放类的类型信息,类型信息包括静态变量和方法信息等,方法信息中包含类的所有方法的字节码。 l 在堆区中存放对象,对象的实例变量。 l 主线程在Java栈区内有一个方法调用栈,每执行一个方法,就会向方法调用栈中压入一个包含该方法的局部变量和参数的栈帧。 l 方法区存放了线程所执行的字节码指令。 l 堆区存放了线程所操纵的数据(以对象的形式存放)。 l Java栈区则是线程的工作区,保存线程的运行状态。 在Java虚拟机进程中,执行程序代码的任务是由线程来完成的。每个线程都有一个独立的程序计数器和方法调用栈(method invocation stack)。 l 程序计数器:也称为PC寄存器,当线程执行一个方法时,程序计数器指向方法区中下一条要执行的字节码指令。 l 方法调用栈:简称方法栈,用来跟踪线程运行中一系列的方法调用过程,栈中的元素称为栈帧。每当线程调用一个方法的时候,就会向方法栈中压入一个新帧。帧用来存储方法的参数、局部变量和运算过程中的临时数据。 栈帧由以下3部分组成: l 局部变量区:存放局部变量和方法参数。 l 操作数栈:是线程的工作区,用来存放运算过程中生成的临时数据。 l 栈数据区:为线程执行指令提供相关的信息,包括如何定位到位于堆区和方法区的特定数据,以及如何正常退出方法或异常中断方法。
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: 3.5.2 虚拟机栈 虚拟机线程拥有一个私有的虚拟机栈,创建线程的时候也同时创建线程栈。 栈存储frames,栈类似于其他语言,如C语言中的栈。存储local 变量和中间结果。同时方法的调用和返回的操作也用到了栈。对Java 虚拟机的栈操作,只能是push和pop frames. 栈内存不需要连续。虚拟机规范栈内存可以固定大小也可以由计算程序自动扩展和缩小。 如果栈大小固定的话,当栈创建的时候,虚拟机栈的大小是有虚拟机自由选择的。没有约束。 但是,如果栈的大小是动态的扩展和缩小的话,则虚拟机可以在栈的初始化,控制栈的最大和最小值。 虚拟机栈的异常条件如下: l 线程的计算请求的栈大小超过了虚拟机提供的最大值,则抛出StackOverflowError。 l 当没有足够多的内存来创建一个新线程请求的初始化栈,则抛出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: 3.5.4 方法区 虚拟器有一个所有线程共享的方法区. 方法区类似于普通语言编译后代码的存储区,也类似于Unix进程的Text segment。存储类结构,像运行期类常量池,字段,方法数据,方法代码,构造方法代码。类中特殊代码,实例的初始化,接口的初始化。 方法区是由虚拟机启动时候创建的,虽然方法区于Java堆内存的一部分,本版虚拟机规范没有制定方法区的位置和方法区如何管理编译后的代码的策略。可以固定,也可以动态增长。内存空间可以不连续。 虚拟机栈的异常条件如下: l 方法区的内存不能满足请求的内存大小时,则抛出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: 3.5.3 堆区 Java的堆是所有虚拟机线程共享的。也是一个running data area. 是为类实例和array 实例分配内存的数据区。虚拟机启动创建。堆为Object分配的存储区域是由自动存储管理系统(也就是垃圾回收系统)回收的。对象自己不能显式的释放。虚拟机没有指定特定类型的垃圾回收系统,而是由实现者根据系统的需要自行制定垃圾回收技术。堆内存可以固定大小也可以动态的扩展和缩小。堆内存可以不连续。 虚拟机的实现者可以提供程序员或者使用者控制堆内存的初始化大小,如果堆内存是动态增长的话,则要控制堆内存的最大和最小值。 虚拟机栈的异常条件如下: 如果计算程序请求的内存超过了自动存储系统能够提供的内存的话,就抛出OutOfMemoryError。
摘自《The Structure of the Java Virtual Machine》
发表评论
-
Sun的Java家族
2009-09-28 21:25 1209JDK Java Development Kit (JDK) ... -
创建String对象
2009-06-14 12:29 821关于String和内存的重要内容 摘自[美]Kath ... -
synchronized
2009-05-23 19:52 8304种用法 1.方法声明 放在访问操作符(public等 ... -
我的书架
2009-05-22 23:36 882《JAVA面向对象编程》作者: 孙卫琴 编著 ISBN: 7 ... -
为什么“局部内部类能访问所在方法中的final类型的参数和变量”
2009-05-22 22:30 18962009-5-21 Thinking In Java里面的说 ... -
List与数组的相互转换
2009-05-22 22:16 9491.List转换成为数组 调用ArrayList的toArra ...
相关推荐
Java虚拟机(JVM)是Java程序运行的核心,它负责解释和执行字节码,为Java应用程序提供了一个跨平台的运行环境。JDK(Java Development Kit)包含了开发和运行Java程序所需的所有工具,包括JVM。当我们谈论"jdk,jvm...
标题中提到了JVM原理、JVM调优、JVM内存模型和JAVA并发,这些都是Java虚拟机(JVM)相关的核心概念。JVM是运行Java字节码的虚拟计算机,为Java提供了一个跨平台的环境,确保Java程序可以在不同的操作系统上运行而...
### JVM 详细介绍:掌握 JVM 的各个组成部分与功能 #### 一、Java 源文件编译及执行 Java 应用程序的核心在于源文件的编译与执行。不同于 C/C++ 这类需要针对不同平台进行编译的语言,Java 采用了一种更为灵活的...
SAP JVM 8.1 64位是一个专为SAP系统设计的Java虚拟机,它基于Oracle的Java Development Kit (JDK) 进行优化,以满足SAP应用程序的特定需求。SAP JVM旨在提高性能、可靠性和安全性,同时确保与SAP产品的无缝集成。...
Java虚拟机(JVM)是Java程序运行的基础,它的调优是提高应用程序性能的关键环节。在JVM调优实践中,了解各个运行时数据区的工作原理至关重要。以下是对这些区域的详细解析: 1. **虚拟机栈**:每个线程都有一个...
JVM(Java Virtual Machine,Java虚拟机)是运行所有Java程序的假想计算机,是Java程序的运行环境,负责执行指令、管理数据、内存、寄存器等,是实现Java跨平台特性的关键部分。JVM指令手册详细记录了JVM的所有操作...
在Java开发领域,JVM(Java Virtual Machine)是运行所有Java程序的核心,它负责解析字节码并执行程序。深入理解JVM的内核原理、诊断技巧以及优化方法对于提升应用性能至关重要。本教程——“深入JVM内核—原理、...
JVM(Java Virtual Machine)是 JDK 的核心组成部分,它负责执行字节码,提供了一个“一次编写,到处运行”的环境。JVM 的源码对于理解 Java 性能优化、垃圾回收机制、类加载过程以及内存管理等方面有着至关重要的...
### JVM必知必会知识点梳理 #### 1. JVM的定义与层次 Java虚拟机(JVM)具有多重含义: - **一套规范**:即Java虚拟机规范,定义了Java虚拟机应该具有的行为。 - **一种实现**:例如HotSpot、J9、JRockit,它们都是...
本系列课程从JVM基础到高级实战,老师手把手教你如何进行JVM调优,思路清晰,没有废话,旨在挑战高薪。 课程亮点: 1、基于阿里arthas进行JVM调优; 2、基于代码排查OOM问题,拒绝空讲; 3、总结JVM通用的调优思路;...
R大作为国内JVM领域的权威专家,分享了一系列与JVM相关的知识点,涉及高级语言虚拟机的基础概念、重要书籍推荐、编译器设计与优化等多个方面。这些内容不仅对初学者友好,也为专业人士提供了深入理解JVM机制的机会。...
《深入JVM内核—原理、诊断与优化》是一份深度探索Java虚拟机(JVM)的视频教程,旨在帮助开发者全面理解JVM的工作机制,掌握性能诊断技巧,并能进行有效的优化。本教程覆盖了从基础到高级的JVM主题,不仅适用于Java...
在Java开发领域,JVM(Java Virtual Machine)是运行Java应用程序的关键组件,它负责解析字节码并执行程序。为了确保应用的高效运行和优化,开发者需要了解如何监测JVM的各项性能指标。JVM自带了一些工具,可以帮助...
标题《JVM系列之性能调优参考手册(实践篇)》涉及的知识点主要集中在Java虚拟机(JVM)性能调优的实践操作。JVM作为Java程序运行的基础环境,对程序性能有着决定性影响。本手册的目的是指导开发者如何对JVM进行性能...
JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来实现的。 引入Java语言虚拟机后,Java语言在不同平台...
JVM(Java Virtual Machine)是Java程序运行的核心组件,它负责解释和执行字节码。然而,当JVM出现严重错误或无法恢复的问题时,它可能会崩溃并生成一个崩溃日志,这通常被称为`hs_err_pid.log`文件。这篇内容将深入...
在这个压缩包中,"JVM图解.png"可能是对JVM内部结构的可视化表示,"JVM图解"可能是一个详细的文档,解释了JVM的工作原理,而"JVM指令手册 中文版"则提供了JVM可执行的所有指令的详细信息。下面,我们将深入探讨JVM的...
5. **JVM配置调整**:JProfiler11还可以提供JVM参数建议,帮助开发者正确设置JVM初始堆大小、最大堆大小、内存池等关键参数,确保应用程序稳定运行。 在实际使用中,JProfiler11的详细报告和可视化界面使得问题定位...
【狂神说JVM探究】是一份集合了多种格式的学习资料,主要涵盖了Java虚拟机(JVM)的基础知识。这份资料出自B站上的【狂神说Java】系列教程,为快速入门JVM提供了详实的笔记。以下是根据这些资源可能包含的一些关键...
Java虚拟机(JVM)是Java程序运行的基础,它是一个抽象的计算机系统,负责执行Java字节码。本文将深入探讨JVM的启动过程及其基本原理。 首先,我们需要理解JVM的基本概念。JVM是Java Virtual Machine的缩写,它是...