• 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
24- Alignment: single-byte aligned
25- Format
26
27| **Name**| **Format**| **Description**                                              |
28| -------------- | -------------- | ------------------------------------------------------------ |
29| `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**).|
30| `data`           | `uint8_t[]` | Null-terminated sequence of characters encoded in MUTF-8 format. |
31
32
33### TaggedValue
34
35- Alignment: single-byte aligned
36- Format
37
38| **Name**| **Format**| **Description**                               |
39| -------------- | -------------- | -------------------------------------------- |
40| `tag`          | `uint8_t`      | Marker indicating the type of data.                          |
41| `data`         | `uint8_t[]`    | Data content. Its type is determined by the tag, and it may be empty.|
42
43
44## TypeDescriptor
45Represents [class](#class) names in the format of **L_ClassName;**, where **ClassName** is the fully qualified name, in which **'.'** is replaced with **'/'**.
46
47
48## Bytecode File Layout
49The 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).
50
51All multi-byte values in bytecode files are stored in little-endian format.
52
53
54### Header
55
56- Alignment: single-byte aligned
57- Format
58
59| **Name**   | **Format**| **Description**                                              |
60| ----------------- | -------------- | ------------------------------------------------------------ |
61| `magic`             | `uint8_t[8]`     | Magic number of the file header. Its value must be **'P' 'A' 'N' 'D' 'A' '\0' '\0' '\0'**.   |
62| `checksum`          | `uint32_t`       | **Adler32** checksum of the content in the bytecode file, excluding the magic number and this checksum field.|
63| `version`           | `uint8_t[4]`     | [Version](#version) of the bytecode file.|
64| `file_size`         | `uint32_t`       | Size of the bytecode file, in bytes.                            |
65| `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.|
66| `foreign_size`      | `uint32_t`       | Size of the foreign region, in bytes.                              |
67| `num_classes`       | `uint32_t`       | Number of elements in the [ClassIndex](#classindex) structure, that is, the number of [classes](#class) defined in the file.|
68| `class_idx_off`     | `uint32_t`       | An offset that points to [ClassIndex](#classindex).|
69| `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.|
70| `lnp_idx_off`       | `uint32_t`       | An offset that points to [LineNumberProgramIndex](#linenumberprogramindex).|
71| `reserved`          | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
72| `reserved`          | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
73| `num_index_regions` | `uint32_t`       | Number of elements in the [IndexSection](#indexsection) structure, that is, the number of [IndexHeaders](#indexheader) in the file.|
74| `index_section_off` | `uint32_t`       | An offset that points to [IndexSection](#indexsection).|
75
76
77### Version
78The bytecode version number consists of four parts in the format of major.minor.feature.build.
79
80| **Name**| **Format**| **Description**                                            |
81| -------------- | -------------- | ---------------------------------------------------------- |
82| Major      | `uint8_t`        | Indicates significant architectural changes.                |
83| Minor      | `uint8_t`        | Indicates changes in local architecture or major features.|
84| Feature    | `uint8_t`        | Indicates changes due to minor features.                    |
85| Build    | `uint8_t`        | Indicates changes due to bug fixes.                    |
86
87
88### ForeignClass
89Represents foreign classes referenced in the bytecode file but declared in other files.
90
91- Alignment: single-byte aligned
92- Format
93
94| **Name**| **Format**| **Description**                                              |
95| -------------- | -------------- | ------------------------------------------------------------ |
96| `name`           | `String`         | Foreign class name, which follows the [TypeDescriptor](#typedescriptor) syntax.|
97
98
99### ForeignMethod
100Represents foreign methods referenced in the bytecode file but declared in other files.
101
102- Alignment: single-byte aligned
103- Format
104
105| **Name**| **Format**| **Description**                                              |
106| -------------- | -------------- | ------------------------------------------------------------ |
107| `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).|
108| `reserved`       | `uint16_t`       | Reserved field for internal use by the Ark bytecode file.              |
109| `name_off`       | `uint32_t`       | An offset to a [string](#string) representing the method name.|
110| `index_data`     | `uleb128`        | [MethodIndexData](#methodindexdata) data of the method.|
111
112> **NOTE**
113>
114> The offset of **ForeignMethod** can be used to locate the appropriate **IndexHeader** for parsing **class_idx**.
115
116
117### ClassIndex
118Facilitates quick lookup of class definitions by name.
119
120- Alignment: 4-byte aligned
121- Format
122
123| **Name**| **Format**| **Description**                                              |
124| -------------- | -------------- | ------------------------------------------------------------ |
125| `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).|
126
127
128### Class
129Represents 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.
130
131- Alignment: single-byte aligned
132- Format
133
134| **Name**| **Format**| **Description**                                              |
135| -------------- | -------------- | ------------------------------------------------------------ |
136| `name`           | `String`         | Class name, which follows the [TypeDescriptor](#typedescriptor) syntax.|
137| `reserved`       | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
138| `access_flags`   | `uleb128`        | Tags to access the class, which is a combination of [ClassAccessFlags](#classaccessflag).|
139| `num_fields`     | `uleb128`        | Number of fields in the class.                                         |
140| `num_methods`    | `uleb128`        | Number of methods in the class.                                         |
141| `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).|
142| `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**.|
143| `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**.|
144
145
146### ClassAccessFlag
147
148| **Name**| **Value**| **Description**                                              |
149| -------------- | ------------ | ------------------------------------------------------------ |
150| `ACC_PUBLIC`     | `0x0001`       | Default attribute. All [classes](#class) in the Ark bytecode file have this tag.|
151| `ACC_ANNOTATION` | `0x2000`       | Declares this class as the [Annotation](#annotation) type.|
152
153
154### ClassTag
155
156- Alignment: single-byte aligned
157- Format
158
159| **Name**| **Value**| **Quantity**| **Format**| **Description**                                              |
160| -------------- | ------------ | -------------- | -------------- | ------------------------------------------------------------ |
161| `NOTHING`        | `0x00`  | `1`  | `none`    | Marks a [TaggedValue](#taggedvalue) as the final item in **class_data**.|
162| `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.|
163| `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.|
164
165> **NOTE**
166>
167> **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).
168
169
170### Field
171Represents fields within the bytecode file.
172
173- Alignment: single-byte aligned
174- Format
175
176| **Name**| **Format**| **Description**                                              |
177| -------------- | -------------- | ------------------------------------------------------------ |
178| `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).|
179| `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.|
180| `name_off`       | `uint32_t`       | An offset to a [string](#string) representing the field name.|
181| `reserved`       | `uleb128`        | Reserved field for internal use by the Ark bytecode file.                          |
182| `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).|
183
184> **NOTE**
185>
186> The offset of **Field** can be used to locate the appropriate **IndexHeader** for parsing **class_idx** and **type_idx**.
187
188
189### FieldTag
190
191- Alignment: single-byte aligned
192- Format
193
194| **Name**| **Value**| **Quantity**| **Format**| **Description** |
195| -------------- | ------------ | -------------- | -------------- | ------------------------------------------------------------ |
196| `NOTHING`        | `0x00`   | `1`   | `none`     | Marks a [TaggedValue](#taggedvalue) as the final item in **field_data**.|
197| `INT_VALUE`      | `0x01`   | `0-1` | `sleb128`  | The **data** type of a [TaggedValue](#taggedvalue) with this tag is of **boolean**, **byte**, **char**, **short**, or **int**.|
198| `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).|
199
200> **NOTE**
201>
202> **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).
203
204
205### Method
206Represents methods within the bytecode file.
207
208- Alignment: single-byte aligned
209- Format
210
211| **Name**| **Format**| **Description**                                              |
212| -------------- | -------------- | ------------------------------------------------------------ |
213| `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).|
214| `reserved`       | `uint16_t`       | Reserved field for internal use by the Ark bytecode file.                          |
215| `name_off`       | `uint32_t`       | An offset to a [string](#string) representing the method name.|
216| `index_data`     | `uleb128`        | [MethodIndexData](#methodindexdata) data of the method.|
217| `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).|
218
219> **NOTE**
220>
221> The offset of **Method** can be used to locate the appropriate **IndexHeader** for parsing **class_idx**.
222
223
224### MethodIndexData
225A 32-bit unsigned integer, divided into three parts.
226
227| **Bit**| **Name**| **Format**| **Description**                                              |
228| ------------ | -------------- | -------------- | ------------------------------------------------------------ |
229| 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.|
230| 16 - 23      | `function_kind`  | `uint8_t`        | Function type ([FunctionKind](#functionkind)) of a method.|
231| 24 - 31      | `reserved`       | `uint8_t`        | Reserved field for internal use by the Ark bytecode file.                          |
232
233
234#### FunctionKind
235
236| **Name**          | **Value**| **Description**  |
237| ------------------------ | ------------ | ---------------- |
238| `FUNCTION`                 | `0x1`          | Common function.      |
239| `NC_FUNCTION`              | `0x2`          | Common arrow function.  |
240| `GENERATOR_FUNCTION`       | `0x3`          | Generator function.    |
241| `ASYNC_FUNCTION`           | `0x4`          | Asynchronous function.      |
242| `ASYNC_GENERATOR_FUNCTION` | `0x5`          | Asynchronous generator function.|
243| `ASYNC_NC_FUNCTION`        | `0x6`          | Asynchronous arrow function.  |
244| `CONCURRENT_FUNCTION`      | `0x7`          | Concurrent function.      |
245
246
247### MethodTag
248
249| **Name**| **Value**| **Quantity**| **Format**| **Description**                                              |
250| -------------- | ------------ | -------------- | -------------- | ------------------------------------------------------------ |
251| `NOTHING`        | `0x00`         | `1`             | `none`           | Marks a [TaggedValue](#taggedvalue) as the final item in **method_data**.|
252| `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.|
253| `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.|
254| `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.|
255| `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.|
256
257> **NOTE**
258>
259> **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).
260
261
262### Code
263
264- Alignment: single-byte aligned
265- Format
266
267| **Name**| **Format**| **Description**                                              |
268| -------------- | -------------- | ------------------------------------------------------------ |
269| `num_vregs`      | `uleb128`        | Number of registers. Registers that store input and default parameters are not counted.        |
270| `num_args`       | `uleb128`        | Total number of input and default parameters.                                    |
271| `code_size`      | `uleb128`        | Total size of all instructions, in bytes.                            |
272| `tries_size`     | `uleb128`        | Length of the **try_blocks** array, that is, the number of [TryBlocks](#tryblock).   |
273| `instructions`   | `uint8_t[]`      | Array of all instructions.                                          |
274| `try_blocks`     | `TryBlock[]`     | An array of **TryBlock** elements.|
275
276
277### TryBlock
278
279- Alignment: single-byte aligned
280- Format
281
282| **Name**| **Format**| **Description**                                              |
283| -------------- | -------------- | ------------------------------------------------------------ |
284| `start_pc`       | `uleb128`        | Offset between the first instruction of the **TryBlock** and the start position of the **instructions** in [Code](#code).|
285| `length`         | `uleb128`        | Size of the **TryBlock** object to create, in bytes.                              |
286| `num_catches`    | `uleb128`        | Number of [CatchBlocks](#catchblock) associated with **TryBlock**. The value is 1.|
287| `catch_blocks`   | `CatchBlock[]`   | Array of **CatchBlocks** associated with **TryBlock**. The array contains one **CatchBlock** that can capture all types of exceptions.|
288
289
290### CatchBlock
291
292- Alignment: single-byte aligned
293- Format
294
295| **Name**| **Format**| **Description**                                 |
296| -------------- | -------------- | ----------------------------------------------- |
297| `type_idx`       | `uleb128`        | If the value is **0**, the **CatchBlock** captures all types of exceptions.|
298| `handler_pc`     | `uleb128`        | Program counter of the first instruction for handling the exception.         |
299| `code_size`      | `uleb128`        | Size of the **CatchBlock**, in bytes.             |
300
301
302### Annotation
303Represents annotations in the bytecode file.
304
305- Alignment: single-byte aligned
306- Format
307
308| **Name**| **Format**     | **Description**                                              |
309| -------------- | ------------------- | ------------------------------------------------------------ |
310| `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).|
311| `count`          | `uint16_t`   | Length of the **elements** array.                                        |
312| `elements`       | AnnotationElement[] | An array of [AnnotationElement](#annotationelement) elements.|
313| `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.|
314
315> **NOTE**
316>
317> The offset of **Annotation** can be used to locate the appropriate **IndexHeader** for parsing **class_idx**.
318
319
320### AnnotationElementTag
321
322| **Name**| **Tag**|
323| -------------- | --------- |
324| `u1`             | `'1'`   |
325| `i8`             | `'2'`   |
326| `u8`             | `'3'`   |
327| `i16`            | `'4'`   |
328| `u16`            | `'5'`   |
329| `i32`            | `'6'`   |
330| `u32`            | `'7'`   |
331| `i64`            | `'8'`   |
332| `u64`            | `'9'`   |
333| `f32`            | `'A'`   |
334| `f64`            | `'B'`   |
335| `string`         | `'C'`   |
336| `method`         | `'E'`   |
337| `annotation`     | `'G'`   |
338| `literalarray`   | `'#'`   |
339| `unknown`        | `'0'`   |
340
341
342### AnnotationElement
343
344- Alignment: single-byte aligned
345- Format
346
347| **Name**| **Format**| **Description**                                              |
348| -------------- | -------------- | ------------------------------------------------------------ |
349| `name_off`       | `uint32_t`       | An offset to a [string](#string) representing the annotation element name.|
350| `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).|
351
352
353### Value formats
354Different value types have different value encoding formats, including **INTEGER**, **LONG**, **FLOAT**, **DOUBLE**, and **ID**.
355
356| **Name**| **Format**| **Description**                                              |
357| -------------- | -------------- | ------------------------------------------------------------ |
358| `INTEGER`        | `uint32_t`       | 4-byte signed integer.                                      |
359| `LONG`           | `uint64_t`       | 8-byte signed integer.                                      |
360| `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.|
361| `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.|
362| `ID`             | `uint32_t`       | 4-byte pattern that indicates the offset to another structure in the file.                  |
363
364
365### LineNumberProgramIndex
366An array that facilitates the use of a more compact index to access the [line number program](#line-number-program).
367
368- Alignment: 4-byte aligned
369- Format
370
371| **Name**| **Format**| **Description**                                              |
372| -------------- | -------------- | ------------------------------------------------------------ |
373| `offsets`        | `uint32_t[]`     | An array of offsets pointing to line number programs. The array length is specified by **num_lnps** in [Header](#header).|
374
375
376### DebugInfo
377Contains 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).
378
379- Alignment: single-byte aligned
380- Format
381
382| **Name**         | **Format**| **Description**                                              |
383| ----------------------- | -------------- | ------------------------------------------------------------ |
384| `line_start`              | `uleb128`        | Initial value of the line number register of the state machine.                                |
385| `num_parameters`          | `uleb128`        | Total number of input and default parameters.                                    |
386| `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.|
387| `constant_pool_size`      | `uleb128`        | Size of the constant pool, in bytes.                                |
388| `constant_pool`           | `uleb128[]`      | Array for storing constant pool data. The array length is **constant_pool_size**.        |
389| `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.|
390
391
392#### Constant Pool
393A 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.
394
395
396#### State Machine
397Generates [DebugInfo](#debuginfo) information. It contains the following registers.
398
399| **Name**   | **Initial Value**                                            | **Description**                                              |
400| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
401| `address`           | 0                                                            | Program counter (points to an instruction in the method), which can only increase monotonically.            |
402| `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**.|
403| `column`            | 0                                                            | Unsigned integer, corresponding to the column number in the source code.                              |
404| `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**.|
405| `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**.|
406| `constant_pool_ptr` | Address of the first byte of the constant pool in [DebugInfo](#debuginfo).| Pointer to the current constant value.                                      |
407
408
409#### Line Number Program
410Consists 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).
411
412| **Operation Code** | **Value**| **Instruction Parameter**  | **Constant Pool Parameters**   | **Parameter Description**| **Description** |
413| ----- | ----- | ------- | ---- | ------- | ------ |
414| `END_SEQUENCE`         | `0x00`  |       |          |        | Marks the end of the line number program.   |
415| `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.|
416| `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.|
417| `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.|
418| `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.|
419| `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.|
420| `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.|
421| `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.|
422| `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. |
423| Special operation code          | `0x0c..0xff`   |   |  |   | Adjusts the **line** and **address** registers to the next address and generate a location entry. Details are described below.|
424
425
426For 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).
427
428| **Step**| **Operation**                                    | **Description**                                              |
429| ----- | -------------------------------------------------- | ------------------------------------------------------------ |
430| 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.|
431| 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.|
432| 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**.|
433| 4     |                                                    | Generates a new location entry.                                      |
434
435> **NOTE**
436>
437> Special operation codes are calculated by using the following formula: (line_increment - LINE_BASE) + (address_increment * LINE_RANGE) + OPCODE_BASE.
438
439
440### IndexSection
441Generally, 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.
442
443- Alignment: 4-byte aligned
444- Format
445
446| **Name**| **Format**| **Description**      |
447| -------------- | -------------- | --------- |
448| `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).|
449
450
451### IndexHeader
452Represents 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.
453
454- Alignment: 4-byte aligned
455- Format
456
457| **Name**       | **Format**| **Description**   |
458| -------------- | -------------- | ---------- |
459| `start_off`                             | `uint32_t`       | Start offset of the region.                                        |
460| `end_off`                               | `uint32_t`       | End offset of the region.                                        |
461| `class_region_idx_size`                 | `uint32_t`       | Number of elements in [ClassRegionIndex](#classregionindex) of the region. The maximum value is **65536**.|
462| `class_region_idx_off`                  | `uint32_t`       | An offset to [ClassRegionIndex](#classregionindex).|
463| `method_string_literal_region_idx_size` | `uint32_t`       | Number of elements in [MethodStringLiteralRegionIndex](#methodstringliteralregionindex) of the region. The maximum value is **65536**.|
464| `method_string_literal_region_idx_off`  | `uint32_t`       | An offset to [MethodStringLiteralRegionIndex](#methodstringliteralregionindex).|
465| `reserved`                              | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
466| `reserved`                              | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
467| `reserved`                              | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
468| `reserved`                              | `uint32_t`       | Reserved field for internal use by the Ark bytecode file.                          |
469
470
471### ClassRegionIndex
472Provides compact indexing for locating [Type](#type) entries.
473
474- Alignment: 4-byte aligned
475- Format
476
477| **Name**| **Format**| **Description**                                              |
478| -------------- | -------------- | ------------------------------------------------------------ |
479| `types`          | `Type[]`         | An array of [Type](#type) elements. The array length is specified by **class_region_idx_size** in [IndexHeader](#indexheader).|
480
481
482### Type
483A 32-bit value representing either a basic type encoding or an offset to a [class](#class).
484
485Basic type encodings are listed below.
486
487| **Type**      | **Encoding**       |
488| -------------- | -------------- |
489| `u1`           | `0x00`         |
490| `i8`           | `0x01`         |
491| `u8`           | `0x02`         |
492| `i16`          | `0x03`         |
493| `u16`          | `0x04`         |
494| `i32`          | `0x05`         |
495| `u32`          | `0x06`         |
496| `f32`          | `0x07`         |
497| `f64`          | `0x08`         |
498| `i64`          | `0x09`         |
499| `u64`          | `0x0a`         |
500| `any`          | `0x0c`         |
501
502
503### MethodStringLiteralRegionIndex
504Provides compact indexing for methods, strings, or literal arrays.
505
506- Alignment: 4-byte aligned
507- Format
508
509| **Name**| **Format**| **Description**                                              |
510| -------------- | -------------- | ------------------------------------------------------------ |
511| `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).|
512
513
514### LiteralArray
515Describes a literal array in the bytecode file.
516
517- Alignment: single-byte aligned
518- Format
519
520| **Name**| **Format**| **Description**                                              |
521| -------------- | -------------- | ------------------------------------------------------------ |
522| `num_literals`   | `uint32_t`       | Length of the **literals** array.                                        |
523| `literals`       | `Literal[]`      | An array of [Literal](#literal) elements.|
524
525
526### Literal
527Describes literals in the bytecode file. There are four encoding formats based on the number of bytes of the literals.
528
529| **Name**| **Format**| **Alignment**| **Description**|
530| -------------- | -------------- | ------------------ | -------------- |
531| ByteOne        | `uint8_t`        | 1 byte           | Single-byte value.  |
532| ByteTwo        | `uint16_t`       | 2 bytes           | Double-byte value.  |
533| ByteFour       | `uint32_t`       | 4 bytes           | Four-byte value.  |
534| ByteEight      | `uint64_t`       | 8 bytes           | Eight-byte value.  |
535