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

来源:互联网 发布:数码宝贝网络侦探 编辑:程序博客网 时间:2024/06/08 02:22

A Subset of the Java Virtual Machine

 

This chapter describes the subset of the Java virtual machine and language that is
supported in the Java Card platform, Version 2.2.2.

这章描述了javacrad平台v2.2.2所支持的java虚拟机的子集 

 

2.1 Why a Subset is Needed

2.1 为什么需要一个子集


It would be ideal if programs for smart cards could be written using all of the Java
programming language, but a full implementation of the Java virtual machine is far
too large to fit on even the most advanced resource-constrained devices available
today.
A typical resource-constrained device has on the order of 1.2K of RAM, 16K of non-
volatile memory (EEPROM or flash) and 32K-48K of ROM. The code for
implementing string manipulation, single and double-precision floating point
arithmetic, and thread management would be larger than the ROM space on such a
device. Even if it could be made to fit, there would be no space left over for class
libraries or application code. RAM resources are also very limited. The only
workable option is to implement Java Card technology as a subset of the Java
platform.

如果直接使用java语言来书写智能卡上的程序当然是很理想的,但是一个完整的java虚拟机哪怕是在当前最先进的资源限制型设备上实现也是太大了。
 一个典型的资源限制型设备被定制为:1.2K的RAM,16K的非易失内存(EEPROM or FLASH)和32-48K的ROM。
 在这样的设备上,实现字符串管理,单(双)精度浮点数运算,线程管理的代码大小应该会比ROM的空间还大。
 即便代码可以放下,也没有剩余的空间来存储类库和应用代码,RAM资源也是非常受限的。唯一切实可行的方案是把java card技术实现为一个java平台的子集。

 

2.2 Java Card Platform Language Subset

2.2 Java Card 语言子集


Applets written for the Java Card platform are written in the Java programming
language. They are compiled using Java compilers. Java Card technology uses a
subset of the Java language, and familiarity with the Java platform is required to
understand the Java Card platform.

The items discussed in this section are not described to the level of a language
specification. For complete documentation on the Java programming language, see
The Java Language Specification.

为java card平台写的应用是基于java编程语言的,使用java编译器编译。java card技术使用java语言的一个子集,熟悉java平台有助于理解java card平台。
 这章描述的话题不在语言规范的层次,如果需要完整的java语言的文档,参考java语言的规范。

 

2.2.1 Unsupported Items

2.2.1 不支持的对象


The items listed in this section are elements of the Java programming language and
platform that are not supported by the Java Card platform.

这章所列举的对象,是被java语言支持,但不被java card平台所支持的。

 

2.2.1.1 Unsupported Features

2.2.1.1 不支持的特性


Dynamic Class Loading


Dynamic class loading is not supported in the Java Card platform. An
implementation of the Java Card platform is not able to load classes dynamically.
Classes are either masked into the card during manufacturing or downloaded
through an installation process after the card has been issued. Programs executing
on the card may only refer to classes that already exist on the card, since there is no
way to download classes during the normal execution of application code.

动态类加载

动态类加载不被java card平台所支持,java card平台不能动态的加载类,类或者在卡片生产的时候预置,或者在发卡后在安装流程进行安装。程序在只运行在卡上已经存在的类,因为在普通应用代码的执行中没有办法来下载类数据。


Security Manager


Security management in the Java Card platform differs significantly from that of the
Java platform. In the Java platform, there is a Security Manager class
(java.lang.SecurityManager) responsible for implementing security features. In
the Java Card platform, language security policies are implemented by the virtual
machine. There is no Security Manager class that makes policy decisions on whether
to allow operations.

安全管理器


javacard平台的安全管理器和java平台的有很大的不同。在java平台,有一个安全管理的类(java.lang.SecurityManager)负责安全特性的实现。在javacard平台,语言安全的机制由虚拟机来实现。
没有安全管理类来产生规则以决定操作是否被允许。

 

Finalization

Finalization is also not supported. finalize() will not be called automatically by
the Java Card virtual machine.

结束操作

结束操作也不被支持,finalize()方法将不会被java card虚拟机自动调用。

 

Threads

 

The Java Card virtual machine does not support multiple threads of control.
Programs for the Java Card platform (“Java Card programs”) cannot use class
Thread or any of the thread-related keywords in the Java programming language.

 线程

javacard虚拟机不支持多线程控制。javacard程序不能使用Thread类或任何在java语言中线程相关的关键字。

 

Cloning


The Java Card platform does not support cloning of objects. Java Card API class
Object does not implement a clone method, and there is no Cloneable interface
provided.

克隆

javacard平台不支持对象的克隆。javacard API中的Object类不实现clone的方法,也没有Cloneable接口提供。

 

Access Control in Java Packages
The Java Card platform language subset supports the package access control defined
in the Java language. However, the cases that are not supported are as follows.
■ If a class implements a method with package access visibility, a subclass cannot
override the method and change the access visibility of the method to protected
or public.
■ A public class cannot contain a public or protected field of type reference to a
package-visible class.
■ A public class cannot contain a public or protected method with a return type of
type reference to a package-visible class.
■ A public or protected method in a public class cannot contain a formal parameter
of type reference to a package-visible class.
■ A package-visible class that is extended by a public class cannot define any public
or protected methods or fields.
■ A package-visible interface that is implemented by a public class cannot define
any fields.
■ A package-visible interface cannot be extended by an interface with public access
visibility.

java中的package类型访问控制
java card语言支持java语言中定义的包访问控制。然而,有以下几个类型不被支持:(因为package 不能export)
■ 如果一个类实现了一个package的方法,子类重载此方法不能修改方法访问范围为protected 或者 public。
■ 一个public的类不能包含一个public或者protected的指向package可见类的reference
■ 一个public的类不能包含一个public或者protected的返回值为package可见类reference的方法。
■ 一个在public类中的public或者protected的方法不能包含一个package可见类的reference参数。
■ 一个被public类继承的package类,不能定义任何public或者protected的方法或者属性。
■ 一个被public类实现了的package接口,不能定义任何属性。
■ 一个package的接口不能被一个public访问权限的接口继承

 

Typesafe Enums

The Java Card platform language subset does not support the enumerated type
facility and the keyword enum.

类型安全的枚举
java卡语言子集不支持枚举类型和enum关键字


Enhanced for Loop
The Java Card platform language subset does not support the enhanced for loop
language construct. Support for the enhanced for loop construct requires support for
array indexing using the integer data type. The Java Card platform only supports
array indexing using the short data type.

增强型循环
java卡平台语言子集不支持增强型循环,支持增强型循环需要数组的下表使用int类型数据,java卡平台只支持short类型的数组下标。

Varargs
The Java Card platform language subset does not support variable-length argument
lists. The variable-length argument construct requires the compiler to generate code
that creates a new array object each time a variable-length argument array method is
invoked, thereby causing implicit memory allocations in Java Card runtime memory
heap.

变长参数
java卡平台语言子集不支持变长类型的参数,变长参数的构建需要编译器自动产生代码,使得在每次方法调用的时候都自动创建一个数组对象。因此可能会在java卡运行态内存堆中增加隐含的内存申请。

Runtime Visible Metadata (Annotations)
The Java Card platform does not support this language feature which lets you
introduce meta-data information into the runtime environment to be accessed
reflectively. The Java Card platform does not support reflection.

运行态可见元数据(注解)
java卡平台不支持可以把元数据信息在运行态环境反射性访问的语言特性。java卡平台不支持反射。


Assertions
The Java Card runtime does not provide runtime support for statements in the Java
programming language called assertions that are used to test assumptions about
program functionality.

断言
java卡运行态不提供java语言中用来测试程序功能性的assert断言声明。

 

2.2.1.2 Keywords

2.2.1.2 关键字


The following keywords indicate unsupported options related to native methods,
threads, floating point, memory management, and debugging.

以下和不支持特性:本地方法,线程,浮点数,内存管理和调试相关的关键字不被支持。

 

2.2.1.3 Unsupported Types

2.2.1.3 不支持的类型


The Java Card platform does not support types char, double, float and long. It
also does not support arrays of more than one dimension.

java卡平台不支持类型:char,double,float和long。同时也不支持超过一维的数组。

 

2.2.1.4 Classes

2.2.1.4 类


In general, none of the Java programming language core API classes are supported
in the Java Card platform. Some classes from the java.lang package are supported
(see Section 2.2.2.4, “Classes” on page 2-7), but none of the rest are. For example,
classes that are not supported are String, Thread (and all thread-related classes),
wrapper classes such as Boolean and Integer, and class Class.

总体上来说,java语言中的核心API在java卡平台上都不被支持。一些java.lang包的类被支持,剩下的则不被支持。比如不支持String类,Thread类,封装类(Boolean,Integer)和Class类。


System

System类


Class java.lang.System is not supported. Java Card technology supplies a class
javacard.framework.JCSystem, which provides an interface to system behavior.

类 java.lang.System不被支持,Java卡技术提供一个叫javacard.framework.JCSystem的类提供一个系统行为的接口。

2.2.2 Supported ItemsIf a language feature is not explicitly described as unsupported, it is part of the
supported subset. Notable supported features are described in this section.

2.2.2 不在非支持列表中的项目默认被支持,一些重要的被支持的属性将在这章进行描述。


2.2.2.1 Features

2.2.2.1 特性


Packages
Software written for the Java Card platform follows the standard rules for the Java
platform packages. Java Card API classes are written as Java source files, which
include package designations. Package mechanisms are used to identify and control
access to classes, static fields and static methods. Except as noted in “Access Control
in Java Packages” (Section 2.2.1.1, “Unsupported Features” on page 2-2), packages in
the Java Card platform are used exactly the way they are in the Java platform.

java卡平台下的软件遵循java平台中包的标准规则。用java实现的javaAPI类将包含包名称。包机制用来标示和控制类,静态属性和静态方法的访问。除了“java中的package类型访问控制"中所不支持的类型外,java卡平台中包的使用和java平台中一样。

 

Dynamic Object Creation
The Java Card platform programs supports dynamically created objects, both class
instances and arrays. This is done, as usual, by using the new operator. Objects are
allocated out of the heap.
A Java Card virtual machine will not necessarily garbage collect objects. Any object
allocated by a virtual machine may continue to exist and consume resources even
after it becomes unreachable. See Section 2.2.3.2, “Object Deletion Mechanism” on
page 2-8 for more information regarding support for an optional object deletion
mechanism.

动态对象创建

java卡平台程序支持动态创建对象,不管是类实例还是数组。这通常是由new关键字来实现的,对象在堆上被创建。

java卡虚拟机并不一定支持对象的垃圾回收,任何被虚拟机生成的对象即便在不被访问后也会继续存在,占用资源。参见2.2.3.2”对象回收机制”来获得更多可选的对象删除机制的信息。

 

Virtual Methods
Since Java Card technology-based objects (“Java Card objects”) are Java
programming language objects, invoking virtual methods on objects in a program
written for the Java Card platform is exactly the same as in a program written for the
Java platform. Inheritance is supported, including the use of the super keyword.
虚方法

因为java卡上基于的是java语言的对象,调用java卡平台上对象的虚方法和java平台是一样的。继承也被支持,包括super关键字的使用。

 

Interfaces
Java Card API classes may define or implement interfaces as in the Java
programming language. Invoking methods on interface types works as expected.
Type checking and the instanceof operator also work correctly with interfaces.

接口

java卡API类可以像java语言一样定义或者实现接口。基于接口类型的方法调用也会做足够的类型检查。instanceof关键字也支持接口类型。


Exceptions
Java Card programs may define, throw and catch exceptions, as in Java programs.
Class Throwable and its relevant subclasses are supported. Some Exception and
Error subclasses are omitted, since those exceptions cannot occur in the Java Card
platform. See Section 2.3.3, “Exceptions” on page 2-19 for specification of errors and
exceptions.

异常

java卡程序可以和java程序一样定义,抛出和捕获异常。 Throwable类和他相关的子类被支持。一些异常和Error类的子类被省略,因为这种类型的异常不可能在java卡平台上产生。参见2.3.3“异常"。

 

Generics
This Java language facility allows a type or method to operate on objects of various
types while providing compile-time type safety. It adds compile-time type safety and
eliminates the need for casting.

泛型

这个java语言的特性语序一个类型或者方法在编译期类型安全的前提下操作一个多钟类型的对象。他提供了编译期类型安全并淘汰掉需要的类型转换。


Static Import
This Java language facility lets you avoid importing an entire class simply to access
its static members or qualifying static members with class names each time it is
used.

静态导入

这个java语言的特性允许在不通过类的操作,直接访问静态成员和方法而避免导入整个类。


Runtime Invisible Metadata (Annotations)
This language feature lets you avoid writing boilerplate code under many
circumstances by enabling tools to generate it from annotations in the source code.
The Java Card platform language subset supports the use of annotations which are
not visible at runtime. These annotations do not themselves use the runtime visible
meta-data annotation @Retention(RetentionPolicy.RUNTIME).

运行态非可见的元数据(标签)

这个语言特性使得你通过允许工具通过源代码中的标签来自动实现模板化代码。java卡平台语言子集支持使用运行态非可见的标签。这些标签不能是通过@Retention(RetentionPolicy.RUNTIME)定义的自有标签。

 

2.2.2.2 Keywords

2.2.2.2 关键字
The following keywords are supported. Their use is the same as in the Java
programming language.

以下的关键字是被支持的,他们的使用和在java语言里面一样。


TABLE 2-2  Supported Keywords


abstract default if private this
boolean do implements protected throw
break else import public throws
byte extends instanceof return try
case final int short void
catch finally interface static while
class for new super
continue goto package switch

 

2.2.2.3 Types

2.2.2.3 类型


Java programming language types boolean, byte, short, and int are supported.
Objects (class instances and single-dimensional arrays) are also supported. Arrays
can contain the supported primitive data types, objects, and other arrays.
Some Java Card implementations might not support use of the int data type. (Refer
to Section 2.2.3.1, “Integer Data Type” on page 2-8).

java语言类型:boolean,byte,short和int被支持,对象(类实例和一维数组)也被支持,数组可以包含原始数据类型,对象,或者其它数组。

一些Java卡平台的实现可能不支持int类型的使用。


2.2.2.4 Classes

2.2.2.4 类

Most of the classes in the java.lang package are not supported on the Java Card
platform. The following classes from java.lang are supported on the card in a
limited form.

大多数java.lang包中的类在java卡平台都不被支持,以下的java.lang中的类在卡上有限的支持。


Object
Java Card API classes descend from java.lang.Object, just as in the Java
programming language. Most of the methods of Object are not available in the Java
Card API, but the class itself exists to provide a root for the class hierarchy.

Object类

和java语言一样,java卡API的类都继承于java.lang.Object。在java卡API中Object的多数方法已经不存在了,但是类自己作为类继承的根留下来了。

 

Throwable
Class Throwable and its subclasses are supported. Most of the methods of
Throwable are not available in the Java Card API, but the class itself exists to
provide a common ancestor for all exceptions.

Throwable类

Throwable类和他的子类是被支持的。在java卡API中Throwable的多数方法已经不存在了,但是类自己作为异常类继承的根留下来了。

 

2.2.3 Optionally Supported Items

2.2.3 选择性支持的项目


This section describes the optional features of the Java Card platform. An optional
feature is not required to be supported in a Java Card platform-compatible
implementation. However, if an implementation does include support for an
optional feature, it must be supported fully, and exactly as specified in this
document.

这章描述了java卡平台中选择性支持的特性。选择性支持的特性不要求java卡平台一定支持。然而如果一个实现决定支持可选特性,它就必须提供这章规定的完整的实现。


2.2.3.1 Integer Data Type
The int keyword and 32-bit integer data type need not be supported in a Java Card
implementation. A Java Card virtual machine that does not support the int data
type will reject programs which use the int data type or 32-bit intermediate values.
The result of an arithmetic expression produced by a Java Card virtual machine
must be equal to the result produced by a Java virtual machine, regardless of the
input values. A Java Card virtual machine that does not support the int data type
must reject expressions that could produce a different result.

2.2.3.1 int类型

int关键字和32-bit的整形数据在java卡实现上不被要求。一个不支持int类型的虚拟机将拒绝使用了int类型或者32位数据的程序的执行。不管使用任何的输入数据,java卡虚拟机的数学运算结果必须和java虚拟机一致。一个不支持int类型数据的虚拟机必须拒绝可能产生不同结果的操作。

 

2.2.3.2 Object Deletion Mechanism
Java Card technology, version 2.2.2 offers an optional, object deletion mechanism.
Applications designed to run on these implementations can use the facility by
invoking the appropriate API. See Application Programming Interface, Java Card
Platform, Version 2.2.2. But, the facility is best suited for updating large objects such
as certificates and keys atomically. Therefore, application programmers should
conserve on the allocation of objects.

2.2.3.2 对象删除机制

java卡技术2.2.2提供了一个可选的对象删除机制。在这个机制下设计的应用可以通过调用合适的API来使用这个功能。


2.2.4 Limitations of the Java Card Virtual Machine

2.2.4 java卡虚拟机的限制


The limitations of resource-constrained hardware prevent Java Card virtual
machines from supporting the full range of functionality of certain Java platform
features. The features in question are supported, but a particular virtual machine
may limit the range of operation to less than that of the Java platform.

To ensure a level of portability for application code, this section establishes a
minimum required level for partial support of these language features.
The limitations here are listed as maximums from the application programmer’s
perspective. Java packages that do not violate these maximum values can be
converted into Java Card technology-based CAP files (“Java Card CAP files”), and
will be portable across all Java Card implementations. From the Java Card virtual
machine implementer’s perspective, each maximum listed indicates a minimum
level of support that will allow portability of applets.

资源受限型的硬件环境阻止了java卡虚拟机实现当前java平台的全部特性。问题是被支持的特性在某些特定的实现里面所支持的范围也要小于java平台。为了保证程序代码的一定程度的移植,这章确定了一个最小最大支持的集合。此处被列出的限制是基于大部分程序开发人员的视角。不违背这个限制的java包可以被转化为java卡支持的CAP文件,并且可以在所有的java卡实现中移植。从java卡虚拟机实现者的视角,每个最大限制表明了一个可移植性的最小支持。

 

2.2.4.1 Packages

2.2.4.1 包


Package References
A package can reference at most 128 other packages.

包引用

一个包最多可以引用128个其它的包


Package Name
The fully qualified name of a package may contain a maximum of 255 characters.
The package name size is further limited if it contains one or more characters which,
when represented in UTF-8 format, requires multiple bytes.

包名

一个完整的包名最多可以支持255字符,如果字符中含有UTF-8的多字节字符,那么这个限制还要更大。(255字节)

 

2.2.4.2 Classes

2.2.4.2 类


Classes in a Package
A package can contain at most 255 classes and interfaces.

包中的类

一个包可以包含最多255个类和接口


Interfaces
A class can implement at most 15 interfaces, including interfaces implemented by
superclasses.
An interface can inherit from at most 14 superinterfaces.

接口

一个类可以最多实现15个接口,其中包含父类实现的接口。

一个接口可以最多继承14个父接口。

 

Static Fields
A class in an applet package can have at most 256 public or protected static non-final
fields. A class in a library package can have at most 255 public or protected static
non-final fields. There is no limit on the number of static final fields (constants)
declared in a class.

静态属性

在applet包中的类可以有最多256个public或者protected 的静态非final的属性。

在library包中的类可以有最多255个public或者protected的静态非final的属性。

对类中的静态final属性(常量)的数目则没有要求。


Static Methods
A class in an applet package can have at most 256 public or protected static methods.
A class in a library package can have at most 255 public or protected static methods.

静态方法

一个applet包中的类可以有最多256个public或者protected的静态方法。

一个library包中的类可以有最多255个public或者protected的静态方法。


2.2.4.3 Objects

2.2.4.3 对象


Methods
A class can implement a maximum of 128 public or protected instance methods, and
a maximum of 128 instance methods with package visibility. These limits include
inherited methods.

方法

一个类可以实现最多128个公有或者protected的实例方法,和最多128个package的实例方法。这个限制包含继承的方法。


Class Instances
Class instances can contain a maximum of 255 fields, where an int data type is
counted as occupying two fields. These limits include inherited fields.

类的实例

类的实例最多可以包含255属性。一个int类型的数据占用两个属性空间,这个限制包含继承的属性。


Arrays
Arrays can hold a maximum of 32767 components.

数组

数组最多可以有32767的空间。(signed short的长度)

 

2.2.4.4 Methods

2.2.4.4 方法
The maximum number of variables that can be used in a method is 255. This limit
includes local variables, method parameters, and, in the case of an instance method
invocation, a reference to the object on which the instance method is being invoked
(meaning, this). An int data type is counted as occupying two local variables.
A method can have at most 32767 Java Card virtual machine bytecodes. The number
of Java Card technology-based bytecodes (“Java Card bytecodes”) may differ from
the number of Java bytecodes in the Java virtual machine implementation of that
method.

The maximum depth of an operand stack associated with a method is 255 16-bit
cells.

方法中最多可以使用的变量是255个,其中包含本地变量,方法参数,在实例方法中的隐含的reference--this。一个int类型的变量将占用两个变量空间。

一个方法可以有最多32767个字节的bytecodes。java卡所处理的字节码可能和java的字节码有数目上的区别。

一个方法所关联的操作栈的最大深度是255个16-bit的单元。

 

2.2.4.5 Switch Statements

2.2.4.5 Switch报表
The format of the Java Card virtual machine switch instructions limits switch
statements to a maximum of 65536 cases. This limit is far greater than the limit
imposed by the maximum size of methods (Section 2.2.4.4, “Methods” on page 2-10).

java卡虚拟机的switch指令限制最多有65536个cases,这个限制远远高于强加于method的最大容量。

 

2.2.4.6 Class Initialization

2.2.4.6 类的初始化


The Java Card virtual machine contains limited support for class initialization
because there is no general mechanism for executing <clinit> methods. Support
for <clinit> methods is limited to the initialization of static field values with the
following constraints:
■ Static fields of applet packages may only be initialized to primitive compile-time
constant values, or arrays of primitive compile-time constants.
■ Static fields of user libraries may only be initialized to primitive compile-time
constant values.
■ Only static fields declared in the current class may be initialized in the <clinit>
method.

java卡虚拟机包含了类初始化支持的限制,因为并没有一个通用的机制来执行<clinit>方法。对<clinit>方法的支持限制为对静态属性值的初始化,当然还有如下的约束:

■ applet包的静态属性只能被初始化为基础类型的常量,或者基础类型常量的数组。

■ libraries包的静态属性只能被初始化为基础类型的常量。

■ 只有当前类的静态属性才能在<clinit>中被初始化。


Primitive constant data types include boolean, byte, short, and int.
Given Java technology source files that adhere to these language-level constraints on
static field initialization, it is expected that reasonable Java compilers will:
■ Inline constants in the bytecodes that reference static final primitive fields that are
initialized in the declaration statement.
■ Produce only the following bytecodes:
■ load a value on the stack: iconst_[m1,0-5], [b|s]ipush, ldc, ldc_w,
aconst_null
■ create an array: newarray([byte|short|boolean|int] )
■ duplicate items on the stack: dup
■ store values in arrays or static fields: [b|i|s]astore, putstatic
■ return from method: return

基础常量类型包括 boolean,byte,short和int

给定的java技术源文件都遵从这些关于静态属性初始化的语言级别的限制,这个要求对java编译器很合理,编译器将:

■ 在bytecode中内连(直接替换)那些被初始化的static final的基本类型的属性。

■只处理如下的bytecode

■在栈上加载一个数值:iconst_,ipush,ldc,ldc_w,aconst_null

■创建一个数组:newarray

■在栈上复制对象:dup

■在数组或者静态属性里面存数值:astore,putstatic

■从函数里面返回:return

 

2.2.5 Multiselectable Applets Restrictions

2.2.5 多重选择应用约束


Applets that implement the javacard.framework.Multiselectable interface
are called multiselectable applets. For more details on multiselection, please see the
Runtime Environment Specification, Java Card Platform, Version 2.2.2.
All applets within a package shall be multiselectable, or none shall be.

实现了javacard.framework.Multiselectable接口的应用被称为多重选择应用,更多的细节参考JCRE规范多重选择的章节。


2.2.6 Java Card Platform Remote Method Invocation

2.2.6 java卡平台远程方法调用


(RMI) Restrictions
This section defines the subset of the RMI system that is supported by Java Card
platform RMI (“Java Card RMI”).

RMI约束

这章定义了被Java卡所支持的RMI系统的子集。

 

2.2.6.1 Remote Classes and Remote Interfaces

2.2.6.1 远程类和远程接口


A class is remote if it or any of its superclasses implements a remote interface.
A remote interface is an interface which satisfies the following requirements:
■ The interface name is java.rmi.Remote or the interface extends, directly or
indirectly, the interface java.rmi.Remote.
■ Each method declaration in the remote interface or its super-interfaces includes
the exception java.rmi.RemoteException (or one of its superclasses) in its
throws clause.
■ In a remote method declaration, if a remote object is declared as a return type, it
is declared as the remote interface, not the implementation class of that interface.
In addition, Java Card RMI imposes additional constraints on the definition of
remote methods. These constraints are as a result of the Java Card platform language
subset and other feature limitations. For more information, see Section 2.2.6.2,
“Access Control of Remote Interfaces” on page 2-12 and Section 2.2.6.3, “Parameters
and Return Values” on page 2-13.

一个类只有在它或者他的父类实现了远程接口之后就可以称为远程类。远程接口是一个满足了如下条件的接口:

■ 接口名是java.rmi.Remote或者直接间接继承于java.rmi.Remote的接口。

■ 每个在远程接口或者其父接口中定义的函数都必须在异常表中包含java.rmi.RemoteException。

■ 在一个远程方法的声明中,如果一个远程对象被声明为返回类型,它将作为远程接口被声明而不不是实现了接口的类。

而且java卡RMI在定义远程方法增加了附加的限制。这些约束是由于java卡平台语言子集和其它特性限制的结果。


2.2.6.2 Access Control of Remote Interfaces

2.2.6.2 远程接口的访问控制


The Java RMI system supports the package access control defined in the Java
language. However, Java Card RMI does not support package-visible remote
interfaces.

java RMI系统支持在java语言中定义的包访问控制,然而java卡RMI不支持包可见的远程接口

 

2.2.6.3 Parameters and Return Values

2.2.6.3 参数和返回值


The parameters of a remote method must only include parameters of the following
types:
■ any primitive type supported by Java Card technology (boolean, byte, short,
int),
■ any single-dimension array type of an primitive type supported by Java Card
technology (boolean[], byte[], short[], int[]).
The return type of a remote method must only be one of the following types:
■ any primitive type supported by Java Card technology (boolean, byte, short,
int),
■ any single-dimension array type of an primitive type supported by Java Card
technology (boolean[], byte[], short[], int[]),
■ any remote interface type
■ type void

远程方法的参数只能有如下的形式:

■ 任意的java卡支持的基本类型(boolean, byte, short, int)

■ 任意的java卡支持的一维基本类型数组。(boolean[],byte[],short[],int[])

 

远程方法的返回值只能是以下的类型:

■ 任意java卡所支持的基本类型(boolean, byte, short, int)

■任意远程接口类型

■空类型

 

2.3 Java Card VM Subset

2.3 java卡虚拟机子集


Java Card technology uses a subset of the Java virtual machine, and familiarity with
the Java platform is required to understand the Java Card virtual machine.
The items discussed in this section are not described to the level of a virtual machine
specification. For complete documentation on the Java virtual machine, refer to the
The Java Virtual Machine Specification.

java卡技术使用了一个java虚拟机的子集,理解java卡虚拟机需要熟悉java平台。这章所讨论的对象不在虚拟机规范这个层次。完整的java虚拟机文档,参照java虚拟机规范。


2.3.1 class File Subset

2.3.1 类文件子集


The operation of the Java Card virtual machine can be defined in terms of standard
Java platform class files. Since the Java Card virtual machine supports only a subset
of the behavior of the Java virtual machine, it also supports only a subset of the
standard class file format.

java卡虚拟机的操作被定义砸标准的java平台的类文件的基础上。因为java卡虚拟机只支持java虚拟机的一个子集,它也只支持标准的类文件格式的一个子集。

 

2.3.1.1 Not Supported in Class Files

2.3.1.1 在类文件中不被支持的。


Class access flags
In class_info and interface_info structures, the access flag ACC_ENUM is not
supported.

类访问标志

在class_info和interface_info结构中,访问标志ACC_ENUM不被支持。


Field Descriptors

属性描述符
Field descriptors may not contain BaseType characters C, D, F or J. ArrayType
descriptors for arrays of more than one dimension may not be used.

属性描述符不包含基础类型中的字符 C,D,F和J(char,double,float,long)。超过一维的数组类型描述符也不被使用。


Constant Pool
Constant pool table entries with the following tag values are not supported.

常量池

常量池中不支持如下的tag


Fields

属性
In field_info structures, the access flags ACC_VOLATILE, ACC_TRANSIENT and
ACC_ENUM are not supported.

在field_info结构里,访问标志ACC_VOLATILE,ACC_TRANSIENT和ACC_ENUM不被支持。


Methods

方法
In method_info structures, the access flags ACC_SYNCHRONIZED, ACC_STRICT,
ACC_NATIVE, and ACC_VARARGS are not supported.

在method_info结构里,访问标志ACC_SYNCHRONIZED,ACC_STRICT,ACC_NATIVE和ACC_VARARGS不被支持。


TABLE 2-3  Unsupported Java Constant Pool Tags

TABLE 2-3 不支持的java常量池Tag


Constant Type Value
CONSTANT_String 8
CONSTANT_Float 4
CONSTANT_Long 5
CONSTANT_Double 6

 

2.3.1.2 Supported in Class Files

2.3.1.2 类文件中支持的类型


ClassFile
All items in the ClassFile structure are supported.
类文件

类文件结构中的所有项目都被支持。

 

Field Descriptors
Field descriptors may contain BaseType characters B, I, S and Z, as well as a
ObjectType. ArrayType descriptors for arrays of a single dimension may a
used.

属性描述符

属性描述符可以包含基本类型B,I,S和Z(byte,int,short,boolean),Object类型L<classname>;,一维数组类型[。


Method Descriptors
All forms of method descriptors are supported.
方法描述符

方法描述符中的所有项目都被支持。

 

Constant pool
Constant pool table entry with the following tag values are supported.

常量池

以下tag的常量池类型被支持:


Fields

属性
In field_info structures, the supported access flags are ACC_PUBLIC,
ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC and ACC_FINAL.
The remaining components of field_info structures are fully supported.

在field_info结构中,支持访问标志有ACC_PUBLIC,ACC_PRIVATE,ACC_PROTECTED,ACC_STATIC和ACC_FINAL

field_info中剩余的组件也完整支持。


TABLE 2-4  Supported Java Constant Pool Tags

TABLE 2-4 支持的java常量池Tag


Constant Type Value
CONSTANT_Class 7
CONSTANT_Fieldref 9
CONSTANT_Methodref 10
CONSTANT_InterfaceMethodref 11
CONSTANT_Integer 3
CONSTANT_NameAndType 12
CONSTANT_Utf8 1

 

Methods

方法

In method_info structures, the supported access flags are ACC_PUBLIC,
ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL and ACC_ABSTRACT.
The remaining components of method_info structures are fully supported.

在method_info结构中,支持的标志有ACC_PUBLIC,ACC_PRIVATE,ACC_PROTECTED,ACC_STATIC,ACC_FINAL,ACC_ABSTRACT.剩下的method_info中的组件全部支持。


Attributes
The attribute_info structure is supported. The Code, ConstantValue,
Exceptions, LocalVariableTable, Synthetic, InnerClasses,
RuntimeInvisibleAnnotations, RuntimeInvisibleParameterAnnotations
and Deprecated attributes are supported.

属性

attribute_info结构被支持。代码,常量,异常和本地变量表,内联类,运行态不可见标签,运行态不可见参数标签和废弃属性被支持。


2.3.2 Bytecode Subset

2.3.2 字节码子集


The following sections detail the bytecodes that are either supported or unsupported
in the Java Card platform. For more details, refer to Chapter 7, “Java Card Virtual
Machine Instruction Set”.

接下来的章节明细化了在java卡平台上支持的bytecode和不支持的bytecode,更多的细节参考第七章。

 

2.3.2.1 Unsupported Bytecodes
2.3.2.1 不支持的字节码

 

TABLE 2-5  Unsupported Bytecodes
lconst_<l> fconst_<f> dconst_<d> ldc2_w2
lload fload dload lload_<n>
fload_<n> dload_<n> laload faload
daload caload lstore fstore
dstore lstore_<n> fstore_<n> dstore_<n>
lastore fastore dastore castore
ladd fadd dadd lsub
fsub dsub lmul fmul
dmul ldiv fdiv ddiv
lrem frem drem lneg
fneg dneg lshl lshr
lushr land lor lxor
i2l i2f i2d l2i
l2f l2d f2i f2d
d2i d2l d2f i2c
lcmp fcmpl fcmpg dcmpl
dcmpg lreturn freturn dreturn
monitorenter monitorexit multianewarray goto_w
jsr_w

 

2.3.2.2 Supported Bytecodes

2.3.2.2 支持的字节码


TABLE 2-6  Supported Bytecodes
nop aconst_null iconst_<i> bipush
sipush ldc ldc_w iload
aload iload_<n> aload_<n> iaload
aaload baload saload istore
astore istore_<n> astore_<n> iastore
aastore bastore sastore pop

 

2.3.2.3 Static Restrictions on Bytecodes

2.3.2.3 字节码的静态约束


A class file must conform to the following restrictions on the static form of
bytecodes.

一个类文件必须遵守如下的字节码静态约束。
ldc, ldc_w
The ldc and ldc_w bytecodes can only be used to load integer constants. The
constant pool entry at index must be a CONSTANT_Integer entry. If a program
contains an ldc or ldc_w instruction that is used to load an integer value less than
-32768 or greater than 32767, that program will require the optional int instructions
(Section 2.2.3.1, “Integer Data Type” on page 2-8).

ldc和ldc_w字节码只能被用于加载字符型常量,对应的索引的常量池必须是一个CONSTANT_Integer入口。如果一个程序包含一个ldc或者ldc_w命令用来导入一个小于-32768或者大于32767的数字,程序应该需要int指令的支持。


lookupswitch
The value of the npairs operand must be less than 65536. This limit is far greater
than the limit imposed by the maximum size of methods (Section 2.2.4.4, “Methods”
on page 2-10). If a program contains a lookupswitch instruction that uses keys of
type int, that program will require the optional int instructions (Section 2.2.3.1,
“Integer Data Type” on page 2-8). Otherwise, key values must be in the range
-32768 to 32767.

遍历匹配

npair操作数的值必须小于65536,这个限制远远的大于方法的容量限制。如果一个包含了lookupswitch指令的程序使用了int类型的key,那么程序需要支持int指令集。否则key值必须在-32768到32767之间。


tableswitch
The bytecode can contain at most 65536 cases. This limit is far greater than the limit
imposed by the maximum size of methods (Section 2.2.4.4, “Methods” on page 2-10).
If a program does not use the optional int instructions (Section 2.2.3.1, “Integer Data
Type” on page 2-8), the values of the high and low operands must both be at least -
32768 and at most 32767.

表遍历

字节码只能包含最多65536个case,这个限制远远大于方法的容量限制,如果一个不支持in类型的程序使用了该字节码,那么case的范围只能在-32768到32767之间。


wide
The wide bytecode can only be used with an iinc instruction.

局部变量索引扩展

wide字节码只能用来扩展iinc指令。


2.3.3 Exceptions

2.3.3 异常


The Java Card platform provides full support for the Java platform’s exception
mechanism. Users can define, throw and catch exceptions just as in the Java
platform. The Java Card platform also makes use of the exceptions and errors
defined in The Java Language Specification. An updated list of the Java platform’s
exceptions is provided in the JDK™ software documentation.
Not all of the Java platform’s exceptions are supported in the Java Card platform.
Exceptions related to unsupported features are naturally not supported. Class loader
exceptions (the bulk of the checked exceptions) are not supported.
Note that some exceptions may be supported to the extent that their error conditions
are detected correctly, but classes for those exceptions will not necessarily be present
in the API.
The supported subset is described in the tables below.

2.3.3 异常
java卡平台提供了java平台异常机制的完整支持。用户可以和在java平台中一样定义,抛出和捕获异常。java卡平台也定义了java语言规范中定义的一些异常和错误。最新的java平台异常列表在JDK的软件文档中提供。
不是所有的java平台的异常在java卡平台中都支持。与不支持特性相关的异常自然也不支持。Class loader异常不被支持。
值得注意的是,一些运行态的异常可以支持,但是这些异常的类并不一定在API中提供。
支持的子集在下表中描述。


2.3.3.1 Uncaught and Uncatchable Exceptions
In the Java platform, uncaught exceptions and errors will cause the virtual machine’s
current thread to exit. As the Java Card virtual machine is single-threaded, uncaught
exceptions or errors will cause the virtual machine to halt. Further response to
uncaught exceptions or errors after halting the virtual machine is an
implementation-specific policy, and is not mandated in this document.
Some error conditions are known to be unrecoverable at the time they are thrown.
Throwing a runtime exception or error that cannot be caught will also cause the
virtual machine to halt. As with uncaught exceptions, implementations may take
further responses after halting the virtual machine. Uncatchable exceptions and

errors which are supported by the Java Card platform may not be reflected in the
Java Card API, though the Java Card platform will correctly detect the error
condition.

2.3.3.1 未捕捉和不能捕捉的异常
在java平台中,未捕获的异常和错误将导致虚拟机当前的线程退出。因为java卡虚拟机是一个单线程的,未捕获的异常或者错误将将导致虚拟机中止。
未捕获异常在中止了虚拟机后进一步的响应是没有在本文档中规定的特定的方案。
一些异常在他们抛出的时候就知道其不可修复。抛出一个未被捕获的运行态异常也会导致虚拟机的中止,而且未捕获的异常在中止虚拟机后还有进一步的操作。
java卡平台所支持的未捕获的异常和错误将不在java卡API中体现。因为java卡平台将正确的检测到错误的发生。


2.3.3.2 Checked Exceptions

2.3.3.2 检测异常
TABLE 2-7  Support of Java Checked Exceptions

TABLE 2-7 java检测异常的支持
Exception                                                 Supported                          Not Supported
ClassNotFoundException                                                                    X
CloneNotSupportedException                                                             X
IllegalAccessException                                                                        X
InstantiationException                                                                        X
InterruptedException                                                                          X
NoSuchFieldException                                                                         X
NoSuchMethodException                                                                     X

 

2.3.3.3 Runtime Exceptions

2.3.3.3 运行态异常

TABLE 2-8  Support of Java Runtime Exceptions

TABLE 2-8 java运行态异常的支持
Runtime Exception                                    Supported               Not Supported
ArithmeticException                                   X
ArrayStoreException                                  X
ClassCastException                                   X
IllegalArgumentException                                                         X
IllegalThreadStateException                                                     X
NumberFormatException                                                           X
IllegalMonitorStateException                                                    X
IllegalStateException                                                               X
IndexOutOfBoundsException                    X
ArrayIndexOutOfBoundsException                                           X
StringIndexOutOfBoundsException                                          X
NegativeArraySizeException                     X
NullPointerException                                 X
SecurityException                                      X

 

2.3.3.4 Errors

2.3.3.4 错误
TABLE 2-9  Support of Java Errors

TABLE 2-9  java错误的支持


Error                                                         Supported               Not Supported
AssertionError                                                                          X
LinkageError                                             X
ClassCircularityError                                 X
ClassFormatError                                     X
ExceptionInInitializerError                       X
IncompatibleClassChangeError               X
AbstractMethodError                               X
IllegalAccessError                                   X
InstantiationError                                   X

NoSuchFieldError                                    X
NoSuchMethodError                               X
NoClassDefFoundError                           X
UnsatisfiedLinkError                               X
Ver i fyEr ror                                           X
ThreadDeath                                                                                 X
VirtualMachineError                                 X
InternalError                                          X  
OutOfMemoryError                                 X
StackOverflowError                                X
UnknownError                                       X
UnsupportedClassVersionError              X

 

原创粉丝点击