The CAP File Format
CAP文件格式
This chapter describes the Java Card converted applet (CAP) file format. Each CAP
file contains all of the classes and interfaces defined in one Java package. Java Card
Converters must be capable of producing CAP files that conform to the specification
provided in this chapter.
这章描述了java卡转化应用CAP文件格式。每个CAP文件包含了一个java包中的所有类和接口。java卡转化器必须有能力使用这章的规范产生CAP文件。
A CAP file consists of a stream of 8-bit bytes. All 16-bit and 32-bit quantities are
constructed by reading in two and four consecutive 8-bit bytes, respectively.
Multibyte data items are always stored in big-endian order, where the high-order
bytes come first. The first bit read of an 8-bit quantity is considered the high bit.
This chapter defines its own set of data types representing Java Card CAP file data:
the types u1, and u2 represent an unsigned one-, and two-byte quantities,
respectively. Some u1 types are represented as bitfield structures, consisting of arrays
of bits. The zeroeth bit in each bit array represents the most significant bit, or high
bit.
CAP文件由8-bit的字节流组成,所有的16-bit和32-bit数都是通过读取2个和4个8-bit字节来组成。多字节数据对象都是大端存储,高字节在前,低字节在后。
这章定义了java卡CAP文件数组自己的数据类型。类型u1和u2代表了一个无符号的单字节,双字节数。一些u1类型用来描述一个bit域的结构,由bit的数组组成。
每个bit数组中的第0个bit代表最高bit。
The Java Card CAP file format is presented using pseudo structures written in a C-
like structure notation. To avoid confusion with the fields of Java Card virtual
machine classes and class instances, the contents of the structures describing the Java
Card CAP file format are referred to as items. Unlike the fields of a C structure,
successive items are stored in the Java Card platform file sequentially, without
padding or alignment.
java卡CAP文件结构使用C风格结构体的伪码来表示,为了避免和java卡虚拟机类和类实例混淆,java卡CAP文件结构的内容以对象来描述。和C结构不同,java卡平台文件中的结构连续存储,不存在对齐的问题。
Variable-sized tables, consisting of variable-sized items, are used in several CAP file
data structures. Although we will use C-like array syntax to refer to table items, the
fact that tables are streams of variable-sized structures means that it is not possible
to directly translate a table index into a byte offset into the table.
A data structure referred to as an array consists of items equal in size.
Some items in the structures of the CAP file format are describe using a C-like union
notation. The bytes contained in a union structure have one of the two formats.
Selection of the two formats is based on the value of the high bit of the structure.
在一些CAP文件的结构中使用了由变长的对象组成的变长的表。尽管我们使用了C风格的数组来表示表对象,事实上,变长结构的流意味着不可能直接把一个表下标转化为偏移。
一些CAP结构中的对象格式使用C风格的union来描述。包含了一个union结构的数据有一两种格式。选择哪种格式由结构的高bit来决定。
6.1 Component Model
6.1 组件模型
A Java Card CAP file consists of a set of components. Each component describes a
set of elements in the Java package defined, or an aspect of the CAP file. A complete
CAP file must contain all of the required components specified in this chapter. Three
components are optional: the Applet Component (Section 6.5, “Applet Component”
on page 6-12), Export Component (Section 6.12, “Export Component” on page 6-47),
and Debug Component (Section 6.14, “Debug Component” on page 6-57). The
Applet Component is included only if one or more Applets are defined in the
package. The Export Component is included only if classes in other packages may
import elements in the package defined. The Debug Component contains all of the
data necessary for debugging a package.
java卡CAP文件由一组组件组成,每个组件描述了一组java包中定义的对象,或者CAP的某个方面。一个完整的CAP文件必须包含这章描述的所有必须的组件。
三个组件是可选的:Applet组件,Export 组件和Debug 组件。
The content of each component defined in a CAP file must conform to the
corresponding format specified in this chapter. All components have the following
general format:
CAP文件中每个组件的内容必须遵照这章的格式,所有的组件有如下通用格式:
Each component begins with a 1-byte tag indicating the kind of component. Valid
tags and their values are listed in TABLE 6-1. The size item indicates the number of
bytes in the info array of the component, not including the tag and size items.
The content and format of the info array varies with the type of component.
每个组件以一个1-byte的标签来标识组件类型。有效的标签和他们的值在TABLE 6-1里面列举。size对象标识了info数组的字节数。不包含标签和size对象。
info数组的内容取决于组件的类型。
component {
u1 tag
u2 size
u1 info[]
}
TABLE 6-1 CAP File Component Tags
Component Type Value
COMPONENT_Header 1
COMPONENT_Directory 2
COMPONENT_Applet 3
COMPONENT_Import 4
COMPONENT_ConstantPool 5
COMPONENT_Class 6
COMPONENT_Method 7
COMPONENT_StaticField 8
COMPONENT_ReferenceLocation 9
COMPONENT_Export 10
COMPONENT_Descriptor 11
COMPONENT_Debug 12
Sun Microsystems, Inc. may define additional components in future versions of this
Java Card virtual machine specification. It is guaranteed that additional components
will have tag values between 13 and 127, inclusive.
sun公司有可能在未来的版本定义额外的组件。它额外组件的值在13到127之间.
6.1.1 Containment in a JAR File
6.1.1 JAR文件中的存储
Each CAP file component is represented as a single file. The component file names
are enumerated in TABLE 6-2. These names are not case sensitive.
每个CAP文件组件都是一个单独的文件,组件文件名在TABLE 6-2中列举。名字是大小写不敏感的。
TABLE 6-2 CAP File Component File Names
Component Type File Name
COMPONENT_Header Header.cap
COMPONENT_Directory Directory.cap
COMPONENT_Applet Applet.cap
COMPONENT_Import Import.cap
COMPONENT_ConstantPool ConstantPool.cap
COMPONENT_Class Class.cap
COMPONENT_Method Method.cap
COMPONENT_StaticField StaticField.cap
COMPONENT_ReferenceLocation RefLocation.cap
COMPONENT_Export Export.cap
COMPONENT_Descriptor Descriptor.cap
COMPONENT_Debug Debug.cap
All CAP file components are stored in a JAR file. As described in Section 4.1.3, “JAR
File Container” on page 4-2, the path to the CAP file component files in a JAR file
consists of a directory called javacard that is in a subdirectory representing the
package’s directory. For example, the CAP file component files of the package
javacard.framework are located in the subdirectory
javacard/framework/javacard. Other files, including other CAP files, may also
reside in a JAR file that contains CAP file component files.
所有的CAP文件组件都存储在一个JAR文件中。在第4.1.3中描述的一样,CAP文件中组件文件的路径又一个包路径和一个叫javacard的子路径组成。
举例,包javacard.framework的CAP文件组件位于JAR文件的javacard/framework/javacard目录下。其它文件,包含其他CAP文件,也可以在JAR文件的其它对应路径下。
The JAR file format provides a vehicle suitable for the distribution of CAP file
components. It is not intended or required that the JAR file format be used as the
load file format for loading CAP file components onto a Java Card technology-
enabled device. See Section 6.2, “Installation” on page 6-5 for more information.
JAR文件格式提供了一个组织CAP文件组件的合适的媒介。在导入CAP文件组件到Java卡的时候,并不一定采用JAR文件结构。参照6.2“安装”。
The name of a JAR file containing CAP file components is not defined as part of this
specification. The naming convention used by the Sun Microsystems, Inc. Java Card
Converter Tool is to append .cap to the simple (meaning not fully qualified)
package name. For example, the CAP file produced for the package
com.sun.javacard.JavaLoyalty would be named JavaLoyalty.cap.
包含CAP文件组件的JAR文件的名字不在这个规范定义的范围之内。Sun公司的converter是以包的简单名字加上.cap后缀来命名的。
举个例子,包com.sun.javacard.JavaLoyalty将会被命名为JavaLoyalty.cap
6.1.2 Defining New Components
6.2.1 定义新的组件
Java Card CAP files are permitted to contain new, or custom, components. All new
components not defined as part of this specification must not affect the semantics of
the specified components, and Java Card virtual machines must be able to accept
CAP files that do not contain new components. Java Card virtual machine
implementations are required to silently ignore components they do not recognize.
New components are identified in two ways: they are assigned both an ISO 7816-5
AID (Section 4.2, “AID-based Naming” on page 4-3) and a tag value. Valid tag
values are between 128 and 255, inclusive. Both of these identifiers are recorded in
the custom_component item of the Directory Component (Section 6.4, “Directory
Component” on page 6-9).
java卡CAP文件允许包含新的或者定制的组件。所有这个规范中没有定义的组件不能影响特定组件的语义。java卡虚拟机必须能够结构不包含新组件的CAP文件。
java卡虚拟机实现要求默认的忽略掉它们不认识的组件。
新组件有两种方式来标识:它们被既被分配了ISO7816-5的AID,又被分配了一个标签值。有效的标签值在128-255之间。所有的这些标志被记录在Directory组件的自定义组件对象中。
The new component must conform to the general component format defined in this
chapter, with a tag value, a size value indicating the number of bytes in the
component (excluding the tag and size items), and an info item containing the
content of the new component.
新的组件必须遵照这张定义的通用组件格式,有一个标签值,一个size值来表示组件中的字节数,一个info对象来容纳新组件的内容。
A new component file is stored in a JAR file, following the same restrictions as those
specified in Section 4.1.3, “JAR File Container” on page 4-2. That is, the file
containing the new component must be located in the
<package_directory>/javacard subdirectory of the JAR file and must have the
extension .cap.
一个新组件文件存储在一个JAR文件中,和上述在JAR文件中的组件遵从一样的标准。也就是说,包含新组件的文件必须位于包目录下的javacard子目录下,也必须有一个cap文件后缀。
6.2 Installation
6.2 安装
Installing a CAP file components onto a Java Card technology-enabled device entails
communication between a Java Card technology-enabled terminal and that device.
While it is beyond the scope of this specification to define a load file format or
installation protocol between a terminal and a device, the CAP file component order
shown in TABLE 6-3 is a reference load order suitable for an implementation with a
simple memory management model on a limited memory device.
安装一个CAP文件组件到一个java卡设备上必须在java卡中断和设备之间建立通讯。
然而定义一个终端到设备见load文件的格式或者安装协议已经超过了这个规范的范围。在TABLE 6-3里面展示了一个合适的CAP文件组件下载顺序。
TABLE 6-3 Reference Component Install Order
Component Type
COMPONENT_Header
COMPONENT_Directory
COMPONENT_Import
COMPONENT_Applet
COMPONENT_Class
COMPONENT_Method
COMPONENT_StaticField
COMPONENT_Export
COMPONENT_ConstantPool
COMPONENT_ReferenceLocation
COMPONENT_Descriptor (optional)
The component type COMPONENT_Debug is not intended for download to the device.
It is intended to be used off-card in conjunction with a suitably instrumented Java
Card virtual machine.
组件COMPONENT_Debug不提供给下载设备,它提供在java卡虚拟机的离卡操作上。
6.3 Header Component
6.3 头组件
The Header Component contains general information about this CAP file and the
package it defines. It is described by the following variable-length structure:
The items in the header_component structure are as follows:
头组件包含了这个CAP文件和包定义的通用信息。用如下的变长结构来描述:
header_component {
u1 tag
u2 size
u4 magic
u1 minor_version
u1 major_version
u1 flags
package_info package
package_name_info package_name
}
tag
标签
The tag item has the value COMPONENT_Header (1).
标签对象的值是 1
size
大小
The size item indicates the number of bytes in the header_component
structure, excluding the tag and size items. The value of the size item must be
greater than zero.
size对象标明了头组件结构中不包含tag和size的字节个数。size对象的值必须大于0
magic
魔术码
The magic item supplies the magic number identifying the Java Card CAP file
format; it has the value 0xDECAFFED.
魔术码对象标明了java卡CAP文件。它的值是0xDECAFFED
minor_version, major_version
次要版本,主要版本
The minor_version and major_version items are the minor and major
version numbers of this CAP file. Together, a major and a minor version number
determine the version of the CAP file format. If a CAP file has the major version
number of M and minor version number of m, the version of the CAP file’s format
is M.m.
次要版本和主要版本对象是CAP文件对应的版本号。两个版本合并到一起决定了CAP文件的版本号。
如果一个CAP文件的主版本号是M,次版本号是m,CAP文件的版本是M.m
A change in the major version number indicates a major incompatibility change,
one that requires a fundamentally different Java Card virtual machine. A Java
Card virtual machine is not required to support CAP files with different major
version numbers. A Java Card virtual machine is required to support CAP files
having a given major version number and all valid minor version numbers in the
range 0 through some particular minor_version where a valid minor version
number is a minor version number that has been defined in a version of the Java
Card virtual machine specification.
主要版本号的修改代表了一个主要的不兼容的修改。需要java卡虚拟机的根本区分。一个java卡虚拟机不要求支持不同主版本号的CAP文件。
java卡虚拟机要求支持一个给定主版本号的所有次版本号的CAP文件。
In this specification, the major version of the CAP file format has the value 2 and
the minor version has the value 2. Only Sun Microsystems, Inc. may define the
meaning and values of new CAP file format versions.
这个规范中,主版本号和次要版本号都是2.只有sun公司可以定义CAP文件版本号。
flags
标识
The flags item is a mask of modifiers that apply to this package. The flags
modifiers are shown in the following table.
标识对象用来修饰做到到这个包的标识。标识如下:
TABLE 6-4 CAP File Package Flags
Flags Value
ACC_INT 0x01
ACC_EXPORT 0x02
ACC_APPLET 0x04
The ACC_INT flag has the value of one if the Java int type is used in this package.
The int type is used if one or more of the following is present:
ACC_INT标识为1标识这个包中是否使用了java的int类型。
■ a parameter to a method of type int,
■ a parameter to a method of type int array,
■ a local variable of type int,
■ a local variable of type int array,
■ a field of type int,
■ a field of type int array,
■ an instruction of type int, or
■ an instruction of type int array.
Otherwise the ACC_INT flag has the value of 0.
■ 方法的参数使用了int类型,
■ 方法的参数使用了int []类型,
■ 本地变量使用了int类型
■ 本地变量使用了int [] 类型
■ 属性使用了int类型
■ 属性使用了int [] 类型
■ 一个int类型的字节码指令
■ 一个int []类型的字节码指令
否则ACC_INT被置为0
The ACC_EXPORT flag has the value of one if an Export Component (Section 6.12,
“Export Component” on page 6-47) is included in this CAP file. Otherwise it has
the value of 0.
ACC_EXPORT标志为1标识了CAP文件中包含了Export组件。否则它的标志为0.
The ACC_APPLET flag has the value of one if an Applet Component (Section 6.5,
“Applet Component” on page 6-12) is included in this CAP file. Otherwise it has
the value of 0.
ACC_APPLET标志为1标识了CAP文件中包含了Applet组件,否则它的标志为0.
All other bits in the flags item not defined in TABLE 6-4 are reserved for future use.
Their values must be zero.
表6-4中未定义的其它bit是保留给未来使用的,它们的值必须是0.
package
包
The package item describes the package defined in this CAP file. It is
represented as a package_info structure:
包对象描述了这个CAP文件中定义的包。遵照如下的结构:
package_info {
u1 minor_version
u1 major_version
u1 AID_length
u1 AID[AID_length]
}
minor_version, major_version
The minor_version and major_version items are the minor and major
version numbers of this package. These values uniquely identify the particular
implementation of this package and indicate the binary compatibility between
packages. See Section 4.5, “Package Versions” on page 4-13 for a description of
assigning and using package version numbers.
AID_length
The AID_length item represents the number of bytes in the AID item. Valid
values are between 5 and 16, inclusive.
AID[]
The AID item represents the Java Card platform name of the package. See ISO
7816-5 for the definition of an AID (Section 4.2, “AID-based Naming” on
page 4-3).
参见Export文件结构中关于CONSTANT_Package的定义。
package_name
包名
The package_name item describes the name of the package defined in this CAP
file. It is represented as a package_name_info[] structure:
The items in the package_name_info[] structure are as follows:
包名对象描述了CAP文件中定义的包名。表现为package_name_info结构:
package_name_info {
u1 name_length
u1 name[name_length]
}
name_length
名字长度
The name_length item is the number of bytes used in the name item to
represent the name of this package in UTF-8 format. The value of this item may
be zero if and only if the package does not define any remote interfaces or
remote classes.
name_length对象是这个包名字的UTF-8格式的字节个数。只有当这个包没有定义任何远程接口和远程类的时候,长度为0.
name[]
名字
The name[] item is a variable length representation of the fully qualified name
of this package in UTF-8 format. The fully qualified name is represented in
internal form as described in Java Virtual Machine Specification (Section 4.2).
name[]对象是这个包全名UTF-8格式的变长数组。全名命名在java虚拟机规范的内部格式中描述。
6.4 Directory Component
6.4 目录组件
The Directory Component lists the size of each of the components defined in this
CAP file. When an optional component is not included, such as the Applet
Component (Section 6.5, “Applet Component” on page 6-12), Export Component
(Section 6.12, “Export Component” on page 6-47), or Debug Component
(Section 6.14, “Debug Component” on page 6-57), it is represented in the Directory
Component with size equal to zero. The Directory Component also includes entries
for new (or custom) components.
The Directory Component is described by the following variable-length structure:
目录组件列出了CAP文件中每个组件的大小。当一个可选的组件比如Applet组件,Export组件或者Debug组件没有包含,它在目录组件对应的大小等于零。
目录组件也包含新组件的入口。
目录组件描述为如下的变长结构:
directory_component {
u1 tag
u2 size
u2 component_sizes[12]
static_field_size_info static_field_size
u1 import_count
u1 applet_count
u1 custom_count
custom_component_info custom_components[custom_count]
}
The items in the directory_component structure are as follows:
目录组件结构对象如下:
tag
标签
The tag item has the value COMPONENT_Directory (2).
标签的值是2
size
大小
The size item indicates the number of bytes in the directory_component
structure, excluding the tag and size items. The value of the size item must be
greater than zero.
size对象标识了目录组件结构不包含tag和size对象的大小。size的值必须大于0.
component_sizes[]
组件大小
The component_sizes item is an array representing the number of bytes in each
of the components in this CAP file. All of the 12 components defined in this
chapter are represented in the component_sizes array. The value of an index
into the array is equal to the value of the tag of the component represented at that
entry, minus 1.
组件大小对象是一个用来标识每个CAP文件中组件大小的数组。所有这章定义的12个组件都在这个数组里面包含,数组的下表是每个组件的tag值-1。
The value in each entry in the component_sizes array is the same as the size
item in the corresponding component. It represents the number of bytes in the
component, excluding the tag and size items.
组件大小数组中的每个入口的值和对应组件中size对象的值相同。提供了除tag和size对象之外的数据字节数。
The value of an entry in the component_sizes array is zero for components not
included in this CAP file. Components that may not be included are the Applet
Component (Section 6.5, “Applet Component” on page 6-12), the Export
Component (Section 6.12, “Export Component” on page 6-47), and the Debug
Component (Section 6.14, “Debug Component” on page 6-57). For all other
components the value is greater than zero.
如果组件不包含在CAP文件中,对应的component_size的入口的值为0.只有Export,Debug,Applet组件可能为0,其它的组件大于0.
static_field_size
静态属性大小
The static_field_size item is a static_field_size_info structure. The
structure is defined as:
static_field_size对象是一个static_field_size_info的结构,结构如下:
static_field_size_info {
u2 image_size
u2 array_init_count
u2 array_init_size
}
The items in the static_field_size_info structure are the following:
image_size
The image_size item has the same value as the image_size item in the
Static Field Component (Section 6.10, “Static Field Component” on page 6-41).
It represents the total number of bytes in the static fields defined in this
package, excluding final static fields of primitive types.
image_size对象和Static Field组件中的image_size的值相同。它提供了这个包中所有的静态属性的全部字节数量,不包含静态基本类型常量。
array_init_count
The array_init_count item has the same value as the array_init_count
item in the Static Field Component (Section 6.10, “Static Field Component” on
page 6-41). It represents the number of arrays initialized in all of the <clinit>
methods in this package.
数组初始化数量
array_init_count对象和静态属性组件中的array_init_count对象的值相同。它展现了在<clinit>类初始化方法中初始的数组个数。
array_init_size
The array_init_size item represents the sum of the count items in the
array_init table item of the Static Field Component (Section 6.10, “Static
Field Component” on page 6-41). It is the total number of bytes in all of the
arrays initialized in all of the <clinit> methods in this package.
数组初始化大小
array_init_size对象提供了静态属性组件中的array_init表的对象大小总数。它是所有在<clinit>类初始化方法中初始的数组的字节总数。
import_count
The import_count item indicates the number of packages imported by classes
and interfaces in this package. This item has the same value as the count item in
the Import Component (Section 6.6, “Import Component” on page 6-13).
导入数
import_count对象标识着本包类和接口导入的包的数量。这个对象的值和导入组件的count对象相同。
applet_count
The applet_count item indicates the number of applets defined in this package.
If an Applet Component Section 6.5, “Applet Component” on page 6-12) is not
included in this CAP file, the value of the applet_count item is zero. Otherwise
the value of the applet_count item is the same as the value of the count item in
the Applet Component (Section 6.5, “Applet Component” on page 6-12).
应用个数
applet_count对象标识着这个包定义的应用的个数。如果Applet组件不包含在CAP文件中,这个值是零。否则和Applet组件中的count对象的值相同。
custom_count
The custom_count item indicates the number of entries in the
custom_components table. Valid values are between 0 and 127, inclusive.
自定义个数
custom_count对象标识custom_components表中入口的个数。有效的值是0到127。
custom_components[]
自定义组件
The custom_components item is a table of variable-length
custom_component_info structures. Each new component defined in this CAP
file must be represented in the table. These components are not defined in this
standard.
The custom_component_info structure is defined as:
自定义组件是一个变长的custom_component_info结构的表。在这个CAP文件中的的每个新组件文件必须在表中体现。
custom_component_info {
u1 component_tag
u2 size
u1 AID_length
u1 AID[AID_length]
}
The items in entries of the custom_component_info structure are:
component_tag
The component_tag item represents the tag of the component. Valid values
are between 128 and 255, inclusive.
组件——标签
component_tag对象代表组件的标签,有效的值在128到255之间。
size
The size item represents the number of bytes in the component, excluding the
tag and size items.
大小
size对象提供了组件的字节数,不包含tag和size对象。
AID_length
The AID_length item represents the number of bytes in the AID item. Valid
values are between 5 and 16, inclusive.
AID_length
AID_length_item代表了AID对象的字节数,有效的数值在5和16之间。
AID[]
The AID item represents the Java Card platform name of the component. See
ISO 7816-5 for the definition of an AID (Section 4.2, “AID-based Naming” on
page 4-3).
AID
AID_item代表了java卡平台组件的名字,参见ISO7816-5中AID的定义。
Each component is assigned an AID conforming to the ISO 7816-5 standard.
Beyond that, there are no constraints on the value of an AID of a custom
component.
每个组件都被分配了符合ISO7816-5规范的AID。对AID的值没有限制。
6.5 Applet Component
6.5 应用组件
The Applet Component contains an entry for each of the applets defined in this
package. Applets are defined by implementing a non-abstract subclass, direct or
indirect, of the javacard.framework.Applet class.
If no applets are defined, this component must not be present in this CAP file.
应用组件为这个包里面的每个应用都包含了一个入口。应用通过直接或者间接实现一个非-抽象的javacard.framework.Applet子类而实现。
如果没有应用,CAP文件中不能包含这个组件。
The Applet Component is described by the following variable-length structure:
应用组件描述如下:
applet_component {
u1 tag
u2 size
u1 count
{ u1 AID_length
u1 AID[AID_length]
u2 install_method_offset
} applets[count]
}
The items in the applet_component structure are as follows:
tag
The tag item has the value COMPONENT_Applet (3).
标签
tag对象的值是3
size
The size item indicates the number of bytes in the applet_component
structure, excluding the tag and size items. The value of the size item must be
greater than zero.
大小
size对象标识着applet组件结构中不包含tag和size对象的字节数。size对象的值必须大于0
count
The count item indicates the number of applets defined in this package. The
value of the count item must be greater than zero.
个数
count对象标识着包中定义的应用个数,count的值必须大于0。
applets[]
The applets item represents a table of variable-length structures each describing
an applet defined in this package.
The items in each entry of the applets table are defined as follows:
应用
applets对象为这个包中定义的每个应用提供了一个变长结构的表。
每个结构如下:
AID_length
The AID_length item represents the number of bytes in the AID item. Valid
values are between 5 and 16, inclusive.
AID长度
AID_length对象提供了AID对象的字节数,有效的长度在5到16之间。
AID[]
The AID item represents the Java Card platform name of the applet.
Each applet is assigned an AID conforming to the ISO 7816-5 standard
(Section 4.2, “AID-based Naming” on page 4-3). The RID (first 5 bytes) of all of
the applet AIDs must have the same value. In addition, the RID of each applet
AIDs must have the same value as the RID of the package defined in this CAP
file.
AID
AID对象提供了java卡平台的应用名。
每个应用都被分配了符合ISO7816-5标准的AID。所有的应用的RID必须相同(等于包的RID)。
install_method_offset
The value of the install_method_offset item must be a 16-bit offset into
the info item of the Method Component (Section 6.9, “Method Component”
on page 6-35). The item at that offset must be a method_info structure that
represents the static install(byte[],short,byte) method of the
applet.
The install(byte[],short,byte) method must be defined in a
class that extends the javacard.framework.applet class, directly or
indirectly. The install(byte[],short,byte) method is called to initialize
the applet.
安装方法偏移
install_method_offset对象的值必须是一个16-bit的偏移来指向Method组件的info对象。对应偏移位置必须是一个method_info结构,提供了static install(byte[],short,byte)方法,用来初始化调用。
6.6 Import Component
6.6 导入组件
The Import Component lists the set of packages imported by the classes in this
package. It does not include an entry for the package defined in this CAP file. The
Import Component is represented by the following structure:
导入组件列表列举了在这个包中类和接口导入的包。结构如下:
import_component {
u1 tag
u2 size
u1 count
package_info packages[count]
}
The items in the import_component structure are as follows:
tag
The tag item has the value COMPONENT_Import (4).
标签
tag对象的值是4
size
The size item indicates the number of bytes in the import_component
structure, excluding the tag and size items. The value of the size item must be
greater than zero.
大小
size对象标明了import结构除了tag和size对象的大小。size对象的值必须大于0.
count
The count item indicates the number of items in the packages table. The value
of the count item must be between 0 and 128, inclusive.
个数
count对象标明了这个包表中的对象数。count对象的值在0到128之间。
packages[]
The packages item represents a table of variable-length package_info
structures as defined for package under Section 6.3, “Header Component” on
page 6-6. The table contains an entry for each of the packages referenced in the
CAP file, not including the package defined.
The major and minor version numbers specified in the package_info structure
are equal to the major and minor versions specified in the imported package’s
export file. See Section 4.5, “Package Versions” on page 4-13 for a description of
assigning and using package version numbers.
Components of this CAP file refer to an imported package by using a index in this
packages table. The index is called a package token (Section 4.3.7.1, “Package” on
page 4-8).
包
packages对象提供了一个变长的package_info结构表,和6.3中“头组件”中对应的结构相同。
在package_info中提供的主要和次要版本号等于export文件中对应的值。
CAP文件中的组件用指向这个表下标方式来标识一个引用的包。这个下标被称为“包令牌”
6.7 Constant Pool Component
6.7 常量池组件
The Constant Pool Component contains an entry for each of the classes, methods,
and fields referenced by elements in the Method Component (Section 6.9, “Method
Component” on page 6-35) of this CAP file. The referencing elements in the Method
Component may be instructions in the methods or exception handler catch types in
the exception handler table.
常量池组件包含这个CAP文件中方法组件中使用的类,方法,属性的引用入口。方法中参考的元素有可能是方法的指令或者一场处理表中的异常句柄。
Entries in the Constant Pool Component reference elements in the Class Component
(Section 6.8, “Class Component” on page 6-21), Method Component (Section 6.9,
“Method Component” on page 6-35), and Static Field Component (Section 6.10,
“Static Field Component” on page 6-41). The Import Component (Section 6.6,
“Import Component” on page 6-13) is also accessed using a package token
(Section 4.3.7.1, “Package” on page 4-8) to describe references to classes, methods
and fields defined in imported packages. Entries in the Constant Pool Component do
not reference other entries internal to itself.
The Constant Pool Component is described by the following structure:
常量池中的入口指向了类组件,方法组件和静态属性组件。导入组件也使用一个包令牌来访问来描述指向类,方法和属性包的索引。
常量池的入口不指向它自己内部的入口。
constant_pool_component {
u1 tag
u2 size
u2 count
cp_info constant_pool[count]
}
The items in the constant_pool_component structure are as follows:
tag
The tag item has the value COMPONENT_ConstantPool (5).
标签
tag对象的值是5
size
The size item indicates the number of bytes in the constant_pool_component
structure, excluding the tag and size items. The value of the size item must be
greater than zero.
大小
size对象标识着constant_pool组件结构除了tag和size对象的大小。size对象的值必须大于0.
count
The count item represents the number entries in the constant_pool[] array.
Valid values are between 0 and 65535, inclusive.
个数
count对象提供了constant_pool数组的入口个数,有效的值是0到65535.
constant_pool[]
The constant_pool[] item represents an array of cp_info structures:
Each item in the constant_pool[] array is a 4-byte structure. Each structure
must begin with a 1-byte tag indicating the kind of cp_info entry. The content
and format of the 3-byte info array varies with the value of the tag. The valid tags
and their values are listed in the following table.
cp_info {
u1 tag
u1 info[3]
}
常量池
constant_pool对象以一组cp_info结构体来表示,每个constant_pool数组都是一个4-byte的结构体。
每个结构必须由一个1字节的tag来标明cp_info入口的类型。3字节的info数组的结构根据tag值的不同而不同。
有效的tag值如下:
TABLE 6-5 CAP File Constant Pool Tags
Constant Type Tag
CONSTANT_Classref 1
CONSTANT_InstanceFieldref 2
CONSTANT_VirtualMethodref 3
CONSTANT_SuperMethodref 4
CONSTANT_StaticFieldref 5
CONSTANT_StaticMethodref 6
Java Card platform constant types (“Java Card constant types”) are more specific
than those in Java class files. The categories indicate not only the type of the item
referenced, but also the manner in which it is referenced.
java卡平台常量类型比java类文件更细致,类型不但标明引用对象的类型,也指示了引用的类型。
For example, in the Java constant pool there is one constant type for method
references, while in the Java Card platform constant pool (“Java Card constant
pool”) there are three constant types for method references: one for virtual
method invocations using the invokevirtual bytecode, one for super method
invocations using the invokespecial bytecode, and one for static method
invocations using either the invokestatic or invokespecial bytecode.
additional information provided by a constant type in Java Card technologies
simplifies resolution of references.
举个例子,在java常量池中有一个方法引用的常量类型。然而在java卡平台常量池中有三种方法引用类型:
一个是使用invokevitual字节码调用的虚方法,一个是使用invokespecial字节码调用的超方法,一个是使用invokestatic或者invokespecial调用的静态方法。
java卡平台提供的常量类型的额外信息简化了引用解析的难度。
There are no ordering constraints on constant pool entries. It is recommended,
however, that CONSTANT_InstanceFieldref (Section 6.7.2,
“CONSTANT_InstanceFieldref, CONSTANT_VirtualMethodref, and
CONSTANT_SuperMethodref” on page 6-18) constants occur early in the array to
permit using getfield_T and putfield_T bytecodes instead of getfield_T_w and
putfield_T_w bytecodes. The former have 1-byte constant pool index
parameters while the latter have 2-byte constant pool index parameters.
常量池入口没有排序机制,然而,建议CONSTANT_InstanceFieldref常量在数组前边,使得可以使用getfield_T和putfield_T字节码来代替getfield_T和putfield_T。
前一种使用一个字节的常量池索引,后一种使用两个字节的常量池索引。
The first entry in the constant pool can not be an exception handler class that is
referenced by a catch_type_index of an exception_handler_info
structure. In such a case the value of the catch_type_index would be equal to
0, but the value of 0 in a catch_type_index is reserved to indicate an
exception_handler_info structure that describes a finally block.
常量池的第一个入口不能是一个用catch_type_index指向的exception_handler_info的异常处理类结构。在这种情况下,catch_type_index的值为0,
但是在catch_type_index的值中,0标志着exception_handler_info指向一个finally块。
6.7.1 CONSTANT_Classref
6.7.1 常量类引用
The CONSTANT_Classref_info structure is used to represent a reference to a class
or an interface. The class or interface may be defined in this package or in an
imported package.
CONSTANT_Classref_info结构使用来表述一个对类和接口的引用,类和接口可以定义在包内,也可以定义在导入的包内。
CONSTANT_Classref_info {
u1 tag
union {
u2 internal_class_ref
{ u1 package_token
u1 class_token
} external_class_ref
} class_ref
u1 padding
}
The items in the CONSTANT_Classref_info structure are the following:
tag
The tag item has the value CONSTANT_Classref (1).
标签
tag对象的值是1
class_ref
The class_ref item represents a reference to a class or interface. If the class or
interface is defined in this package the structure represents an
internal_class_ref and the high bit of the structure is zero. If the class or
interface is defined in another package the structure represents an
external_class_ref and the high bit of the structure is one.
类引用
class_ref对象提供了指向一个类或者接口的引用,如果类或者接口定义在本包,结构使用internal_class_ref,并且结构的最高bit是0.
如果类或者接口定义在其它的包,结构使用external_class_ref,结构的最高bit是1.
internal_class_ref
The internal_class_ref structure represents a 16-bit offset into the info
item of the Class Component (Section 6.8, “Class Component” on page 6-21) to
an interface_info or class_info structure. The interface_info or
class_info structure must represent the referenced class or interface.
The value of the internal_class_ref item must be between 0 and 32767,
inclusive, making the high bit equal to zero.
内部类引用
internal_class_ref结构提供了一个指向Class组件info段的16-bit偏移,目的是一个interface_info或者class_info结构。interface_info或者class_info必须提供对应的类和接口的信息。
internal_class_ref的值必须在0到32767之间,使得最高bit等于0.
external_class_ref
The external_class_ref structure represents a reference to a class or
interface defined in an imported package. The high bit of this structure is one.
外部类引用
external_class_ref结构提供了一个指向导入包的类或者接口,结构的最高bit是1.
package_token
The package_token item represents a package token (Section 4.3.7.1,
“Package” on page 4-8) defined in the Import Component (Section 6.6,
“Import Component” on page 6-13) of this CAP file. The value of this token
must be a valid index into the packages table item of the
import_component structure. The package represented at that index must
be the imported package.
The value of the package token must be between 0 and 127, inclusive.
The high bit of the package_token item is equal to one.
包令牌
package_token对象提供了CAP中一个定义在导入组件中的包令牌。这个令牌的值必须是一个指向import_component结构中的packages表中的有效索引。
对应的包必须是导入的包。
包令牌的值必须在0到127之间,包令牌的最高bit等于1
class_token
The class_token item represents the token of the class or interface
(Section 4.3.7.2, “Classes and Interfaces” on page 4-8) of the referenced class
or interface. It has the value of the class token of the class as defined in the
Export file of the imported package.
类令牌
class_token对象提供了类或者接口的令牌。它的值被定义在导入包的导出文件中。
padding
The padding item has the value zero. It is present to make the size of a
CONSTANT_Classref_info structure the same as all other constants in the
constant_pool[] array.
补齐字
padding对象的值是0.它是用来保证CONSTANT_Classref_info结构的长度和其它的长度相同。
6.7.2 CONSTANT_InstanceFieldref,
CONSTANT_VirtualMethodref, and
CONSTANT_SuperMethodref
6.7.2 实例属性常量引用,虚方法常量引用,和超级方法常量引用。
References to instance fields, and virtual methods are represented by similar
structures:
都采取类似的结构:类的令牌+令牌
CONSTANT_InstanceFieldref_info {
u1 tag
class_ref class
u1 token
}
CONSTANT_VirtualMethodref_info {
u1 tag
class_ref class
u1 token
}
CONSTANT_SuperMethodref_info {
u1 tag
class_ref class
u1 token
}
The items in these structures are as follows:
tag
The tag item of a CONSTANT_InstanceFieldref_info structure has the value
CONSTANT_InstanceFieldref (2).
The tag item of a CONSTANT_VirtualMethodref_info structure has the value
CONSTANT_VirtualMethodref (3).
The tag item of a CONSTANT_SuperMethodref_info structure has the value
CONSTANT_SuperMethodref (4).
标签
实例属性常量引用的标签是2
虚方法常量引用的标签是3
超级方法常量引用的标签是4
class
The class item represents the class associated with the referenced instance field,
virtual method, or super method invocation. It is a class_ref structure
(Section 6.7.1, “CONSTANT_Classref” on page 6-16). If the referenced class is
defined in this package the high bit is equal to zero. If the reference class is
defined in an imported package the high bit of this structure is equal to one.
The class referenced in the CONSTANT_InstanceField_info structure must be
the class that contains the declaration of the instance field.
The class referenced in the CONSTANT_VirtualMethodref_info structure must
be a class that contains a declaration or definition of the virtual method.
The class referenced in the CONSTANT_SuperMethodref_info structure must be
the class that defines the method that contains the Java language-level super
invocation.
类
class对象标识了对应于实例属性,虚方法或者超级方法调用的类。它是一个class_ref结构(参见 6.7.1)。
如果引用的类定义在本包,最高bit等于0。如果应用类定义在一个导入的包内,最高bit等于1.
对应的类必须有实例属性,虚方法和语言级别的super调用。
token
令牌
The token item in the CONSTANT_InstanceFieldref_info structure
represents an instance field token (Section 4.3.7.5, “Instance Fields” on page 4-9)
of the referenced field. The value of the instance field token is defined within the
scope of the class indicated by the class item.
CONSTANT_InstanceFieldref_info结构中的令牌对象描述了一个指向实例属性的令牌。实例属性令牌的定义范围在类的范围内。被类对象定义。
The token item of the CONSTANT_VirtualMethodref_info structure
represents the virtual method token (Section 4.3.7.6, “Virtual Methods” on
page 4-9) of the referenced method. The virtual method token is defined within
the scope of the hierarchy of the class indicated by the class item. If the referenced
method is public or protected the high bit of the token item is zero. If the
referenced method is package-visible the high bit of the token item is one. In this
case the class item must represent a reference to a class defined in this package.
CONSTANT_VirtualMehtodref_info结构中的token对象描述了引用该方法的虚方法令牌。虚方法令牌被定义在类对象指定的类中。
如果指向的方法是public或者protected,token的高bit是0。如果指向的是一个包可见的方法,令牌的最高bit是1.
在这个情况下,class对象必须提供一个定义在这个包中的引用。
The token item of the CONSTANT_SuperMethodref_info structure represents
the virtual method token (Section 4.3.7.6, “Virtual Methods” on page 4-9) of the
referenced method. Unlike in the CONSTANT_VirtualMethodref_info
structure, the virtual method token is defined within the scope of the hierarchy of
the superclass of the class indicated by the class item. If the referenced method
is public or protected the high bit of the token item is zero. If the referenced
method is package-visible the high bit of the token item is one. In the latter case
the class item must represent a reference to a class defined in this package and
at least one superclass of the class that contains a definition of the virtual method
must also be defined in this package.
CONSTANT_SuperMethodref_info结构的token对象提供了对应方法的方法令牌。和CONSTANT_VirtualMethodref_info不同,虚方法令牌定义在指定类对象的父类上。
如果引用的方法是public或者protected的,token对象的高bit是0.如果引用的方法是包可见的,最高bit是1.在后边的例子下,class对象必须提供一个定义到这个包的类和
最少一个类的包含了指定虚方法。
6.7.3 CONSTANT_StaticFieldref and
CONSTANT_StaticMethodref
6.7.3 静态属性常量引用和静态方法常量引用
References to static fields and methods are represented by similar structures:
静态属性和静态方法有类似的结构表示
CONSTANT_StaticFieldref_info {
u1 tag
union {
{
u1 padding
u2 offset
} internal_ref
{
u1 package_token
u1 class_token
u1 token
} external_ref
} static_field_ref
}
CONSTANT_StaticMethodref_info {
u1 tag
union {
{
u1 padding
u2 offset
} internal_ref
{
u1 package_token
u1 class_token
u1 token
} external_ref
} static_method_ref
}
The items in these structures are as follows:
tag
The tag item of a CONSTANT_StaticFieldref_info structure has the value
CONSTANT_StaticFieldref (5).
The tag item of a CONSTANT_StaticMethodref_info structure has the value
CONSTANT_StaticMethodref (6).
标签
静态属性tag的值是5
静态方法tag的值是6
static_field_ref and static_method_ref
The static_field_ref and static_method_ref item represents a reference
to a static field or static method, respectively. Static method references
include references to static methods, constructors, and private virtual methods.
If the referenced item is defined in this package the structure represents an
internal_ref and the high bit of the structure is zero. If the referenced item is
defined in another package the structure represents an external_ref and the
high bit of the structure is one.
静态属性引用和静态方法引用
static_field_ref和static_method_ref对象提供了一个指向静态属性和方法的引用。静态方法引用包含静态方法,构造函数和私有虚方法的引用。
如果指向的对象在本包内,结构提供internal_ref,并且结构的最高bit是0.如果参照的对象定义在包外,结构的最高bit是1.
internal_ref
The internal_ref item represents a reference to a static field or method
defined in this package. The items in the structure are:
内部引用
internal_ref对象提供了一个本包内定义的静态属性或者方法的引用。结构如下:
padding
The padding item is equal to 0.
补充字
padding对象等于0
offset
The offset item of a CONSTANT_StaticFieldref_info structure
represents a 16-bit offset into the Static Field Image defined by the Static
Field component (Section 6.10, “Static Field Component” on page 6-41) to
this static field.
The offset item of a CONSTANT_StaticMethodref_info structure
represents a 16-bit offset into the info item of the Method Component
(Section 6.9, “Method Component” on page 6-35) to a method_info
structure. The method_info structure must represent the referenced
method.
偏移
CONSTANT_StaticFieldref_info结构标明了一个静态属性组件中指向Static Field Image的偏移来指向一个静态属性。
external_ref
The external_ref item represents a reference to a static field or method
defined in an imported package. The items in the structure are:
外部引用
external_ref对象标明了一个指向导入包的静态属性或者方法,结构如下:
package_token
The package_token item represents a package token (Section 4.3.7.1,
“Package” on page 4-8) defined in the Import Component (Section 6.6,
“Import Component” on page 6-13) of this CAP file. The value of this token
must be a valid index into the packages table item of the
import_component structure. The package represented at that index must
be the imported package.
The value of the package token must be between 0 and 127, inclusive.
The high bit of the package_token item is equal to one.
包令牌
package_token对象提供了一个定义在导入组件中的包令牌。这个令牌的值必须是一个有效的下表指向import_component结构。
对应下表所指的包,必须是个导入包。
包令牌的值必须在0到127之间。package_token的高bit等于1.
class_token
The class_token item represents the token (Section 4.3.7.2, “Classes and
Interfaces” on page 4-8) of the class of the referenced class. It has the value
of the class token of the class as defined in the Export file of the imported
package.
The class indicated by the class_token item must define the referenced
field or method.
class_token对象提供了引用类的类令牌。它的值和导入包的导出文件中定义的值一致。
class_token所指出的类必须定义了引用的属性或者方法。
token
The token item of a CONSTANT_StaticFieldref_info structure
represents a static field token (Section 4.3.7.3, “Static Fields” on page 4-8) as
defined in the Export file of the imported package. It has the value of the
token of the referenced field.
The token item of a CONSTANT_StaticMethodref_info structure
represents a static method token (Section 4.3.7.4, “Static Methods and
Constructors” on page 4-8) as defined in the Export file of the imported
package. It has the value of the token of the referenced method.
令牌
CONSTANT_StaticFieldref_info结构中的token对象和定义在导入包的导出文件中的静态属性令牌一致。
CONSTANT_StaticMethodref_info结构中的token对象和定义在导入包的导出文件中的静态方法令牌一致。
6.8 Class Component
6.8 类组件
The Class Component describes each of the classes and interfaces defined in this
package. It does not contain complete access information and content details for each
class and interface. Instead, the information included is limited to that required to
execute operations associated with a particular class or interface, without
performing verification. Complete details regarding the classes and interfaces
defined in this package are included in the Descriptor Component (Section 6.13,
“Descriptor Component” on page 6-49).
类组件描述了本包内所有的类和接口,不包含每个类和接口完整的访问信息和上下文细节。作为替代的,包含的信息是被限制到特定的类的执行中。
完整的细节参见描述组件中关于类和接口的定义。
The information included in the Class Component for each interface is sufficient to
uniquely identify the interface and to test whether or not a cast to that interface is
valid.
类组件中每个接口包含的信息是足够的唯一标识接口并且可以测试是否一个接口转化是有效的。
The information included in the Class Component for each class is sufficient to
resolve operations associated with instances of a class. The operations include
creating an instance, testing whether or not a cast of the instance is valid,
dispatching virtual method invocations, and dispatching interface method
invocations. Also included is sufficient information to locate instance fields of type
reference, including arrays.
类组件中每个类包含的信息足够处理类实例的操作。操作包含创建实例,测试是否一个实例的转化是有效的。分派虚方法调用,分派接口方法调用。
而且包含了足够的信息来定位实例的属性和类型引用,包含数组。
The classes represented in the Class Component reference other entries in the Class
Component in the form of superclass, superinterface and implemented interface
references. When a superclass, superinterface or implemented interface is defined in
an imported package the Import Component is used in the representation of the
reference.
类组件中描述的类在类中引用其它的入口,以超类,超接口和实现接口引用的方式。当一个超类,超接口和实现的接口定义在一个导入包中,导入组件用来标识引用。
The classes represented in the Class Component also contain references to virtual
methods defined in the Method Component (Section 6.9, “Method Component” on
page 6-35) of this CAP file. References to virtual methods defined in imported
packages are not explicitly described. Instead such methods are located through a
superclass within the hierarchy of the class, where the superclass is defined in the
same imported package as the virtual method.
类组件提供的类也包含了定义到这个CAP中Method组件的虚方法引用。引用导入包的虚方法没有被明确的描述。作为替代这种方法通过一个类的父类继承来定位。
The Constant Pool Component (Section 6.7, “Constant Pool Component” on
page 6-14), Export Component (Section 6.12, “Export Component” on page 6-47),
Descriptor Component (Section 6.13, “Descriptor Component” on page 6-49) and
Debug Component (Section 6.14, “Debug Component” on page 6-57) reference
classes and interfaces defined in the Class Component. No other CAP file
components reference the Class Component.
The Class Component is represented by the following structure:
常量池组件,导出组件,描述组件和调试组件引用定义在类组件中的类和方法。没有其他的CAP组件引用类组件。
The Class Component is represented by the following structure:
类组件的格式如下:
class_component {
u1 tag
u2 size
u2 signature_pool_length
type_descriptor signature_pool[]
interface_info interfaces[]
}
The items in the class_component structure are as follows:
tag
The tag item has the value COMPONENT_Class (6).
标签
tag对象的值是6
size
The size item indicates the number of bytes in the class_component structure,
excluding the tag and size items. The value of the size item must be greater
than zero.
大小
size对象标明了class_component结构中除了tag和size对象的字节长度。size对象的值必须大于0.
signature_pool_length
The signature_pool_length item indicates the number of bytes in the
signature_pool[] item. The value of the signature_pool_length item
must be zero if the package does not define any remote interfaces or remote
classes.
签名池长度
signature_pool_length对象标识了signature_pool[]对象中的字节数。signature_pool_length对象的值在包不定义任何远程接口或远程类的时候必须为0.
signature_pool[]
The signature_pool[] item represents a list of variable-length
type_descriptor structures. These descriptors represent the signatures of the
remote methods.
签名池
signature_pool[] 对象提供了一个变长type_descriptor结构,这些描述符提供了远程方法的签名
interfaces[]
The interfaces item represents an array of interface_info structures. Each
interface defined in this package is represented in the array. The entries are
ordered based on hierarchy such that a superinterface has a lower index than any
of its subinterfaces.
接口
interface对象提供了一个interface_info结构的数组。包中定义的每个接口都在这个数组中。排序规则是父接口的索引比子接口小。
classes[]
The classes item represents a table of variable-length class_info structures.
Each class defined in this package is represented in the array. The entries are
ordered based on hierarchy such that a superclass has a lower index than any of
its subclasses.
类
class对象提供了一个变长的class_info结构数组。包中的每个类都在这个数组中,排序规则是父类的索引比子类小。
6.8.1 type_descriptor
6.8.1 类型描述符
The type_descriptor structure represents the type of a field or the signature of a
method.
The type_descriptor structure contains the following elements:
类型描述符结构提供了一个方法的属性或者签名的类型。结构如下:
type_descriptor {
u1 nibble_count;
u1 type[(nibble_count+1) / 2];
}
nibble_count
The nibble_count value represents the number of nibbles required to describe
the type encoded in the type array.
半字节数
nibble_count值提供了用来描述类型数组里面类型的半字节的个数。
type[]
类型
The type array contains an encoded description of the type, composed of
individual nibbles. If the nibble_count item is an odd number, the last nibble in
the type array must be 0x0. The values of the type descriptor nibbles are defined
in the following table.
类型数组包含了一个类型的编码描述,由各个独立的半字节组成。如果半字节个数是奇数,类型数组中的最后一个半字节必须是0.类型描述半字节的定义如下:
TABLE 6-6 Type Descriptor Values
Type Value
void 0x1
boolean 0x2
byte 0x3
short 0x4
int 0x5
reference 0x6
array of boolean 0xA
array of byte 0xB
array of short 0xC
array of int 0xD
array of reference 0xE
Class reference types are described using the reference nibble 0x6, followed by
a 2-byte (4-nibble) class_ref structure. The class_ref structure is defined as
part of the CONSTANT_Classref_info structure (Section 6.7.1,
“CONSTANT_Classref” on page 6-16). For example, a field of type reference to
p1.c1 in a CAP file defining package p0 is described as:
类引用类型使用半字节0x6,跟着一个2字节(4半字节)的class_ref结构。class_ref结构在CONSTANT_Classref的结构中被定义。
举个例子,CAP中的一个指向p1.c1的引用被描述为:
TABLE 6-7 Encoded Reference Type p1.c1
Nibble Value Description
0 0x6 reference
1 <p1> package token
2 (high bit on)
3 <c1> class token
4
5 0x0 padding
The following are examples of the array types:
接下来是数组类型:
TABLE 6-8 Encoded Byte Array Type
Nibble Value Description
0 0xB array of byte
1 0x0 padding
指向p1.c1的引用数组类型:
TABLE 6-9 Encoded Reference Array Type p1.c1
Nibble Value Description
0 0xE array of reference
1 <p1> package token
2 (high bit on)
3 <c1> class token
4
5 0x0 padding
Method signatures are encoded in the same way, with the return type of the
method encoded at the end of the sequence of nibbles. The return type is encoded
in as many nibbles as required to represent it. For example:
方法签名也是用相同的方式编码,方法的返回类型编码在半字节序列的尾部。返回类型使用所有半字节组合而成,举例子:
TABLE 6-10 Encoded Method Signature ()V
Nibble Value Description
0 0x1 void
1 0x0 padding
TABLE 6-11 Encoded Method Signature (Lp1.ci;)S
Nibble Value Description
0 0x6 reference
1 <p1> package token
2 (high bit on)
3 <c1> class token
4
5 0x4 short
6.8.2 interface_info and class_info
The interface_info and class_info structures represent interfaces and classes,
respectively. The two are differentiated by the value of the high bit in the structures.
They are defined as follows:
interface_info {
u1 bitfield {
bit[4] flags
bit[4] interface_count
}
class_ref superinterfaces[interface_count]
interface_name_info interface_name
}
class_info {
u1 bitfield {
bit[4] flags
bit[4] interface_count
}
class_ref super_class_ref
u1 declared_instance_size
u1 first_reference_token
u1 reference_count
u1 public_method_table_base
u1 public_method_table_count
u1 package_method_table_base
u1 package_method_table_count
u2 public_virtual_method_table[public_method_table_count]
u2 package_virtual_method_table[package_method_table_count]
implemented_interface_info interfaces[interface_count]
remote_interface_info remote_interfaces
}
1 The interface_name[] item is required if the value of ACC_REMOTE is one. This
item must be omitted otherwise. See the description of this field for more information.
interface_name[]对象只有在ACC_REMOTE等于1的时候才需要,否则这个对象必须省略。更多的信息参见这个属性的描述。
2 The remote_interfaces item is required if the value of ACC_REMOTE is one. This
item must be omitted otherwise. See the description of this field for more information.
remote_interfaces对象只有在ACC_REMOTE等于1的时候才需要,否则这个对象必须省略。更多的信息参见这个属性的描述。
6.8.2.1 interface_info and class_info shared Items
6.8.2.1 interface_info和class_info共享的对象
flags
The flags item is a mask of modifiers used to describe this interface or class.
Valid values are shown in the following table:
标志
flag对象是一个描述接口或者类的标志,有效的值如下:
TABLE 6-12 CAP File Interface and Class Flags
Name Value
ACC_INTERFACE 0x8
ACC_SHAREABLE 0x4
ACC_REMOTE 0x2
The ACC_INTERFACE flag indicates whether this interface_info or
class_info structure represents an interface or a class. The value must be one if
it represents an interface_info structure and zero if a class_info structure.
ACC_INTERFACE标志标志着是否这个结构表示了一个接口或者是一个类。如果是一个interface_info结构,此值必须为1,如果是class_info结构,此值为0.
The ACC_SHAREABLE flag in an interface_info structure indicates whether this
interface is shareable. The value of this flag must be one if and only if the
interface is javacard.framework.Shareable interface or extends that
interface directly or indirectly.
The ACC_SHAREABLE flag in a class_info structure indicates whether this class
is shareable.The value of this flag must be one if and only if this class or any of
its superclasses implements an interface that is shareable.
ACC_SHAREABLE标志在interface_info结构中标志着是否接口是shareable的。只有接口是javacard.framework.Shareable或者是直接间接继承于此类。
ACC_SHAREABLE标志在class_info结构中标志着是否这个类是shareable的。只有类或者它的任何超类实现了shareable接口的时候这个值是1.
The ACC_REMOTE flag indicates whether this class or interface is remote. The
value of this flag must be one if and only if the class or interface satisfies the
requirements defined in Section 2.2.6.1, “Remote Classes and Remote Interfaces”
on page 2-12.
ACC_REMOTE标志标识着是否类和接口是远程的,只有类或者接口满足了2.2.6.1中远程类和接口的定义这个值才是1.
All other flag values are reserved. Their values must be zero.
所有其他的标志值被保留,他们的值必须是0.
interface_count
接口数
The interface_count item of the interface_info structure indicates the
number of entries in the superinterfaces[] table item. The value represents
the number of direct and indirect superinterfaces of this interface. Indirect
superinterfaces are the set of superinterfaces of the direct superinterfaces. Valid
values are between 0 and 14, inclusive.
The interface_count item of the class_info structure indicates the number
of entries in the interfaces table item. The value represents the number of
interfaces implemented by this class, including superinterfaces of those interfaces
and potentially interfaces implemented by superclasses of this class. Valid values
are between 0 and 15, inclusive.
interface_info结构的interface_count对象标识了superinterfaces[]对象的入口数。这个值表明了这个接口的直接和间接的父接口个数。
间接父接口是一系列直接父接口的集合。有效的值在0到14之间。
class_info结构的interface_count对象标识了interfaces[]对象的入口数。这个值表明了这个类实现的接口,(包含父类隐含的父接口)注。有效的值在0到15之间。
[注]:此部分和后续interfaces对应的部分冲突,Converter采用的后续说法,但是Verifier采用的是这个说法,此出为sun的一个bug。
6.8.2.2 interface_info Items
6.8.2.2 interface_info 对象
superinterfaces[]
The superinterfaces[] item of the interface_info structure is an array of
class_ref structures representing the superinterfaces of this interface. The
class_ref structure is defined as part of the CONSTANT_Classref_info
structure (Section 6.7.1, “CONSTANT_Classref” on page 6-16). This array is empty
if this interface has no superinterfaces. Both direct and indirect superinterfaces are
represented in the array. Class Object is not included.
父接口[]
interface_info结构中的superinterfaces[]对象是一个class_ref结构的数组展示了这个接口的父接口。
class_ref结构是作为CONSTANT_Classref_info结构中的部分被定义的。如果这个接口没有父接口这个数组是空的。
直接和间接父接口都体现在这个数组中。类对象不包含。
interface_name[]
The interface_name[] item represents interface name information required if
the interface is remote. The interface_name[] item is defined by a
interface_name_info structure. If the value of the ACC_REMOTE flag is zero,
the structure is defined as:
接口名字[]
如果接口是远程的,interface_name[]对象展示了需要的接口名字信息。interface_name[]对象通过结构interface_name_info定义。
如果ACC_REMOTE的标志是0,结构如下:
interface_name_info {
}
If the value of the ACC_REMOTE flag is one, the structure is defined as:
如果ACC_REMOTE的标志是1,结构如下:
interface_name_info {
u1 interface_name_length
u1 interface_name[interface_name_length]
}
The values in the interface_name_info structure are defined as follows:
interface_name_length
The interface_name_length item is the number of bytes in
interface_name[] item.
接口名长度
interface_name_length对象是interface_name对象中的字节数。
interface_name
The item is a variable length representation of the name of this interface in UTF-8
format.
interface_name
对象是一个变长的数组用来表示接口的名字。使用UTF-8编码。
6.8.2.3 class_info Items
6.8.2.3 class_info对象
super_class_ref
The super_class_ref item of the class_info structure is a class_ref
structure representing the superclass of this class. The class_ref structure is
defined as part of the CONSTANT_Classref_info structure (Section 6.7.1,
“CONSTANT_Classref” on page 6-16).
The super_class_ref item has the value of 0xFFFF only if this class does not
have a superclass. Otherwise the value of the super_class_ref item is limited
only by the constraints of the class_ref structure.
父类信息
class_info结构中super_class_ref对象表示类的父类。class_ref结构被定义为CONSTANT_Classref_info中的一部分。
如果这个类没有父类,这个值是0xFFFF。否则这个值必为父类的class_ref结构。
declared_instance_size
The declared_instance_size item of the class_info structure represents
the number of 16-bit cells required to represent the instance fields declared by this
class. It does not include instance fields declared by superclasses of this class.
Instance fields of type int are represented in two 16-bit cells, while all other field
types are represented in one 16-bit cell.
声明实例大小
class_info结构中的declared_instance_size对象提供了这个类声明的用16-bit槽表示的实例属性个数。不包含父类定义的实例属性。
int类型的实例属性用两个16-bit的槽来表示,其它的属性类型都用一个16-bit槽来表示。
first_reference_token
The first_reference_token item of the class_info structure represents the
instance field token (Section 4.3.7.5, “Instance Fields” on page 4-9) value of the
first reference type instance field defined by this class. It does not include instance
fields defined by superclasses of this class.
If this class does not define any reference type instance fields, the value of the
first_reference_token is 0xFF. Otherwise the value of the
first_reference_token item must be within the range of the set of instance
field tokens of this class.
第一个引用令牌
class_info结构中的first_reference_token对象提供了这个类第一个引用类型实例属性的值。不包括这个类的父类定义的实例属性。
如果这个类没有定义任何的引用类型属性,first_reference_token是0xFF。否则这个值必须在这个类实例属性的范围内。
reference_count
The reference_count item of the class_info structure represents the number
of reference type instance field defined by this class. It does not include reference
type instance fields defined by superclasses of this class.
Valid values of the reference_count item are between 0 and the maximum
number of instance fields defined by this class.
引用数
class_info结构中的reference_count对象表明了这个类中引用类型属性的个数。不包含其父类定义的引用类型属性。
public_method_table_base
The public_method_table_base item of the class_info structure is equal to the
virtual method token value (Section 4.3.7.6, “Virtual Methods” on page 4-9) of the
first method in the public_virtual_method_table[] array. If the
public_virtual_method_table[] array is empty, the value of the
public_method_table_base item is equal to the public_method_table_base
item of the class_info structure of this class’ superclass plus the
public_method_table_count item of the class_info structure of this class’
superclass. If this class has no superclass and the
public_virtual_method_table[] array is empty, the value of the
public_method_table_base item is zero.
公有方法表起址
class_info结构中的public_method_table_base对象等于public_virtual_method_table[]数组中的第一个方法的方法令牌。如果public_virtual_method_table[]是空的,
public_method_table_base对象等于这个类的父类的public_method_table_base加上这个类父类的public_method_table_count.
如果这个类没有父类,并且public_virtual_method_table[]数组是空的,public_method_table_base对象是0
public_method_table_count
The public_method_table_count item of the class_info structure indicates the
number of entries in the public_virtual_method_table[] array.
If this class does not define any public or protected override methods, the
minimum valid value of public_method_table_count item is the number of
public and protected virtual methods declared by this class. If this class defines
one or more public or protected override methods, the minimum valid value of
public_method_table_count item is the value of the largest public or
protected virtual method token, minus the value of the smallest public or
protected virtual override method token, plus one.
The maximum valid value of the public_method_table_count item is the
value of the largest public or protected virtual method token, plus one.
Any value for the public_method_table_count item between the minimum
and maximum specified here is valid. However, the value must correspond to the
number of entries in the public_virtual_method_table[] array.
公有方法表个数
class_info结构中的public_method_table_count对象标识了public_virtual_methdo_table表数组的个数。
如果这个类没有定义任何public或者protected重载的方法。这个对象的最小有效值是这个类定义的public或者protected的方法个数。
如果这个类定义了一个或多个public或者protected重载方法,这个对象的最小有效值是最大的public或者protected的令牌减最小的重载的public或者protected方法的令牌加一。
最大有效值是最大public或者protected的虚方法令牌加1.在最大和最小有效值之间的的值都是有效的,然而这个值必须参照public_virtual_method_table[]数组的入口个数。
package_method_table_base
The package_method_table_base item of the class_info structure is equal to
the virtual method token value (Section 4.3.7.6, “Virtual Methods” on page 4-9) of
the first entry in the package_virtual_method_table[] array. If the
package_virtual_method_table[] array is empty, the value of the
package_method_table_base item is equal to the
package_method_table_base item of the class_info structure of this class’
superclass, plus the package_method_table_count item of the class_info
structure of this class’ superclass. If this class has no superclass or inherits from a
class defined in another package and the package_virtual_method_table[]
array is empty, the value of the package_method_table_base item is zero.
package_method_table_count
The package_method_table_count item of the class_info structure indicates
the number of entries in the package_virtual_method_table[] array.
If this class does not define any override methods, the minimum valid value of
package_method_table_count item is the number of package visible virtual
methods declared by this class. If this class defines one or more package visible
override methods, the minimum valid value of package_method_table_count
item is the value of the largest package visible virtual method token, minus the
value of the smallest package visible virtual override method token, plus one.
The maximum valid value of the package_method_table_count item is the
value of the largest package visible method token, plus one.
Any value for the package_method_table_count item between the minimum
and maximum specified here are valid. However, the value must correspond to
the number of entries in the package_virtual_method_table[].
包方法表起址和包方法表个数
用以描述protected_virtual_mehtod_table,原理同上。
public_virtual_method_table[]
The public_virtual_method_table[] item of the class_info structure
represents an array of public and protected virtual methods. These methods can
be invoked on an instance of this class. The public_virtual_method_table[]
array includes methods declared or defined by this class. It may also include
methods declared or defined by any or all of its superclasses. The value of an
index into this table must be equal to the value of the virtual method token of the
indicated method, minus the value of the public_method_table_base item.
Entries in the public_virtual_method_table[] array that represent methods
defined or declared in this package contain offsets into the info item of the
Method Component (Section 6.9, “Method Component” on page 6-35) to the
method_info structure representing the method. Entries that represent methods
defined or declared in an imported package contain the value 0xFFFF.
Entries for methods that are declared abstract are represented in the
public_virtual_method_table[] array in the same way as non-abstract
methods.
公有虚方法表
class_info结构中的public_vitual_method_table[]对象提供了一个public和protected类型的虚函数数组。
这些方法可以被这个类的一个实例所调用。public_virtual_method_table[]数组包含这个类声明和定义的方法。
也可以包含所有父类声明和定义的方法。这个表的下表必须等于对应的虚函数令牌减public_method_table_base对象。
public_virtual_method_table数组的入口表示了定义在这个包的Method组件中的指向method_info的偏移。指向导入包的入口值为0xFFFF。
对于抽象方法的入口定义和非抽象的方法一致。
package_virtual_method_table[]
The package_virtual_method_table[] item of the class_info structure
represents an array of package-visible virtual methods. These methods can be
invoked on an instance of this class. The package_virtual_method_table[]
array includes methods declared or defined by this class. It may also include
methods declared or defined by any or all of its superclasses that are defined in
this package. The value of an index into this table must be equal to the value of
the virtual method token of the indicated method & 0x7F, minus the value of the
package_method_table_base item.
All entries in the package_virtual_method_table[] array represent methods
defined or declared in this package. They contain offsets into the info item of the
Method Component (Section 6.9, “Method Component” on page 6-35) to the
method_info structure representing the method.
Entries for methods that are declared abstract, not including those defined by
interfaces, are represented in the package_virtual_method_table[] array in
the same way as non-abstract methods.
包虚方法表
同上,唯一的不同是,package_virtual_method_table中不包含指向外包的入口。
interfaces[]
The interfaces item of the class_info structure represents a table of
variable-length implemented_interface_info structures. The table must
contain an entry for each of the directly implemented interfaces indicated in the
declaration of this class and each of the interfaces in the hierarchies of those
interfaces. Interfaces that occur more than once are represented by a single entry.
Given the declarations below, the number of entries for class c0 is 1 and the entry
in the interfaces array is i0. The number of entries for class c1 is 3 and the
entries in the interfaces array are i1, i2, and i3. The entries for class c1 must
not include interface i0, which is implemented only by the superclass of c1.
接口
class_info结构中的interfaces对象提供了一个变长的implemented_interface_info结构表。表必须为这个类直接实现的接口和其父接口提供入口。
出现超过一次的接口提供了一个唯一的入口。描述如下,class c0的入口数是1,并且interface数组中的接口是i0.class c1的入口数是3,并且interface
数组中的接口是i1,i2,i3。c1的入口必须不能包含仅仅被c1父类实现的接口i0。
interface i0 {}
interface i1 {}
interface i2 extends i1 {}
interface i3 {}
class c0 implements i0 {}
class c1 extends c0 implements i2, i3 {}
remote_interfaces
The remote_interfaces item represents information required if this class or
any of its super classes implements a remote interface. This item must be omitted
if the ACC_REMOTE flag has a value of zero. The remote_interfaces item is
defined by a remote_interface_info structure.
远程接口
如果这个类或者任何它的父类实现了一个远程接口,remote_interface对象提供了要求的信息。如果ACC_REMOTE标志是0,这个对象必须省略。
remote_interfaces对象是通过remote_interface_info结构定义的。
6.8.2.4 implemented_interface_info
6.8.2.4 实现的接口信息
The implemented_interface_info structure is defined as follows:
implemented_interface_info结构如下:
implemented_interface_info {
class_ref interface
u1 count
u1 index[count]
}
The items in the implemented_interface_info structure are defined as follows:
interface
The interface item has the form of a class_ref structure. The class_ref
structure is defined as part of the CONSTANT_Classref_info structure
(Section 6.7.1, “CONSTANT_Classref” on page 6-16). The interface_info
structure referenced by the interface item represents an interface implemented by
this class.
interface对象和class_ref的结构一致。class_ref结构定义在CONSTANT_Class_info结构中的一部分。
interface_info指向了一个被这个类实现的接口。
count
The count item indicates the number of entries in the index[] array.
个数
count对象表明了index数组的个数。
index[]
The index[] item is an array that maps declarations of interface methods to
implementations of those methods in this class. It is a representation of the set of
methods declared by the interface and its superinterfaces.
index[]对象是一个数组用来表示这个类中实现的的接口方法。它用一组接口和它父亲接口声明的函数来标识。
Entries in the index array must be ordered such that the interface method token
value (Section 4.3.7.7, “Interface Methods” on page 4-10) of the interface method
is equal to the index into the array. The interface method token value is assigned
to the method within the scope of the interface definition, not within the scope of
this class.
index数组的下标入口必须被排序因为interface方法的interface方法令牌等于数组的下标。
接口方法令牌值是在接口定义的范围内分配的,而不是在类的范围内。
The values in the index[] array represent the virtual method tokens
(Section 4.3.7.6, “Virtual Methods” on page 4-9) of the implementations of the
interface methods. The virtual method token values are defined within the scope
of the hierarchy of this class.
index数组中的值表示了实现了这个接口的虚方法的令牌。虚方法令牌的值被定义在这个类的继承链上。
6.8.2.5 remote_interface_info
6.8.2.5 远程接口信息
If the value of the ACC_REMOTE flag is zero, this structure is defined as:
如果ACC_REMOTE标志的值是0,这个结构的定义如下:
remote_interface_info {
}
If the value of the ACC_REMOTE flag is one, this structure is defined as:
如果ACC_REMOTE标志的值是1,这个结构的定义如下:
remote_interface_info {
u1 remote_methods_count
remote_method_info remote_methods[remote_methods_count]
u1 hash_modifier_length
u1 hash_modifier[hash_modifier_length]
u1 class_name_length
u1 class_name[class_name_length]
u1 remote_interfaces_count
class_ref remote_interfaces[remote_interfaces_count]
}
The remote_interface_info structure is defined as:
remote_methods_count
The remote_methods_count item indicates the number of entries in the
remote_methods array.
远程方法个数
remote_methods_count对象标明了远程方法数组中的入口数。
remote_methods[]
The remote_methods item of the class_info structure is an array of
remote_method_info structures that maps each remote method available in the
class to its hash code and its type definition in the signature_pool[]. The
methods are listed in numerically ascending order of hash values.
The remote_method_info structure is defined as follows:
远程方法
class_info结构中的remote_methods是一个remote_method_info结构的数组。用类中的每个远程方法映射到它的hash值和它在signature_pool中的类型定义。
方法使用hash值的数字升序排列。
remote_method_info {
u2 remote_method_hash
u2 signature_offset
u1 virtual_method_token
}
The items in the remote_method_info structure are defined as follows:
remote_method_hash
The remote_method_hash item contains a two-byte hash value for the
method. The hash value is computed from the simple (not fully qualified)
name of the method concatenated with its method descriptor. The
representation of the method descriptor is the same as in a Java class file. See
the specification described in Java Virtual Machine Specification (§4.3.3).
The hash value uniquely identifies the method within the class.
The hash code is defined as the first two bytes of the SHA-1 message digest
function performed on the hash_modifier[] item described below followed
by the name of the method followed by the method descriptor representation
in UTF-8 format. Rare hash collisions are averted automatically during package
conversion by adjusting the anti-collision string.
远程方法哈希值
remote_method_hash对象包含一个方法的双字节哈希值。hash值是用方法的简单名连接他的方法描述计算出来的。方法的描述符和java类文件中的结构一致。
hash值唯一的表示了类中的方法。
hash值被定义为数据的SHA-1结果的前两个字节。数据的组成为hash_modifier对象跟着方法名跟着方法描述,以UTF-8来组织。
少见的hash值冲突通过调整防碰撞串的方式在包转化的时候自动完成了。
signature_offset
The signature_offset item contains an offset from the signature_pool
item of the info item of the Class Component to the variable-length type
descriptor structure inside the signature_pool[] item. This structure
represents the signature of the remote method.
签名偏移
signature_offset对象包含了一个指向signature_pool对象的偏移,这个结构标明了远程方法的签名。
virtual_method_token
The virtual_method_token item is the virtual method token of the remote
method in this class.
虚方法令牌
vitual_method_token对象是这个类的远程方法的令牌。
hash_modifier_length
The hash_modifier_length item is the number of bytes in the following
hash_modifier item. The value of this item must be zero if an anti-collision
string is not required.
hash修正值长度
hash_modifier_length对象是hash_modifier对象的字节长度。如果不需要防冲撞串,这个对象的值必须是0.
hash_modifier[]
The hash_modifier[] item is a variable length representation of the anti-
collision string in UTF-8 format.
hash修正串
hash_modifier[]对象是一个变长的UTF-8结构的防冲撞串。
class_name_length
The class_name_length item is the number of bytes used in the
class_name[] item.
类名字长度
class_name_length对象是class_name对象的字节数。
class_name[]
The class_name[] item is a variable length representation of the name of this
class in UTF-8 format.
类名
class_name对象是一个变长的UTF-8结构的串用来表明这个类的名字。
remote_interfaces_count
The remote_interfaces_count item is the number of interfaces listed in the
following remote_interfaces[] item.
远程接口数
remote_interfaces_count对象是以下remote_interfaces中的接口数。
remote_interfaces[]
The remote_interfaces[] item is a variable length array of class_ref items.
It represents the remote interfaces implemented by this class. The remote
interfaces listed in this array, together with their superinterfaces must be the
complete set of remote interfaces implemented by this class and all its
superclasses.
Each entry has the form of a class_ref structure. Each class_ref structure
must reference an interface_info structure representing a remote interface
implemented by this class.
The entries in the remote_interfaces[] array must be ordered such that all
remote interfaces from the same package are listed consecutively.
远程接口
remote_interfaces[]对象是一个变长的class_ref对象的数组。它提供了这个类实现的远程接口。
所有类实现的远程接口和其父接口必须列在这个数组中。
remote_interface的入口必须被排序,因为同一个包的所有远程接口都是连续排列的。
6.9 Method Component
6.9 方法组件
The Method Component describes each of the methods declared in this package,
excluding <clinit> methods and interface method declarations. Abstract methods
defined by classes (not interfaces) are included. The exception handlers associated
with each method are also described.
方法组件描述了这个包内所有的方法。不包含<clinit>方法和接口方法声明。类定义的虚方法被包含在内。
关联到每个方法上的异常处理也有描述。
The Method Component does not contain complete access information and
descriptive details for each method. Instead, the information is optimized for size
and therefore limited to that required to execute each method without performing
verification. Complete details regarding the methods defined in this package are
included in the Descriptor Component (Section 6.13, “Descriptor Component” on
page 6-49). Among other information, the Descriptor Component contains the
location and number of bytecodes for each method in the Method Component. This
information can be used to parse the methods in the Method Component.
Method组件不为每个方法包含完整的访问信息和描述细节。用以替代的是,信息做了大小的优化,因此对执行每个方法都不要求执行校验。
这个包中定义的完整的方法细节参见Descriptor组件。和其他信息一样,Descriptor组件包含了方法组件中每个方法的字节码的位置和数量。
这个信息可以被用来分析方法组件中的方法。
Instructions and exception handler catch types in the Method Component reference
entries in the Constant Pool Component (Section 6.7, “Constant Pool Component” on
page 6-14). No other CAP file components, including the Method Component, are
referenced by the elements in the Method Component.
在方法组件中的指令和异常处理捕获类型通过常量池组件来引用。除了常量池包括方法组件,没有组件关联到方法组件上。
The Applet Component (Section 6.5, “Applet Component” on page 6-12), Constant
Pool Component (Section 6.7, “Constant Pool Component” on page 6-14), Class
Component (Section 6.8, “Class Component” on page 6-21), Export Component
(Section 6.12, “Export Component” on page 6-47), Descriptor Component
(Section 6.13, “Descriptor Component” on page 6-49), and Debug Component
(Section 6.14, “Debug Component” on page 6-57) reference methods defined in the
Method Component. The Reference Location Component (Section 6.11, “Reference
Location Component” on page 6-44) references all constant pool indices contained in
the Method Component. No other CAP file components reference the Method
Component.
应用组件,常量池组件,类组件,到处组件,描述符组件,和调试组件引用了定义在方法组件中的方法。
因为位置组件引用了所有常量池中包含到方法组件的对象。没有其它的CAP组件引用方法组件。
The Method Component is represented by the following structure:
方法组件的结构如下:
method_component {
u1 tag
u2 size
u1 handler_count
exception_handler_info exception_handlers[handler_count]
method_info methods[]
}
The items in the method_component structure are as follows:
tag
The tag item has the value COMPONENT_Method (7).
标签
tag对象的值是7.
size
The size item indicates the number of bytes in the method_component
structure, excluding the tag and size items. The value of the size item must be
greater than zero.
大小
size对象标识着方法组件结构除了tag和size对象的大小。size对象的值必须大于0.
handler_count
The handler_count item represents the number of entries in the
exception_handlers array. Valid values are between 0 and 255, inclusive.
句柄个数
handler_count对象提供了异常处理数组中的入口个数,有效的值在0到255之间。
exception_handlers[]
The exception_handlers item represents an array of 8-byte
exception_handler_info structures. Each exception_handler_info
structure represents a catch or finally block defined in a method of this package.
Entries in the exception_handlers array are sorted in ascending order by the
the offset to the handler of the exception handler. Smaller offset values occur first
in the array. This ordering constraint ensures that the first match found when
searching for an exception handler is the correct match.
There are two consequences of this ordering constraint. First, a handler that is
nested with the active range (try block) of another handler occurs first in the
array. Second, when multiple handlers are associated with the same active range,
they are ordered as they occur in a method. This is consistent with the ordering
异常处理句柄
exception_handlers对象提供了一个8-byte的exception_handler_info结构数组。每个exception_handler_info结构提供了一个定义在这个包的某个方法中的catch或者finally块。
exception_handlers数组中的入口使用到异常处理的偏移升序来组织。小偏移值先出现。这个组织约束确保搜索异常匹配的时候能最先匹配。
这种排序的策略有两种结果。首先,一个try块中级联的块在数组中先出现。其次,当多个句柄关联到相同的范围,他们将按照在方法中的顺序组织,和方法中的顺序是一致的。
constraints defined for Java class files. An example is shown below.
java类文件定义的约束例子如下:
CODE EXAMPLE 6-1 Exception Handler Example
try {
...
try {
...
} catch (NullPointerException e) { // first
...
}
...
} catch (Exception e) { // second
...
} finally { // third
...
}
...
try {
...
} catch (SecurityException e) { // fourth
...
}
methods[]
The methods item represents a table of variable-length method_info structures.
Each entry represents a method declared in a class of this package. <clinit>
methods and interface method declaration are not included; all other methods,
including non-interface abstract methods, are.
methods对象提供了一个变长的method_info结构表。每个入口提供了一个定义在这个包中某个类的方法。
<clinit>方法和接口方法的声明不包含在内。所有其它的方法,包含非接口的虚方法都包含在内。
6.9.1 exception_handler_info
6.9.1 异常处理信息
The exception_handler_info structure is defined as follows:
exception_handler_info结构如下:
exception_handler_info {
u2 start_offset
u2 bitfield {
bit[1] stop_bit
bit[15] active_length
}
u2 handler_offset
u2 catch_type_index
}
The items in the exception_handler_info structure are as follows:
start_offset, active_length
The start_offset and active_length pair indicate the active range (try
block) an exception handler. The start_offset item indicates the beginning of
the active range while the active_length item indicates the number of bytes
contained in the active range.
起偏移,活动长度
start_offset和active_length对标识着(try块)异常处理的有效范围。start_offset对象标识着有效区域的开始位置,而active_length对象标明了有效区范围的字节数。
end_offset is defined as start_offset plus active_length.
The start_offset item and end_offset are byte offsets into the info item of
the Method Component. The value of the start_offset must be a valid offset
into a bytecodes array of a method_info structure to an opcode of an
instruction. The value of the end_offset either must be a valid offset into a
bytecodes array of the same method_info structure to an opcode of an
instruction, or must be equal to the method’s bytecode count, the length of the
bytecodes array of the method_info structure. The value of the start_offset
must be less than the value of the end_offset.
end_offset被定义为start_offset+active_length.
start_offset对象和end_offset是指向Method组件的info对象的字节偏移。start_offset的值必须是指向同一个method_info结构的有效的字节码偏移,
或者必须等于方法的字节码数。start_offset的值必须小于end_offset的值。
The start_offset is inclusive and the end_offset is exclusive; that is, the
exception handler must be active while the execution address is within the
interval [start_offset, end_offset).
start_offset是闭区间,end_offset是开区间。也就是说异常处理必须处于[start_address,end_offset)之间。
stop_bit
The stop_bit item indicates whether the active range (try block) of this exception
handler is contained within or is equal to the active range of any succeeding
exception_handler_info structures in this exception_handlers array. At
the Java source level, this indicates whether an active range is nested within
another, or has at least one succeeding exception handler associated with the
same range. The latter occurs when there is at least one succeeding catch block or
a finally block.
The stop_bit item is equal to 1 if the active range does not intersect with a
succeeding exception handler’s active range, and this exception handler is the last
handler applicable to the active range. It is equal to 0 if the active range is
contained within the active range of another exception handler, or there is at least
one succeeding handler applicable to the same active range.
The stop_bit provides an optimization to be used during the interpretation of
the athrow bytecode. As the interpreter searches for an appropriate exception
handler, it may terminate the search of the exception handlers in this Method
Component under the following conditions:
■ the location of the current program counter is less than the end_offset of this
exception handler, and
■ the stop_bit of this exception handler is equal to 1.
When these conditions are satisfied it is guaranteed that none of the succeeding
exception handlers in this Method Component will contain an active range
appropriate for the current exception.
In CODE EXAMPLE 6-1, the stop_bit item is set for both the third and fourth
handlers.
终止比特
stop_bit对象标识了是否一个这个异常处理的有效范围被包含或者等于数组后边的exception_handler_info的范围。
在java源代码的层次,这标识了是否一个有效的范围被其他嵌套,或者是否有一个后续的exception_handler_info关心同样的范围。
这种情况在有后续的catch块或者finally块的时候发生。
stop_bit只有在有效范围和后续的异常处理范围不交叉,而且是本有效范围的最后一个异常处理的时候才置1.在有效范围和别的块交叉,或者后续有至少一个关注同一个有效范围的异常处理出现的时候为0.
stop_bit提供了一个解释athrow字节码的优化方式。当解释器搜索一个合适的异常处理的时候,它可以在如下条件下结束异常处理的查找:
■ 当前程序的指针小于这个异常处理表的end_offset,并且
■ stop_bit的值是1.
当这些条件满足,它确保了这个函数对应的范围没有有效的异常处理。
在例子6-1中,第三和第四个异常处理的stop_bit是1.
handler_offset
The handler_offset item represents a byte offset into the info item of the
Method Component. It indicates the start of the exception handler. At the Java
source level, this is equivalent to the beginning of a catch or finally block. The
value of the item must be a valid offset into a bytecodes array of a method_info
structure to an opcode of an instruction, and must be less than the value of the
method’s bytecode count.
异常处理偏移
handler_offset对象提供了一个指向method组件的info对象的字节偏移。它表示了异常处理的开始。在java源代码层面,这代表着catch或者finally块的开始。
对象的值必须是一个指向method_info的有效偏移,目标是一个指令的操作数。而且必须小于方法的字节码数。
catch_type_index
If the value of the catch_type_index item is non-zero, it must be a valid index
into the constant_pool[] array of the Constant Pool Component (Section 6.7,
“Constant Pool Component” on page 6-14). The constant_pool[] entry at that
index must be a CONSTANT_Classref_info structure, representing the class of
the exception caught by this exception_handlers array entry.
If the exception_handlers table entry represents a finally block, the value of
the catch_type_index item is zero. In this case the exception handler is called
for all exceptions that are thrown within the start_offset and end_offset
range.
The order of constants in the constant pool is constrained such that all entries
referenced by catch_type_index items that represent catch block (not finally
blocks) are located at non-zero entries.
捕获类型索引
catch_type_index的值如果是非0的,它必须是一个有效的指向constant_pool数组的下标。constant_pool对应的入口必须是一个CONSTANT_Classref_info结构。
对应这个异常处理数组入口的异常类。
catch_type_index的值如果是0,则代表着是一个finally块。在这种情况下,对所有在start_offset和end_offset之间的异常都转到异常处理部分。
常量池的顺序来保证对应于catch块的下标都被分配到非0的入口上。
6.9.2 method_info
6.9.2 方法信息
The method_info structure is defined as follows:
method_info结构被定义为如下结构:
method_info {
method_header_info method_header
u1 bytecodes[]
}
The items in the method_info structure are as follows:
method_header
The method_header item represents either a method_header_info or an
extended_method_header_info structure:
方法头对象提供了method_header_info或者extended_method_info结构。
method_header_info {
u1 bitfield {
bit[4] flags
bit[4] max_stack
}
u1 bitfield {
bit[4] nargs
bit[4] max_locals
}
}
extended_method_header_info {
u1 bitfield {
bit[4] flags
bit[4] padding
}
u1 max_stack
u1 nargs
u1 max_locals
}
The items of the method_header_info and extended_method_header_info
structures are as follows:
flags
The flags item is a mask of modifiers defined for this method. Valid flag
values are shown in the following table.
标识
flags对象是一个方法的描述符。有效flag值如下:
TABLE 6-13 CAP File Method Flags
Flags Values
ACC_EXTENDED 0x8
ACC_ABSTRACT 0x4
The value of the ACC_EXTENDED flag must be one if the method_header is
represented by an extended_method_header_info structure. Otherwise the
value must be zero.
ACC_EXTENDED标识当method_header使用extended_method_header_info结构的时候置1.否则必须是0.
The value of the ACC_ABSTRACT flag must be one if this method is defined as
abstract. In this case the bytecodes array must be empty. If this method is not
abstract the value of the ACC_ABSTRACT flag must be zero.
All other flag values are reserved. Their values must be zero.
ACC_ABSTACT标识当方法是虚方法的时候置1.在这种情况下字节码数组必须是空的。如果这个方法不是虚方法,ACC_ABSTRACT的值必须是0.
其它所有标识都是保留的,他们的值必须是0.
padding
The padding item has the value of zero. This item is only defined for the
extended_method_header_info structure.
填充
padding对象的值是0,仅仅在extend_method_header_info结构中存在。
max_stack
The max_stack item indicates the maximum number of 16-bit cells required on
the operand stack during execution of this method.
Stack entries of type int are represented in two 16-bit cells, while all others are
represented in one 16-bit cell.
最大栈
max_stack对象标识了执行这个方法时,操作栈16-bit单元的最大个数。
int类型的栈入口被描述为两个16-bit单元。其它的类型都被描述为一个16-bit单元。
nargs
The nargs item indicates the number of 16-bit cells required to represent the
parameters passed to this method, including the this pointer if this method is a
virtual method.
Parameters of type int are represented in two 16-bit cells, while all others are
represented in one 16-bit cell.
参数个数
nargs对象标识了传递给这个方法的参数的16-bit单元个数,如果方法是虚方法,包含this指针。
int类型的参数作为两个16-bit单元来表示,其它类型的都被描述为一个16-bit单元。
max_locals
The max_locals item indicates the number of 16-bit cells required to represent
the local variables declared by this method, not including the parameters passed
to this method on invocation.
Local variables of type int are represented in two 16-bit cells, while all others are
represented in one 16-bit cell. If an entry in the local variables array of the stack
frame is reused to store more than one local variable (for example, local variables
from separate scopes), the number of cells required for storage is two if one or
more of the local variables is of type int.
最大本地变量
max_locals对象标识着方法声明的本地参数的16-bit个数。不包含传入的调用参数。
int类型的本地参数用两个16-bit的单元来描述,其它的都用一个16-bit来描述。如果栈帧上的本地参数数组的入口被复用来存储超过一个本地变量,
如果其中之一是int类型的,那么需要存储的单元个数为2.
bytecodes[]
The bytecodes item represents an array of Java Card bytecodes that implement
this method. Valid instructions are defined in Chapter 7, “Java Card Virtual
Machine Instruction Set.” The impdep1 and impdep2 bytecodes cannot be
present in the bytecodes array item.
If this method is abstract the bytecodes item must contain zero elements.
字节码
bytecodes对象提供了这个方法实现的字节码数组。有效的字节码在第7章定义。
impdep1和impdep2字节码不能出现在字节码数组对象中。
如果这个方法是虚方法,字节码对象必须包含0个对象。
6.10 Static Field Component
6.10 静态属性组件
The Static Field Component contains all of the information required to create and
initialize an image of all of the static fields defined in this package, referred to as the
static field image. Offsets to particular static fields are offsets into the static field
image, not the Static Field Component.
静态属性组件包含这个包定义的所有用来创建和初始化静态属性的映像。到特定的静态属性的偏移是值到特定的映像的偏移,而不是到静态属性组件的偏移。
Final static fields of primitive types are not represented in the static field image.
Instead these compile-time constants must be placed in line in Java Card technology-
based instructions (“Java Card instructions”).
基本类型的常量不包含在静态属性映像中,这种运行态的常量必须被放在java卡技术技术的指令中。
The Static Field Component includes all information required to initialize classes. In
the Java virtual machine a class is initialized by executing its <clinit> method. In
the Java Card virtual machine the functionality of <clinit> methods is represented
in the Static Field Component as array initialization data and non-default values of
primitive types data. Section 2.2.4.6, “Class Initialization” on page 2-11 contains a
description of the subset of <clinit> functionality supported in the Java Card
virtual machine.
静态属性组件包含所有的用来初始化一个类的信息。在java卡虚拟机中,类是通过执行<clinit>方法进行初始化的。
在java卡虚拟机中,<clinit>方法的功能是通过静态属性组件中的数组初始化数据和非默认值基本类型数据来完成的。
第2.2.4.6章包含了一个在java卡中<clinit>功能性的子集。
The Static Field Component does not reference any other component in this CAP file.
The Constant Pool Component (Section 6.7, “Constant Pool Component” on
page 6-14), Export Component (Section 6.12, “Export Component” on page 6-47),
Descriptor Component (Section 6.13, “Descriptor Component” on page 6-49), and
Debug Component (Section 6.14, “Debug Component” on page 6-57) reference fields
in the static field image defined by the Static Field Component.
The ordering constraints, or segments, associated with a static field image are shown
in TABLE 6-14. Reference types occur first in the image. Arrays initialized through
Java <clinit> methods occur first within the set of reference types. Primitive types
occur last in the image, and primitive types initialized to non-default values occur
last within the set of primitive types.
静态属性组件不引用这个CAP文件中的任何其它组件。常量池组件,导出组件,描述符组件引用了定义在静态属性组件中的静态映像。
静态属性映像的排序,分割,组织规则如表TABLE 6-14所述。引用类型首先出现在映像中。数组通过java<clinit>方法出现
TABLE 6-14 Segments of a Static Field Image
category segment content
reference 1 arrays of primitive types initialized by <clinit> methods
types 2 reference types initialized to null, including arrays
primitive
types 3 primitive types initialized to default values
4 primitive types initialized to non-default values
The number of bytes used to represent each field type in the static field image is
shown in the following table.
用来描述每个属性类型在静态属性影响中的字节数如下:
TABLE 6-15 Static Field Sizes
Type Bytes
boolean 1
byte 1
short 2
int 4
reference, including arrays 2
The static_field_component structure is defined as:
静态属性组件结构如下:
static_field_component {
u1 tag
u2 size
u2 image_size
u2 reference_count
u2 array_init_count
array_init_info array_init[array_init_count]
u2 default_value_count
u2 non_default_value_count
u1 non_default_values[non_default_values_count]
}
The items in the static_field_component structure are as follows:
tag
The tag item has the value COMPONENT_StaticField (8).
标签
tag对象的标签值是8
size
The size item indicates the number of bytes in the static_field_component
structure, excluding the tag and size items. The value of the size item must be
greater than zero.
大小
size对象表明了静态属性组件结构中除了tag和size对象的字节数。size的值必须大于0.
image_size
The image_size item indicates the number of bytes required to represent the
static fields defined in this package, excluding final static fields of primitive types.
This value is the number of bytes in the static field image. The number of bytes
required to represent each field type is shown in TABLE 6-15.
The value of the image_size item does not include the number of bytes require
to represent the initial values of array instances enumerated in the Static Field
Component.
The value of the image_size is defined as:
镜像大小
image_size对象标识了这个包中静态属性的字节数,不包含静态基本类型常量。这个值是静态属性镜像的字节个数。
字节数需要表示表6-15中的所有属性类型。
image_size对象的值不包含静态属性组件中的数组实力的初始值个字节数。
image_size的值如下定义:
image_size =
reference_count * 2 +
default_value_count +
non_default_value_count.
reference_count
The reference_count item indicates the number of reference type static fields
defined in this package. This is the number of fields represented in segments 1
and 2 of the static field image as described in TABLE 6-14.
The value of the reference_count item may be 0 if no reference type fields are
defined in this package. Otherwise it must be equal to the number of reference
type fields defined.
引用个数
reference_count对象标识了包中静态属性中索引类型的个数。这是表6-14中第一段和第二段的个数。
如果这个包中没有引用类型,reference_count对象可以是0.否则它必须等于引用类型属性的个数。
array_init_count
The array_init_count item indicates the number of elements in the
array_init array. This is the number of fields represented in segment 1 of the
static field image as described in TABLE 6-14. It represents the number of arrays
initialized in all of the <clinit> methods in this package.
If this CAP file defines a library package the value of array_init_count must
be zero.
数组初始化个数
array_init_count对象标识着array_init数组中对象的个数。这是表TABLE 6-14中的第一段的类型。
它提供了<clinit>函数中需要初始化的数组的个数。
array_init[]
The array_init item represents an array of array_init_info structures that
specify the initial array values of static fields of arrays of primitive types. These
initial values are indicated in Java <clinit> methods. The array_init_info
structure is defined as:
数组初始化
array_init对象提供了一个array_init_info结构数组,定义静态属性中基本类型数组的初始值。
这个初始值在java的<clinit>方法中定义。array_init_info结构定义如下:
array_init_info {
u1 type
u2 count
u1 values[count]
}
The items in the array_init_info structure are defined as follows:
type
The type item indicates the type of the primitive array. Valid values are shown
in the following table.
类型
type对象表明了基本类型数组的类型。有效的值如下:
TABLE 6-16 Array Types
Type Value
boolean 2
byte 3
short 4
int 5
count
The count item indicates the number of bytes in the values array. It does not
represent the number of elements in the static field array (referred to as length
in the Java programming language), since the values array is an array of bytes
and the static field array may be a non-byte type. The Java programming
language length of the static field array is equal to the count item divided by
the number of bytes required to represent the static field type (TABLE 6-15)
indicated by the type item.
个数
count对象标明了values数组中的字节数。它不代表静态数组中的元素个数,因为values数组是一个字节数组,而静态属性数组可能是个非字节类型。
Java变成语言中静态属性数组的长度等于count对象除以表6-15中的类型对应的字节数。
values
The values item represents a byte array containing the initial values of the
static field array. The number of entries in the values array is equal to the size
in bytes of the type indicated by the type item. The size in bytes of each type
is shown in TABLE 6-15.
值
values对象提供了一个包含静态数组属性的初始值的字节数组。values数组的入口数等于各个类型对象对应的字节大小。
default_value_count
The default_value_count item indicates the number of bytes required to
initialize the set of static fields represented in segment 3 of the static field image
as described in TABLE 6-14. These static fields are primitive types initialized to
default values. The number of bytes required to initialize each static field type is
equal to the size in bytes of the type as shown in TABLE 6-15.
默认值个数
default_value_count对象标识了表6-14中第三段的字节数。这些静态属性是被初始化到默认值的基本类型。
每个静态属性类型需要初始化的长度参考表6-15.
non_default_value_count
The non_default_value_count item represents the number bytes in the
non_default_values array. This value is equal to the number of bytes in
segment 4 of the static field image as described in TABLE 6-14. These static fields
are primitive types initialized to non-default values.
非默认值个数
non_default_value_count对象提供了non_default_values_array中的字节个数。这个值等于第四段的字节数。
这些静态基本类型被初始化为非默认值。
non_default_values[]
The non_default_values item represents an array of bytes of non-default
initial values. This is the exact image of segment 4 of the static field image as
described in TABLE 6-14. The number of entries in the non_default_values
array for each static field type is equal to the size in bytes of the type as shown in
TABLE 6-15.
The value of a boolean type is 1 to represent true and 0 to represent false.
非默认值
non_default_values对象提供了一个非默认值初始值的字节数组。这对应着第四段的静态属性。
每个静态属性的字节大小参见表6-15
boolean类型的值是1来代表真,0来代表假。
6.11 Reference Location Component
6.11 引用位置组件
The Reference Location Component represents lists of offsets into the info item of the
Method Component (Section 6.9, “Method Component” on page 6-35) to items that
contain indices into the constant_pool[] array of the Constant Pool Component
(Section 6.7, “Constant Pool Component” on page 6-14). This includes all constant
pool index operands of instructions, and all non-zero catch_type_index items of
the exception_handlers array. The catch_type_index items that have the
value of 0 are not included since they represent finally blocks instead of particular
exception classes.
引用位值组件提供了指向Method组件的info对象的偏移列表到那些包含着到指向常量池组件的常量数组的对象。
它包含了所有的指令操作的常量池下标,和所有的非零的异常处理数组的catch_type_index对象。catch_type_index为0的对象不在内,
因为0被认为是finally块。
Some of the constant pool indices are represented in one-byte values while others are
represented in two-byte values. Operands of getfield_T and putfield_T
instructions are one-byte constant pool indices. All other indices in a Method
Component are two-byte values.
The Reference Location Component is not referenced by any other component in this
CAP file.
The Reference Location Component structure is defined as:
一些常量池的下表使用一个字节的值,然而其它的使用两个字节的值。操作数getfield_T和putfield_T使用一个字节的下表。
其他发发组件中的引用使用双字节值。
引用位值组件不被其它CAP内任何组件引用。
结构如下:
reference_location_component {
u1 tag
u2 size
u2 byte_index_count
u1 offsets_to_byte_indices[byte_index_count]
u2 byte2_index_count
u1 offsets_to_byte2_indices[byte2_index_count]
}
The items of the reference_location_component structure are as follows:
tag
The tag item has the value COMPONENT_ReferenceLocation (9).
标签
tag对象的值是9.
size
The size item indicates the number of bytes in the
reference_location_component structure, excluding the tag and size
items. The value of the size item must be greater than zero.
大小
size对象表明了reference_location_component结构中除了tag和size对象的大小。size对象必须大于0.
byte_index_count
The byte_index_count item represents the number of elements in the
offsets_to_byte_indices array.
单字节下标数
byte_index_count对象提供了offsets_to_byte_indices数组的元素个数。
offsets_to_byte_indices[]
The offsets_to_byte_indices item represents an array of 1-byte jump offsets
into the info item of the Method Component to each 1-byte constant_pool[]
array index. Each entry represents the number of bytes (or distance) between the
current index to the next. If the distance is greater than or equal to 255 then there
are n entries equal to 255 in the array, where n is equal to the distance divided by
255. The nth entry of 255 is followed by an entry containing the value of the
distance modulo 255.
An example of the jump offsets in an offsets_to_byte_indices array is
shown in the following table.
单字节下标偏移:
offsets_to_byte_indices对象为每个单字节常量池数组下标提供了一个到方法组件的info对象指向单constant pool index操作的单字节跳转偏移。
每个入口表示了当前下标到下一个下标的偏移。如果距离大于等于255,则那就应该放n个255在数组中,n等于距离除255.第n个255跟着一个值为距离模255.
TABLE 6-17 One-byte Reference Location Example
Instruction Offset to Operand Jump Offset
getfield_a 0 10 10
putfield_b 2 65 55
255
255
getfield_s 1 580 5
255
putfield_a 0 835 0
getfield_i 3 843 8
All 1-byte constant_pool[] array indices in the Method Component must be
represented in offsets_to_byte_indices array.
所有在方法组件中使用到单字节常量池下标的操作数必须在这个数组得到体现。
byte2_index_count
The byte2_index_count item represents the number of elements in the
offsets_to_byte2_indices array.
双字节下标偏移数
byte2_index_count对象提供了offset_to_byte2_indices的元素个数。
offsets_to_byte2_indices[]
The offsets_to_byte2_indices item represents an array of 1-byte jump
offsets into the info item of the Method Component to each 2-byte
constant_pool[] array index. Each entry represents the number of bytes (or
distance) between the current index to the next. If the distance is greater than or
equal to 255 then there are n entries equal to 255 in the array, where n is equal to
the distance divided by 255. The nth entry of 255 is followed by an entry
containing the value of the distance modulo 255.
An example of the jump offsets in an offsets_to_byte_indices array is
shown in TABLE 6-17. The same example applies to the
offsets_to_byte2_indices array if the instructions are changed to those with
2-byte constant_pool[] array indices.
All 2-byte constant_pool[] array indices in the Method Component must be
represented in offsets_to_byte2_indices array, including those represented
in catch_type_index items of the exception_handler_info array.
双字节下标偏移
offsets_to_bytes_indices对象表明了一个到方法组件的info对象的指向双constant pool index操作的单字节跳转偏移。
每个入口提供了当前下标到前一个的偏移。如果距离大于等于255,则需要有n个255在数组中,n等于距离除255,第n个255跟着一个值为距离模255.
当操作数换成双字节的时候,表6-17也能描述双字节下标偏移。
所有在方法组件中的的双字节常量池数组下标操作必须出现在数组中。包含在exception_handler_info数组中的catch_type_index对象。
【注】 这个组件的作用主要是反映常量池下标到字节码的映射关系。在运行态貌似没有什么用。但是如果有对常量池的优化涉及到影响原有下标的情况下,
该组件可以辅助同步字节码中的常量池下标引用。
6.12 Export Component
6.12 导出组件
The Export Component lists all static elements in this package that may be imported
by classes in other packages. Instance fields and virtual methods are not represented
in the Export Component.
导出组件列出了这个包内所有的可能被其它包的类导入的静态元素。实例属性和虚方法不在这个组件内。
If this CAP file does not include an Applet Component (Section 6.5, “Applet
Component” on page 6-12), the Export Component contains an entry for each public
class and public interface defined in this package. Furthermore, for each public class
there is an entry for each public or protected static field defined in that class, for
each public or protected static method defined in that class, and for each public or
protected constructor defined in that class. Final static fields of primitive types
(compile-time constants) are not included.
如果CAP文件不包含应用组件。导出组件包含了这个包定义的每个公有类和公有接口。而且,对每个公有类的每个公有或者保护的静态属性都提供一个入口,
对每个公有类的每个公有或者保护的静态方法和构造函数都有一个入口。静态基本类型常量不在内。
If this CAP file includes an Applet Component (Section 6.5, “Applet Component” on
page 6-12), the Export Component includes entries only for all public interfaces that
are shareable.
An interface is shareable if and only if it is the
javacard.framework.Shareable interface or implements (directly or indirectly)
that interface.
如果CAP文件包含了一个应用组件,导出组件只包含shareable的公有接口。
一个接口只有它继承或者实现了javacard.framework.Shareable接口才是shareable接口。
Elements in the Export Component reference elements in the Class Component
(Section 6.8, “Class Component” on page 6-21), Method Component (Section 6.9,
“Method Component” on page 6-35), and Static Field Component (Section 6.10,
“Static Field Component” on page 6-41). No other component in this CAP file
references the Export Component.
The Export Component is represented by the following structure:
导出组件引用了类组件中的元素,方法组件,和静态属性组件。这个CAP文件中没有其它的组件引用这个组件。
结构如下:
export_component {
u1 tag
u2 size
u1 class_count
class_export_info {
u2 class_offset
u1 static_field_count
u1 static_method_count
u2 static_field_offsets[static_field_count]
u2 static_method_offsets[static_method_count]
} class_exports[class_count]
}
The items of the export_component structure are as follows:
tag
The tag item has the value COMPONENT_Export (10).
标签
标签对象的值是10.
size
The size item indicates the number of bytes in the export_component
structure, excluding the tag and size items. The value of the size item must be
greater than zero.
大小
size对象标识了导出组件结构中不包含tag和size对象的的字节数。size的值必须大于0.
class_count
The class_count item represents the number of entries in the class_exports
table. The value of the class_count item must be greater than zero.
类个数
class_count对象提供了class_exports表中的入口数。class_count对象的值必须大于0.
class_exports[]
The class_exports item represents a variable-length table of
class_export_info structures. If this package is a library package, the table
contains an entry for each of the public classes and public interfaces defined in
this package. If this package is an applet package, the table contains an entry for
each of the public shareable interfaces defined in this package.
An index into the table to a particular class or interface is equal to the token value
of that class or interface (Section 4.3.7.2, “Classes and Interfaces” on page 4-8).
The token value is published in the Export file (Section 5.7, “Classes and
Interfaces” on page 5-8) of this package.
The items in the class_export_info structure are:
导出类
class_exports对象提供了一个变长的class_export_info结构的表,如果这个包是一个库包,表为每个公有类和公有接口提供入口。
如果包是一个应用包,表包含了包中定义的所有公有shareable接口。
到表中一个特定类或者接口的下表等于这个类或者接口的令牌值。令牌值在这个包的导出文件中公布。
class_export_info结构中的对象是:
class_offset
The class_offset item represents a byte offset into the info item of the Class
Component (Section 6.8, “Class Component” on page 6-21). If this package
defines a library package, the item at that offset must be either an
interface_info or a class_info structure. The interface_info or
class_info structure at that offset must represent the exported class or
interface.
If this package defines an applet package, the item at the class_offset in the
info item of the Class Component must be an interface_info structure. The
interface_info structure at that offset must represent the exported,
shareable interface. In particular, the ACC_SHAREABLE flag of the
interface_info structure must be equal to 1.
类偏移
class_offset对象提供了一个到类组件的info对象的字节偏移。如果这个包是一个库包,对应偏移位置的对象必须是一个interface_info或者一个class_info结构。
对应的interface_info和class_info必须对应相应的导出类。
如果这个包定义为一个应用包,对应偏移位置必须是一个interface_info结构,interface_info结构必须表示导出共享接口。对应interface_info的ACC_SHAREABLE标志必须为1.
static_field_count
The static_field_count item represents the number of elements in the
static_field_offsets array. This value indicates the number of public and
protected static fields defined in this class, excluding final static fields of
primitive types.
If the class_offset item represents an offset to an interface_info
structure, the value of the static_field_count item must be zero.
静态属性个数
static_field_count对象提供了static_field_offsets数组内的元素个数。这个值标识了这个类的公有和保护静态属性的个数。不包含静态基本类型常量。
如果class_offset对象对应的偏移是一个interface_info结构,static_field_count必须是0.
static_method_count
The static_method_count item represents the number of elements in the
static_method_offsets array. This value indicates the number of public and
protected static methods and constructors defined in this class.
If the class_offset item represents an offset to an interface_info
structure, the value of the static_method_count item must be zero.
静态方法个数
static_method_count对象提供了static_method_offsets数组中元素的个数。这个值表明了这个类中定义的静态方法和构造方法的个数。
如果class_offset对应的是一个interface_info结构,static_method_count对象必须是0.
static_field_offsets[]
The static_field_offsets item represents an array of 2-byte offsets into
the static field image defined by the Static Field Component (Section 6.10,
“Static Field Component” on page 6-41). Each offset must be to the beginning
of the representation of the exported static field.
An index into the static_field_offsets array must be equal to the token
value of the field represented by that entry. The token value is published in the
Export file (Section 5.9, “Methods” on page 5-13) of this package.
静态属性偏移
static_field_offsets对象提供了一个2-byte的偏移数组指向静态属性组件中定义的静态属性映像。每个偏移必须是导出的静态属性的开始位置。
static_field_offsets的下表必须等于属性的令牌值。令牌值在导出文件中发布。
static_method_offsets[]
The static_method_offsets item represents a table of 2-byte offsets into
the info item of the Method Component (Section 6.9, “Method Component” on
page 6-35). Each offset must be to the beginning of a method_info structure.
The method_info structure must represent the exported static method or
constructor.
An index into the static_method_offsets array must be equal to the token
value of the method represented by that entry.
静态方法偏移
static_method_offsets对象提供了一个2-byte的偏移表指向方法组件的info对象。每个偏移必须是一个method_info结构的开始位置。
method_info结构必须表示导出的静态方法或构造函数。
指向static_method_offsets数组的下表必须等于对应入口方法的令牌值。
6.13 Descriptor Component
6.13 描述符组件
The Descriptor Component provides sufficient information to parse and verify all
elements of the CAP file. It references, and therefore describes, elements in the
Constant Pool Component (Section 6.7, “Constant Pool Component” on page 6-14),
Class Component (Section 6.8, “Class Component” on page 6-21), Method
Component (Section 6.9, “Method Component” on page 6-35), and Static Field
Component (Section 6.10, “Static Field Component” on page 6-41). No components
in the CAP file reference the Descriptor Component.
The Descriptor Component is represented by the following structure:
描述符组件提供了足够的信息来分析和校验CAP文件中的所有元素。它引用,也因此描述了常量池中的元素,类组件,方法组件,静态属性组件。
CAP文件中没有组件引用描述符组件。
descriptor_component {
u1 tag
u2 size
u1 class_count
class_descriptor_info classes[class_count]
type_descriptor_info types
}
The items of the descriptor_component structure are as follows:
tag
The tag item has the value COMPONENT_Descriptor (11).
标签
tag对象的值是11
size
The size item indicates the number of bytes in the descriptor_component
structure, excluding the tag and size items. The value of the size item must be
greater than zero.
size对象包含了descriptor_component结构中不包含tag和size对象的字节个数。size对象的值必须大于0.
class_count
The class_count item represents the number of entries in the classes table.
类个数
class_count对象提供了类表中的入口个数。
classes[]
The classes item represents a table of variable-length
class_descriptor_info structures. Each class and interface defined in this
package is represented in the table.
类
classes对象描述了一个变长class_descriptor_info结构的表。在这个包中定义的每个类和接口都在表中体现。
types
The types item represents a type_descriptor_info structure. This structure
lists the set of field types and method signatures of the fields and methods
defined or referenced in this package. Those referenced are enumerated in the
Constant Pool Component.
类型
types对象描述了一个type_descriptor_info结构,这个结构列出了这个包中定义的属性和方法签名的类型。这些引用在常量池中引用。
6.13.1 class_descriptor_info
The class_descriptor_info structure is used to describe a class or interface
defined in this package:
class_descriptor_info结构用来描述一个类或者接口:
class_descriptor_info {
u1 token
u1 access_flags
class_ref this_class_ref
u1 interface_count
u2 field_count
u2 method_count
class_ref interfaces [interface_count]
field_descriptor_info fields[field_count]
method_descriptor_info methods[method_count]
}
The items of the class_descriptor_info structure are as follows:
token
The token item represents the class token (Section 4.3.7.2, “Classes and
Interfaces” on page 4-8) of this class or interface. If this class or interface is
package-visible it does not have a token assigned. In this case the value of the
token item must be 0xFF.
令牌
令牌对象提供了这个类和接口的类令牌,如果这个类或者接口是包可见的,它没有分配令牌,在这种情况下token对象必须是0xFF.
access_flags
The access_flags item is a mask of modifiers used to describe the access
permission to and properties of this class or interface. The access_flags
modifiers for classes and interfaces are shown in the following table.
访问标志
access_flags对象是一个用来描述类和接口的访问权限的标志。值如下:
TABLE 6-18 CAP File Class Descriptor Flags
Name Value
ACC_PUBLIC 0x01
ACC_FINAL 0x10
ACC_INTERFACE 0x40
ACC_ABSTRACT 0x80
The class access and modifier flags defined in the table above are a subset of those
defined for classes and interfaces in a Java class file. They have the same meaning,
and are set under the same conditions, as the corresponding flags in a Java class
file.
All other flag values are reserved. Their values must be zero.
访问标志是java类文件中的访问标志的子集。他们有相同的意义,并且在相同的条件下设置。
其它所有的标志值都是保留的,他们的值必须是0.
this_class_ref
The this_class_ref item is a class_ref structure indicating the location of
the class_info structure in the Class Component (Section 6.8, “Class
Component” on page 6-21). The class_ref structure is defined as part of the
CONSTANT_Classref_info structure (Section 6.7.1, “CONSTANT_Classref” on
page 6-16).
本类引用
this_class_ref对象是一个指向类组件中class_info结构引用。class_ref结构被定义作为CONSTANT_Classref_info结构的一部分。
interface_count
The interface_count item represents the number of entries in the interfaces
array. For an interface, interface_count is always set to zero.
接口数
interface_count对象表示interfaces数组中的入口个数。对一个接口而言,interface_count总是被设置为0.
field_count
The field_count item represents the number of entries in the fields array. If this
class_descriptor_info structure represents an interface, the value of the
field_count item is equal to zero.
Static final fields of primitive types are not represented as fields in a CAP file, but
instead these compile-time constants are placed inline in bytecode sequences. The
field_count item does not include static final field of primitive types defined
by this class.
属性个数
field_count对象提供了fields数组的入口个数。如果这个结构对应的是一个接口,值为0.
静态基本类型常量在CAP中不被认为是属性,而是在编译器在bytecode内部做替换。filed_count也不包含基本类型常量。
method_count
The method_count item represents the number of entries in the methods array.
方法个数
method_count对象标明了methods数组的入口数。
interfaces[]
The interfaces item represents an array of interfaces implemented by this
class. The elements in the array are class_ref structures indicating the location
of the interface_info structure in the Class Component (Section 6.8, “Class
Component” on page 6-21). The class_ref structure is defined as part of the
CONSTANT_Classref_info structure (Section 6.7.1, “CONSTANT_Classref” on
page 6-16).
接口
interfaces对象表示这个类实现的接口数组。数组中的对象是class_ref结构,指向类组件中的interface_info结构。class_ref结构在CONSTANT_Classref_info中定义。
fields[]
The fields item represents an array of field_descriptor_info structures.
Each field declared by this class is represented in the array, except static final
fields of primitive types. Inherited fields are not included in the array.
属性
fields对象提供了一组field_descriptor_info结构。
这个类定义的每个属性都表示在本数组内。除了静态基本类型常量。继承的属性不包含在数组中。
methods[]
The methods item represents an array of method_descriptor_info structures.
Each method declared or defined by this class or interface is represented in the
array. For a class, inherited methods are not included in the array. For an
interface, inherited methods are included in the array.
方法
methods对象表明了一个method_descriptor_info结构的数组。
这个类和接口中定义的每个方法都体现在这个数组红。对一个类来说,继承下来的方法不包含在数组内。对一个接口来说,继承下来的方法包含在数组内。
6.13.2 field_descriptor_info
6.13.2 属性描述符信息
The field_descriptor_info structure is used to describe a field defined in this
package:
field_descriptor_info结构用来描述一个属性,结构如下:
field_descriptor_info {
u1 token
u1 access_flags
union {
static_field_ref static_field
{
class_ref class
u1 token
} instance_field
} field_ref
union {
u2 primitive_type
u2 reference_type
} type
}
The items of the field_descriptor_info structure are as follows:
token
The token item represents the token of this field. If this field is private or
package-visible static field it does not have a token assigned. In this case the
value of the token item must be 0xFF.
令牌
token对象描述了这个属性的令牌,如果这个属性是私有的或者包可见的静态属性,它没有令牌分配,这种情况下,令牌的值必须是0xFF
access_flags
The access_flags item is a mask of modifiers used to describe the access
permission to and properties of this field. The access_flags modifiers for fields
are shown in the following table.
访问标志
access_flags对象是一个用来描述这个属性访问权限的标志。如下:
TABLE 6-19 CAP File Field Descriptor Flags
Name Value
ACC_PUBLIC 0x01
ACC_PRIVATE 0x02
ACC_PROTECTED 0x04
ACC_STATIC 0x08
ACC_FINAL 0x10
The field access and modifier flags defined in the table above are a subset of those
defined for fields in a Java class file. They have the same meaning, and are set
under the same conditions, as the corresponding flags in a Java class file.
All other flag values are reserved. Their values must be zero.
属性访问标志是java class定义的子集。他们有相同的意义和相同的设置条件。
所有其他的标志都是保留的,他们的值必须是0.
field_ref
The field_ref item represents a reference to this field. If the ACC_STATIC flag
is equal to 1, this item represents a static_field_ref as defined in the
CONSTANT_StaticFieldref structure (Section 6.7.3,
“CONSTANT_StaticFieldref and CONSTANT_StaticMethodref” on page 6-19).
If the ACC_STATIC flag is equal to 0, this item represents a reference to an
instance field. It contains a class_ref item and an instance field token item.
These items are defined in the same manner as in the
CONSTANT_InstanceFieldref structure (Section 6.7.2,
“CONSTANT_InstanceFieldref, CONSTANT_VirtualMethodref, and
CONSTANT_SuperMethodref” on page 6-18).
属性引用
field_ref对象提供了指向这个属性的引用,如果ACC_STATIC标志等于1,这个对象使用定义在CONSTANT_StaticFieldref_info结构中的static_field_ref来表述。
如果ACC_STATIC标志等于0,这个对象代表一个实例属性。它包含一个class_ref对象和一个实例属性令牌对象。
这些对象和CONSTANT_InstanceFieldref结构中定义的相同。
type
The type item indicates the type of this field. directly or indirectly. If this field is
a primitive type (boolean, byte, short, or int) the high bit of this item is equal
to 1, otherwise the high bit of this item is equal to 0.
类型
type对象标志着这个属性的类型。如果这个属性是一个基本类型,这个对象的最高bit等于1.否则最高bit等于0.
primitive_type
The primitive_type item represents the type of this field using the values in
the table below. As noted above, the high bit of the primitive_type item is
equal to 1.
基本类型
primitive_type对象表示这个属性的类型,使用下表中的定义。
TABLE 6-20 Primitive Type Descriptor Values
Data Type Value
boolean 0x0002
byte 0x0003
short 0x0004
int 0x0005
reference_type
引用类型
The reference_type item represents a 15-bit offset into the
type_descriptor_info structure. The item at the offset must represent the
reference type of this field. As noted above, the high bit of the
reference_type item is equal to 0.
reference_type对象表示着一个到type_descriptor_info的15-bit偏移。偏移位置的对象必须提供这个属性的引用类型。
如上面提到,最高比特等于0.
6.13.3 method_descriptor_info
6.13.3 方法描述信息
The method_descriptor_info structure is used to describe a method defined in
this package. This structure contains sufficient information to locate and parse the
methods in the Method Component, while the Method Component does not.
method_descriptor_info结构是用来描述一个定义在这个包内的方法。这个结构包含了足够的信息来定位和分析方法组件中的方法。
method_descriptor_info {
u1 token
u1 access_flags
u2 method_offset
u2 type_offset
u2 bytecode_count
u2 exception_handler_count
u2 exception_handler_index
}
The items of the method_descriptor_info structure are as follows:
token
The token item represents the static method token (Section 4.3.7.4, “Static
Methods and Constructors” on page 4-8) or virtual method token (Section 4.3.7.6,
“Virtual Methods” on page 4-9) or interface method token (Section 4.3.7.7,
“Interface Methods” on page 4-10) of this method. If this method is a private or
package-visible static method, a private or package-visible constructor, or a
private virtual method it does not have a token assigned. In this case the value of
the token item must be 0xFF.
令牌
令牌对象提供了对应方法的静态方法令牌或者虚方法令牌或者接口方法令牌。如果这个方法是一个私有或者包可见的静态方法,一个私有或者包可见的构造函数,
或者一个私有的虚方法,它没有令牌分配,在这种情况下令牌的值必须是0xFF
access_flags
The access_flags item is a mask of modifiers used to describe the access
permission to and properties of this method. The access_flags modifiers for
methods are shown in the following table.
访问标志
access_flags对象用来描述这个方法的访问标志。如下:
TABLE 6-21 CAP File Method Descriptor Flags
Name Value
ACC_PUBLIC 0x01
ACC_PRIVATE 0x02
ACC_PROTECTED 0x04
ACC_STATIC 0x08
ACC_FINAL 0x10
ACC_ABSTRACT 0x40
ACC_INIT 0x80
The method access and modifier flags defined in the table above, except the
ACC_INIT flag, are a subset of those defined for methods in a Java class file.
They have the same meaning, and are set under the same conditions, as the
corresponding flags in a Java class file.
方法访问表和属性访问表除了ACC_INIT标志之外都相同。是作为java类文件的子集。他们有着相同的意义,
并且在相同的条件下设置。
The ACC_INIT flag is set if the method descriptor identifies a constructor
methods. In Java a constructor method is recognized by its name, <init>, but in
Java Card systems, the name is replaced by a token. As in the Java verifier, these
methods require special checks by the verifier for the Java Card platform (“Java
Card verifier”).
只有方法描述符标志着一个构造方法的时候ACC_INIT标志才设置。在java语言中,构造函数通过它的名字被组织<init>,但是在
java卡系统,名字已经被令牌替换了。所以在java的校验中,这些方法需要java卡平台的特殊检查。
All other flag values are reserved. Their values must be zero.
其它的标志都是保留的,他们的值必须是0.
method_offset
If the class_descriptor_info structure that contains this
method_descriptor_info structure represents a class, the method_offset
item represents a byte offset into the info item of the Method Component
(Section 6.9, “Method Component” on page 6-35). The element at that offset must
be the beginning of a method_info structure. The method_info structure must
represent this method.
If the class_descriptor_info structure that contains this
method_descriptor_info structure represents an interface, the value of the
method_offset item must be zero.
方法偏移
如果class_descriptor_info结构对应的是一个类,方法偏移指向了一个类组件的info对象的偏移。对应偏移的对象
必须是一个method_info结构,method_info结构必须指出这个方法。
如果class_descriptor_info结构对应的是一个接口。偏移的值必须是0.
type_offset
The type_offset item must be a valid offset into the type_descriptor_info
structure. The type described at that offset represents the signature of this
method.
类型偏移
type_offset对象必须是一个指向type_descriptor_info结构的有效偏移。对应位置是这个方法的签名类型。
bytecode_count
The bytecode_count item represents the number of bytecodes in this method.
The value is equal to the length of the bytecodes array item in the method_info
structure in the method component (Section 6.9, “Method Component” on
page 6-35) of this method.
字节码个数
bytecode_count对象提供了这个方法的字节码个数,值等于这个方法method_info中的bytecodes数组的长度。
exception_handler_count
The exception_handler_count item represents the number of exception
handlers implemented by this method.
异常处理个数
exception_handler_count对象提供了这个方法实现的异常处理的个数。
exception_handler_index
The exception_handler_index item represents the index to the first
exception_handlers table entry in the method component (Section 6.9,
“Method Component” on page 6-35) implemented by this method. Succeeding
exception_handlers table entries, up to the value of the
exception_handler_count item, are also exception handlers implemented by
this method.
The value of the exception_handler_index item is 0 if the value of the
exception_handler_count item is 0.
异常处理下标
exception_handler_index对象提供了方法组件中第一个异常处理表的入口。
如果异常处理个数的值为0,则此值也为0.
6.13.4 type_descriptor_info
6.13.4 类型描述符信息
The type_descriptor_info structure represents the types of fields and signatures
of methods defined in this package:
type_descriptor_info结构提供了属性的类型和方法的签名。
type_descriptor_info {
u2 constant_pool_count
u2 constant_pool_types[constant_pool_count]
type_descriptor type_desc[]
}
The type_descriptor_info structure contains the following elements:
constant_pool_count
The constant_pool_count item represents the number of entries in the
constant_pool_types array. This value is equal to the number of entries in the
constant_pool array of the Constant Pool Component (Section 6.7, “Constant
Pool Component” on page 6-14).
常量池个数
constant_pool_count对象提供了常量池类型数组的入口个数。这个值等于常量池组件中的常量池入口个数。
constant_pool_types[]
The constant_pool_types item is an array that describes the types of the fields
and methods referenced in the Constant Pool Component. This item has the same
number of entries as the constant_pool[] array of the Constant Pool
Component, and each entry describes the type of the corresponding entry in the
constant_pool[] array.
If the corresponding constant_pool[] array entry represents a class or
interface reference, it does not have an associated type. In this case the value of
the entry in the constant_pool_types array item is 0xFFFF.
If the corresponding constant_pool[] array entry represents a field or method,
the value of the entry in the constant_pool_types array is an offset into the
type_descriptor_info structure. The element at that offset must describe the
type of the field or the signature of the method.
常量池类型
constant_pool_types对象是一个数组用来描述在常量池组件中引用的属性和方法的类型。这个对象的下标和常量池中的下标一致。
如果对应的常量池数组入口是一个类或者接口引用,它没有关联的类型。在这种情况下,对应的值为0xFFFF。
如果对应的常量池数组入口是一个属性或者方法,对应的值是指向type_descriptor_info结构的偏移。对应偏移位置必须是属性的类型或者类的标签。
type_desc[]
The type_desc item represents a table of variable-length type_descriptor
structures. These descriptors represent the types of fields and signatures of
methods. For a description of the type_descriptor structure, see Section 6.8.1,
“type_descriptor” on page 6-23.
类型描述
type_desc对象提供了一个变长的type_descriptor结构的表。这个描述符提供了属性的类型和方法的签名。具体的结构参见第六章 6.8.1
6.14 Debug Component
6.14 Debug组件
This section specifies the format for the Debug Component. The Debug Component
contains all the metadata necessary for debugging a package on a suitably
instrumented Java Card virtual machine. It is not required for executing Java Card
programs in a non-debug environment.
这张定义了Debug组件的格式,Debug组件包含了在一个合适的java卡虚拟机上调试包所需要的元信息。
它不需要包含在非debug的执行环境里面。
The Debug Component references the Class Component (Section 6.8, “Class
Component” on page 6-21), Method Component (Section 6.9, “Method Component”
on page 6-35), and Static Field Component (Section 6.10, “Static Field Component”
on page 6-41). No components reference the Debug Component.
The Debug Component is represented by the following structure:
Debug组件引用了类组件,方法组件,静态属性组件。没有组件引用了Debug组件。结构如下:
debug_component {
u1 tag
u2 size
u2 string_count
utf8_info strings_table[string_count]
u2 package_name_index
u2 class_count
class_debug_info classes[class_count]
}
The items in the debug_component structure are defined as follows:
tag
The tag item has the value COMPONENT_Debug (12).
标签
tag对象的值是12
size
The number of bytes in the component, excluding the tag and size items. The
value of size must be greater than zero.
大小
组件内除了tag和size对象的长度就是size。size对象的值必须大于0.
string_count
The number of strings in the strings_table[] table.
串个数
在strings_table表中串的个数。
strings_table[]
A table of all the strings used in this component. Various items that occur through
this component represent unsigned two-byte indices into this table.
Each entry in the table is a utf8_info structure. A utf8_info structure is
represented by the following structure:
串表
这个组件内用到的所有串的表。不同的对象使用双字节的表的下标来引用这个表。表的每个入口都是一个utf8_info结构,如下:
utf8_info {
u2 length
u1 bytes[length]
}
The items in the utf8_info structure are defined as follows:
length
The number of bytes in the string.
长度
字符串的字节个数。
bytes
The bytes of the string in UTF-8 format.
字节
string在UTF8格式下的字节数。
package_name_index
Contains an index into the strings_table[] item. The strings_table[]
item entry referenced by this index must contain the fully-qualified name of the
package in this CAP file.
package_name_index
包含了一个index指向string_table对象。对应的入口必须包含这个CAP文件中包的全路径名。
class_count
The number of classes in the classes table.
类个数
classes表中类的个数。
classes[]
Contains a single class_debug_info[] structure for each class in this package.
类
为包中每个类包含一个class_debug_info结构。
6.14.1 The class_debug_info Structure
6.14.1 class_debug_info结构
The class_debug_info structure contains all of the debugging information for a
class or interface. It also contains tables of debugging information for all its classes’
fields and methods.
class_debug_info结构包含一个类或者接口的所有debug信息。它也包含类中所有属性和方法的debug信息。
class_debug_info {
u2 name_index
u2 access_flags
u2 location
u2 superclass_name_index
u2 source_file_index
u1 interface_count
u2 field_count
u2 method_count
u2 interface_names_indexes[interface_count]
field_debug_info fields[field_count]
method_debug_info methods[method_count]
}
The items in the class_debug_info structure are defined as follows:
name_index
名字下标
Contains an index into the strings_table[] item of the
debug_component structure. The strings_table[] entry at the indexed
location must be the fully-qualified name of this class.
包含一个指向string_table对象的下表,对应的位置应该是这个类的全名。
access_flags
A two-byte mask of modifiers that apply to this class. The modifiers are:
访问标志
一个双字节的标志,用来表示类的状态,如下:
TABLE 6-22 Class Access and Modifier Flags
Modifier Value
ACC_PUBLIC 0x0001
ACC_FINAL 0x0010
ACC_REMOTE 0x0020
ACC_INTERFACE 0x0200
ACC_ABSTRACT 0x0400
ACC_SHAREABLE 0x0800
The ACC_SHAREABLE flag indicates whether this class or interface is shareable.
A class is shareable if it implements (directly or indirectly) the
javacard.framework.Shareable interface. An interface is shareable if it is or
extends (directly or indirectly) the javacard.framework.Shareable interface.
ACC_SHAREABLE标志着是否这个类或者接口是shareable的。 一个类只有是javacard.framework.shareable接口或者子接口,或者实现了这些接口才能称之为shareable。
The ACC_REMOTE flag indicates whether this class or interface is remote. The
value of this flag must be one if and only if the class or interface satisfies the
requirements defined in Section 2.2.6.1, “Remote Classes and Remote Interfaces”
on page 2-12.
ACC_REMOTE标志标识是否这个类或者接口是远程的。只有这个类或者接口满足2.2.61的规定,才能成为远程接口。
All other class access and modifier flags are defined in the same way and with the
same restrictions as described in The Java Virtual Machine Specification.
所有其它的标识和java虚拟机规范中的一致
location
The byte offset of the class_info or interface_info record for this class or
interface into the info item of the Class Component (Section 6.8, “Class
Component” on page 6-21).
位置
指向类组件info对象偏移对应类或者接口的class_info结构。
superclass_name_index
Contains an index into the strings_table[] item of the debug_component
structure. The strings_table[] entry at the indexed location must be the fully-
qualified name of the superclass of this class or the string “null” if the class has
no superclass.
父类名下标
包含一个指向string_table的下标,对应的位置必须是这个类的父类的全名。如果类没有父类,为null。
source_file_index
Contains the index into the strings_table[] item of the debug_component
structure. The strings_table[] entry at the indexed location must be the name
of the source file in which this class is defined.
源文件下标
包含一个指向string_table对象的下表。对应位置必须是此类对应的源文件的名字。
interface_count
The number of indexes in the interface_names_indexes[] table.
接口个数
在interface_name_indexs[]表中下标的个数。
field_count
The number of field_debug_info structures in the fields[] table.
在fields表中下标的个数。
method_count
The number of method_debug_info structures in the methods[] table.
在methods表中下标的个数。
interface_names_indexes[]
Contains the indexes into the strings_table[] item of the debug_component
structure. The strings_table[] entry at each indexed location must be the
name of an interface implemented by this class. There must be an index value
present for every interface implemented by this class, including interfaces
implemented by superclasses of this class and superinterfaces of the implemented
interfaces.
If ACC_INTERFACE is set, the strings_table[] entry at each indexed location
must be the name of a super interface directly or indirectly extended by this
interface. There must be an index value present for every super interface directly
or indirectly extended by this interface.
接口名下标
包含指向string_table对象的下标。对应位置必须是这个类实现的接口名,包含这个类的父类实现的接口和实现接口的父接口。
如果ACC_INTERFACE被设置,对应的位置必须是一个这个接口的直接或者非直接的父接口。对每个直接或者间接的父接口都必须有一个对应的下标。
fields[]
Contains field_debug_info structures for all the fields declared by this class,
including static final fields of primitive types. Inherited fields are not included in
this array.
属性
包含这个类中定义的field_debug_info结构信息,包含静态基本类型常量,继承的属性不包含在内。
methods[]
Contains method_debug_info structures for all the methods declared or defined
in this class. Inherited methods are not included in this array.
方法
包含这个类中定义的method_debug_info结构,继承的方法不包含在数组内。
6.14.1.1 The field_debug_info Structure
6.14.1.1 sield_debug_info结构
The field_debug_info structure describes a field in a class. It can describe either
an instance field, a static field, or a constant (primitive final static) field. The contents
union will have the form of a token_var if the field is an instance field, a
location_var if it is a static field, or a const_value if it is a constant.
The field_debug_info structure is defined as follows:
field_debug_info结构描述了一个类中的属性。它可以描述实例属性,静态属性或者一个常数属性。content联合体
在实例属性的时候表现为token_var的格式。在静态属性的时候表现为local_var格式,或者是个常量值。结构如下:
field_debug_info {
u2 name_index
u2 descriptor_index
u2 access_flags
union {
{
u1 pad1
u1 pad2
u1 pad3
u1 token
} token_var
{
u2 pad
u2 location
} location_var
u4 const_value
} contents
}
The items in the field_debug_info structure are defined as follows:
name_index
Contains an index into the strings_table[] item of the debug_component
structure. The strings_table[] entry at the indexed location must be the
simple (meaning, not fully-qualified) name of the field (for example, “applets”).
名字下标
包含一个指向string_table的下标,对应下标的位置是属性的非全路径名。
descriptor_index
Contains an index into the strings_table[] item of the debug_component
structure. The strings_table[] entry at the indexed location must be the type
of the field. Class types are fully-qualified (for example,
“[Ljavacard/framework/Applet;”).
描述符下标:
包含一个指向string_table的下标,对应下标的位置是属性的描述符。类的类型是全名。
access_flags
A two-byte mask of modifiers that apply to this field.
访问标志
TABLE 6-23 Field Access and Modifier Flags
Modifier Value
ACC_PUBLIC 0x0001
ACC_PRIVATE 0x0002
ACC_PROTECTED 0x0004
ACC_STATIC 0x0008
ACC_FINAL 0x0010
The above field access and modifier flags are defined in the same way and with
the same restrictions as described in the Java Virtual Machine Specification.
contents
以上的属性和java虚拟机规范中的定义相同。
A field_debug_info structure can describe an instance field, a static field, or a
static final field (a constant). Constants can be either primitive data or arrays of
primitive data. Depending on the kind of field described, the contents item is
interpreted in different ways. The kind and type of the field can be determined by
examining the field’s descriptor and access flags.
一个field_debug_info结构可以描述实例属性,静态属性或者一个常量。常量可以是基本类型或者基本类型数组。
在属性描述符的基础上,contents对象分为几种方式。属性的种类和类型可以通过access_flags标志和属性的描述符来表示。
token_var
If the field is an instance field, this value is the instance field token of the field.
The pad1, pad2, and pad3 items are padding only; their values should be
ignored.
令牌参数
如果field是一个实例属性,pad1,pad2,pad3仅仅是为了占位,他们的值应该被忽略。
location_var
If the field is a non-final static field or a final static field with an array type (a
constant array), this value is the byte offset of the location for this field in the
static field image defined by the Static Field Component (Section 6.10, “Static
Field Component” on page 6-41). The pad item is padding only; its value
should be ignored.
本地参数
如果属性是一个非最终的静态属性,或者是一个最终静态数组类型属性,这个值是指向静态属性镜像的偏移。pad对象仅仅占位,它的值应该被忽略。
const_value
If the field is a final static field of type byte, boolean, short, or int, this
value is interpreted as a signed 32-bit constant.
常数
如果属性是一个静态基本类型常量,值将被直接以32bit的方式填入。
6.14.1.2 The method_debug_info Structure
6.14.1.2 method_debug_info结构
The method_debug_info structure describes a method of a class. It can describe
methods that are either virtual or non-virtual (static or initialization methods). The
structure is defined as follows:
method_debug_info结构描述了一个类中的方法,它可以描述虚方法或者非虚方法(静态或者构造方法)。结构如下:
method_debug_info {
u2 name_index
u2 descriptor_index
u2 access_flags
u2 location
u1 header_size
u2 body_size
u2 variable_count
u2 line_count
variable_info variable_table[variable_count]
line_info line_table[line_count]
}
The items in the method_debug_info structure are defined as follows:
name_index
Contains an index into the strings_table[] item of the debug_component
structure. The strings_table[] entry at the indexed location must be the
simple (meaning, not fully-qualified) name of the method (for example,
“lookupAID”).
名字下标
包含一个指向string_table表的下标。string_table对应的入口必须是方法的简单名字。(比如lookupAID)
descriptor_index
Contains an index into the strings_table[] item of the debug_component
structure. The strings_table[] entry at the indexed location must be the
argument and return types of the method (meaning, the signature without the
method name). Class types are fully-qualified (for example,
“([BSB)Ljavacard/framework/AID;”)
描述符下标
包含一个指向string_table表的下标,string_table对应的位置必须是方法的参数和返回类型的签名。类名是全路径的(比如([BSB)Ljavacard/framework/AID = AID XXXX(byte[],short,byte);)
access_flags
A two-byte mask of modifiers that apply to this method.
访问标志
两个字节的访问标志来描述方法:
TABLE 6-24 Method Modifier Flags
Modifier Value
ACC_PUBLIC 0x0001
ACC_PRIVATE 0x0002
ACC_PROTECTED 0x0004
ACC_STATIC 0x0008
ACC_FINAL 0x0010
ACC_NATIVE 0x0100
ACC_ABSTRACT 0x0400
The ACC_NATIVE flag is only valid for methods of a package located in the card
mask. It cannot be used for methods contained in a CAP file.
ACC_NATIVE标志只能对掩模到卡里面的方法有效。不能用在CAP文件中的方法。
All other method access and modifier flags are defined in the same way and with
the same restrictions as described in The Java Virtual Machine Specification.
所有其它的方法访问标志和java虚拟机规范的约束相同。
location
A byte offset of the method_info structure for this method into the info item of
the Method Component (Section 6.9, “Method Component” on page 6-35).
Abstract methods have a location of zero.
位置
指向方法组件的info字节偏移。虚方法的位置是0.
header_size
The size in bytes of the header of the method. Abstract methods have a
header_size of zero.
头大小
方法头的字节数,虚方法的头信息是0.
body_size
The size in bytes of the body of the method, not including the method header.
Abstract methods have a body_size of zero.
体大小
方法体的字节大小,不包含方法头,虚方法的体信息是0.
variable_count
The number of variable_info entries in the variable_table[] item.
Abstract methods have a variable_count of zero.
参数个数
variable_table中variable_info入口的个数。虚方法的variable_count是0.
line_count
The number of line_info entries in the line_table[] item. Abstract methods
have a line_count of zero.
行数
line_table中line_info入口的个数,虚方法的行数是0.
variable_table[]
Contains the variable_info structures for all variables in this method.
The variable_info structure describes a single local variable of a method. It
indicates the index into the local variables of the current frame at which the local
variable can be found, as well as the name and type of the variable. It also
indicates the range of bytecodes within which the variable has a value.
参数表
包含这个方法的所有参数对应的variable_info结构。variable_info结构描述了一个方法的单个的本地参数。
它包含了指出当前frame中的本地变量的下标。它也描述了变量有效的字节码个数。
variable_info {
u1 index
u2 name_index
u2 descriptor_index
u2 start_pc
u2 length
}
The items in the variable_info structure are defined as follows:
index
The index of the variable in the local stack frame, as used in load and store
bytecodes. If the variable at index is of type int, it occupies both index and
index + 1.
下标
变量在本地栈帧的下标,bytecode load 和 store使用这个小表。如果参数是个int类型。它占用两个下标,下标+1.
name_index
Contains an index into the strings_table[] item of the debug_component
structure. The strings_table[] entry at the indexed location must be the
name of the local variable, (for example, “applets”).
名字下标
包含了一个指向string_table表的下标,对应的位置必须是本地参数的名字。
descriptor_index
Contains an index into the strings_table[] item of the debug_component
structure. The strings_table[] entry at the indexed location must be the
type of the local variable. Class types are fully-qualified (for example,
“[Ljavacard/framework/Applet;”).
描述符下标
包含了一个指向string_table表的下标,对应的位置必须是参数的描述符。
start_pc
The index of the first bytecode in which the variable is in-scope and valid.
开始pc
指向参数有效的第一个字节码。
length
Number of bytecodes in which the variable is in-scope and valid. The value of
start_pc + length will be either the index of the next bytecode after the
valid range, or the first index beyond the end of the bytecode array.
长度
参数有效的字节码长度。start_pc+length的值将是有效范围内的下一个字节码或者字节码数组后的第一个字节。
line_table[]
Contains the line_info structures that map bytecode instructions of this
method to lines in the class’s source file.
Each line_info item represents a mapping of a range of bytecode instructions
to a particular line in the source file that contains the method. The range of
instructions is from start_pc to end_pc, inclusive. start_pc and end_pc
represent a zero-based byte offset within the method. The source_line is the
one-based line number in the source file. The structure is defined as follows:
行表
包含line_info结构,用来映射这个方法的字节码指令到类的源文件的行上。
每个line_info对象都提供了一个字节码指令的范围到一个源文件对应的行上。
line_info {
u2 start_pc
u2 end_pc
u2 source_line
}
The items in the line_info structure are defined as follows:
start_pc
The byte offset of the first bytecode in the range of instructions.
指向第一个字节码的pc
end_pc
The byte offset of the last operand of the last bytecode in the range of
instructions.
指向最后一个字节码的pc
source_line
Line number in the source file.
源文件行数