现在的位置: 首页 > 综合 > 正文

JVMS Specification

2013年11月04日 ⁄ 综合 ⁄ 共 2878字 ⁄ 字号 评论关闭

一、The Structure of the Java Virtual Matchine
To implement the java virtual machine correctly, you need only be able to read the Class file format and corrently perform operations 
specified therein.Implementation details that are not part of the Java virtual machine'specification would unnecessarily constrain the creativity of implementors.For example,the memory layout of runtime data areas,the garbage-collection algorithm used,and any
internal optimization of the java virtual machine instructions(for example,translating them into machine code) are left to the discretion of the implementor.
要实现正确的java虚拟机,你只需要读到正确的Class格式的文件然后在里面正确的执行指令,具体的实现不包括在java虚拟机规范里,这样会限制实现者的创造能力。比如内存布局的运行时数据区域,垃圾回收器的使用,和java虚拟机内部指令的优化(如,转换它们为机器代码)留给实现者自己去判断。

(1) The class File Format

Compiled code to be executed by the java virtual machine is represented using a hardware and operationg system-independent binary format,typically(but not necessarily) stored in a file,known as the class file format.The class file format precisely defines
the representation of a class or interface,including details such as byte ordering that might be taken for granted in aplatform-specific object file format.

编译完被java虚拟机执行的代码是硬件和操作系统独立使用的二进制格式。一般来说,(但不是必须的)存储成一个class文件,这个class文件精确的描述了这个类或者接口,包括详细信息,比如字节顺序可能会被视为一个特定于平台的对象文件格式。

(2) Data Type
Like the java programming language,the java virtual machine operates on two kind s of types:primitive types and reference types.There are correspondingly,two kinds of values that can be stored in variables,passed as arguments,returned by method,and operated
upon:primitive values and preference valuesThe java virtual machine expects that nearly all type checking is done prior to runtime,typically by compiler,and does not have to be done by the java virtual machine itself.Vales of primitive type nedd not be tagged
or otherwise be inspectable to  determine their types at runtime, or to be distinguished fromvalues of reference types. Instead, the instruction set of the Java virtual machinedistinguishes its operand types using instructions intended to operate on values
of specific types. For instance,  iadd,  ladd,  fadd, and  dadd are all Java virtual machine instructions that add two numeric values and produce numeric results,but each is specialized  for its operand type:  int,  long,  float, and  double,respectively.
For a summary of type support in the Java virtual machine instruc-tion set. 
The Java virtual machine contains explicit support for objects. An object is either a dynamically allocated class instance or an array. A reference to an object is considered to have Java virtual machine type reference. Values oftype reference can be thought
of as pointers to objects. More than one refer-ence to an object may exist. Objects are always operated on, passed, and tested via values of type 
就像Java编程语言,java虚拟机两种类型起作用:基本数据类型和引用数据类型。相对应的两种值被存储在变量里面,通过方法的参数或者返回值来操作。java虚拟机希望所有的类型在运行之前被检查,一般是被编译器,并且不需要Java虚拟机自己去做。基本数据类型的值不需要被标记,在运行时他们的类型会被检查,还和引用类型做区分。反而Java虚拟机的指令集区分操作数类型使用指令操作特定类型的值。比如 iadd,ladd,fadd,and dadd 这些都是Java虚拟机指令对两个数字值相加,得到的结果是一个数字,但是特定操作数类型之间比如
int long float double 之间又是相互独立的。
java虚拟机明确包含支持对象,一个对象或者是一个类的实例或者是一个数组,一个对象的引用被看作是java虚拟机类型引用,类型引用的值被认为是指针指向的对象,一个对象可能存在多个引用,对象总是被引用操作,传递,或者测试。

(3) Primitive Types and Values 

【上篇】
【下篇】

抱歉!评论已关闭.