• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Ark Bytecode File Format
2The Ark bytecode file is the binary output generated by compiling ArkTS/TS/JS code. This topic describes the Ark bytecode file format in detail, aiming to help you understand its structure and facilitate the analysis and modification of bytecode files.
3
4
5## Constraints
6This topic is applicable only to Ark bytecode of version 12.0.6.0. The version number is an internal field of the Ark compiler and does not require your attention.
7
8
9## Bytecode File Data Types
10
11### Integer
12
13| **Name**       | **Description**                          |
14| -------------- | ---------------------------------- |
15| `uint8_t`      | 8-bit unsigned integer.                 |
16| `uint16_t`     | 16-bit unsigned integer in little-endian mode.  |
17| `uint32_t`     | 32-bit unsigned integer in little-endian mode.  |
18| `uleb128`      | Unsigned integer encoded in LEB128 format.            |
19| `sleb128`      | Signed integer encoded in LEB128 format.            |
20
21
22### String
23- Alignment: single-byte aligned
24- Format
25
26| **Name**| **Format**| **Description**                                              |
27| -------------- | -------------- | ------------------------------------------------------------ |
28| `utf16_length`   | `uleb128`  | The value is **len << 1 \**| **is_ascii**, where **len** is the length of a string encoded by UTF-16, and **is_ascii** specifies whether the string contains only ASCII characters (**0** or **1**).|
29| `data`           | `uint8_t[]` | Null-terminated sequence of characters encoded in MUTF-8 format. |
30
31
32### TaggedValue
33- Alignment: single-byte aligned
34- Format
35
36| **Name**| **Format**| **Description**                               |
37| -------------- | -------------- | -------------------------------------------- |
38| `tag`          | `uint8_t`      | Marker indicating the type of data.                          |
39| `data`         | `uint8_t[]`    | Data content. Its type is determined by the tag, and it may be empty.|
40
41
42## TypeDescriptor
43Represents [class](#class) names in the format of **L_ClassName;**, where **ClassName** is the fully qualified name, in which **'.'** is replaced with **'/'**.
44
45
46## Bytecode File Layout
47The bytecode file begins with the [Header](#header) structure, from which all other structures can be accessed directly or indirectly. References within the file use offsets (32-bit) and indexes (16-bit). Offsets indicate the position relative to the file header, starting from 0. Indexes point to specific entries within index regions. More details are provided in [IndexSection](#indexsection).
48
49All multi-byte values in bytecode files are stored in little-endian format.
50
51
52### Header
53- Alignment: single-byte aligned
54- Format
55
56| **Name**   | **Format**| **Description**                                              |
57| ----------------- | -------------- | ------------------------------------------------------------ |
58| `magic`             | `uint8_t[8]`     | Magic number of the file header. Its value must be **'P' 'A' 'N' 'D' 'A' '\0' '\0' '\0'**.   |
59| `checksum`          | `uint32_t`       | **Adler32** checksum of the content in the bytecode file, excluding the magic number and this checksum field.|
60| `version`           | `uint8_t[4]`     | [Version](#version) of the bytecode file.|
61| `file_size`         | `uint32_t`       | Size of the bytecode file, in bytes.                            |
62| `foreign_off`       | `uint32_t`       | An offset that points to a foreign region, which contains only elements of the type [ForeignClass](#foreignclass) or [ForeignMethod](#foreignmethod). **foreign_off** points to the first element in the region.|
63| `foreign_size`      | `uint32_t`       | Size of the foreign region, in bytes.                              |
64| `num_classes`       | `uint32_t`       | Number of elements in the [ClassIndex](#classindex) structure, that is, the number of [classes](#class) defined in the file.|
65| `class_idx_off`     | `uint32_t`       | An offset that points to [ClassIndex](#classindex).|
66| `num_lnps`          | `uint32_t`       | Number of elements in the [LineNumberProgramIndex](#linenumberprogramindex) structure, that is, the number of [line number programs](#line-number-program) defined in the file.|
67| `lnp_idx_off`       | `uint32_t`       | An offset that points to [LineNumberProgramIndex](#linenumberprogramindex).|
68| `reserved`          | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
69| `reserved`          | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
70| `num_index_regions` | `uint32_t`       | Number of elements in the [IndexSection](#indexsection) structure, that is, the number of [IndexHeaders](#indexheader) in the file.|
71| `index_section_off` | `uint32_t`       | An offset that points to [IndexSection](#indexsection).|
72
73
74### Version
75The bytecode version number consists of four parts in the format of major.minor.feature.build.
76
77| **Name**| **Format**| **Description**                                            |
78| -------------- | -------------- | ---------------------------------------------------------- |
79| Major      | `uint8_t`        | Indicates significant architectural changes.                |
80| Minor      | `uint8_t`        | Indicates changes in local architecture or major features.|
81| Feature    | `uint8_t`        | Indicates changes due to minor features.                    |
82| Build    | `uint8_t`        | Indicates changes due to bug fixes.                    |
83
84
85### ForeignClass
86Represents foreign classes referenced in the bytecode file but declared in other files.
87- Alignment: single-byte aligned
88- Format
89
90| **Name**| **Format**| **Description**                                              |
91| -------------- | -------------- | ------------------------------------------------------------ |
92| `name`           | `String`         | Foreign class name, which follows the [TypeDescriptor](#typedescriptor) syntax.|
93
94
95### ForeignMethod
96Represents foreign methods referenced in the bytecode file but declared in other files.
97- Alignment: single-byte aligned
98- Format
99
100| **Name**| **Format**| **Description**                                              |
101| -------------- | -------------- | ------------------------------------------------------------ |
102| `class_idx`      | `uint16_t`       | An index of the class to which the method belongs. It points to a position in [ClassRegionIndex](#classregionindex), and the position value is an offset pointing to [Class](#class) or [ForeignClass](#foreignclass).|
103| `reserved`       | `uint16_t`       | Reserved field for internal use by the Ark bytecode file.              |
104| `name_off`       | `uint32_t`       | An offset to a [string](#string) representing the method name.|
105| `index_data`     | `uleb128`        | [MethodIndexData](#methodindexdata) data of the method.|
106
107**NOTE**<br>
108The offset of **ForeignMethod** can be used to locate the appropriate **IndexHeader** for parsing **class_idx**.
109
110
111### ClassIndex
112Facilitates quick lookup of class definitions by name.
113- Alignment: 4-byte aligned
114- Format
115
116| **Name**| **Format**| **Description**                                              |
117| -------------- | -------------- | ------------------------------------------------------------ |
118| `offsets`        | `uint32_t[]`     | An array of offsets pointing to [classes](#class). Elements in the array are sorted by the class name, which follows the [TypeDescriptor](#typedescriptor) syntax. The array length is specified by **num_classes** in [Header](#header).|
119
120
121### Class
122Represents either a source code file or an internal [Annotation](#annotation). For a source code file, **methods** correspond to functions in the source code file, and **fields** correspond to internal information in the source file. For **Annotation**, **fields** or **methods** are not contained. A class in the source code file is represented as a constructor in the bytecode file.
123
124- Alignment: single-byte aligned
125- Format
126
127| **Name**| **Format**| **Description**                                              |
128| -------------- | -------------- | ------------------------------------------------------------ |
129| `name`           | `String`         | Class name, which follows the [TypeDescriptor](#typedescriptor) syntax.|
130| `reserved`       | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
131| `access_flags`   | `uleb128`        | Tags to access the class, which is a combination of [ClassAccessFlags](#classaccessflag).|
132| `num_fields`     | `uleb128`        | Number of fields in the class.                                         |
133| `num_methods`    | `uleb128`        | Number of methods in the class.                                         |
134| `class_data`     | `TaggedValue[]`  | Array with variable length. Each element in the array is of the [TaggedValue](#taggedvalue) type, and the element tag is of the [ClassTag](#classtag) type. Elements in the array are sorted in ascending order based on the tag (except the **0x00** tag).|
135| `fields`         | `Field[]`        | Array of fields in the class. Each element in this array is of the [Field](#field) type. The array length is specified by **num_fields**.|
136| `methods`        | `Method[]`       | Array of methods in the class. Each element in this array is of the [Method](#method) type. The array length is specified by **num_methods**.|
137
138
139### ClassAccessFlag
140
141| **Name**| **Value**| **Description**                                              |
142| -------------- | ------------ | ------------------------------------------------------------ |
143| `ACC_PUBLIC`     | `0x0001`       | Default attribute. All [classes](#class) in the Ark bytecode file have this tag.|
144| `ACC_ANNOTATION` | `0x2000`       | Declares this class as the [Annotation](#annotation) type.|
145
146
147### ClassTag
148- Alignment: single-byte aligned
149- Format
150
151| **Name**| **Value**| **Quantity**| **Format**| **Description**                                              |
152| -------------- | ------------ | -------------- | -------------- | ------------------------------------------------------------ |
153| `NOTHING`        | `0x00`  | `1`  | `none`    | Marks a [TaggedValue](#taggedvalue) as the final item in **class_data**.|
154| `SOURCE_LANG`    | `0x02`  | `0-1 ` | `uint8_t` | **data** of a [TaggedValue](#taggedvalue) with this tag is **0**, indicating that the source code language is in ArkTS, TS, or JS.|
155| `SOURCE_FILE`    | `0x07`  | `0-1`  | `uint32_t`| **data** of a [TaggedValue](#taggedvalue) with this tag is an offset that points to a [string](#string) representing the source file name.|
156
157**NOTE**<br>
158**ClassTag** is a marker of the element ([TaggedValue](#taggedvalue)) in **class_data**. **Quantity** in the table header refers to the number of occurrences of the element with this tag in **class_data** of a [class](#class).
159
160
161### Field
162Represents fields within the bytecode file.
163
164- Alignment: single-byte aligned
165- Format
166
167| **Name**| **Format**| **Description**                                              |
168| -------------- | -------------- | ------------------------------------------------------------ |
169| `class_idx`      | `uint16_t`       | An index of the class to which the field belongs. It points to a position in [ClassRegionIndex](#classregionindex). The value of the position is of the [Type](#type) type and is an offset pointing to [Class](#class).|
170| `type_idx`       | `uint16_t`       | An index of the type of the field. It points to a position in [ClassRegionIndex](#classregionindex). The value of the position is of the [Type](#type) type.|
171| `name_off`       | `uint32_t`       | An offset to a [string](#string) representing the field name.|
172| `reserved`       | `uleb128`        | Reserved field for internal use by the Ark bytecode file.                          |
173| `field_data`     | `TaggedValue[]`  | Array with variable length. Each element in the array is of the [TaggedValue](#taggedvalue) type, and the element tag is of the [FieldTag](#fieldtag) type. Elements in the array are sorted in ascending order based on the tag (except the **0x00** tag).|
174
175**NOTE**<br>
176The offset of **Field** can be used to locate the appropriate **IndexHeader** for parsing **class_idx** and **type_idx**.
177
178
179### FieldTag
180
181- Alignment: single-byte aligned
182- Format
183
184| **Name**| **Value**| **Quantity**| **Format**| **Description** |
185| -------------- | ------------ | -------------- | -------------- | ------------------------------------------------------------ |
186| `NOTHING`        | `0x00`   | `1`   | `none`     | Marks a [TaggedValue](#taggedvalue) as the final item in **field_data**.|
187| `INT_VALUE`      | `0x01`   | `0-1` | `sleb128`  | The **data** type of a [TaggedValue](#taggedvalue) with this tag is of **boolean**, **byte**, **char**, **short**, or **int**.|
188| `VALUE`          | `0x02`   | `0-1` | `uint32_t` | The **data** type of a [TaggedValue](#taggedvalue) with this tag is of **FLOAT** or **ID** in [Value formats](#value-formats).|
189
190**NOTE**<br>
191**FieldTag** is a marker of the element ([TaggedValue](#taggedvalue)) in **field_data**. **Quantity** in the table header refers to the number of occurrences of the element with this tag in **field_data** of a [field](#field).
192
193
194### Method
195Represents methods within the bytecode file.
196
197- Alignment: single-byte aligned
198- Format
199
200| **Name**| **Format**| **Description**                                              |
201| -------------- | -------------- | ------------------------------------------------------------ |
202| `class_idx`      | `uint16_t`       | An index of the class to which the method belongs. It points to a position in [ClassRegionIndex](#classregionindex). The value of the position is of the [Type](#type) type and is an offset pointing to [Class](#class).|
203| `reserved`       | `uint16_t`       | Reserved field for internal use by the Ark bytecode file.                          |
204| `name_off`       | `uint32_t`       | An offset to a [string](#string) representing the method name.|
205| `index_data`     | `uleb128`        | [MethodIndexData](#methodindexdata) data of the method.|
206| `method_data`    | `TaggedValue[]`  | Array with variable length. Each element in the array is of the [TaggedValue](#taggedvalue) type, and the element tag is of the [MethodTag](#methodtag) type. Elements in the array are sorted in ascending order based on the tag (except the **0x00** tag).|
207
208**NOTE**<br>
209The offset of **Method** can be used to locate the appropriate **IndexHeader** for parsing **class_idx**.
210
211
212### MethodIndexData
213A 32-bit unsigned integer, divided into three parts.
214
215| **Bit**| **Name**| **Format**| **Description**                                              |
216| ------------ | -------------- | -------------- | ------------------------------------------------------------ |
217| 0 - 15       | `header_index`   | `uint16_t`       | Points to a position in [IndexSection](#indexsection). The value of this position is [IndexHeader](#indexheader). You can use **IndexHeader** to find the offsets of all methods ([Method](#method)), [string](#string), or literal array ([LiteralArray](#literalarray)) referenced by this method.|
218| 16 - 23      | `function_kind`  | `uint8_t`        | Function type ([FunctionKind](#functionkind)) of a method.|
219| 24 - 31      | `reserved`       | `uint8_t`        | Reserved field for internal use by the Ark bytecode file.                          |
220
221
222#### FunctionKind
223
224| **Name**          | **Value**| **Description**  |
225| ------------------------ | ------------ | ---------------- |
226| `FUNCTION`                 | `0x1`          | Common function.      |
227| `NC_FUNCTION`              | `0x2`          | Common arrow function.  |
228| `GENERATOR_FUNCTION`       | `0x3`          | Generator function.    |
229| `ASYNC_FUNCTION`           | `0x4`          | Asynchronous function.      |
230| `ASYNC_GENERATOR_FUNCTION` | `0x5`          | Asynchronous generator function.|
231| `ASYNC_NC_FUNCTION`        | `0x6`          | Asynchronous arrow function.  |
232| `CONCURRENT_FUNCTION`      | `0x7`          | Concurrent function.      |
233
234
235### MethodTag
236
237| **Name**| **Value**| **Quantity**| **Format**| **Description**                                              |
238| -------------- | ------------ | -------------- | -------------- | ------------------------------------------------------------ |
239| `NOTHING`        | `0x00`         | `1`             | `none`           | Marks a [TaggedValue](#taggedvalue) as the final item in **method_data**.|
240| `CODE`           | `0x01`         | `0-1 `           | `uint32_t`       | **data** of a [TaggedValue](#taggedvalue) with this tag is an offset pointing to [Code](#code), indicating the code segment of the method.|
241| `SOURCE_LANG`    | `0x02`         | `0-1`            | `uint8_t`        | **data** of a [TaggedValue](#taggedvalue) with this tag is **0**, indicating that the source code language is in ArkTS, TS, or JS.|
242| `DEBUG_INFO`     | `0x05`         | `0-1`            | `uint32_t`       | **data** of a [TaggedValue](#taggedvalue) with this tag is an offset pointing to [DebugInfo](#debuginfo), indicating the debugging information of the method.|
243| `ANNOTATION`     | `0x06`         | `>=0`            | `uint32_t`       | **data** of a [TaggedValue](#taggedvalue) with this tag is an offset pointing to [Annotation](#annotation), indicating the annotation of the method.|
244
245**NOTE**<br>
246**MethodTag** is a marker of the element ([TaggedValue](#taggedvalue)) in **method_data**. **Quantity** in the table header refers to the number of occurrences of the element with this tag in **method_data** of a [method](#method).
247
248
249### Code
250
251- Alignment: single-byte aligned
252- Format
253
254| **Name**| **Format**| **Description**                                              |
255| -------------- | -------------- | ------------------------------------------------------------ |
256| `num_vregs`      | `uleb128`        | Number of registers. Registers that store input and default parameters are not counted.        |
257| `num_args`       | `uleb128`        | Total number of input and default parameters.                                    |
258| `code_size`      | `uleb128`        | Total size of all instructions, in bytes.                            |
259| `tries_size`     | `uleb128`        | Length of the **try_blocks** array, that is, the number of [TryBlocks](#tryblock).   |
260| `instructions`   | `uint8_t[]`      | Array of all instructions.                                          |
261| `try_blocks`     | `TryBlock[]`     | An array of **TryBlock** elements.|
262
263
264### TryBlock
265
266- Alignment: single-byte aligned
267- Format
268
269| **Name**| **Format**| **Description**                                              |
270| -------------- | -------------- | ------------------------------------------------------------ |
271| `start_pc`       | `uleb128`        | Offset between the first instruction of the **TryBlock** and the start position of the **instructions** in [Code](#code).|
272| `length`         | `uleb128`        | Size of the **TryBlock** object to create, in bytes.                              |
273| `num_catches`    | `uleb128`        | Number of [CatchBlocks](#catchblock) associated with **TryBlock**. The value is 1.|
274| `catch_blocks`   | `CatchBlock[]`   | Array of **CatchBlocks** associated with **TryBlock**. The array contains one **CatchBlock** that can capture all types of exceptions.|
275
276
277### CatchBlock
278
279- Alignment: single-byte aligned
280- Format
281
282| **Name**| **Format**| **Description**                                 |
283| -------------- | -------------- | ----------------------------------------------- |
284| `type_idx`       | `uleb128`        | If the value is **0**, the **CatchBlock** captures all types of exceptions.|
285| `handler_pc`     | `uleb128`        | Program counter of the first instruction for handling the exception.         |
286| `code_size`      | `uleb128`        | Size of the **CatchBlock**, in bytes.             |
287
288
289### Annotation
290Represents annotations in the bytecode file.
291
292- Alignment: single-byte aligned
293- Format
294
295| **Name**| **Format**     | **Description**                                              |
296| -------------- | ------------------- | ------------------------------------------------------------ |
297| `class_idx`      | `uint16_t`   | An index of the class to which the **Annotation** belongs. It points to a position in [ClassRegionIndex](#classregionindex). The value of the position is of the [Type](#type) type and is an offset pointing to [Class](#class).|
298| `count`          | `uint16_t`   | Length of the **elements** array.                                        |
299| `elements`       | AnnotationElement[] | An array of [AnnotationElement](#annotationelement) elements.|
300| `element_types`  | `uint8_t[]`  | An array, in which each element is of the [AnnotationElementTag](#annotationelementtag) type and is used to describe an **AnnotationElement.** The position of each element in the **element_types** array is the same as that of the corresponding **AnnotationElement** in the **elements** array.|
301
302**NOTE**<br>
303The offset of **Annotation** can be used to locate the appropriate **IndexHeader** for parsing **class_idx**.
304
305
306### AnnotationElementTag
307
308| **Name**| **Tag**|
309| -------------- | --------- |
310| `u1`             | `'1'`   |
311| `i8`             | `'2'`   |
312| `u8`             | `'3'`   |
313| `i16`            | `'4'`   |
314| `u16`            | `'5'`   |
315| `i32`            | `'6'`   |
316| `u32`            | `'7'`   |
317| `i64`            | `'8'`   |
318| `u64`            | `'9'`   |
319| `f32`            | `'A'`   |
320| `f64`            | `'B'`   |
321| `string`         | `'C'`   |
322| `method`         | `'E'`   |
323| `annotation`     | `'G'`   |
324| `literalarray`   | `'#'`   |
325| `unknown`        | `'0'`   |
326
327
328### AnnotationElement
329
330- Alignment: single-byte aligned
331- Format
332
333| **Name**| **Format**| **Description**                                              |
334| -------------- | -------------- | ------------------------------------------------------------ |
335| `name_off`       | `uint32_t`       | An offset to a [string](#string) representing the annotation element name.|
336| `value`          | `uint32_t`       | Value of the annotation element. If the width of the value is less than 32 bits, the value itself is stored here. Otherwise, the value stored here is an offset pointing to the [value formats](#value-formats).|
337
338
339### Value formats
340Different value types have different value encoding formats, including **INTEGER**, **LONG**, **FLOAT**, **DOUBLE**, and **ID**.
341
342| **Name**| **Format**| **Description**                                              |
343| -------------- | -------------- | ------------------------------------------------------------ |
344| `INTEGER`        | `uint32_t`       | 4-byte signed integer.                                      |
345| `LONG`           | `uint64_t`       | 8-byte signed integer.                                      |
346| `FLOAT`          | `uint32_t`       | 4-byte pattern that is zero-extended to the right. The system interprets this pattern as a 32-bit floating-point value in IEEE754 format.|
347| `DOUBLE`         | `uint64_t`       | 8-byte pattern that is zero-extended to the right. The system interprets this pattern as a 64-bit floating-point value in IEEE754 format.|
348| `ID`             | `uint32_t`       | 4-byte pattern that indicates the offset to another structure in the file.                  |
349
350
351### LineNumberProgramIndex
352An array that facilitates the use of a more compact index to access the [line number program](#line-number-program).
353
354- Alignment: 4-byte aligned
355- Format
356
357| **Name**| **Format**| **Description**                                              |
358| -------------- | -------------- | ------------------------------------------------------------ |
359| `offsets`        | `uint32_t[]`     | An array of offsets pointing to line number programs. The array length is specified by **num_lnps** in [Header](#header).|
360
361
362### DebugInfo
363Contains mappings between program counters of the method and the line/column numbers in the source code, as well as information about local variables. The format of the debugging information is derived from the contents in section 6.2 of [DWARF 3.0 Standard](https://dwarfstd.org/dwarf3std.html). The execution model of the [state machine](#state-machine) interprets the [line number program](#line-number-program) to obtain the mappings and local variable information code. To deduplicate programs with the same line number in different methods, all constants referenced in the programs are moved to the [constant pool](#constant-pool).
364
365- Alignment: single-byte aligned
366- Format
367
368| **Name**         | **Format**| **Description**                                              |
369| ----------------------- | -------------- | ------------------------------------------------------------ |
370| `line_start`              | `uleb128`        | Initial value of the line number register of the state machine.                                |
371| `num_parameters`          | `uleb128`        | Total number of input and default parameters.                                    |
372| `parameters`              | `uleb128[]`      | Array that stores the names of input parameters. The array length is specified by **num_parameters**. The value of each element is the offset to the string or **0**. If the value is **0**, the corresponding parameter does not have a name.|
373| `constant_pool_size`      | `uleb128`        | Size of the constant pool, in bytes.                                |
374| `constant_pool`           | `uleb128[]`      | Array for storing constant pool data. The array length is **constant_pool_size**.        |
375| `line_number_program_idx` | `uleb128`        | An index that points to a position in [LineNumberProgramIndex](#linenumberprogramindex). The value of this position is an offset pointing to [Line number program](#line-number-program). The length of **Line number program** is variable and ends with the **END_SEQUENCE** operation code.|
376
377
378#### Constant Pool
379A structure within **DebugInfo** for storing constants. Many methods have similar line number programs, differing only in variable names, variable types, and file names. To eliminate redundancy in these programs, all referenced constants are stored in the constant pool. During program interpretation, the state machine maintains a pointer to the constant pool. When interpreting an instruction that requires a constant parameter, the state machine reads the value from the position pointed to by the constant pool pointer and then increments the pointer.
380
381
382#### State Machine
383Generates [DebugInfo](#debuginfo) information. It contains the following registers.
384
385| **Name**   | **Initial Value**                                            | **Description**                                              |
386| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
387| `address`           | 0                                                            | Program counter (points to an instruction in the method), which can only increase monotonically.            |
388| `line`              | Value of **line_start** in [DebugInfo](#debuginfo)| Unsigned integer, corresponding to the line number in the source code. All lines are numbered from 1. Therefore, the register value cannot be less than **1**.|
389| `column`            | 0                                                            | Unsigned integer, corresponding to the column number in the source code.                              |
390| `file`              | Value of **SOURCE_FILE** in **class_data** (see [Class](#class)), or 0.| An offset to a [string](#string) representing the source file name. If there is no file name (no **SOURCE_FILE** tag in [Class](#class)), the register value is **0**.|
391| `source_code`       | 0                                                            | An offset to a [string](#string) representing the source code of the source file. If there is no source code information, the register value is **0**.|
392| `constant_pool_ptr` | Address of the first byte of the constant pool in [DebugInfo](#debuginfo).| Pointer to the current constant value.                                      |
393
394
395#### Line Number Program
396Consists of instructions, each containing a single-byte operation code and optional parameters. Depending on the operation code, the parameter values may be encoded within the instruction (called instruction parameters) or retrieved from the constant pool (called constant pool parameters).
397
398| **Operation Code** | **Value**| **Instruction Parameter**  | **Constant Pool Parameters**   | **Parameter Description**| **Description** |
399| ----- | ----- | ------- | ---- | ------- | ------ |
400| `END_SEQUENCE`         | `0x00`  |       |          |        | Marks the end of the line number program.   |
401| `ADVANCE_PC`           | `0x01`  |    | `uleb128 addr_diff`   | **addr_diff**: value to increment the **address** register.   | Increments the **address** register by **addr_diff** to point to the next address, without generating a location entry.|
402| `ADVANCE_LINE`         | `0x02` |     | `sleb128 line_diff`  | **line_diff**: value to increment the **line** register.   | Increments the **line** register by **line_diff** to point to the next line position, without generating a location entry.|
403| `START_LOCAL`          | `0x03` | `sleb128 register_num` | `uleb128 name_idx`<br>`uleb128 type_idx`   | **register_num**: register containing the local variable.<br>**name_idx**: an offset to a [string](#string) representing the variable name.<br>**type_idx**: an offset to a [string](#string) representing the variable type.| Introduces a local variable with a name and type at the current address. The number of the register that will contain this variable is encoded in the instruction. If **register_num** is **-1**, it indicates an accumulator register. The values of **name_idx** and **type_idx** may be **0**, indicating no such information.|
404| `START_LOCAL_EXTENDED` | `0x04` | `sleb128 register_num` | `uleb128 name_idx`<br>`uleb128 type_idx`<br>`uleb128 sig_idx` | **register_num**: register containing the local variable.<br>**name_idx**: an offset to a [string](#string) representing the variable name.<br>**type_idx**: an offset to a [string](#string) representing the variable type.<br>**sig_idx**: an offset to a [string](#string) representing the variable signature.| Introduces a local variable with a name, type, and signature at the current address. The number of the register that will contain this variable is encoded in the instruction. If **register_num** is **-1**, it indicates an accumulator register. The values of **name_idx**, **type_idx**, and **sig_idx** may be **0**, indicating no such information.|
405| `END_LOCAL`            | `0x05` | `sleb128 register_num` |    | **register_num**: register containing the local variable. | Marks the local variable in the specified register as out of scope at the current address. If **register_num** is **-1**, it indicates an accumulator register.|
406| `SET_FILE`             | `0x09`  |    | `uleb128 name_idx`  | **name_idx**: an offset to a [string](#string) representing the file name.| Sets the value of the file register. The value of **name_idx** may be **0**, indicating no such information.|
407| `SET_SOURCE_CODE`      | `0x0a`  |    | `uleb128 source_idx` | **source_idx**: an offset to a [string](#string) representing the source code of the file.| Sets the value of the **source_code** register. The value of **source_idx** may be **0**, indicating no such information.|
408| `SET_COLUMN`           | `0x0b` |    | `uleb128 column_num`   | **column_num**: column number to be set.  | Sets the value of the **column** register and generates a location entry. |
409| Special operation code          | `0x0c..0xff`   |   |  |   | Adjusts the **line** and **address** registers to the next address and generate a location entry. Details are described below.|
410
411
412For special operation codes in the range **0x0c** to **0xff** (included), the state machine performs the following steps to adjust the **line** and **address** registers and then generates a new location entry. For details, see section 6.2.5.1 "Special Opcodes" in [DWARF 3.0 Standard](https://dwarfstd.org/dwarf3std.html).
413
414| **Step**| **Operation**                                    | **Description**                                              |
415| ----- | -------------------------------------------------- | ------------------------------------------------------------ |
416| 1     | `adjusted_opcode = opcode - OPCODE_BASE`            | Calculates the adjusted operation code. The value of **OPCODE_BASE** is **0x0c**, which is the first special operation code.|
417| 2     | `address += adjusted_opcode / LINE_RANGE`            | Increments the **address** register. The value of **LINE_RANGE** is 15, which is used to calculate changes in the line number information.|
418| 3     | `line += LINE_BASE + (adjusted_opcode % LINE_RANGE)` | Increments the **line** register. The value of **LINE_BASE** is **-4**, which is the minimum line number increment. The maximum increment is **LINE_BASE + LINE_RANGE - 1**.|
419| 4     |                                                    | Generates a new location entry.                                      |
420
421**NOTE**<br>
422Special operation codes are calculated by using the following formula: **(line_increment - LINE_BASE) + (address_increment * LINE_RANGE) + OPCODE_BASE**.
423
424
425### IndexSection
426Generally, bytecode files use 32-bit offsets for referencing structures. When a structure references another structure, the current structure records a 32-bit offset of the referenced structure. To optimize file size, the bytecode file is segmented into index regions that use 16-bit indices instead of 32-bit offsets. The **IndexSection** structure provides an overview of these regions.
427
428- Alignment: 4-byte aligned
429- Format
430
431| **Name**| **Format**| **Description**      |
432| -------------- | -------------- | --------- |
433| `headers`        | `IndexHeader[]`  | An array of [IndexHeader](#indexheader) elements. Elements in the array are sorted based on the start offset of the region. The array length is specified by **num_index_regions** in [Header](#header).|
434
435
436### IndexHeader
437Represents an index region. Each index region has two types of indexes: indexes pointing to [Type](#type) and indexes pointing to methods, strings, or literal arrays.
438
439- Alignment: 4-byte aligned
440- Format
441
442| **Name**       | **Format**| **Description**   |
443| -------------- | -------------- | ---------- |
444| `start_off`                             | `uint32_t`       | Start offset of the region.                                        |
445| `end_off`                               | `uint32_t`       | End offset of the region.                                        |
446| `class_region_idx_size`                 | `uint32_t`       | Number of elements in [ClassRegionIndex](#classregionindex) of the region. The maximum value is **65536**.|
447| `class_region_idx_off`                  | `uint32_t`       | An offset to [ClassRegionIndex](#classregionindex).|
448| `method_string_literal_region_idx_size` | `uint32_t`       | Number of elements in [MethodStringLiteralRegionIndex](#methodstringliteralregionindex) of the region. The maximum value is **65536**.|
449| `method_string_literal_region_idx_off`  | `uint32_t`       | An offset to [MethodStringLiteralRegionIndex](#methodstringliteralregionindex).|
450| `reserved`                              | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
451| `reserved`                              | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
452| `reserved`                              | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
453| `reserved`                              | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
454
455
456### ClassRegionIndex
457Provides compact indexing for locating [Type](#type) entries.
458
459- Alignment: 4-byte aligned
460- Format
461
462| **Name**| **Format**| **Description**                                              |
463| -------------- | -------------- | ------------------------------------------------------------ |
464| `types`          | `Type[]`         | An array of [Type](#type) elements. The array length is specified by **class_region_idx_size** in [IndexHeader](#indexheader).|
465
466
467### Type
468A 32-bit value representing either a basic type encoding or an offset to a [class](#class).
469
470Basic type encodings are listed below.
471
472| **Type**      | **Encoding**       |
473| -------------- | -------------- |
474| `u1`           | `0x00`         |
475| `i8`           | `0x01`         |
476| `u8`           | `0x02`         |
477| `i16`          | `0x03`         |
478| `u16`          | `0x04`         |
479| `i32`          | `0x05`         |
480| `u32`          | `0x06`         |
481| `f32`          | `0x07`         |
482| `f64`          | `0x08`         |
483| `i64`          | `0x09`         |
484| `u64`          | `0x0a`         |
485| `any`          | `0x0c`         |
486
487
488### MethodStringLiteralRegionIndex
489Provides compact indexing for methods, strings, or literal arrays.
490
491- Alignment: 4-byte aligned
492- Format
493
494| **Name**| **Format**| **Description**                                              |
495| -------------- | -------------- | ------------------------------------------------------------ |
496| `offsets`      | `uint32_t[]`   | An array of offsets to methods, strings, or literal arrays. The array length is specified by **method_string_literal_region_idx_size** in [IndexHeader](#indexheader).|
497
498
499### LiteralArray
500Describes a literal array in the bytecode file.
501
502- Alignment: single-byte aligned
503- Format
504
505| **Name**| **Format**| **Description**                                              |
506| -------------- | -------------- | ------------------------------------------------------------ |
507| `num_literals`   | `uint32_t`       | Length of the **literals** array.                                        |
508| `literals`       | `Literal[]`      | An array of [Literal](#literal) elements.|
509
510
511### Literal
512Describes literals in the bytecode file. There are four encoding formats based on the number of bytes of the literals.
513
514| **Name**| **Format**| **Alignment**| **Description**|
515| -------------- | -------------- | ------------------ | -------------- |
516| ByteOne        | `uint8_t`        | 1 byte           | Single-byte value.  |
517| ByteTwo        | `uint16_t`       | 2 bytes           | Double-byte value.  |
518| ByteFour       | `uint32_t`       | 4 bytes           | Four-byte value.  |
519| ByteEight      | `uint64_t`       | 8 bytes           | Eight-byte value.  |
520