(JavaCard)JavaCard222VM Spec(JavaCard 2.2.2 虚拟机规范-中英文对照,第三章)

来源:互联网 发布:阿里云qq 编辑:程序博客网 时间:2024/06/16 00:01

Structure of the Java Card Virtual
Machine
java卡虚拟机的结构

The specification of the Java Card virtual machine is in many ways quite similar to
that of the Java virtual machine. This similarity is of course intentional, as the design
of the Java Card virtual machine was based on that of the Java virtual machine.
Rather than reiterate all the details of this specification which are shared with that of
the Java virtual machine, this chapter will mainly refer to its counterpart in The Java
Virtual Machine Specification, 2nd Edition, providing new information only where the
Java Card virtual machine differs.
java卡虚拟机的规范从许多方面和java虚拟机非常相近。这种相近是因为java卡虚拟机本来就是基于java虚拟机构建的。
与其处处重申这个规范和java虚拟机规范的所有相同的部分,还不如直接强调本虚拟机与java 2 虚拟机的不同。

3.1 Data Types and Values
3.1 数据类型和值
The Java Card virtual machine supports the same two kinds of data types as the Java
virtual machine: primitive types and reference types. Likewise, the same two kinds of
values are used: primitive values and reference values.
Java卡虚拟机和java虚拟机一样支持两种数据类型:基础类型和引用类型。同样的,也提供两种类型的值:基本类型值和引用值。

The primitive data types supported by the Java Card virtual machine are the numeric
types, the boolean type, and the returnAddress type. The numeric types consist only
of these types:
■ byte, whose values are 8-bit signed two’s complement integers
■ short, whose values are 16-bit signed two’s complement integers

java卡虚拟机支持的基础类型是数字类型,布尔型,和返回地址类型。数字类型仅由以下类型组成:
■ byte:8-bit有符号的2进制整数
■ short:16-bit有符号的2进制整数

Some Java Card virtual machine implementations may also support an additional
integral type:
■ int, whose values are 32-bit signed two’s complement integers
一些java卡虚拟机也可以支持附加的整形
■ int,32-bit有符号的二进制整数。

Support for the boolean type is identical to that in the Java virtual machine. The
value 1 is used to represent true and the value of 0 is used to represent false.
Support for reference types is identical to that in the Java virtual machine.
布尔类型的支持和java虚拟机一样,1代表真,0代表假。索引类型的支持也和java虚拟机一样。

3.2 Words
3.2 字
The Java Card virtual machine is defined in terms of an abstract storage unit called a
word. This specification does not mandate the actual size in bits of a word on a
specific platform. A word is large enough to hold a value of type byte, short,
reference or returnAddress. Two words are large enough to hold a value of
type int.
java卡虚拟机在一个叫做”字“的抽象的存储单元上定义的。这个规范不指定一个平台上字确切的bit大小。一个字应该足够来承载一个byte,short,reference或者返回地址。两个字应该可以容纳一个int数值。

The actual storage used for values in an implementation is platform-specific. There
is enough information present in the descriptor component of a CAP file to allow an
implementation to optimize the storage used for values in variables and on the
stack.
在实现上,真正的存储大小事平台相关的,在CAP文件的descriptor组件中有足够的信息可以让一个实现来优化在变量区和栈上的存储。

3.3 Runtime Data Areas
3.3 运行态数据域
The Java Card virtual machine can support only a single thread of execution. Any
runtime data area in the Java virtual machine which is duplicated on a per-thread
basis will have only one global copy in the Java Card virtual machine.
The Java Card virtual machine's heap is not required to be garbage collected. Objects
allocated from the heap will not necessarily be reclaimed.
This specification does not include support for native methods, so there are no
native method stacks.
Otherwise, the runtime data areas are as documented for the Java virtual machine.
java卡虚拟机只能支持一个线程的执行。任何java虚拟机在每个线程独立的运行态的数据域在java卡虚拟机上只有唯一的一份拷贝。
java卡虚拟机的堆不一定支持垃圾回收,堆上申请的对象有可能不会重新回收。
这个规范不包含本地方法的支持,所以也没有本地方法栈。

3.4 Contexts
3.4 上下文
Each applet running on a Java Card virtual machine is associated with an execution
context. The Java Card virtual machine uses the context of the current frame to
enforce security policies for inter-applet operations.
There is a one-to-one mapping between contexts and packages in which applets are
defined. An easy way to think of a context is as the runtime equivalent of a package,
since Java packages are compile-time constructs and have no direct representation at
runtime. As a consequence, all applet instances from the same package will share the
same context.
每个运行中java卡虚拟机上的应用都关联到了一个执行上下文。java卡虚拟机使用当前帧的上下文来执行内部操作的安全策略。
在存在应用的包中,上下文和包是一一对应的。简单的理解上下文就是运行态的包,因为java的包是编译期构造,在运行态并没有直接描述。作为结果,一个包下面的所有应用实例都应该共享相同的上下文。

The Java Card Runtime Environment also has its own context. Framework objects
execute in this Java Card RE context.
java卡运行环境也拥有他自己的上下文。框架里面的对象砸JCRE上下文运行。

The context of the currently executing method is known as the current context. Every
object in a Java Card virtual machine is owned by a particular context. The owning
context is the context that was current when the object was created.
当前执行方法的上下文被认为是当前上下文。java卡虚拟机里面的所有对象都属于特定的上下文。拥有对象的上下文就是对象创建时的当前上下文。

When a method in one context successfully invokes a method on an object in another
context, the Java Card virtual machine performs a context switch. Afterwards the
invoked method's context becomes the current context. When the invoked method
returns, the current context is switched back to the previous context.
当一个上下文中的方法成功执行了另外一个上下文下的对象的方法,java卡虚拟机将执行上下文切换。然后调用方法的上下文成为当前的上下文。当调用的方法返回,当前上下文将切换回原来的上下文。

3.5 Frames
3.5 帧
Java Card virtual machine frames are very similar to those defined for the Java
virtual machine. Each frame has a set of local variables and an operand stack.
Frames also contain a reference to a constant pool, but since all constant pools for all
classes in a package are merged, the reference is to the constant pool for the current
class’ package.
Each frame also includes a reference to the context in which the current method is
executing.
java卡虚拟机帧和java虚拟机中定义的帧非常相近。每个帧有一套本地变量和一个操作栈。帧也包含一个指向常量池的引用,但因为一个包里面所有类在常量池是一体的,所以引用是指向当前类的包。
每个帧也包含了一个指向当前方法执行的上下文的引用。

3.6 Representation of Objects
3.6 对象的描述
The Java Card virtual machine does not mandate a particular internal structure for
objects or a particular layout of their contents. However, the core components in a
CAP file are defined assuming a default structure for certain runtime structures (such
as descriptions of classes), and a default layout for the contents of dynamically
allocated objects. Information from the descriptor component of the CAP file can be
used to format objects in whatever way an implementation requires.
java卡虚拟机兵部制定一个对象的特定内部实现,或者一个特定的内容设计。然而,在一个CAP文件中的核心组件都运行在动态申请对象的默认结构上。CAP文件中的descriptor组件可以用来在任何实现前提下来格式化对象。

3.7 Special Initialization Methods
3.7 特殊初始化方法

The Java Card virtual machine supports instance initialization methods exactly as does
the Java virtual machine.
java卡虚拟机支持和java虚拟机一样的实例初始化方法。

The Java Card virtual machine includes only limited support for class or interface
initialization methods. There is no general mechanism for executing
<clinit> methods on a Java Card virtual machine. Instead, a CAP file includes
information for initializing class data as defined in Section 2.2.4.6, “Class
Initialization” on page 2-11.
java卡虚拟机包含仅支持类和接口的初始化方法。在java卡虚拟机上没有通用过程来执行<clinit>方法。作为替代,初始化类数据所包含的信息在”类初始化“一章。

3.8 Exceptions
3.8 异常

Exception support in the Java Card virtual machine is identical to support for
exceptions in the Java virtual machine.
java卡虚拟机的异常支持和java虚拟机的异常支持相同。

3.9 Binary File Formats
3.9 二进制文件格式

This specification defines two binary file formats which enable platform-
independent development, distribution and execution of Java Card programs.
The CAP file format describes files that contain executable code and can be
downloaded and installed onto a Java Card technology-enabled device. A CAP file is
produced by a Java Card platform Converter tool, and contains a converted form of
an entire package of Java classes. This file format's relationship to the Java Card
virtual machine is analogous to the relationship of the class file format to the Java
virtual machine.
这个规范定义了两种支持平台无关开发的二进制文件格式,用来发布和执行java卡程序。
CAP结构描述文件包含了可以下载和安装到java卡设备上的可执行代码。CAP文件是由java卡平台的Converter工具生成的,并且包含一个java类文件转化格式。这个文件格式和java卡虚拟机的关系和class文件和java虚拟机的关系类似。

The export file format describes files that contain the public linking information of
Java Card API packages. A package’s export file is used when converting client
packages of that package.
EXP结构描述文件描述了包含java卡API包的公有链接信息。当转化使用端包的时候需要使用包的导出文件。

3.10 Instruction Set Summary
The Java Card virtual machine instruction set is quite similar to the Java virtual
machine instruction set. Individual instructions consist of a one-byte opcode and zero
or more operands. The pseudo-code for the Java Card virtual machine's instruction
fetch-decode-execute loop is the same. Multi-byte operand data is also encoded in
big-endian order.
3.10 指令集汇总
java卡虚拟机指令集和java虚拟机指令集非常类似。个别的指令由一个字节操作码,零或者更多的操作数组成。java卡虚拟机指令的 获取-解码-执行 循环也是相同的。多字节的操作数大端编码。

There are a number of ways in which the Java Card virtual machine instruction set
diverges from that of the Java virtual machine. Most of the differences are due to the
Java Card virtual machine's more limited support for data types. Another source of
divergence is that the Java Card virtual machine is intended to run on 8-bit and 16-
bit architectures, whereas the Java virtual machine was designed for a 32-bit
architecture. The rest of the differences are all oriented in one way or another
toward optimizing the size or performance of either the Java Card virtual machine
or Java Card programs. These changes include inlining constant pool data directly in
instruction opcodes or operands, adding multiple versions of a particular instruction
to deal with different datatypes, and creating composite instructions for operations
on the current object.
也有一些在java卡虚拟机和java虚拟机指令集分歧的途径。大多数的不同取决于java卡虚拟机在数据类型上有更多的限制。另外一个分歧的源头是因为java卡虚拟机是被认为执行在8-bit和16-bit的体系结构下的。然而java虚拟机被设计为运行在32-bit的体系结构下。
剩下的不同都是为了节省空间或者提高java卡虚拟机的效率。这些修改包含在操作码和操作数中内联常量池数据。对特定类型的指令提供多种数据类型下的版本,创建当前对象操作的复合指令。

3.10.1 Types and the Java Card Virtual Machine
3.10.1 类型和java卡虚拟机

The Java Card virtual machine supports only a subset of the types supported by the
Java virtual machine. This subset is described in Chapter 2. Type support is reflected
in the instruction set, as instructions encode the data types on which they operate.
Given that the Java Card virtual machine supports fewer types than the Java virtual
machine, there is an opportunity for better support for smaller data types. Lack of
support for large numeric data types frees up space in the instruction set. This extra
instruction space has been used to directly support arithmetic operations on the
short data type.
java卡虚拟机仅支持java虚拟机支持的类型的子集。这个子集在第二章描述了。类型支持在指令集中得到了体现,因为指令是按他们操作的数据类型进行编码的。
因为java卡虚拟机支持java虚拟机更少的类型,有机会对小数据类型做更好的支持。对大数据类型数据的放弃释放了指令集的空间,这个额外的指令空间可以用来直接支持短数据类型的算术操作。

Some of the extra instruction space has also been used to optimize common
operations. Type information is directly encoded in field access instructions, rather
than being obtained from an entry in the constant pool.
一些其它的指令空间也被用来精简通用操作,类型信息被直接编码在属性访问的指令里面,好过每次都从常量池里面去获取。