Jvm Specification-Runtime Data Areas(1)

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.

     每个线程都拥有自己的数据区,在线程启动的时候创建,在线程消亡的时候销毁。

1. PC Register

     The Java virtual machine can support many threads of execution at once.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 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.

         jvm支持同时有许多线程在运行,每个jvm线程都拥有自己的PC Register。在每个时刻,每个jvm线程在执行一个该线程当前的方法。若该方法不是NATIVE代码,则PC Register包括了当前jvm执行的指令。若该方法是NATIVE代码,则不会定义PC Register。PC Register的数据范围足够容纳返回地址和所依赖的平台上本地指针。

2. Stacks

    Each Java virtual machine thread has a private Java virtual machine stack, created at the same time as the thread. A Java virtual machine stack stores frames. 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.

   每个jvm线程都有一个私有的Stack,在线程创建的时候随之产生。jvm Stack存储的是frames. jvm的Stack类似于传统的C语的Stack:存储局部变量和返回结果,与方法的调用和返回有关。因为jvm Stack从来不是被直接操作除了压入、弹出frame之外,所以frames可以是堆分配的。每个jvm Stack的内存也没有必要是连续的。

  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.

   jvm Specification允许jvm Stack为固定大小,也充许根据估计值动态的扩展。如果jvm Stack是固定大小,则创建Stack的时候,每个jvm Stack大小都是独立选择的。jvm的实现可能支持编程人员和用户控制在jvm Stack的初始大小的基础上控制stack的大小,同样地在动态地扩展或缩小jvm Stack的大小这种情况下,stack大小在最大最小值之间。

   jvm Stack可以产生两种异常:

  • 若一个线程估算的jvm Stack超出了允许的范围,jvm会抛出StackOverflowError.
  • 如果jvm Stack可以动态扩展,当线程企图扩展但是没有足够的内存实现这种扩展,或者没有足够的内存为新的线程分配初始Stack空间时,jvm会抛出OutOfMemoryError.

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.

   jvm的heap是被所有jvm线程共享的一块区域。所有的类实例和数组都是在heap中分配内存。

   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.

    Heap在jvm启动的时候创建的,它存储对象Objects,这些objects可以被GC回收,objects从来不会被显示的销毁。Jvm没有特定的存储自动管理系统,存储管理技术可以根据需要实现的系统要求进行选择。Heap可以是固定的大小,也可以是根据估算进行扩展,也可以缩小如果一个比较大的heap变得无用时。Heap的内存不要求是连续的。

    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.

    jvm的实现可能提供编程人员和用户在初始大小的基础上控制heap的大小,如果heap可以动态的扩展或者缩小,则可以在最大小最值的基础上灵活控制。Z

    jvm Heap可以产生一种异常:

  • 如果估算出的Heap大小超出了存储系统管理的存储范围,jvm将抛出OutOfMemoryError.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值