1b1994897Sopenharmony_ci# Panda Binary File Format 2b1994897Sopenharmony_ci 3b1994897Sopenharmony_ciThis document describes Panda binary file format with the following goals in mind: 4b1994897Sopenharmony_ci 5b1994897Sopenharmony_ci* Compactness. 6b1994897Sopenharmony_ci* Support for fast access to information. 7b1994897Sopenharmony_ci* Support for low memory footprint. 8b1994897Sopenharmony_ci* Extensibility and compatibility. 9b1994897Sopenharmony_ci 10b1994897Sopenharmony_ci## Compactness 11b1994897Sopenharmony_ci 12b1994897Sopenharmony_ciMany mobile applications use a lot of types, methods and fields. Their number is so large that it 13b1994897Sopenharmony_cidoesn't fit in 16-bit unsigned integer. It leads to application developer have to create several 14b1994897Sopenharmony_cifiles and as a result not all data can be deduplicated. 15b1994897Sopenharmony_ci 16b1994897Sopenharmony_ciCurrent binary file format should extend these limits to conform to the modern requirements. 17b1994897Sopenharmony_ci 18b1994897Sopenharmony_ciTo achieve this, all references in the binary file are 4 bytes long. It allows to have 4Gb for 19b1994897Sopenharmony_ciaddressing fields, methods, classes, etc. 20b1994897Sopenharmony_ci 21b1994897Sopenharmony_ciThe format uses [TaggedValue](#taggedvalue) which allows to store only information we have and 22b1994897Sopenharmony_ciavoid 0 offsets to absent information. 23b1994897Sopenharmony_ci 24b1994897Sopenharmony_ciBut to achieve more compactness 16-bit indexes are used to refer classes, methods and fields in 25b1994897Sopenharmony_cithe bytecode and some metadata. File can contain multiple indexes each one covers part of the 26b1994897Sopenharmony_cifile and described by [RegionHeader](#regionheader). 27b1994897Sopenharmony_ci 28b1994897Sopenharmony_ci## Fast information access 29b1994897Sopenharmony_ci 30b1994897Sopenharmony_ciBinary file format should support fast access to information. It means that 31b1994897Sopenharmony_ciredundant references should be avoided. Also, if it possible, binary file format should avoid data 32b1994897Sopenharmony_ciindexes (like sorted list of strings). However, the described binary format supports one index: 33b1994897Sopenharmony_cia sorted list of offsets to classes. This index is compact and allows to find a type definition 34b1994897Sopenharmony_ciquickly, which runtime requires a lot during application launch time. 35b1994897Sopenharmony_ci 36b1994897Sopenharmony_ciAll classes, fields and methods are separated into 2 groups: foreign and local. 37b1994897Sopenharmony_ciForeign classes, fields and methods are declared in other files, with references from the 38b1994897Sopenharmony_cicurrent binary file. Local classes, fields and methods are declared in the current file. 39b1994897Sopenharmony_ciLocal entities has the same header as the corresponding foreign. So 40b1994897Sopenharmony_cihaving an offset to an entity it doesn't matter whether the entity is local or foreign. 41b1994897Sopenharmony_ci 42b1994897Sopenharmony_ciRuntime can easily check type of an offset by checking it is in the foreign region 43b1994897Sopenharmony_ci(*\[foreign_off; foreign_off + foreign_size)*). 44b1994897Sopenharmony_ciDepending on the result runtime can search the entity in other files (for foreign entities) 45b1994897Sopenharmony_cior create a runtime object from the definition by the offset (for local entities). 46b1994897Sopenharmony_ci 47b1994897Sopenharmony_ciTo improve data access speed most data structures have 4 bytes alignment. 48b1994897Sopenharmony_ciSince most target architectures are little endian all multibyte values are little endian. 49b1994897Sopenharmony_ci 50b1994897Sopenharmony_ci## Offsets 51b1994897Sopenharmony_ci 52b1994897Sopenharmony_ciUnless otherwise specified, all offsets are calculated from the beginning of the file. 53b1994897Sopenharmony_ciAn offset cannot contain values in the range *\[0; 32)*, except for specially mentioned cases. 54b1994897Sopenharmony_ci 55b1994897Sopenharmony_ci## Support for low memory footprint 56b1994897Sopenharmony_ci 57b1994897Sopenharmony_ciAs practice shows, most of file data is not used by the application. It means memory footprint 58b1994897Sopenharmony_ciof a file may be significantly reduced by grouping frequently used data. 59b1994897Sopenharmony_ciTo support this feature, the described binary file format uses offsets and doesn't specify how 60b1994897Sopenharmony_cistructures should be located relatively to each other. 61b1994897Sopenharmony_ci 62b1994897Sopenharmony_ci## Extensibility and compatibility 63b1994897Sopenharmony_ci 64b1994897Sopenharmony_ciThe binary file format supports future changes via version number. 65b1994897Sopenharmony_ciThe version field in the header is 4 bytes long and is encoded as byte array to 66b1994897Sopenharmony_ciavoid misinterpretation on platforms with different endianness. 67b1994897Sopenharmony_ci 68b1994897Sopenharmony_ciAny tool which supports format version `N` must support format version `N - 1` too. 69b1994897Sopenharmony_ci 70b1994897Sopenharmony_ci## Data types 71b1994897Sopenharmony_ci 72b1994897Sopenharmony_ci| Type | Description | 73b1994897Sopenharmony_ci| ---- | ----------- | 74b1994897Sopenharmony_ci| `uint8_t` | 8-bit unsigned integer value | 75b1994897Sopenharmony_ci| `uint16_t` | 16-bit unsigned integer value | 76b1994897Sopenharmony_ci| `uint32_t` | 32-bit little endian unsigned integer value. | 77b1994897Sopenharmony_ci| `uleb128` | unsigned integer value in leb128 encoding. | 78b1994897Sopenharmony_ci| `sleb128` | signed integer value in leb128 encoding. | 79b1994897Sopenharmony_ci 80b1994897Sopenharmony_ci### MUTF-8 Encoding 81b1994897Sopenharmony_ci 82b1994897Sopenharmony_ciBinary file format uses MUTF-8 (Modified UTF-8) encoding for strings. 83b1994897Sopenharmony_ci 84b1994897Sopenharmony_ci### String 85b1994897Sopenharmony_ci 86b1994897Sopenharmony_ciAlignment: none 87b1994897Sopenharmony_ci 88b1994897Sopenharmony_ciFormat: 89b1994897Sopenharmony_ci 90b1994897Sopenharmony_ci| Name | Format | Description | 91b1994897Sopenharmony_ci| ---- | ------ | ----------- | 92b1994897Sopenharmony_ci| `utf16_length` | `uleb128` | `len << 1 \| is_ascii` where `len` is the length of the string in UTF-16 code units. | 93b1994897Sopenharmony_ci| `data` | `uint8_t[]` | 0-terminated character sequence in MUTF-8 encoding. | 94b1994897Sopenharmony_ci 95b1994897Sopenharmony_ci### TaggedValue 96b1994897Sopenharmony_ci 97b1994897Sopenharmony_ciAlignment: none 98b1994897Sopenharmony_ci 99b1994897Sopenharmony_ciFormat: 100b1994897Sopenharmony_ci 101b1994897Sopenharmony_ci| Name | Format | Description | 102b1994897Sopenharmony_ci| ---- | ------ | ----------- | 103b1994897Sopenharmony_ci| `tag_value` | `uint8_t` | The first 8 bits contain tag which determines the meaning of the data. Depending on the tag there may be optional data. Runtime must be able to determine size of the data. | 104b1994897Sopenharmony_ci| `data` | `uint8_t[]` | Optional payload. | 105b1994897Sopenharmony_ci 106b1994897Sopenharmony_ci## String syntax 107b1994897Sopenharmony_ci 108b1994897Sopenharmony_ci### TypeDescriptor 109b1994897Sopenharmony_ci 110b1994897Sopenharmony_ci``` 111b1994897Sopenharmony_ciTypeDescriptor -> PrimitiveType | ArrayType | RefType 112b1994897Sopenharmony_ciPrimitiveType -> 'Z' | 'B' | 'H' | 'S' | 'C' | 'I' | 'U' | 'J' | 'Q' | 'F' | 'D' | 'A' 113b1994897Sopenharmony_ciArrayType -> '[' TypeDescriptor 114b1994897Sopenharmony_ciRefType -> 'L' ClassName ';' 115b1994897Sopenharmony_ci``` 116b1994897Sopenharmony_ci 117b1994897Sopenharmony_ci`PrimitiveType` is a one letter encoding for primitive type 118b1994897Sopenharmony_ci 119b1994897Sopenharmony_ci| Type | Encoding | 120b1994897Sopenharmony_ci| ---- | :--: | 121b1994897Sopenharmony_ci| `u1` | `Z` | 122b1994897Sopenharmony_ci| `i8` | `B` | 123b1994897Sopenharmony_ci| `u8` | `H` | 124b1994897Sopenharmony_ci| `i16` | `S` | 125b1994897Sopenharmony_ci| `u16` | `C` | 126b1994897Sopenharmony_ci| `i32` | `I` | 127b1994897Sopenharmony_ci| `u32` | `U` | 128b1994897Sopenharmony_ci| `f32` | `F` | 129b1994897Sopenharmony_ci| `f64` | `D` | 130b1994897Sopenharmony_ci| `i64` | `J` | 131b1994897Sopenharmony_ci| `u64` | `Q` | 132b1994897Sopenharmony_ci| `any` | `A` | 133b1994897Sopenharmony_ci 134b1994897Sopenharmony_ci`ClassName` is a qualified name of a class with `.` replaced with `/`. 135b1994897Sopenharmony_ci 136b1994897Sopenharmony_ci## Access flags 137b1994897Sopenharmony_ci 138b1994897Sopenharmony_ci#### Field access flags 139b1994897Sopenharmony_ci 140b1994897Sopenharmony_ci| Name | Value | Description | 141b1994897Sopenharmony_ci| ---- | :---: | ----------- | 142b1994897Sopenharmony_ci| `ACC_PUBLIC` | `0x0001` | Declared public; may be accessed from outside its package. | 143b1994897Sopenharmony_ci| `ACC_PRIVATE` | `0x0002` | Declared private; usable only within the defining class. | 144b1994897Sopenharmony_ci| `ACC_PROTECTED` | `0x0004` | Declared protected; may be accessed within subclasses. | 145b1994897Sopenharmony_ci| `ACC_STATIC` | `0x0008` | Declared static. | 146b1994897Sopenharmony_ci| `ACC_FINAL` | `0x0010` | Declared final; never directly assigned to after object construction (JLS §17.5). | 147b1994897Sopenharmony_ci| `ACC_VOLATILE` | `0x0040` | Declared volatile; cannot be cached. | 148b1994897Sopenharmony_ci| `ACC_TRANSIENT` | `0x0080` | Declared transient; not written or read by a persistent object manager. | 149b1994897Sopenharmony_ci| `ACC_SYNTHETIC` | `0x1000` | Declared synthetic; not present in the source code. | 150b1994897Sopenharmony_ci| `ACC_ENUM` | `0x4000` | Declared as an element of an enum. | 151b1994897Sopenharmony_ci 152b1994897Sopenharmony_ci#### Method access flags 153b1994897Sopenharmony_ci 154b1994897Sopenharmony_ci| Name | Value | Description | 155b1994897Sopenharmony_ci| ---- | :---: | ----------- | 156b1994897Sopenharmony_ci| `ACC_PUBLIC` | `0x0001` | Declared public; may be accessed from outside its package. | 157b1994897Sopenharmony_ci| `ACC_PRIVATE` | `0x0002` | Declared private; accessible only within the defining class. | 158b1994897Sopenharmony_ci| `ACC_PROTECTED` | `0x0004` | Declared protected; may be accessed within subclasses. | 159b1994897Sopenharmony_ci| `ACC_STATIC` | `0x0008` | Declared static. | 160b1994897Sopenharmony_ci| `ACC_FINAL` | `0x0010` | Declared final; must not be overridden. | 161b1994897Sopenharmony_ci| `ACC_SYNCHRONIZED` | `0x0020` | Declared synchronized; invocation is wrapped by a monitor use. | 162b1994897Sopenharmony_ci| `ACC_BRIDGE` | `0x0040` | A bridge method, generated by the compiler. | 163b1994897Sopenharmony_ci| `ACC_VARARGS` | `0x0080` | Declared with variable number of arguments. | 164b1994897Sopenharmony_ci| `ACC_NATIVE` | `0x0100` | Declared native; | 165b1994897Sopenharmony_ci| `ACC_ABSTRACT` | `0x0400` | Declared abstract; no implementation is provided. | 166b1994897Sopenharmony_ci| `ACC_STRICT` | `0x0800` | Declared strictfp; floating-point mode is FP-strict. | 167b1994897Sopenharmony_ci| `ACC_SYNTHETIC` | `0x1000` | Declared synthetic; not present in the source code. | 168b1994897Sopenharmony_ci 169b1994897Sopenharmony_ci#### Class access flags 170b1994897Sopenharmony_ci 171b1994897Sopenharmony_ci| Name | Value | Description | 172b1994897Sopenharmony_ci| ---- | :---: | ----------- | 173b1994897Sopenharmony_ci| `ACC_PUBLIC` | `0x0001` | Declared public; may be accessed from outside its package. | 174b1994897Sopenharmony_ci| `ACC_FINAL` | `0x0010` | Declared final; no subclasses allowed. | 175b1994897Sopenharmony_ci| `ACC_SUPER` | `0x0020` | No special meaning, exists for compatibility | 176b1994897Sopenharmony_ci| `ACC_INTERFACE` | `0x0200` | Is an interface, not a class. | 177b1994897Sopenharmony_ci| `ACC_ABSTRACT` | `0x0400` | Declared abstract; must not be instantiated. | 178b1994897Sopenharmony_ci| `ACC_SYNTHETIC` | `0x1000` | Declared synthetic; not present in the source code. | 179b1994897Sopenharmony_ci| `ACC_ANNOTATION` | `0x2000` | Declared as an annotation type. | 180b1994897Sopenharmony_ci| `ACC_ENUM` | `0x4000` | Declared as an enum type. | 181b1994897Sopenharmony_ci 182b1994897Sopenharmony_ci## Source language 183b1994897Sopenharmony_ci 184b1994897Sopenharmony_ciA file can be emitted from sources that are written in following languages: 185b1994897Sopenharmony_ci 186b1994897Sopenharmony_ci| Name | Value | 187b1994897Sopenharmony_ci| ---- | ---- | 188b1994897Sopenharmony_ci| Reserved | `0x00` | 189b1994897Sopenharmony_ci| `Panda Assembly` | `0x01` | 190b1994897Sopenharmony_ci| Reserved | `0x02 - 0x0f` | 191b1994897Sopenharmony_ci 192b1994897Sopenharmony_ci 193b1994897Sopenharmony_ciSource language can be specified for classes and methods. For classes Panda Assembly language is assumed by default. Default language for methods is the class's one. 194b1994897Sopenharmony_ci 195b1994897Sopenharmony_ci## Data layout 196b1994897Sopenharmony_ci 197b1994897Sopenharmony_ciA file begins with the header which is located at offset 0. 198b1994897Sopenharmony_ciAll other data can be reached from the header. 199b1994897Sopenharmony_ci 200b1994897Sopenharmony_ci### Header 201b1994897Sopenharmony_ci 202b1994897Sopenharmony_ciAlignment: 4 bytes 203b1994897Sopenharmony_ci 204b1994897Sopenharmony_ciFormat: 205b1994897Sopenharmony_ci 206b1994897Sopenharmony_ci| Name | Format | Description | 207b1994897Sopenharmony_ci| ---- | ------ | ----------- | 208b1994897Sopenharmony_ci| `magic` | `uint8_t[8]` | Magic string. Must be 'P' 'A' 'N' 'D' 'A' '\\0' '\\0' '\\0' | 209b1994897Sopenharmony_ci| `checksum` | `uint8_t[4]` | adler32 checksum of the file except magic and checksum fields. | 210b1994897Sopenharmony_ci| `version` | `uint8_t[4]` | Version of the format. Current version is 0002. | 211b1994897Sopenharmony_ci| `file_size` | `uint32_t` | Size of the file in bytes. | 212b1994897Sopenharmony_ci| `foreign_off` | `uint32_t` | Offset to the foreign region. The region must contain elements only of types [ForeignField](#foreignfield), [ForeignMethod](#foreignmethod), or [ForeignClass](#foreignclass). It is not necessary `foreign_off` points to the first entity. Runtime should use `foreign_off` and `foreign_size` to determine type of an offset. | 213b1994897Sopenharmony_ci| `foreign_size` | `uint32_t` | Size of the foreign region in bytes. | 214b1994897Sopenharmony_ci| `num_classes` | `uint32_t` | Number of classes defined in the file. Also this is the number of elements in the [ClassIndex](#classindex) structure. | 215b1994897Sopenharmony_ci| `class_idx_off` | `uint32_t` | Offset to the class index structure. The offset must point to a structure in [ClassIndex](#classindex) format. | 216b1994897Sopenharmony_ci| `num_lnps` | `uint32_t` | Number of line number programs in the file. Also this is the number of elements in the [LineNumberProgramIndex](#linenumberprogramindex) structure. | 217b1994897Sopenharmony_ci| `lnp_idx_off` | `uint32_t` | Offset to the line number program index structure. The offset must point to a structure in [LineNumberProgramIndex](#linenumberprogramindex) format. | 218b1994897Sopenharmony_ci| `num_literalarrays` | `uint32_t` | Number of literalArrays defined in the file. Also this is the number of elements in the [LiteralArrayIndex](#literalarrayindex) structure. | 219b1994897Sopenharmony_ci| `literalarray_idx_off` | `uint32_t` | Offset to the literalarray index structure. The offset must point to a structure in [LiteralArrayIndex](#literalarrayindex) format. | 220b1994897Sopenharmony_ci| `num_index_regions` | `uint32_t` | Number of the index regions in the file. Also this is the number of elements in the [RegionIndex](#regionindex) structure. | 221b1994897Sopenharmony_ci| `index_section_off` | `uint32_t` | Offset to the index section. The offset must point to a structure in [RegionIndex](#indexheaderindex) format. | 222b1994897Sopenharmony_ci 223b1994897Sopenharmony_ciConstraint: size of header must be > 16 bytes. [FieldType](#fieldType) uses this fact. 224b1994897Sopenharmony_ci 225b1994897Sopenharmony_ci### RegionHeader 226b1994897Sopenharmony_ci 227b1994897Sopenharmony_ciTo address file structures using 16-bit indexes file is split into regions. Each region has class, method, field and proto indexes and described by `RegionHeader` structure. 228b1994897Sopenharmony_ci 229b1994897Sopenharmony_ciAlignment: 4 bytes 230b1994897Sopenharmony_ci 231b1994897Sopenharmony_ciFormat: 232b1994897Sopenharmony_ci 233b1994897Sopenharmony_ci| Name | Format | Description | 234b1994897Sopenharmony_ci| ---- | ------ | ----------- | 235b1994897Sopenharmony_ci| `start_off` | `uint32_t` | Start offset of the region. | 236b1994897Sopenharmony_ci| `end_off` | `uint32_t` | End offset of the region. | 237b1994897Sopenharmony_ci| `class_idx_size` | `uint32_t` | Number of elements in the [ClassRegionIndex](#classregionindex) structure. Max value is 65536. | 238b1994897Sopenharmony_ci| `class_idx_off` | `uint32_t` | Offset to the class index structure. The offset must point to a structure in [ClassRegionIndex](#classregionindex) format. | 239b1994897Sopenharmony_ci| `method_idx_size` | `uint32_t` | Number of elements in the [MethodRegionIndex](#methodregionindex) structure. Max value is 65536. | 240b1994897Sopenharmony_ci| `method_idx_off` | `uint32_t` | Offset to the method index structure. The offset must point to a structure in [MethodRegionIndex](#methodregionindex) format. | 241b1994897Sopenharmony_ci| `field_idx_size` | `uint32_t` | Number of elements in the [FieldRegionIndex](#fieldregionindex) structure. Max value is 65536. | 242b1994897Sopenharmony_ci| `field_idx_off` | `uint32_t` | Offset to the field index structure. The offset must point to a structure in [FieldRegionIndex](#fieldregionindex) format. | 243b1994897Sopenharmony_ci| `proto_idx_size` | `uint32_t` | Number of elements in the [ProtoRegionIndex](#protoregionindex) structure. Max value is 65536. | 244b1994897Sopenharmony_ci| `proto_idx_off` | `uint32_t` | Offset to the proto index structure. The offset must point to a structure in [ProtoRegionIndex](#protoregionindex) format. | 245b1994897Sopenharmony_ci 246b1994897Sopenharmony_ciConstraint: regions must not overlap each other. 247b1994897Sopenharmony_ci 248b1994897Sopenharmony_ci### RegionIndex 249b1994897Sopenharmony_ci 250b1994897Sopenharmony_ci`RegionIndex` structure is aimed to allow runtime to find index structure that covers specified offset in the file. 251b1994897Sopenharmony_ciIt is organized as an array of [RegionHeader](#regionheader) structures. 252b1994897Sopenharmony_ciAll regions are sorted by the start offset of the region. Number of elements in the index is `num_index_regions` 253b1994897Sopenharmony_cifrom [Header](#header). 254b1994897Sopenharmony_ci 255b1994897Sopenharmony_ciAlignment: 4 bytes 256b1994897Sopenharmony_ci 257b1994897Sopenharmony_ci### ForeignField 258b1994897Sopenharmony_ci 259b1994897Sopenharmony_ciAlignment: none 260b1994897Sopenharmony_ci 261b1994897Sopenharmony_ciFormat: 262b1994897Sopenharmony_ci 263b1994897Sopenharmony_ci| Name | Format | Description | 264b1994897Sopenharmony_ci| ---- | ------ | ----------- | 265b1994897Sopenharmony_ci| `class_idx` | `uint16_t` | Index of the declaring class in a [`ClassRegionIndex`](#classregionindex) structure. Corresponding index entry must be an offset to a [Class](#class) or a [ForeignClass](#foreignclass). | 266b1994897Sopenharmony_ci| `type_idx` | `uint16_t` | Index of the field's type in a [`ClassRegionIndex`](#classregionindex) structure. Corresponding index entry must be in [FieldType](#fieldtype) format. | 267b1994897Sopenharmony_ci| `name_off` | `uint32_t` | Offset to the name of the field. The offset must point to a [String](#string) | 268b1994897Sopenharmony_ci 269b1994897Sopenharmony_ciNote: Proper region index to resolve `class_idx` and `type_idx` can be found by foreign field's offset. 270b1994897Sopenharmony_ci 271b1994897Sopenharmony_ci### Field 272b1994897Sopenharmony_ci 273b1994897Sopenharmony_ciAlignment: none 274b1994897Sopenharmony_ci 275b1994897Sopenharmony_ciFormat: 276b1994897Sopenharmony_ci 277b1994897Sopenharmony_ci| Name | Format | Description | 278b1994897Sopenharmony_ci| ---- | ------ | ----------- | 279b1994897Sopenharmony_ci| `class_idx` | `uint16_t` | Index of the declaring class in a [`ClassRegionIndex`](#classregionindex) structure. Corresponding index entry must be an offset to a [Class](#class). | 280b1994897Sopenharmony_ci| `type_idx` | `uint16_t` | Index of the field's type in a [`ClassRegionIndex`](#classregionindex) structure. Corresponding index entry must be in [FieldType](#fieldtype) format. | 281b1994897Sopenharmony_ci| `name_off` | `uint32_t` | Offset to the name of the field. The offset must point to a [String](#string) | 282b1994897Sopenharmony_ci| `access_flags` | `uleb128` | Access flags of the field. The value must be a combination of the [Field access flags](#field-access-flags). | 283b1994897Sopenharmony_ci| `field_data` | `TaggedValue[]` | Variable length list of tagged values. Each element must have type [TaggedValue](#taggedvalue). Tag must have values from [FieldTag](#fieldtag) and follow in order of increasing tag (except `0x00` tag). | 284b1994897Sopenharmony_ci 285b1994897Sopenharmony_ciNote: Proper region index to resolve `class_idx` and `type_idx` can be found by field's offset. 286b1994897Sopenharmony_ci 287b1994897Sopenharmony_ci### FieldTag 288b1994897Sopenharmony_ci 289b1994897Sopenharmony_ci| Name | Tag | Quantity | Data format | Description | 290b1994897Sopenharmony_ci| ---- | :-: | :------: | ----------- | ----------- | 291b1994897Sopenharmony_ci| `NOTHING` | `0x00` | `1` | `none` | No more values. The value with this tag must be the last. | 292b1994897Sopenharmony_ci| `INT_VALUE` | `0x01` | `0-1` | `sleb128` | Integral value of the field. This tag is used when the field has type `boolean`, `byte`, `char`, `short` or `int`. | 293b1994897Sopenharmony_ci| `VALUE` | `0x02` | `0-1` | `uint8_t[4]` | Contains value in the [Value](#value) format. | 294b1994897Sopenharmony_ci| `RUNTIME_ANNOTATIONS` | `0x03` | `>=0` | `uint8_t[4]` | Offset to runtime **visible** annotation of the field. The tag may be repeated in case the field has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 295b1994897Sopenharmony_ci| `ANNOTATIONS` | `0x04` | `>=0` | `uint8_t[4]` | Offset to runtime **invisible** annotation of the field. The tag may be repeated in case the field has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 296b1994897Sopenharmony_ci| `RUNTIME_TYPE_ANNOTATION` | `0x05` | `>=0` | `uint8_t[4]` | Offset to runtime **visible** type annotation of the field. The tag may be repeated in case the field has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 297b1994897Sopenharmony_ci| `TYPE_ANNOTATION` | `0x06` | `>=0` | `uint8_t[4]` | Offset to runtime **invisible** type annotation of the field. The tag may be repeated in case the field has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 298b1994897Sopenharmony_ci 299b1994897Sopenharmony_ciNote: Only `INT_VALUE` or `VALUE` tags must be present. 300b1994897Sopenharmony_ci 301b1994897Sopenharmony_ci### FieldType 302b1994897Sopenharmony_ci 303b1994897Sopenharmony_ciSince the first bytes of the file contain the header and size of the header > 16 bytes, any offset in the range `[0; sizeof(Header))` is invalid. 304b1994897Sopenharmony_ci`FieldType` encoding uses this fact to encode primitive types of the field in the low 4 bits. 305b1994897Sopenharmony_ciFor non-primitive type the value is an offset to [Class](#class) or to 306b1994897Sopenharmony_ci[ForeignClass](#foreignclass). In both cases [FieldType](#fieldtype) is `uint32_t`. 307b1994897Sopenharmony_ci 308b1994897Sopenharmony_ciPrimitive types are encoded as follows: 309b1994897Sopenharmony_ci 310b1994897Sopenharmony_ci| Type | Code | 311b1994897Sopenharmony_ci| ---- | :--: | 312b1994897Sopenharmony_ci| `u1` | 0x00 | 313b1994897Sopenharmony_ci| `i8` | 0x01 | 314b1994897Sopenharmony_ci| `u8` | 0x02 | 315b1994897Sopenharmony_ci| `i16` | 0x03 | 316b1994897Sopenharmony_ci| `u16` | 0x04 | 317b1994897Sopenharmony_ci| `i32` | 0x05 | 318b1994897Sopenharmony_ci| `u32` | 0x06 | 319b1994897Sopenharmony_ci| `f32` | 0x07 | 320b1994897Sopenharmony_ci| `f64` | 0x08 | 321b1994897Sopenharmony_ci| `i64` | 0x09 | 322b1994897Sopenharmony_ci| `u64` | 0x0a | 323b1994897Sopenharmony_ci| `any` | 0x0b | 324b1994897Sopenharmony_ci 325b1994897Sopenharmony_ci### ForeignMethod 326b1994897Sopenharmony_ci 327b1994897Sopenharmony_ciAlignment: none 328b1994897Sopenharmony_ci 329b1994897Sopenharmony_ciFormat: 330b1994897Sopenharmony_ci 331b1994897Sopenharmony_ci| Name | Format | Description | 332b1994897Sopenharmony_ci| ---- | ------ | ----------- | 333b1994897Sopenharmony_ci| `class_idx` | `uint16_t` | Index of the declaring class in a [`ClassRegionIndex`](#classregionindex) structure. Corresponding index entry must be an offset to a [Class](#class) or a [ForeignClass](#foreignclass). | 334b1994897Sopenharmony_ci| `proto_idx` | `uint16_t` | Index of the method's prototype in a [`ProtoRegionIndex`](#classregionindex) structure. Corresponding index entry must be an offset to a [Proto](#proto). | 335b1994897Sopenharmony_ci| `name_off` | `uint32_t` | Offset to the name of the method. The offset must point to a [String](#string). | 336b1994897Sopenharmony_ci| `access_flags` | `uleb128` | Access flags of the method. The value must be a combination of [Method access flags](#method-access-flags). For foreign methods, only `ACC_STATIC` flag is used, other flags should be ignored. | 337b1994897Sopenharmony_ci 338b1994897Sopenharmony_ciNote: Proper region index to resolve `class_idx` and `proto_idx` can be found by foreign method's offset. 339b1994897Sopenharmony_ci 340b1994897Sopenharmony_ci### Method 341b1994897Sopenharmony_ci 342b1994897Sopenharmony_ciAlignment: none 343b1994897Sopenharmony_ci 344b1994897Sopenharmony_ciFormat: 345b1994897Sopenharmony_ci 346b1994897Sopenharmony_ci| Name | Format | Description | 347b1994897Sopenharmony_ci| ---- | ------ | ----------- | 348b1994897Sopenharmony_ci| `class_idx` | `uint16_t` | Index of the declaring class in a [`ClassRegionIndex`](#classregionindex) structure. Corresponding index entry must be an offset to a [Class](#class). | 349b1994897Sopenharmony_ci| `proto_idx` | `uint16_t` | Index of the method's prototype in a [`ProtoRegionIndex`](#classregionindex) structure. Corresponding index entry must be an offset to a [Proto](#proto). | 350b1994897Sopenharmony_ci| `name_off` | `uint32_t` | Offset to the name of the method. The offset must point to a [String](#string). | 351b1994897Sopenharmony_ci| `access_flags` | `uleb128` | Access flags of the method. The value must be a combination of [Method access flags](#method-access-flags). | 352b1994897Sopenharmony_ci| `method_data` | `TaggedValue[]` | Variable length list of tagged values. Each element must have type [TaggedValue](#taggedvalue). Tag must have values from [MethodTag](#methodtag) and follow in order of increasing tag (except `0x00` tag). | 353b1994897Sopenharmony_ci 354b1994897Sopenharmony_ciNote: Proper region index to resolve `class_idx` and `proto_idx` can be found by method's offset. 355b1994897Sopenharmony_ci 356b1994897Sopenharmony_ci### MethodTag 357b1994897Sopenharmony_ci 358b1994897Sopenharmony_ci| Name | Tag | Quantity | Data format | Description | 359b1994897Sopenharmony_ci| ---- | :-: | :------: | ----------- | ----------- | 360b1994897Sopenharmony_ci| `NOTHING` | `0x00` | `1` | `none` | No more values. The value with this tag must be the last. | 361b1994897Sopenharmony_ci| `CODE` | `0x01` | `0-1` | `uint8_t[4]` | Data represents the offset to method's code. The offset must point to [Code](#code). | 362b1994897Sopenharmony_ci| `SOURCE_LANG` | `0x02` | `0-1` | `uint8_t` | Data represents the [source language](#source-language). | 363b1994897Sopenharmony_ci| `RUNTIME_ANNOTATION` | `0x03` | `>=0` | `uint8_t[4]` | Data represents the offset to runtime **visible** annotation of the method. The tag may be repeated in case the method has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 364b1994897Sopenharmony_ci| `RUNTIME_PARAM_ANNOTATION` | `0x04` | `0-1` | `uint8_t[4]` | Data represents the offset to the runtime **visible** annotations of the method's parameters. The offset must point to the value in [ParamAnnotations](#paramannotations) format. | 365b1994897Sopenharmony_ci| `DEBUG_INFO` | `0x05` | `0-1` | `uint8_t[4]` | Data represents the offset to debug information related to the method. The offset must point to [DebugInfo](#debuginfo). | 366b1994897Sopenharmony_ci| `ANNOTATION` | `0x06` | `>=0` | `uint8_t[4]` | Data represents the offset to runtime **invisible** annotation of the method. The tag may be repeated in case the method has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 367b1994897Sopenharmony_ci| `PARAM_ANNOTATION` | `0x07` | `0-1` | `uint8_t[4]` | Data represents the offset to the runtime **invisible** annotations of the method's parameters. The offset must point to the value in [ParamAnnotations](#paramannotations) format. | 368b1994897Sopenharmony_ci| `TYPE_ANNOTATION` | `0x08` | `>=0` | `uint8_t[4]` | Data represents the offset to runtime **invisible** type annotation of the method. The tag may be repeated in case the method has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 369b1994897Sopenharmony_ci| `RUNTIME_TYPE_ANNOTATION` | `0x09` | `>=0` | `uint8_t[4]` | Data represents the offset to runtime **visible** type annotation of the method. The tag may be repeated in case the method has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 370b1994897Sopenharmony_ci 371b1994897Sopenharmony_ci### ForeignClass 372b1994897Sopenharmony_ci 373b1994897Sopenharmony_ciAlignment: none 374b1994897Sopenharmony_ci 375b1994897Sopenharmony_ciFormat: 376b1994897Sopenharmony_ci 377b1994897Sopenharmony_ci| Name | Format | Description | 378b1994897Sopenharmony_ci| ---- | ------ | ----------- | 379b1994897Sopenharmony_ci| `name` | `String` | Name of the foreign type. The name must conform to [TypeDescriptor](#typedescriptor) syntax. | 380b1994897Sopenharmony_ci 381b1994897Sopenharmony_ci### Class 382b1994897Sopenharmony_ci 383b1994897Sopenharmony_ciAlignment: none 384b1994897Sopenharmony_ci 385b1994897Sopenharmony_ciFormat: 386b1994897Sopenharmony_ci 387b1994897Sopenharmony_ci| Name | Format | Description | 388b1994897Sopenharmony_ci| ---- | ------ | ----------- | 389b1994897Sopenharmony_ci| `name` | `String` | Name of the class. The name must conform to [TypeDescriptor](#typedescriptor) syntax. | 390b1994897Sopenharmony_ci| `super_class_off` | `uint8_t[4]` | Offset to the name of the super class or `0` for root object class (`panda.Object` in Panda Assembly, plugin-specific in plugins). Non-zero offset must point to a [ForeignClass](#foreignclass) or to a [Class](#class). | 391b1994897Sopenharmony_ci| `access_flags` | `uleb128` | Access flags of the class. The value must be a combination of [Class access flags](#class-access-flags). | 392b1994897Sopenharmony_ci| `num_fields` | `uleb128` | Number of fields the class has. 393b1994897Sopenharmony_ci| `num_methods` | `uleb128` | Number of methods the class has. 394b1994897Sopenharmony_ci| `class_data` | `TaggedValue[]` | Variable length list of tagged values. Each element must have type [TaggedValue](#taggedvalue). Tag must have values from [ClassTag](#classtag) and follow in order of increasing tag (except `0x00` tag). | 395b1994897Sopenharmony_ci| `fields` | `Field[]` | Class fields. Number of elements is `num_fields`. Each element must have [Field](#field) format. | 396b1994897Sopenharmony_ci| `methods` | `Method[]` | Class methods. Number of elements is `num_methods`. Each element must have [Method](#method) format. | 397b1994897Sopenharmony_ci 398b1994897Sopenharmony_ci#### ClassTag 399b1994897Sopenharmony_ci 400b1994897Sopenharmony_ci| Name | Tag | Quantity | Data format | Description | 401b1994897Sopenharmony_ci| ---- | :-: | :------: | ----------- | ----------- | 402b1994897Sopenharmony_ci| `NOTHING` | `0x00` | `1` | `none` | No more values. The value with this tag must be the last. | 403b1994897Sopenharmony_ci| `INTERFACES` | `0x01` | `0-1` | `uleb128 uint8_t[]` | List of interfaces the class implements. Data contains number of interfaces encoded in `uleb128` format followed by indexes of the interfaces in a [`ClassRegionIndex`](#classregionindex) structure. Each index is 2 bytes long and must be resolved to offset point to a [ForeignClass](#foreignclass) or to a [Class](#class). Number of indexes is equal to number of interfaces. | 404b1994897Sopenharmony_ci| `SOURCE_LANG` | `0x02` | `0-1` | `uint8_t` | Data represents the [source language](#source-language). | 405b1994897Sopenharmony_ci| `RUNTIME_ANNOTATION` | `0x03` | `>=0` | `uint8_t[4]` | Offset to runtime **visible** annotation of the class. The tag may be repeated in case the class has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 406b1994897Sopenharmony_ci| `ANNOTATION` | `0x04` | `>=0` | `uint8_t[4]` | Offset to runtime **invisible** annotation of the class. The tag may be repeated in case the class has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 407b1994897Sopenharmony_ci| `RUNTIME_TYPE_ANNOTATION` | `0x05` | `>=0` | `uint8_t[4]` | Offset to runtime **visible** type annotation of the class. The tag may be repeated in case the class has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 408b1994897Sopenharmony_ci| `TYPE_ANNOTATION` | `0x06` | `>=0` | `uint8_t[4]` | Offset to runtime **invisible** type annotation of the class. The tag may be repeated in case the class has several annotations. The offset must point to the value in [Annotation](#annotation) format. | 409b1994897Sopenharmony_ci| `SOURCE_FILE` | `0x07` | `0-1` | `uint8_t[4]` | Offset to a file name string containing source code of this class. | 410b1994897Sopenharmony_ci 411b1994897Sopenharmony_ciNote: Proper region index to resolve interfaces indexes can be found by class's offset. 412b1994897Sopenharmony_ci 413b1994897Sopenharmony_ci### LiteralArray 414b1994897Sopenharmony_ci 415b1994897Sopenharmony_ciAlignment: none 416b1994897Sopenharmony_ci 417b1994897Sopenharmony_ci| Name | Format | Description | 418b1994897Sopenharmony_ci| ---- | ------ | ----------- | 419b1994897Sopenharmony_ci| `num_literals` | `uint32_t` | num of literals that a literalarray has. | 420b1994897Sopenharmony_ci| `literals` | `literal[]` | Array of `literal` in one LiteralArray. The array has `num_literals` elements in [Literal](#literal) format. | 421b1994897Sopenharmony_ci 422b1994897Sopenharmony_ci### Proto 423b1994897Sopenharmony_ci 424b1994897Sopenharmony_ciAlignment: 2 bytes 425b1994897Sopenharmony_ci 426b1994897Sopenharmony_ciFormat: 427b1994897Sopenharmony_ci 428b1994897Sopenharmony_ci| Name | Format | Description | 429b1994897Sopenharmony_ci| ---- | ------ | ----------- | 430b1994897Sopenharmony_ci| `shorty` | `uint16_t[]` | Short representation of the prototype. Encoding of the shorty is described in [Shorty](#shorty). | 431b1994897Sopenharmony_ci| `reference_types` | `uint16_t[]` | Array of indexes of the method's signature non-primitive types. For each non-primitive type in the shorty there is the corresponding element in the array. Size of the array is equals to number of reference types in the shorty. | 432b1994897Sopenharmony_ci 433b1994897Sopenharmony_ciNote: Proper region index to resolve reference types indexes can be found by proto's offset. 434b1994897Sopenharmony_ci 435b1994897Sopenharmony_ci#### Shorty 436b1994897Sopenharmony_ci 437b1994897Sopenharmony_ciShorty is a short description of method's signature without detailed information about reference types. 438b1994897Sopenharmony_ciA shorty begins with a return type followed by method arguments and ends with `0x0`. 439b1994897Sopenharmony_ci 440b1994897Sopenharmony_ciShorty syntax: 441b1994897Sopenharmony_ci 442b1994897Sopenharmony_ci``` 443b1994897Sopenharmony_ciShorty -> ReturnType ParamTypeList End 444b1994897Sopenharmony_ciReturnType -> Type 445b1994897Sopenharmony_ciParamTypeList -> '' | Type ParamTypeList 446b1994897Sopenharmony_ciType -> <encoded type> 447b1994897Sopenharmony_ciEnd -> 0x0 448b1994897Sopenharmony_ci``` 449b1994897Sopenharmony_ci 450b1994897Sopenharmony_ci`<encoded type>` must be one of: 451b1994897Sopenharmony_ci 452b1994897Sopenharmony_ci| Type | Value | 453b1994897Sopenharmony_ci| ---- | :---: | 454b1994897Sopenharmony_ci| `void` | `0x01` | 455b1994897Sopenharmony_ci| `u1` | `0x02` | 456b1994897Sopenharmony_ci| `i8` | `0x03` | 457b1994897Sopenharmony_ci| `u8` | `0x04` | 458b1994897Sopenharmony_ci| `i16` | `0x05` | 459b1994897Sopenharmony_ci| `u16` | `0x06` | 460b1994897Sopenharmony_ci| `i32` | `0x07` | 461b1994897Sopenharmony_ci| `u32` | `0x08` | 462b1994897Sopenharmony_ci| `f32` | `0x09` | 463b1994897Sopenharmony_ci| `f64` | `0x0a` | 464b1994897Sopenharmony_ci| `i64` | `0x0b` | 465b1994897Sopenharmony_ci| `u64` | `0x0c` | 466b1994897Sopenharmony_ci| `ref` | `0x0d` | 467b1994897Sopenharmony_ci| `any` | `0x0e` | 468b1994897Sopenharmony_ci 469b1994897Sopenharmony_ciAll shorty elements are divided into groups of 4 elements starting from the beginning. 470b1994897Sopenharmony_ciEach group is encoded in `uint16_t`. Each element is encoded in 4 bits. 471b1994897Sopenharmony_ciA group with 4 elements `v1`, `v2`, ..., `v4` is encoded in `uint16_t` as follow: 472b1994897Sopenharmony_ci 473b1994897Sopenharmony_ci``` 474b1994897Sopenharmony_ci| bits | 0 - 3 | 4 - 7 | 8 - 11 | 12 - 15 | 475b1994897Sopenharmony_ci| ------ | ----- | ----- | ------ | ------- | 476b1994897Sopenharmony_ci| values | v1 | v2 | v3 | v4 | 477b1994897Sopenharmony_ci``` 478b1994897Sopenharmony_ci 479b1994897Sopenharmony_ciIf the group contains less then 4 elements the rest bits are filled with `0x0`. 480b1994897Sopenharmony_ci 481b1994897Sopenharmony_ci### Code 482b1994897Sopenharmony_ci 483b1994897Sopenharmony_ciAlignment: none 484b1994897Sopenharmony_ci 485b1994897Sopenharmony_ciFormat: 486b1994897Sopenharmony_ci 487b1994897Sopenharmony_ci| Name | Format | Description | 488b1994897Sopenharmony_ci| ---- | ------ | ----------- | 489b1994897Sopenharmony_ci| `num_vregs` | `uleb128` | Number of registers (without argument registers). | 490b1994897Sopenharmony_ci| `num_args` | `uleb128` | Number of arguments. | 491b1994897Sopenharmony_ci| `code_size` | `uleb128` | Size of instructions in bytes. | 492b1994897Sopenharmony_ci| `tries_size` | `uleb128` | Number of try blocks. | 493b1994897Sopenharmony_ci| `instructions` | `uint8_t[]` | Instructions. | 494b1994897Sopenharmony_ci| `try_blocks` | `TryBlock[]` | Array of try blocks. The array has `tries_size` elements in [TryBlock](#tryblock) format. | 495b1994897Sopenharmony_ci 496b1994897Sopenharmony_ci### TryBlock 497b1994897Sopenharmony_ci 498b1994897Sopenharmony_ciAlignment: none 499b1994897Sopenharmony_ci 500b1994897Sopenharmony_ciFormat: 501b1994897Sopenharmony_ci 502b1994897Sopenharmony_ci| Name | Format | Description | 503b1994897Sopenharmony_ci| ---- | ------ | ----------- | 504b1994897Sopenharmony_ci| `start_pc` | `uleb128` | Start `pc` of the `try` block. This `pc` points to the first instruction covered by this try block. | 505b1994897Sopenharmony_ci| `length` | `uleb128` | Number of instructions covered by the `try` block. | 506b1994897Sopenharmony_ci| `num_catches` | `uleb128` | Number of catch blocks associated with the `try` block. | 507b1994897Sopenharmony_ci| `catch_blocks` | `CatchBlock[]` | Array of `catch` blocks associated with the `try` block. The array has `num_catches` elements in [CatchBlock](#catchblock) format. Catch blocks follows in the order runtime must check the exception's type. The `catch all` block, if present, must be the last. | 508b1994897Sopenharmony_ci 509b1994897Sopenharmony_ci### CatchBlock 510b1994897Sopenharmony_ci 511b1994897Sopenharmony_ciAlignment: none 512b1994897Sopenharmony_ci 513b1994897Sopenharmony_ciFormat: 514b1994897Sopenharmony_ci 515b1994897Sopenharmony_ci| Name | Format | Description | 516b1994897Sopenharmony_ci| ---- | ------ | ----------- | 517b1994897Sopenharmony_ci| `type_idx` | `uleb128` | Index + 1 of the exception's type the block handles in a [`ClassRegionIndex`](#classregionindex) structure or 0 in case of `catch all` block. Corresponding index entry must be an offset to a [ForeignClass](#foreignclass) or to [Class](#class). The case when the index is 0 means it is a `catch all` block which catches all exceptions. | 518b1994897Sopenharmony_ci| `handler_pc` | `uleb128` | `pc` of the first instruction of the exception handler. | 519b1994897Sopenharmony_ci| `code_size` | `uleb128` | Handler's code size in bytes | 520b1994897Sopenharmony_ci 521b1994897Sopenharmony_ciNote: Proper region index to resolve `type_idx` can be found by corresponding method's offset. 522b1994897Sopenharmony_ci 523b1994897Sopenharmony_ci### Annotation 524b1994897Sopenharmony_ci 525b1994897Sopenharmony_ciAlignment: none 526b1994897Sopenharmony_ci 527b1994897Sopenharmony_ciFormat: 528b1994897Sopenharmony_ci 529b1994897Sopenharmony_ci| Name | Format | Description | 530b1994897Sopenharmony_ci| ---- | ------ | ----------- | 531b1994897Sopenharmony_ci| `class_idx` | `uint16_t` | Index of the declaring class in a [`ClassRegionIndex`](#classregionindex) structure. Corresponding index entry must be an offset to a [Class](#class) or a [ForeignClass](#foreignclass). | 532b1994897Sopenharmony_ci| `count` | `uint16_t` | Number of name-value pairs in the annotation (number of elements in `elements` array). | 533b1994897Sopenharmony_ci| `elements` | `AnnotationElement[]` | Array of annotation elements. Each element is in [AnnotationElement](#annotationelement) format. Order of elements must be the same as they follow in the annotation class. | 534b1994897Sopenharmony_ci| `element_types` | `uint8_t[]` | Array of annotation element's types. Each element in the array describes the type of `AnnotationElement`. The order of elements in the array matches the order of `elements` field. | 535b1994897Sopenharmony_ci 536b1994897Sopenharmony_ciNote: Proper region index to resolve `class_idx` can be found by annotation's offset. 537b1994897Sopenharmony_ci 538b1994897Sopenharmony_ci### Tags description 539b1994897Sopenharmony_ci 540b1994897Sopenharmony_ci| Type | Tag | 541b1994897Sopenharmony_ci| ------------------| --- | 542b1994897Sopenharmony_ci| `u1` | `1` | 543b1994897Sopenharmony_ci| `i8` | `2` | 544b1994897Sopenharmony_ci| `u8` | `3` | 545b1994897Sopenharmony_ci| `i16` | `4` | 546b1994897Sopenharmony_ci| `u16` | `5` | 547b1994897Sopenharmony_ci| `i32` | `6` | 548b1994897Sopenharmony_ci| `u32` | `7` | 549b1994897Sopenharmony_ci| `i64` | `8` | 550b1994897Sopenharmony_ci| `u64` | `9` | 551b1994897Sopenharmony_ci| `f32` | `A` | 552b1994897Sopenharmony_ci| `f64` | `B` | 553b1994897Sopenharmony_ci| `string` | `C` | 554b1994897Sopenharmony_ci| `record` | `D` | 555b1994897Sopenharmony_ci| `method` | `E` | 556b1994897Sopenharmony_ci| `enum` | `F` | 557b1994897Sopenharmony_ci| `annotation` | `G` | 558b1994897Sopenharmony_ci| `method_handle` | `J` | 559b1994897Sopenharmony_ci| `array` | `H` | 560b1994897Sopenharmony_ci| `u1[]` | `K` | 561b1994897Sopenharmony_ci| `i8[]` | `L` | 562b1994897Sopenharmony_ci| `u8[]` | `M` | 563b1994897Sopenharmony_ci| `i16[]` | `N` | 564b1994897Sopenharmony_ci| `u16[]` | `O` | 565b1994897Sopenharmony_ci| `i32[]` | `P` | 566b1994897Sopenharmony_ci| `u32[]` | `Q` | 567b1994897Sopenharmony_ci| `i64[]` | `R` | 568b1994897Sopenharmony_ci| `u64[]` | `S` | 569b1994897Sopenharmony_ci| `f32[]` | `T` | 570b1994897Sopenharmony_ci| `f64[]` | `U` | 571b1994897Sopenharmony_ci| `string[]` | `V` | 572b1994897Sopenharmony_ci| `record[]` | `W` | 573b1994897Sopenharmony_ci| `method[]` | `X` | 574b1994897Sopenharmony_ci| `enum[]` | `Y` | 575b1994897Sopenharmony_ci| `annotation[]` | `Z` | 576b1994897Sopenharmony_ci| `method_handle[]` | `@` | 577b1994897Sopenharmony_ci| `nullptr string` | `*` | 578b1994897Sopenharmony_ci 579b1994897Sopenharmony_ciThe correct value for element with `nullptr string` tag is 0 (`\x00\x00\x00\x00`) 580b1994897Sopenharmony_ci 581b1994897Sopenharmony_ci### AnnotationElement 582b1994897Sopenharmony_ci 583b1994897Sopenharmony_ciAlignment: none 584b1994897Sopenharmony_ci 585b1994897Sopenharmony_ciFormat: 586b1994897Sopenharmony_ci 587b1994897Sopenharmony_ci| Name | Format | Description | 588b1994897Sopenharmony_ci| ---- | ------ | ----------- | 589b1994897Sopenharmony_ci| `name_off` | `uint32_t` | Offset to the element's name. The offset must point to a [String](#string). | 590b1994897Sopenharmony_ci| `value` | `uint32_t` | Value of the element. If the annotation element has type boolean, byte, short, char, int or float the field *value* contains the value itself in the corresponding [Value](#value) format. Else the field contains offset to a [Value](#value). Format of the value could be determined based on element's type. | 591b1994897Sopenharmony_ci 592b1994897Sopenharmony_ci 593b1994897Sopenharmony_ci### ParamAnnotations 594b1994897Sopenharmony_ci 595b1994897Sopenharmony_ciAlignment: none 596b1994897Sopenharmony_ci 597b1994897Sopenharmony_ciFormat: 598b1994897Sopenharmony_ci 599b1994897Sopenharmony_ci| Name | Format | Description | 600b1994897Sopenharmony_ci| ---- | ------ | ----------- | 601b1994897Sopenharmony_ci| `count` | `uint32_t` | Number of parameters the method has. This number includes synthetic and mandated parameters. | 602b1994897Sopenharmony_ci| `annotations` | `AnnotationArray[]` | Array of annotation lists for each parameter. The array has `count` elements and each element is in [AnnotationArray](#annotationarray) format. | 603b1994897Sopenharmony_ci 604b1994897Sopenharmony_ci### AnnotationArray 605b1994897Sopenharmony_ci 606b1994897Sopenharmony_ciAlignment: none 607b1994897Sopenharmony_ci 608b1994897Sopenharmony_ciFormat: 609b1994897Sopenharmony_ci 610b1994897Sopenharmony_ci| Name | Format | Description | 611b1994897Sopenharmony_ci| ---- | ------ | ----------- | 612b1994897Sopenharmony_ci| `count` | `uint32_t` | Number of elements in the array. | 613b1994897Sopenharmony_ci| `offsets` | `uint32_t[]` | Array of offsets to the parameter annotations. Each offset must refers to an [Annotation](#annotation). The array has `count` elements. | 614b1994897Sopenharmony_ci 615b1994897Sopenharmony_ci### Value 616b1994897Sopenharmony_ci 617b1994897Sopenharmony_ciThere are different value encodings depending on the value's type. 618b1994897Sopenharmony_ci 619b1994897Sopenharmony_ci#### ByteValue 620b1994897Sopenharmony_ci 621b1994897Sopenharmony_ciAlignment: None 622b1994897Sopenharmony_ci 623b1994897Sopenharmony_ciFormat: 624b1994897Sopenharmony_ci 625b1994897Sopenharmony_ci| Name | Format | Description | 626b1994897Sopenharmony_ci| ---- | ------ | ----------- | 627b1994897Sopenharmony_ci| `value` | `uint8_t` | Signed 1-byte integer value. | 628b1994897Sopenharmony_ci 629b1994897Sopenharmony_ci#### ShortValue 630b1994897Sopenharmony_ci 631b1994897Sopenharmony_ciAlignment: 2 bytes 632b1994897Sopenharmony_ci 633b1994897Sopenharmony_ciFormat: 634b1994897Sopenharmony_ci 635b1994897Sopenharmony_ci| Name | Format | Description | 636b1994897Sopenharmony_ci| ---- | ------ | ----------- | 637b1994897Sopenharmony_ci| `value` | `uint8_t[2]` | Signed 2-byte integer value. | 638b1994897Sopenharmony_ci 639b1994897Sopenharmony_ci#### IntegerValue 640b1994897Sopenharmony_ci 641b1994897Sopenharmony_ciAlignment: 4 bytes 642b1994897Sopenharmony_ci 643b1994897Sopenharmony_ciFormat: 644b1994897Sopenharmony_ci 645b1994897Sopenharmony_ci| Name | Format | Description | 646b1994897Sopenharmony_ci| ---- | ------ | ----------- | 647b1994897Sopenharmony_ci| `value` | `uint8_t[4]` | Signed 4-byte integer value. | 648b1994897Sopenharmony_ci 649b1994897Sopenharmony_ci#### LongValue 650b1994897Sopenharmony_ci 651b1994897Sopenharmony_ciAlignment: 8 bytes 652b1994897Sopenharmony_ci 653b1994897Sopenharmony_ciFormat: 654b1994897Sopenharmony_ci 655b1994897Sopenharmony_ci| Name | Format | Description | 656b1994897Sopenharmony_ci| ---- | ------ | ----------- | 657b1994897Sopenharmony_ci| `value` | `uint8_t[8]` | Signed 8-byte integer value. | 658b1994897Sopenharmony_ci 659b1994897Sopenharmony_ci#### FloatValue 660b1994897Sopenharmony_ci 661b1994897Sopenharmony_ciAlignment: 4 bytes 662b1994897Sopenharmony_ci 663b1994897Sopenharmony_ciFormat: 664b1994897Sopenharmony_ci 665b1994897Sopenharmony_ci| Name | Format | Description | 666b1994897Sopenharmony_ci| ---- | ------ | ----------- | 667b1994897Sopenharmony_ci| `value` | `uint8_t[4]` | 4-byte bit pattern, zero-extended to the right, and interpreted as an IEEE754 32-bit floating point value. | 668b1994897Sopenharmony_ci 669b1994897Sopenharmony_ci#### DoubleValue 670b1994897Sopenharmony_ci 671b1994897Sopenharmony_ciAlignment: 8 bytes 672b1994897Sopenharmony_ci 673b1994897Sopenharmony_ciFormat: 674b1994897Sopenharmony_ci 675b1994897Sopenharmony_ci| Name | Format | Description | 676b1994897Sopenharmony_ci| ---- | ------ | ----------- | 677b1994897Sopenharmony_ci| `value` | `uint8_t[8]` | 8-byte bit pattern, zero-extended to the right, and interpreted as an IEEE754 64-bit floating point value. | 678b1994897Sopenharmony_ci 679b1994897Sopenharmony_ci#### StringValue 680b1994897Sopenharmony_ci 681b1994897Sopenharmony_ciAlignment: 4 bytes 682b1994897Sopenharmony_ci 683b1994897Sopenharmony_ciFormat: 684b1994897Sopenharmony_ci 685b1994897Sopenharmony_ci| Name | Format | Description | 686b1994897Sopenharmony_ci| ---- | ------ | ----------- | 687b1994897Sopenharmony_ci| `value` | `uint32_t` | The value represents an offset to [String](#string). | 688b1994897Sopenharmony_ci 689b1994897Sopenharmony_ci#### EnumValue 690b1994897Sopenharmony_ci 691b1994897Sopenharmony_ciAlignment: 4 bytes 692b1994897Sopenharmony_ci 693b1994897Sopenharmony_ciFormat: 694b1994897Sopenharmony_ci 695b1994897Sopenharmony_ci| Name | Format | Description | 696b1994897Sopenharmony_ci| ---- | ------ | ----------- | 697b1994897Sopenharmony_ci| `value` | `uint32_t` | The value represents an offset to an enum's field. The offset must point to [Field](#field) or [ForeignField](#foreignfield). | 698b1994897Sopenharmony_ci 699b1994897Sopenharmony_ci#### ClassValue 700b1994897Sopenharmony_ci 701b1994897Sopenharmony_ciAlignment: 4 bytes 702b1994897Sopenharmony_ci 703b1994897Sopenharmony_ciFormat: 704b1994897Sopenharmony_ci 705b1994897Sopenharmony_ci| Name | Format | Description | 706b1994897Sopenharmony_ci| ---- | ------ | ----------- | 707b1994897Sopenharmony_ci| `value` | `uint32_t` | The value represents an offset to [Class](#class) or [ForeignClass](#foreignclass). | 708b1994897Sopenharmony_ci 709b1994897Sopenharmony_ci#### AnnotationValue 710b1994897Sopenharmony_ci 711b1994897Sopenharmony_ciAlignment: 4 bytes 712b1994897Sopenharmony_ci 713b1994897Sopenharmony_ciFormat: 714b1994897Sopenharmony_ci 715b1994897Sopenharmony_ci| Name | Format | Description | 716b1994897Sopenharmony_ci| ---- | ------ | ----------- | 717b1994897Sopenharmony_ci| `value` | `uint32_t` | The value represents an offset to [Annotation](#annotation). | 718b1994897Sopenharmony_ci 719b1994897Sopenharmony_ci#### MethodValue 720b1994897Sopenharmony_ci 721b1994897Sopenharmony_ciAlignment: 4 bytes 722b1994897Sopenharmony_ci 723b1994897Sopenharmony_ciFormat: 724b1994897Sopenharmony_ci 725b1994897Sopenharmony_ci| Name | Format | Description | 726b1994897Sopenharmony_ci| ---- | ------ | ----------- | 727b1994897Sopenharmony_ci| `value` | `uint32_t` | The value represents an offset to [Method](#method) or [ForeignMethod](#foreignmethod). | 728b1994897Sopenharmony_ci 729b1994897Sopenharmony_ci#### MethodHandleValue 730b1994897Sopenharmony_ci 731b1994897Sopenharmony_ciAlignment: 4 bytes 732b1994897Sopenharmony_ci 733b1994897Sopenharmony_ciFormat: 734b1994897Sopenharmony_ci 735b1994897Sopenharmony_ci| Name | Format | Description | 736b1994897Sopenharmony_ci| ---- | ------ | ----------- | 737b1994897Sopenharmony_ci| `value` | `uint32_t` | The value represents an offset to [MethodHandle](#methodhandle). | 738b1994897Sopenharmony_ci 739b1994897Sopenharmony_ci#### MethodTypeValue 740b1994897Sopenharmony_ci 741b1994897Sopenharmony_ciAlignment: 4 bytes 742b1994897Sopenharmony_ci 743b1994897Sopenharmony_ciFormat: 744b1994897Sopenharmony_ci 745b1994897Sopenharmony_ci| Name | Format | Description | 746b1994897Sopenharmony_ci| ---- | ------ | ----------- | 747b1994897Sopenharmony_ci| `value` | `uint32_t` | The value represents an offset to [Proto](#proto). | 748b1994897Sopenharmony_ci 749b1994897Sopenharmony_ci#### ArrayValue 750b1994897Sopenharmony_ci 751b1994897Sopenharmony_ciAlignment: None 752b1994897Sopenharmony_ci 753b1994897Sopenharmony_ciFormat: 754b1994897Sopenharmony_ci 755b1994897Sopenharmony_ci| Name | Format | Description | 756b1994897Sopenharmony_ci| ---- | ------ | ----------- | 757b1994897Sopenharmony_ci| `count` | `uleb128` | Number of elements in the array. | 758b1994897Sopenharmony_ci| `elements` | `Value[]` | Unaligned array of [Value](#value) items. The array has `count` elements. | 759b1994897Sopenharmony_ci 760b1994897Sopenharmony_ci### Literal 761b1994897Sopenharmony_ci 762b1994897Sopenharmony_ciThere are different literal encodings depending on the num of value's bytes. 763b1994897Sopenharmony_ci 764b1994897Sopenharmony_ci#### ByteOne 765b1994897Sopenharmony_ci 766b1994897Sopenharmony_ciAlignment: None 767b1994897Sopenharmony_ci 768b1994897Sopenharmony_ciFormat: 769b1994897Sopenharmony_ci 770b1994897Sopenharmony_ci| Name | Format | Description | 771b1994897Sopenharmony_ci| ---- | ------ | ----------- | 772b1994897Sopenharmony_ci| `value` | `uint8_t` | 1-byte value. | 773b1994897Sopenharmony_ci 774b1994897Sopenharmony_ci#### ByteTwo 775b1994897Sopenharmony_ci 776b1994897Sopenharmony_ciAlignment: 2 bytes 777b1994897Sopenharmony_ci 778b1994897Sopenharmony_ciFormat: 779b1994897Sopenharmony_ci 780b1994897Sopenharmony_ci| Name | Format | Description | 781b1994897Sopenharmony_ci| ---- | ------ | ----------- | 782b1994897Sopenharmony_ci| `value` | `uint8_t[2]` | 2-byte value. | 783b1994897Sopenharmony_ci 784b1994897Sopenharmony_ci#### ByteFour 785b1994897Sopenharmony_ci 786b1994897Sopenharmony_ciAlignment: 4 bytes 787b1994897Sopenharmony_ci 788b1994897Sopenharmony_ciFormat: 789b1994897Sopenharmony_ci 790b1994897Sopenharmony_ci| Name | Format | Description | 791b1994897Sopenharmony_ci| ---- | ------ | ----------- | 792b1994897Sopenharmony_ci| `value` | `uint8_t[4]` | 4-byte value. | 793b1994897Sopenharmony_ci 794b1994897Sopenharmony_ci#### ByteEight 795b1994897Sopenharmony_ci 796b1994897Sopenharmony_ciAlignment: 8 bytes 797b1994897Sopenharmony_ci 798b1994897Sopenharmony_ciFormat: 799b1994897Sopenharmony_ci 800b1994897Sopenharmony_ci| Name | Format | Description | 801b1994897Sopenharmony_ci| ---- | ------ | ----------- | 802b1994897Sopenharmony_ci| `value` | `uint8_t[8]` | 8-byte value. | 803b1994897Sopenharmony_ci 804b1994897Sopenharmony_ci### ClassIndex 805b1994897Sopenharmony_ci 806b1994897Sopenharmony_ci`ClassIndex` structure is aimed to allow runtime to find a type definition by name quickly. 807b1994897Sopenharmony_ciThe structure is organized as an array of offsets from the beginning of the file to the 808b1994897Sopenharmony_ci[Class](#class) or [ForeignClass](#foreignclass) structures. All the offsets are sorted by corresponding class names. 809b1994897Sopenharmony_ciNumber of elements in the index is `num_classes` from [Header](#header). 810b1994897Sopenharmony_ci 811b1994897Sopenharmony_ciAlignment: 4 bytes 812b1994897Sopenharmony_ci 813b1994897Sopenharmony_ciFormat: 814b1994897Sopenharmony_ci 815b1994897Sopenharmony_ci| Name | Format | Description | 816b1994897Sopenharmony_ci| ---- | ------ | ----------- | 817b1994897Sopenharmony_ci| `offsets` | `uint32_t[]` | Sorted array of offsets to [Class](#class) or [ForeignClass](#foreignclass) structures. The array must be sorted by class names. | 818b1994897Sopenharmony_ci 819b1994897Sopenharmony_ci### LineNumberProgramIndex 820b1994897Sopenharmony_ci 821b1994897Sopenharmony_ci`LineNumberProgramIndex` structure is aimed to allow use more compact references to [Line Number Program](#line-number-program). 822b1994897Sopenharmony_ciThe structure is organized as an array of offsets from the beginning of the file to the [Line Number Program](#line-number-program) 823b1994897Sopenharmony_cistructures. Number of elements in the index is `num_lnps` from [Header](#header). 824b1994897Sopenharmony_ci 825b1994897Sopenharmony_ciAlignment: 4 bytes 826b1994897Sopenharmony_ci 827b1994897Sopenharmony_ciFormat: 828b1994897Sopenharmony_ci 829b1994897Sopenharmony_ci| Name | Format | Description | 830b1994897Sopenharmony_ci| ---- | ------ | ----------- | 831b1994897Sopenharmony_ci| `offsets` | `uint32_t[]` | Array of offsets to [Line Number Program](#line-number-program) structures. | 832b1994897Sopenharmony_ci 833b1994897Sopenharmony_ci### ClassRegionIndex 834b1994897Sopenharmony_ci 835b1994897Sopenharmony_ci`ClassRegionIndex` structure is aimed to allow runtime to find a type definition by index. 836b1994897Sopenharmony_ciThe structure is organized as an array of [FieldType](#fieldtype). Number of elements in the index is `class_idx_size` from [RegionHeader](#regionheader). 837b1994897Sopenharmony_ci 838b1994897Sopenharmony_ciAlignment: 4 bytes 839b1994897Sopenharmony_ci 840b1994897Sopenharmony_ciFormat: 841b1994897Sopenharmony_ci 842b1994897Sopenharmony_ci| Name | Format | Description | 843b1994897Sopenharmony_ci| ---- | ------ | ----------- | 844b1994897Sopenharmony_ci| `types` | `FieldType[]` | Array of [FieldType](#fieldtype) structures. | 845b1994897Sopenharmony_ci 846b1994897Sopenharmony_ci### MethodRegionIndex 847b1994897Sopenharmony_ci 848b1994897Sopenharmony_ci`MethodRegionIndex` structure is aimed to allow runtime to find a method definition by index. 849b1994897Sopenharmony_ciThe structure is organized as an array of offsets from the beginning og the file to the [Method](#method) or the [ForeignMethod](#foreignmethod) structure. 850b1994897Sopenharmony_ciNumber of elements in the index is `method_idx_size` from [RegionHeader](#regionheader). 851b1994897Sopenharmony_ci 852b1994897Sopenharmony_ciAlignment: 4 bytes 853b1994897Sopenharmony_ci 854b1994897Sopenharmony_ciFormat: 855b1994897Sopenharmony_ci 856b1994897Sopenharmony_ci| Name | Format | Description | 857b1994897Sopenharmony_ci| ---- | ------ | ----------- | 858b1994897Sopenharmony_ci| `offsets` | `uint32_t[]` | Array of offsets to [Method](#method) or [ForeignMethod](#foreignmethod) structures. | 859b1994897Sopenharmony_ci 860b1994897Sopenharmony_ci### FieldRegionIndex 861b1994897Sopenharmony_ci 862b1994897Sopenharmony_ci`FieldRegionIndex` structure is aimed to allow runtime to find a field definition by index. 863b1994897Sopenharmony_ciThe structure is organized as an array of offsets from the beginning og the file to the [Field](#field) or the [ForeignField](#foreignfield) structure. 864b1994897Sopenharmony_ciNumber of elements in the index is `field_idx_size` from [RegionHeader](#regionheader). 865b1994897Sopenharmony_ci 866b1994897Sopenharmony_ciAlignment: 4 bytes 867b1994897Sopenharmony_ci 868b1994897Sopenharmony_ciFormat: 869b1994897Sopenharmony_ci 870b1994897Sopenharmony_ci| Name | Format | Description | 871b1994897Sopenharmony_ci| ---- | ------ | ----------- | 872b1994897Sopenharmony_ci| `offsets` | `uint32_t[]` | Array of offsets to [Field](#field) or [ForeignField](#foreignfield) structures. | 873b1994897Sopenharmony_ci 874b1994897Sopenharmony_ci### ProtoRegionIndex 875b1994897Sopenharmony_ci 876b1994897Sopenharmony_ci`ProtoRegionIndex` structure is aimed to allow runtime to find a proto definition by index. 877b1994897Sopenharmony_ciThe structure is organized as an array of offsets from the beginning og the file to the [Proto](#proto) structure. 878b1994897Sopenharmony_ciNumber of elements in the index is `proto_idx_size` from [RegionHeader](#regionheader). 879b1994897Sopenharmony_ci 880b1994897Sopenharmony_ciAlignment: 4 bytes 881b1994897Sopenharmony_ci 882b1994897Sopenharmony_ciFormat: 883b1994897Sopenharmony_ci 884b1994897Sopenharmony_ci| Name | Format | Description | 885b1994897Sopenharmony_ci| ---- | ------ | ----------- | 886b1994897Sopenharmony_ci| `offsets` | `uint32_t[]` | Array of offsets to [Proto](#proto) structures. | 887b1994897Sopenharmony_ci 888b1994897Sopenharmony_ci### LiteralArrayIndex 889b1994897Sopenharmony_ci 890b1994897Sopenharmony_ci`LiteralArrayIndex` structure is aimed to allow runtime to find a LiteralArray definition by index. 891b1994897Sopenharmony_ciThe structure is organized as an array of offsets from the beginning of the file to the [LiteralArray](#literalarray) structures. 892b1994897Sopenharmony_ciNumber of elements in the index is `num_literalarrays` from [Header](#header). 893b1994897Sopenharmony_ci 894b1994897Sopenharmony_ciAlignment: 4 bytes 895b1994897Sopenharmony_ci 896b1994897Sopenharmony_ciFormat: 897b1994897Sopenharmony_ci 898b1994897Sopenharmony_ci| Name | Format | Description | 899b1994897Sopenharmony_ci| ---- | ------ | ----------- | 900b1994897Sopenharmony_ci| `offsets` | `uint32_t[]` | Sorted array of offsets to [LiteralArray](#literalarray) structures. | 901b1994897Sopenharmony_ci 902b1994897Sopenharmony_ci### DebugInfo 903b1994897Sopenharmony_ci 904b1994897Sopenharmony_ciDebug information contains mapping between program counter of a method and line numbers in source 905b1994897Sopenharmony_cicode and information about local variables. The format is derived from DWARF Debugging Information 906b1994897Sopenharmony_ciFormat, Version 3 (see item 6.2). The mapping and local variable information are encoded in 907b1994897Sopenharmony_ci[line number program](#line-number-program) which is interpreted by 908b1994897Sopenharmony_ci[the state machine](#state-machine). To deduplicate the same line number programs of different 909b1994897Sopenharmony_cimethods all constants the program refers to are moved into [the constant pool](#constant-pool). 910b1994897Sopenharmony_ci 911b1994897Sopenharmony_ciAlignment: none 912b1994897Sopenharmony_ci 913b1994897Sopenharmony_ciFormat: 914b1994897Sopenharmony_ci 915b1994897Sopenharmony_ci| Name | Format | Description | 916b1994897Sopenharmony_ci| ---- | ------ | ----------- | 917b1994897Sopenharmony_ci| `line_start` | `uleb128` | The initial value of line register of [the state machine](#state-machine). | 918b1994897Sopenharmony_ci| `num_parameters` | `uleb128` | Number of method parameters. | 919b1994897Sopenharmony_ci| `parameters` | `uleb128[]` | Parameters names of the method. The array has `num_parameters` elements. Each element is an offset to [String](#string) or 0 if there is no name. | 920b1994897Sopenharmony_ci| `constant_pool_size` | `uleb128` | Size of constant pool in bytes. | 921b1994897Sopenharmony_ci| `constant_pool` | `uleb128[]` | [Constant pool](#constant-pool) data of length `constant_pool_size` bytes. | 922b1994897Sopenharmony_ci| `line_number_program_idx` | `uleb128` | [Line number program](#line-number-program) index in a [`LineNumberProgramIndex`](#linenumberprogramindex) structure. The program has variable length and ends with `DBG_END_SEQUENCE` opcode. | 923b1994897Sopenharmony_ci 924b1994897Sopenharmony_ci#### Constant pool 925b1994897Sopenharmony_ci 926b1994897Sopenharmony_ciMany methods has similar line number program. The difference is only in variable names, 927b1994897Sopenharmony_civariable types and file names. To deduplicate such programs all constants the program refers to 928b1994897Sopenharmony_ciare stored in the constant pool. During interpretation of the program 929b1994897Sopenharmony_ci[the state machine](#state-machine) tracks a pointer to the constant pool. 930b1994897Sopenharmony_ciWhen [the state machine](#state-machine) interprets an instruction which requires a constant 931b1994897Sopenharmony_ciargument the machine reads the value from memory constant pool pointer points to and then increments 932b1994897Sopenharmony_cithe pointer. Thus programs has no explicit references to constants and could be deduplicated. 933b1994897Sopenharmony_ci 934b1994897Sopenharmony_ci#### State Machine 935b1994897Sopenharmony_ci 936b1994897Sopenharmony_ciThe aim of the state machine is to generate a mapping between program counter and line numbers and 937b1994897Sopenharmony_cilocal variable information. The machine has the following registers: 938b1994897Sopenharmony_ci 939b1994897Sopenharmony_ci| Name | Initial value | Description | 940b1994897Sopenharmony_ci| ---- | ------------- | ----------------- | 941b1994897Sopenharmony_ci| `address` | 0 | Program counter (refers to method's instructions). Must only monotonically increase. | 942b1994897Sopenharmony_ci| `line` | `line_start` from [DebugInfo](#debug_info). | Unsigned integer which corresponds to line number in source code. All lines are numbered beginning at 1 so the register mustn't have value less then 1. | 943b1994897Sopenharmony_ci| `file` | Value of `SOURCE_FILE` tag in `class_data` (see [Class](#class)) or 0 | Offset to the name of source file. If there is no such information (`SOURCE_FILE` tag is absent in [Class](#class)) then the register has value 0. | 944b1994897Sopenharmony_ci| `prologue_end` | `false` | The register indicates the current address is one where entry breakpoint of the method could be set. | 945b1994897Sopenharmony_ci| `epilogue_begin` | `false` | The register indicates the current address is one where exit breakpoint of the method could be set. | 946b1994897Sopenharmony_ci| `constant_pool_ptr` | Address of the `constant_pool`'s first byte from [DebugInfo](#debug_info). | Pointer to the current constant value. | 947b1994897Sopenharmony_ci 948b1994897Sopenharmony_ci#### Line Number Program 949b1994897Sopenharmony_ci 950b1994897Sopenharmony_ciA line number program consists of instructions. Each instruction has one byte opcode and optional arguments. Depending on opcode argument's value may be encoded into the instruction or the instruction requires reading the value from constant pool. 951b1994897Sopenharmony_ci 952b1994897Sopenharmony_ci| Opcode | Value | Instruction Format | Constant pool arguments | Description | 953b1994897Sopenharmony_ci| ------ | ----- | ------------------ | ----------------------- | ----------- | 954b1994897Sopenharmony_ci| `END_SEQUENCE` | `0x00` | | | Marks the end of line number program. | 955b1994897Sopenharmony_ci| `ADVANCE_PC` | `0x01` | | `uleb128` | Increment `address` register by the value `constant_pool_ptr` refers to without emitting a line. | 956b1994897Sopenharmony_ci| `ADVANCE_LINE` | `0x02` | | `sleb128` | Increment `line` register by the value `constant_pool_ptr` refers to without emitting a line. | 957b1994897Sopenharmony_ci| `START_LOCAL` | `0x03` | `sleb128` | `uleb128 uleb128` | Introduce a local variable with name and type the `constant_pool_ptr` refers to at the current address. The number of the register contains the variable is encoded in the instruction. The register's value `-1` means the accumulator register. The name is an offset to [String](#String) and the type is an offset to [ForeignClass](#foreignclass) or [Class](#class). The offsets may be `0` which means the corresponding information is absent. | 958b1994897Sopenharmony_ci| `START_LOCAL_EXTENDED` | `0x04` | `sleb128` | `uleb128 uleb128 uleb128` | Introduce a local variable with name, type and type signature the *constant_pool_ptr* refers to at the current address. The number of the register contains the variable is encoded in the instruction. The register's value `-1` means the accumulator register. The name is an offset to [String](#String), the type is an offset to [ForeignClass](#foreignclass) or [Class](#class) and the signature is an offset to TODO: figure out what are signatures. The offsets may be `0` which means the corresponding information is absent. | 959b1994897Sopenharmony_ci| `END_LOCAL` | `0x05` | `sleb128` | | Mark the local variable in the specified register is out of scope. The register number is encoded in the instruction. The register's value `-1` means the accumulator register. | 960b1994897Sopenharmony_ci| `RESTART_LOCAL` | `0x06` | `sleb128` | | Re-introduces a local variable at the specified register. The name and type are the same as the last local that was in the register. The register number is encoded in the instruction. The register's value `-1` means the accumulator register. | 961b1994897Sopenharmony_ci| `SET_PROLOGUE_END` | `0x07` | | | Set `prologue_end` register to `true`. Any special opcodes clear `prologue_end` register. | 962b1994897Sopenharmony_ci| `SET_EPILOGUE_BEGIN` | `0x08` | | | Set `epilogue_end` register to `true`. Any special opcodes clear `epilogue_end` register. | 963b1994897Sopenharmony_ci| `SET_FILE` | `0x09` | | `uleb128` | Set `file` register to the value `constant_pool_ptr` refers to. The argument is an offset to [String](#string) which represents the file name or `0`. | 964b1994897Sopenharmony_ci| `SET_SOURCE_CODE` | `0x0a` | | `uleb128` | Set `source_code` register to the value `constant_pool_ptr` refers to. The argument is an offset to [String](#string) which represents the source code or `0`. | 965b1994897Sopenharmony_ci| SET_COLUMN | `0x0b` | | `uleb128` | Set `column` register by the value `constant_pool_ptr` refers to | 966b1994897Sopenharmony_ci| Special opcodes | `0x0c..0xff` | | | | 967b1994897Sopenharmony_ci 968b1994897Sopenharmony_ciSpecial opcodes: 969b1994897Sopenharmony_ci 970b1994897Sopenharmony_ci[The state machine](#state-machine) interprets each special opcode as follow 971b1994897Sopenharmony_ci(see DWARF Debugging Information Format item 6.2.5.1 Special Opcodes): 972b1994897Sopenharmony_ci 973b1994897Sopenharmony_ci1. Calculate the adjusted opcode: `adjusted_opcode = opcode - OPCODE_BASE`. 974b1994897Sopenharmony_ci2. Increment `address` register: `address += adjusted_opcode / LINE_RANGE`. 975b1994897Sopenharmony_ci3. Increment `line` register: `line += LINE_BASE + (adjusted_opcode % LINE_RANGE)`. 976b1994897Sopenharmony_ci4. Emit line number. 977b1994897Sopenharmony_ci5. Set `prologue_end` register to `false`. 978b1994897Sopenharmony_ci6. Set `epilogue_begin` register to `false`. 979b1994897Sopenharmony_ci 980b1994897Sopenharmony_ciWhere: 981b1994897Sopenharmony_ci 982b1994897Sopenharmony_ci* `OPCODE_BASE = 0x0c`: the first special opcode. 983b1994897Sopenharmony_ci* `LINE_BASE = -4`: the smallest line number increment. 984b1994897Sopenharmony_ci* `LINE_RANGE = 15`: the number of line increments presented. 985b1994897Sopenharmony_ci 986b1994897Sopenharmony_ci### MethodHandle 987b1994897Sopenharmony_ci 988b1994897Sopenharmony_ciAlignment: none 989b1994897Sopenharmony_ci 990b1994897Sopenharmony_ciFormat: 991b1994897Sopenharmony_ci 992b1994897Sopenharmony_ci| Name | Format | Description | 993b1994897Sopenharmony_ci| ---- | ------ | ----------- | 994b1994897Sopenharmony_ci| `type` | `uint8_t` | Type of the handle. Must be one of [MethodHandle's type](#types_of_methodhandle). | 995b1994897Sopenharmony_ci| `offset` | `uleb128` | Offset to the entity of the corresponding type. Type of the entity is determined depending on handle's type (see [Types of MethodHandle](#types_of_methodhandle)). | 996b1994897Sopenharmony_ci 997b1994897Sopenharmony_ci#### Types of MethodHandle 998b1994897Sopenharmony_ci 999b1994897Sopenharmony_ciThe available types of a method handle are: 1000b1994897Sopenharmony_ci 1001b1994897Sopenharmony_ci| Name | Code | Description | 1002b1994897Sopenharmony_ci| ---- | :--: | ----------- | 1003b1994897Sopenharmony_ci| `PUT_STATIC` | `0x00` | Method handle refers to a static setter. Offset in [MethodHandle](#methodhandle) must point to [Field](#field) or [ForeignField](#foreignfield). | 1004b1994897Sopenharmony_ci| `GET_STATIC` | `0x01` | Method handle refers to a static getter. Offset in [MethodHandle](#methodhandle) must point to [Field](#field) or [ForeignField](#foreignfield). | 1005b1994897Sopenharmony_ci| `PUT_INSTANCE` | `0x02` | Method handle refers to an instance getter. Offset in [MethodHandle](#methodhandle) must point to [Field](#field) or [ForeignField](#foreignfield). | 1006b1994897Sopenharmony_ci| `GET_INSTANCE` | `0x03` | Method handle refers to an instance setter. Offset in [MethodHandle](#methodhandle) must point to [Field](#field) or [ForeignField](#foreignfield). | 1007b1994897Sopenharmony_ci| `INVOKE_STATIC` | `0x04` | Method handle refers to a static method. Offset in [MethodHandle](#methodhandle) must point to [Method](#method) or [ForeignMethod](#foreignmethod). | 1008b1994897Sopenharmony_ci| `INVOKE_INSTANCE` | `0x05` | Method handle refers to an instance method. Offset in [MethodHandle](#methodhandle) must point to [Method](#method) or [ForeignMethod](#foreignmethod). | 1009b1994897Sopenharmony_ci| `INVOKE_CONSTRUCTOR` | `0x06` | Method handle refers to a constructor. Offset in [MethodHandle](#methodhandle) must point to [Method](#method) or [ForeignMethod](#foreignmethod). | 1010b1994897Sopenharmony_ci| `INVOKE_DIRECT` | `0x07` | Method handle refers to a direct method. Offset in [MethodHandle](#methodhandle) must point to [Method](#method) or [ForeignMethod](#foreignmethod). | 1011b1994897Sopenharmony_ci| `INVOKE_INTERFACE` | `0x08` | Method handle refers to an interface method. Offset in [MethodHandle](#methodhandle) must point to [Method](#method) or [ForeignMethod](#foreignmethod). | 1012b1994897Sopenharmony_ci 1013b1994897Sopenharmony_ci#### Argument Types 1014b1994897Sopenharmony_ci 1015b1994897Sopenharmony_ciA bootstrap method can accept static arguments of the following types: 1016b1994897Sopenharmony_ci 1017b1994897Sopenharmony_ci| Type | Code | Description | 1018b1994897Sopenharmony_ci| ----- | :--: | ----------- | 1019b1994897Sopenharmony_ci| `Integer` | `0x00` | The corresponding argument has [IntegerValue](#integervalue) encoding. | 1020b1994897Sopenharmony_ci| `Long` | `0x01` | The corresponding argument has [LongValue](#longvalue) encoding. | 1021b1994897Sopenharmony_ci| `Float` | `0x02` | The corresponding argument has [FloatValue](#floatvalue) encoding. | 1022b1994897Sopenharmony_ci| `Double` | `0x03` | The corresponding argument has [DoubleValue](#doublevalue) encoding. | 1023b1994897Sopenharmony_ci| `String` | `0x04` | The corresponding argument has [StringValue](#stringvalue) encoding. | 1024b1994897Sopenharmony_ci| `Class` | `0x05` | The corresponding argument has [ClassValue](#classvalue) encoding. | 1025b1994897Sopenharmony_ci| `MethodHandle` | `0x06` | The corresponding argument has [MethodHandleValue](#methodhandlevalue) encoding. | 1026b1994897Sopenharmony_ci| `MethodType` | `0x07` | The corresponding argument has [MethodTypeValue](#methodtypevalue) encoding. | 1027