The CAP File Format
6.10 Static Field Component
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 instructions.
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. §2.2.4.6 contains a description of the subset of <clinit>
functionality supported in the Java Card virtual machine.
1. Unlike in Java Card CAP files, in Java class files the max_locals item includes both the local variables declared by the method and the parameters passed to the method.
The Static Field Component does not reference any other component in this CAP file.
The Constant Pool Component (§6.7), Export Component (§6.12), Descriptor Component (§6.13), and Debug Component (§6.14) 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.
TABLE 6-14 Segments of a static field image
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
The static_field_component structure is defined as:
static_field_component {
The items in the static_field_component structure are as follows:
category segment content
reference types
1 arrays of primitive types initialized by <clinit>
methods
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
Type Bytes
boolean 1
byte 1
short 2
int 4
reference, including arrays 2
tag
The tag item has the value COMPONENT_StaticField (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.
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 =
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 seg-ments 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.
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[]
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:
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.
TABLE 6-16 Array types 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 Java), since the values array is an array of bytes and the static field array may be a non-byte type. The Java 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.
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.
default_value_count
The default_value_count item indicates the number of bytes required to ini-tialize 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.
non_default_value_count
The non_default_value_count item represents the number bytes in the
Type Value
boolean 2
byte 3
short 4
int 5
non_default_values array. This value is equal to the number of bytes in seg-ment 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_values[]
The non_default_values item represents an array of bytes of non-default ini-tial 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.