2019独角兽企业重金招聘Python工程师标准>>>

Like the local variables, the operand stack is organized as an array of words. But unlike the local variables, which are accessed via array indices, the operand stack is accessed by pushing and popping values. If an instruction pushes a value onto the operand stack, a later instruction can pop and use that value.

和局部变量区一样,操作数栈也是被组织成一个以字长为单位的数组。但是和前者不同的是,它不是通过索引来访问,而是通过标准的栈操作—压栈和出栈—来访问的。比如,如果某个指令把一个值压入到操作数栈中,稍后另一个指令就可以弹出这个值来使用。

The virtual machine stores the same data types in the operand stack that it stores in the local variables: int,long, float, double, reference, and returnType. It converts values of type byte, short, and char to intbefore pushing them onto the operand stack.

虚拟机在操作数栈中存储数据的方式和在局部变量区中是一样的:如int、long、float、double、reference和returnType的存储。对于byte、short以及char类型的值在压入到操作数栈之前,也会被转换为int。

Other than the program counter, which canít be directly accessed by instructions, the Java Virtual Machine has no registers. The Java Virtual Machine is stack-based rather than register-based because its instructions take their operands from the operand stack rather than from registers. Instructions can also take operands from other places, such as immediately following the opcode (the byte representing the instruction) in the bytecode stream, or from the constant pool. The Java Virtual Machine instruction set's main focus of attention, however, is the operand stack.

不同于程序计数器,Java虚拟机没有寄存器,程序计数器也无法被程序指令直接访问。Java虚拟机的指令是从操作数栈中而不是从寄存器中取得操作数的,因此它的运行方式是基于栈的而不是基于寄存器的。虽然指令也可以从其他地方取得操作数,比如从字节码流中跟随在操作码(代表指令的字节)之后的字节中或从常量池中,但是主要还是从操作数栈中获得操作数。

The Java Virtual Machine uses the operand stack as a work space. Many instructions pop values from the operand stack, operate on them, and push the result. For example, the iadd instruction adds two integers by popping two ints off the top of the operand stack, adding them, and pushing the int result. Here is how a Java Virtual Machine would add two local variables that contain ints and store the int result in a third local variable:

虚拟机把操作数栈作为它的工作区——大多数指令都要从这里弹出数据,执行运算,然后把结果压回操作数栈。比如,iadd指令就要从操作数栈中弹出两个整数,执行加法运算,其结果又压回到操作数栈中,看看下面的示例,它演示了虚拟机是如何把两个int类型的局部变量相加,再把结果保存到第三个局部变量的:

 

begin

iload_0 // push the int in local variable 0 onto the stack

iload_1 // push the int in local variable 1 onto the stack

iadd // pop two ints, add them, push result

istore_2 // pop int, store into local variable 2

end

In this sequence of bytecodes, the first two instructions, iload_0 and iload_1, push the ints stored in local variable positions zero and one onto the operand stack. The iadd instruction pops those two int values, adds them, and pushes the int result back onto the operand stack. The fourth instruction, istore_2, pops the result of the add off the top of the operand stack and stores it into local variable position two. In Figure 5-10, you can see a graphical depiction of the state of the local variables and operand stack while executing the above instructions. In this figure, unused slots of the local variables and operand stack are left blank.

在这个字节码序列里,前两个指令iload_0和iload_1将存储在局部变量中索引为0和1的整数压入操作数栈中,其后iadd指令从操作数栈中弹出那两个整数相加,再将结果压入操作数栈。第四条指令istore_2则从操作数栈中弹出结果,并把它存储到局部变量区索引为2的位置。图5-10详细表述了这个过程中局部变量和操作数栈的状态变化,图中没有使用的局部变量区和操作数栈区域以空白表示。

转载于:https://my.oschina.net/tantexian/blog/737697

JVM学习-操作数栈(Operand Stack-官方翻译)相关推荐

  1. JVM之Java栈Java stack

    JVM之Java栈Java stack 目录: JVM体系结构概览 JVM之Java栈解析 1. JVM体系结构概览 2. JVM之Java栈解析 stack图 先简单认识,图示在一个栈中有两个栈帧: ...

  2. 欧尼酱讲JVM(10)——操作数栈

    首先要明确一个概念:操作数栈在栈帧中.我红色框圈起来的部分. 操作数栈的理解 每一个独立的栈针中除了包含局部变量表以外,还包含一个后进先出的操作数栈,也叫 表达式栈. 操作数栈在方法执行过程中,根据字 ...

  3. JVM学习笔记之-运行时数据区概述及线程概述,程序计数器(PC寄存器),虚拟机栈(栈,局部变量表,操作数栈,动态连接,方法调用,方法返回地址等),本地方法接口,本地方法栈

    运行时数据区概述及线程概述 内存是非常重要的系统资源,是硬盘和CPU的中间仓库及桥梁,承载着操作系统和应用程序的实时运行.JVM内存布局规定了Java在运行过程中内存申请.分配.管理的策略,保证了JV ...

  4. JVM学习笔记汇总:结合尚硅谷宋红康老师视频教程及PPT

    JVM学习笔记汇总:结合尚硅谷宋红康老师视频教程及PPT 第一章:JVM虚拟机的介绍 1.1虚拟机的分类 虚拟机通常分为两类:系统虚拟机和程序虚机.其中,系统虚拟机是指完全对物理计算机的仿真,而程序虚 ...

  5. JVM -- 运行时栈帧结构简介

    栈帧(Stack Frame)是用于支持虚拟机进行方法调用和方法执行的数据结构,它是虚拟机运行时数据区的虚拟机栈(Virtual Machine Stack)的栈元素.栈帧存储了方法的局部变量表,操作 ...

  6. JVM运行时栈帧结构

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_36367789/article/details/81711223 栈帧(Stack Frame ...

  7. JVM学习(八):虚拟机栈(字节码程度深入剖析)

    目录 一.概述 1.1 基于栈结构的虚拟机 1.2 栈和堆 二.虚拟机栈(Java Virtual Machine Stack)详述 2.1 虚拟机栈介绍 2.2 虚拟机栈作用 2.3 虚拟机栈特点 ...

  8. 你只知道JVM栈,知不知道栈帧、局部变量表、slot、操作数栈?

    目录 虚拟机栈基础 虚拟机栈出现的背景 栈是运行时的单位,而堆是存储的单位 Java虚拟机栈 栈中可能出现的异常 设置Java栈大小 栈中存储什么? 栈运行原理 栈帧的内部结构 每个栈帧中存储着 局部 ...

  9. Java #JVM(HotSpot) 运行时数据区 #程序计数器(PC寄存器)#虚拟机栈(栈帧:局部变量表、操作数栈……)#堆……

    目录 JVM中线程的说明 程序计数器(PC寄存器) 虚拟机栈 · 栈帧 ·· 局部变量表 ·· 操作数栈 ·· 动态链接 ·· 方法返回地址 ·· 本地方法栈 堆 · 查看堆的大小 · 堆的默认大小 ...

最新文章

  1. 我在不炎熱也不抑鬱的秋天,依然不抽煙
  2. Mask-RCNN论文解读
  3. Java 面试,这样拿 Offer!
  4. 3.3 神经网络的输出-深度学习-Stanford吴恩达教授
  5. @change=“change()“与@change=“change“的区别
  6. Web存储—本地存储Cookie
  7. git clone 某一特定分支转
  8. Heroku + node.js错误(Web进程在启动后60秒内未能绑定到$ PORT)
  9. 九九乘法表 利用for语句
  10. IntelliJ IDEA 将 Maven 构建的 Java 项目打包
  11. CCNP系列三十四--- Bgp的本地优先属性
  12. 新版掌上阅读小说源码+支持公众号/分站/封装APP
  13. 抖音投放怎么收费?抖音投放展现方式有哪些
  14. win10安装kafka kafka_2.13-2.8.1
  15. 以58同城为例详解如何用爬虫采集二手房房源数据及中介联系方式
  16. Word 2007 XML 解压缩格式
  17. 卡方分布上侧α分位数的近似公式及其证明
  18. DDL、DML、DCL区别
  19. 2022 最新 Android 基础教程,从开发入门到项目实战【b站动脑学院】学习笔记——实战二:简易登录+找回密码
  20. 极智开发 | 中科泰坦服务器调节风扇转速方法

热门文章

  1. 【Java】@transient代表着什么
  2. 8.Springcloud的Feign嵌入Ribbon实现接口式调用(改变restTemplate和Ribbon的调用方式)...
  3. 接口测试--apipost接口断言详解
  4. jsoup对象的使用
  5. java解决斐波那契数列(Fibonacci sequence)
  6. java writeint_Java DataOutputStream writeInt()方法
  7. three.js 求两个vector3 的夹角_初中数学:动点问题-阿氏圆最值模型(2),求PD-1/2PC的最大值...
  8. linux脚本生成数字写入文本,4.2 编写Shell脚本(P80-85)——《Linux就该这么学》学习笔记16...
  9. web前端开发,自学的流程可以怎样?
  10. F - 数据结构实验之链表四:有序链表的归并