1425bb815Sopenharmony_ci# High-Level Design 2425bb815Sopenharmony_ci 3425bb815Sopenharmony_ci 4425bb815Sopenharmony_ciThe diagram above shows the interactions between the major components of JerryScript: Parser and Virtual Machine (VM). Parser performs translation of input ECMAScript application into the byte-code with the specified format (refer to [Bytecode](#byte-code) and [Parser](#parser) page for details). Prepared bytecode is executed by the Virtual Machine that performs interpretation (refer to [Virtual Machine](#virtual-machine) and [ECMA](#ecma) pages for details). 5425bb815Sopenharmony_ci 6425bb815Sopenharmony_ci# Parser 7425bb815Sopenharmony_ci 8425bb815Sopenharmony_ciThe parser is implemented as a recursive descent parser. The parser converts the JavaScript source code directly into byte-code without building an Abstract Syntax Tree. The parser depends on the following subcomponents. 9425bb815Sopenharmony_ci 10425bb815Sopenharmony_ci## Lexer 11425bb815Sopenharmony_ci 12425bb815Sopenharmony_ciThe lexer splits input string (ECMAScript program) into sequence of tokens. It is able to scan the input string not only forward, but it is possible to move to an arbitrary position. The token structure described by structure `lexer_token_t` in `./jerry-core/parser/js/js-lexer.h`. 13425bb815Sopenharmony_ci 14425bb815Sopenharmony_ci## Scanner 15425bb815Sopenharmony_ci 16425bb815Sopenharmony_ciScanner (`./jerry-core/parser/js/js-parser-scanner.c`) pre-scans the input string to find certain tokens. For example, scanner determines whether the keyword `for` defines a general for or a for-in loop. Reading tokens in a while loop is not enough because a slash (`/`) can indicate the start of a regular expression or can be a division operator. 17425bb815Sopenharmony_ci 18425bb815Sopenharmony_ci## Expression Parser 19425bb815Sopenharmony_ci 20425bb815Sopenharmony_ciExpression parser is responsible for parsing JavaScript expressions. It is implemented in `./jerry-core/parser/js/js-parser-expr.c`. 21425bb815Sopenharmony_ci 22425bb815Sopenharmony_ci## Statement Parser 23425bb815Sopenharmony_ci 24425bb815Sopenharmony_ciJavaScript statements are parsed by this component. It uses the [Expression parser](#expression-parser) to parse the constituent expressions. The implementation of Statement parser is located in `./jerry-core/parser/js/js-parser-statm.c`. 25425bb815Sopenharmony_ci 26425bb815Sopenharmony_ciFunction `parser_parse_source` carries out the parsing and compiling of the input ECMAScript source code. When a function appears in the source `parser_parse_source` calls `parser_parse_function` which is responsible for processing the source code of functions recursively including argument parsing and context handling. After the parsing, function `parser_post_processing` dumps the created opcodes and returns an `ecma_compiled_code_t*` that points to the compiled bytecode sequence. 27425bb815Sopenharmony_ci 28425bb815Sopenharmony_ciThe interactions between the major components shown on the following figure. 29425bb815Sopenharmony_ci 30425bb815Sopenharmony_ci 31425bb815Sopenharmony_ci 32425bb815Sopenharmony_ci# Byte-code 33425bb815Sopenharmony_ci 34425bb815Sopenharmony_ciThis section describes the compact byte-code (CBC) representation. The key focus is reducing memory consumption of the byte-code representation without sacrificing considerable performance. Other byte-code representations often focus on performance only so inventing this representation is an original research. 35425bb815Sopenharmony_ci 36425bb815Sopenharmony_ciCBC is a CISC like instruction set which assigns shorter instructions for frequent operations. Many instructions represent multiple atomic tasks which reduces the bytecode size. This technique is basically a data compression method. 37425bb815Sopenharmony_ci 38425bb815Sopenharmony_ci## Compiled Code Format 39425bb815Sopenharmony_ci 40425bb815Sopenharmony_ciThe memory layout of the compiled bytecode is the following. 41425bb815Sopenharmony_ci 42425bb815Sopenharmony_ci 43425bb815Sopenharmony_ci 44425bb815Sopenharmony_ciThe header is a `cbc_compiled_code` structure with several fields. These fields contain the key properties of the compiled code. 45425bb815Sopenharmony_ci 46425bb815Sopenharmony_ciThe literals part is an array of ecma values. These values can contain any ECMAScript value types, e.g. strings, numbers, functions and regexp templates. The number of literals is stored in the `literal_end` field of the header. 47425bb815Sopenharmony_ci 48425bb815Sopenharmony_ciCBC instruction list is a sequence of bytecode instructions which represents the compiled code. 49425bb815Sopenharmony_ci 50425bb815Sopenharmony_ci## Byte-code Format 51425bb815Sopenharmony_ci 52425bb815Sopenharmony_ciThe memory layout of a byte-code is the following: 53425bb815Sopenharmony_ci 54425bb815Sopenharmony_ci 55425bb815Sopenharmony_ci 56425bb815Sopenharmony_ciEach byte-code starts with an opcode. The opcode is one byte long for frequent and two byte long for rare instructions. The first byte of the rare instructions is always zero (`CBC_EXT_OPCODE`), and the second byte represents the extended opcode. The name of common and rare instructions start with `CBC_` and `CBC_EXT_` prefix respectively. 57425bb815Sopenharmony_ci 58425bb815Sopenharmony_ciThe maximum number of opcodes is 511, since 255 common (zero value excluded) and 256 rare instructions can be defined. Currently around 215 frequent and 70 rare instructions are available. 59425bb815Sopenharmony_ci 60425bb815Sopenharmony_ciThere are three types of bytecode arguments in CBC: 61425bb815Sopenharmony_ci 62425bb815Sopenharmony_ci * __byte argument__: A value between 0 and 255, which often represents the argument count of call like opcodes (function call, new, eval, etc.). 63425bb815Sopenharmony_ci 64425bb815Sopenharmony_ci * __literal argument__: An integer index which is greater or equal than zero and less than the `literal_end` field of the header. For further information see next section Literals (next). 65425bb815Sopenharmony_ci 66425bb815Sopenharmony_ci * __relative branch__: An 1-3 byte long offset. The branch argument might also represent the end of an instruction range. For example the branch argument of `CBC_EXT_WITH_CREATE_CONTEXT` shows the end of a `with` statement. More precisely the position after the last instruction in the with clause. 67425bb815Sopenharmony_ci 68425bb815Sopenharmony_ciArgument combinations are limited to the following seven forms: 69425bb815Sopenharmony_ci 70425bb815Sopenharmony_ci* no arguments 71425bb815Sopenharmony_ci* a literal argument 72425bb815Sopenharmony_ci* a byte argument 73425bb815Sopenharmony_ci* a branch argument 74425bb815Sopenharmony_ci* a byte and a literal arguments 75425bb815Sopenharmony_ci* two literal arguments 76425bb815Sopenharmony_ci* three literal arguments 77425bb815Sopenharmony_ci 78425bb815Sopenharmony_ci## Literals 79425bb815Sopenharmony_ci 80425bb815Sopenharmony_ciLiterals are organized into groups whose represent various literal types. Having these groups consuming less space than assigning flag bits to each literal. 81425bb815Sopenharmony_ci(In the followings, the mentioned ranges represent those indicies which are greater than or equal to the left side and less than the right side of the range. For example a range between `ident_end` and `literal_end` fields of the byte-code header contains those indicies, which are greater than or equal to `ident_end` 82425bb815Sopenharmony_ciand less than `literal_end`. If `ident_end` equals to `literal_end` the range is empty.) 83425bb815Sopenharmony_ci 84425bb815Sopenharmony_ciThe two major group of literals are _identifiers_ and _values_. 85425bb815Sopenharmony_ci 86425bb815Sopenharmony_ci * __identifier__: A named reference to a variable. Literals between zero and `ident_end` of the header belongs to here. All of these literals must be a string or undefined. Undefined can only be used for those literals which cannot be accessed by a literal name. For example `function (arg,arg)` has two arguments, but the `arg` identifier only refers to the second argument. In such cases the name of the first argument is undefined. Furthermore optimizations such as *CSE* may also introduce literals without name. 87425bb815Sopenharmony_ci 88425bb815Sopenharmony_ci * __value__: A reference to an immediate value. Literals between `ident_end` and `const_literal_end` are constant values such as numbers or strings. These literals can be used directly by the Virtual Machine. Literals between `const_literal_end` and `literal_end` are template literals. A new object needs to be constructed each time when their value is accessed. These literals are functions and regular expressions. 89425bb815Sopenharmony_ci 90425bb815Sopenharmony_ciThere are two other sub-groups of identifiers. *Registers* are those identifiers which are stored in the function call stack. *Arguments* are those registers which are passed by a caller function. 91425bb815Sopenharmony_ci 92425bb815Sopenharmony_ciThere are two types of literal encoding in CBC. Both are variable length, where the length is one or two byte long. 93425bb815Sopenharmony_ci 94425bb815Sopenharmony_ci * __small__: maximum 511 literals can be encoded. 95425bb815Sopenharmony_ci 96425bb815Sopenharmony_ciOne byte encoding for literals 0 - 254. 97425bb815Sopenharmony_ci 98425bb815Sopenharmony_ci```c 99425bb815Sopenharmony_cibyte[0] = literal_index 100425bb815Sopenharmony_ci``` 101425bb815Sopenharmony_ci 102425bb815Sopenharmony_ciTwo byte encoding for literals 255 - 510. 103425bb815Sopenharmony_ci 104425bb815Sopenharmony_ci```c 105425bb815Sopenharmony_cibyte[0] = 0xff 106425bb815Sopenharmony_cibyte[1] = literal_index - 0xff 107425bb815Sopenharmony_ci``` 108425bb815Sopenharmony_ci 109425bb815Sopenharmony_ci * __full__: maximum 32767 literal can be encoded. 110425bb815Sopenharmony_ci 111425bb815Sopenharmony_ciOne byte encoding for literals 0 - 127. 112425bb815Sopenharmony_ci 113425bb815Sopenharmony_ci```c 114425bb815Sopenharmony_cibyte[0] = literal_index 115425bb815Sopenharmony_ci``` 116425bb815Sopenharmony_ci 117425bb815Sopenharmony_ciTwo byte encoding for literals 128 - 32767. 118425bb815Sopenharmony_ci 119425bb815Sopenharmony_ci```c 120425bb815Sopenharmony_cibyte[0] = (literal_index >> 8) | 0x80 121425bb815Sopenharmony_cibyte[1] = (literal_index & 0xff) 122425bb815Sopenharmony_ci``` 123425bb815Sopenharmony_ci 124425bb815Sopenharmony_ciSince most functions require less than 255 literal, small encoding provides a single byte literal index for all literals. Small encoding consumes less space than full encoding, but it has a limited range. 125425bb815Sopenharmony_ci 126425bb815Sopenharmony_ci## Literal Store 127425bb815Sopenharmony_ci 128425bb815Sopenharmony_ciJerryScript does not have a global string table for literals, but stores them into the Literal Store. During the parsing phase, when a new literal appears with the same identifier that has already occurred before, the string won't be stored once again, but the identifier in the Literal Store will be used. If a new literal is not in the Literal Store yet, it will be inserted. 129425bb815Sopenharmony_ci 130425bb815Sopenharmony_ci## Byte-code Categories 131425bb815Sopenharmony_ci 132425bb815Sopenharmony_ciByte-codes can be placed into four main categories. 133425bb815Sopenharmony_ci 134425bb815Sopenharmony_ci### Push Byte-codes 135425bb815Sopenharmony_ci 136425bb815Sopenharmony_ciByte-codes of this category serve for placing objects onto the stack. As there are many instructions representing multiple atomic tasks in CBC, there are also many instructions for pushing objects onto the stack according to the number and the type of the arguments. The following table list a few of these opcodes with a brief description. 137425bb815Sopenharmony_ci 138425bb815Sopenharmony_ci<span class="CSSTableGenerator" markdown="block"> 139425bb815Sopenharmony_ci 140425bb815Sopenharmony_ci| byte-code | description | 141425bb815Sopenharmony_ci| --------------------- | ----------------------------------------------------- | 142425bb815Sopenharmony_ci| CBC_PUSH_LITERAL | Pushes the value of the given literal argument. | 143425bb815Sopenharmony_ci| CBC_PUSH_TWO_LITERALS | Pushes the values of the given two literal arguments. | 144425bb815Sopenharmony_ci| CBC_PUSH_UNDEFINED | Pushes an undefined value. | 145425bb815Sopenharmony_ci| CBC_PUSH_TRUE | Pushes a logical true. | 146425bb815Sopenharmony_ci| CBC_PUSH_PROP_LITERAL | Pushes a property whose base object is popped from the stack, and the property name is passed as a literal argument. | 147425bb815Sopenharmony_ci 148425bb815Sopenharmony_ci</span> 149425bb815Sopenharmony_ci 150425bb815Sopenharmony_ci### Call Byte-codes 151425bb815Sopenharmony_ci 152425bb815Sopenharmony_ciThe byte-codes of this category perform calls in different ways. 153425bb815Sopenharmony_ci 154425bb815Sopenharmony_ci<span class="CSSTableGenerator" markdown="block"> 155425bb815Sopenharmony_ci 156425bb815Sopenharmony_ci| byte-code | description | 157425bb815Sopenharmony_ci| --------------------- | ------------------------------------------------------------------------------------ | 158425bb815Sopenharmony_ci| CBC_CALL0 | Calls a function without arguments. The return value won't be pushed onto the stack. | 159425bb815Sopenharmony_ci| CBC_CALL1 | Calls a function with one argument. The return value won't be pushed onto the stack. | 160425bb815Sopenharmony_ci| CBC_CALL | Calls a function with n arguments. n is passed as a byte argument. The return value won't be pushed onto the stack. | 161425bb815Sopenharmony_ci| CBC_CALL0_PUSH_RESULT | Calls a function without arguments. The return value will be pushed onto the stack. | 162425bb815Sopenharmony_ci| CBC_CALL1_PUSH_RESULT | Calls a function with one argument. The return value will be pushed onto the stack. | 163425bb815Sopenharmony_ci| CBC_CALL2_PROP | Calls a property function with two arguments. The base object, the property name, and the two arguments are on the stack. | 164425bb815Sopenharmony_ci 165425bb815Sopenharmony_ci</span> 166425bb815Sopenharmony_ci 167425bb815Sopenharmony_ci### Arithmetic, Logical, Bitwise and Assignment Byte-codes 168425bb815Sopenharmony_ci 169425bb815Sopenharmony_ciThe opcodes of this category perform arithmetic, logical, bitwise and assignment operations. 170425bb815Sopenharmony_ci 171425bb815Sopenharmony_ci<span class="CSSTableGenerator" markdown="block"> 172425bb815Sopenharmony_ci 173425bb815Sopenharmony_ci| byte-code | description | 174425bb815Sopenharmony_ci| ----------------------- | --------------------------------------------------------------------------------------------------- | 175425bb815Sopenharmony_ci| CBC_LOGICAL_NOT | Negates the logical value that popped from the stack. The result is pushed onto the stack. | 176425bb815Sopenharmony_ci| CBC_LOGICAL_NOT_LITERAL | Negates the logical value that given in literal argument. The result is pushed onto the stack. | 177425bb815Sopenharmony_ci| CBC_ADD | Adds two values that are popped from the stack. The result is pushed onto the stack. | 178425bb815Sopenharmony_ci| CBC_ADD_RIGHT_LITERAL | Adds two values. The left one popped from the stack, the right one is given as literal argument. | 179425bb815Sopenharmony_ci| CBC_ADD_TWO_LITERALS | Adds two values. Both are given as literal arguments. | 180425bb815Sopenharmony_ci| CBC_ASSIGN | Assigns a value to a property. It has three arguments: base object, property name, value to assign. | 181425bb815Sopenharmony_ci| CBC_ASSIGN_PUSH_RESULT | Assigns a value to a property. It has three arguments: base object, property name, value to assign. The result will be pushed onto the stack. | 182425bb815Sopenharmony_ci 183425bb815Sopenharmony_ci</span> 184425bb815Sopenharmony_ci 185425bb815Sopenharmony_ci### Branch Byte-codes 186425bb815Sopenharmony_ci 187425bb815Sopenharmony_ciBranch byte-codes are used to perform conditional and unconditional jumps in the byte-code. The arguments of these instructions are 1-3 byte long relative offsets. The number of bytes is part of the opcode, so each byte-code with a branch argument has three forms. The direction (forward, backward) is also defined by the opcode since the offset is an unsigned value. Thus, certain branch instructions has six forms. Some examples can be found in the following table. 188425bb815Sopenharmony_ci 189425bb815Sopenharmony_ci<span class="CSSTableGenerator" markdown="block"> 190425bb815Sopenharmony_ci 191425bb815Sopenharmony_ci| byte-code | description | 192425bb815Sopenharmony_ci| -------------------------- | ----------------------------------------------------------- | 193425bb815Sopenharmony_ci| CBC_JUMP_FORWARD | Jumps forward by the 1 byte long relative offset argument. | 194425bb815Sopenharmony_ci| CBC_JUMP_FORWARD_2 | Jumps forward by the 2 byte long relative offset argument. | 195425bb815Sopenharmony_ci| CBC_JUMP_FORWARD_3 | Jumps forward by the 3 byte long relative offset argument. | 196425bb815Sopenharmony_ci| CBC_JUMP_BACKWARD | Jumps backward by the 1 byte long relative offset argument. | 197425bb815Sopenharmony_ci| CBC_JUMP_BACKWARD_2 | Jumps backward by the 2 byte long relative offset argument. | 198425bb815Sopenharmony_ci| CBC_JUMP_BACKWARD_3 | Jumps backward by the 3 byte long relative offset argument. | 199425bb815Sopenharmony_ci| CBC_BRANCH_IF_TRUE_FORWARD | Jumps forward if the value on the top of the stack is true by the 1 byte long relative offset argument. | 200425bb815Sopenharmony_ci 201425bb815Sopenharmony_ci</span> 202425bb815Sopenharmony_ci 203425bb815Sopenharmony_ci## Snapshot 204425bb815Sopenharmony_ci 205425bb815Sopenharmony_ciThe compiled byte-code can be saved into a snapshot, which also can be loaded back for execution. Directly executing the snapshot saves the costs of parsing the source in terms of memory consumption and performance. The snapshot can also be executed from ROM, in which case the overhead of loading it into the memory can also be saved. 206425bb815Sopenharmony_ci 207425bb815Sopenharmony_ci 208425bb815Sopenharmony_ci# Virtual Machine 209425bb815Sopenharmony_ci 210425bb815Sopenharmony_ciVirtual machine is an interpreter which executes byte-code instructions one by one. The function that starts the interpretation is `vm_run` in `./jerry-core/vm/vm.c`. `vm_loop` is the main loop of the virtual machine, which has the peculiarity that it is *non-recursive*. This means that in case of function calls it does not calls itself recursively but returns, which has the benefit that it does not burdens the stack as a recursive implementation. 211425bb815Sopenharmony_ci 212425bb815Sopenharmony_ci# ECMA 213425bb815Sopenharmony_ci 214425bb815Sopenharmony_ciECMA component of the engine is responsible for the following notions: 215425bb815Sopenharmony_ci 216425bb815Sopenharmony_ci* Data representation 217425bb815Sopenharmony_ci* Runtime representation 218425bb815Sopenharmony_ci* Garbage collection (GC) 219425bb815Sopenharmony_ci 220425bb815Sopenharmony_ci## Data Representation 221425bb815Sopenharmony_ci 222425bb815Sopenharmony_ciThe major structure for data representation is `ECMA_value`. The lower three bits of this structure encode value tag, which determines the type of the value: 223425bb815Sopenharmony_ci 224425bb815Sopenharmony_ci* simple 225425bb815Sopenharmony_ci* number 226425bb815Sopenharmony_ci* string 227425bb815Sopenharmony_ci* object 228425bb815Sopenharmony_ci* symbol 229425bb815Sopenharmony_ci* error 230425bb815Sopenharmony_ci 231425bb815Sopenharmony_ci 232425bb815Sopenharmony_ci 233425bb815Sopenharmony_ciIn case of number, string and object the value contains an encoded pointer, and 234425bb815Sopenharmony_cisimple value is a pre-defined constant which can be: 235425bb815Sopenharmony_ci 236425bb815Sopenharmony_ci* undefined 237425bb815Sopenharmony_ci* null 238425bb815Sopenharmony_ci* true 239425bb815Sopenharmony_ci* false 240425bb815Sopenharmony_ci* empty (uninitialized value) 241425bb815Sopenharmony_ci 242425bb815Sopenharmony_ci### Compressed Pointers 243425bb815Sopenharmony_ci 244425bb815Sopenharmony_ciCompressed pointers were introduced to save heap space. 245425bb815Sopenharmony_ci 246425bb815Sopenharmony_ci 247425bb815Sopenharmony_ci 248425bb815Sopenharmony_ciThese pointers are 8 byte aligned 16 bit long pointers which can address 512 Kb of 249425bb815Sopenharmony_cimemory which is also the maximum size of the JerryScript heap. To support even more 250425bb815Sopenharmony_cimemory the size of compressed pointers can be extended to 32 bit to cover the entire 251425bb815Sopenharmony_ciaddress space of a 32 bit system by passing "--cpointer_32_bit on" to the build 252425bb815Sopenharmony_cisystem. These "uncompressed pointers" increases the memory consumption by around 20%. 253425bb815Sopenharmony_ci 254425bb815Sopenharmony_ci### Number 255425bb815Sopenharmony_ci 256425bb815Sopenharmony_ciThere are two possible representation of numbers according to standard IEEE 754: 257425bb815Sopenharmony_ciThe default is 8-byte (double), 258425bb815Sopenharmony_cibut the engine supports the 4-byte (single precision) representation by setting JERRY_NUMBER_TYPE_FLOAT64 to 0 as well. 259425bb815Sopenharmony_ci 260425bb815Sopenharmony_ci 261425bb815Sopenharmony_ci 262425bb815Sopenharmony_ciSeveral references to single allocated number are not supported. Each reference holds its own copy of a number. 263425bb815Sopenharmony_ci 264425bb815Sopenharmony_ci### String 265425bb815Sopenharmony_ci 266425bb815Sopenharmony_ciStrings in JerryScript are not just character sequences, but can hold numbers and so-called magic ids too. For common character sequences (defined in `./jerry-core/lit/lit-magic-strings.ini`) there is a table in the read only memory that contains magic id and character sequence pairs. If a string is already in this table, the magic id of its string is stored, not the character sequence itself. Using numbers speeds up the property access. These techniques save memory. 267425bb815Sopenharmony_ci 268425bb815Sopenharmony_ci### Object / Lexical Environment 269425bb815Sopenharmony_ci 270425bb815Sopenharmony_ciAn object can be a conventional data object or a lexical environment object. Unlike other data types, object can have references (called properties) to other data types. Because of circular references, reference counting is not always enough to determine dead objects. Hence a chain list is formed from all existing objects, which can be used to find unreferenced objects during garbage collection. The `gc-next` pointer of each object shows the next allocated object in the chain list. 271425bb815Sopenharmony_ci 272425bb815Sopenharmony_ci[Lexical environments](http://www.ecma-international.org/ecma-262/5.1/#sec-10.2) are implemented as objects in JerryScript, since lexical environments contains key-value pairs (called bindings) like objects. This simplifies the implementation and reduces code size. 273425bb815Sopenharmony_ci 274425bb815Sopenharmony_ci 275425bb815Sopenharmony_ci 276425bb815Sopenharmony_ciThe objects are represented as following structure: 277425bb815Sopenharmony_ci 278425bb815Sopenharmony_ci * Reference counter - number of hard (non-property) references 279425bb815Sopenharmony_ci * Next object pointer for the garbage collector 280425bb815Sopenharmony_ci * type (function object, lexical environment, etc.) 281425bb815Sopenharmony_ci 282425bb815Sopenharmony_ci### Properties of Objects 283425bb815Sopenharmony_ci 284425bb815Sopenharmony_ci 285425bb815Sopenharmony_ci 286425bb815Sopenharmony_ciObjects have a linked list that contains their properties. This list actually contains property pairs, in order to save memory described in the followings: 287425bb815Sopenharmony_ciA property is 7 bit long and its type field is 2 bit long which consumes 9 bit which does not fit into 1 byte but consumes 2 bytes. Hence, placing together two properties (14 bit) with the 2 bit long type field fits into 2 bytes. 288425bb815Sopenharmony_ci 289425bb815Sopenharmony_ci#### Property Hashmap 290425bb815Sopenharmony_ci 291425bb815Sopenharmony_ciIf the number of property pairs reach a limit (currently this limit is defined to 16), a hash map (called [Property Hashmap](#property-hashmap)) is inserted at the first position of the property pair list, in order to find a property using it, instead of finding it by iterating linearly over the property pairs. 292425bb815Sopenharmony_ci 293425bb815Sopenharmony_ciProperty hashmap contains 2<sup>n</sup> elements, where 2<sup>n</sup> is larger than the number of properties of the object. Each element can have tree types of value: 294425bb815Sopenharmony_ci 295425bb815Sopenharmony_ci* null, indicating an empty element 296425bb815Sopenharmony_ci* deleted, indicating a deleted property, or 297425bb815Sopenharmony_ci* reference to the existing property 298425bb815Sopenharmony_ci 299425bb815Sopenharmony_ciThis hashmap is a must-return type cache, meaning that every property that the object have, can be found using it. 300425bb815Sopenharmony_ci 301425bb815Sopenharmony_ci#### Internal Properties 302425bb815Sopenharmony_ci 303425bb815Sopenharmony_ciInternal properties are special properties that carry meta-information that cannot be accessed by the JavaScript code, but important for the engine itself. Some examples of internal properties are listed below: 304425bb815Sopenharmony_ci 305425bb815Sopenharmony_ci* [[Class]] - class (type) of the object (ECMA-defined) 306425bb815Sopenharmony_ci* [[Code]] - points where to find bytecode of the function 307425bb815Sopenharmony_ci* native code - points where to find the code of a native function 308425bb815Sopenharmony_ci* [[PrimitiveValue]] for Boolean - stores the boolean value of a Boolean object 309425bb815Sopenharmony_ci* [[PrimitiveValue]] for Number - stores the numeric value of a Number object 310425bb815Sopenharmony_ci 311425bb815Sopenharmony_ci### LCache 312425bb815Sopenharmony_ci 313425bb815Sopenharmony_ciLCache is a hashmap for finding a property specified by an object and by a property name. The object-name-property layout of the LCache presents multiple times in a row as it is shown in the figure below. 314425bb815Sopenharmony_ci 315425bb815Sopenharmony_ci 316425bb815Sopenharmony_ci 317425bb815Sopenharmony_ciWhen a property access occurs, a hash value is extracted from the demanded property name and than this hash is used to index the LCache. After that, in the indexed row the specified object and property name will be searched. 318425bb815Sopenharmony_ci 319425bb815Sopenharmony_ciIt is important to note, that if the specified property is not found in the LCache, it does not mean that it does not exist (i.e. LCache is a may-return cache). If the property is not found, it will be searched in the property-list of the object, and if it is found there, the property will be placed into the LCache. 320425bb815Sopenharmony_ci 321425bb815Sopenharmony_ci### Collections 322425bb815Sopenharmony_ci 323425bb815Sopenharmony_ciCollections are array-like data structures, which are optimized to save memory. Actually, a collection is a linked list whose elements are not single elements, but arrays which can contain multiple elements. 324425bb815Sopenharmony_ci 325425bb815Sopenharmony_ci### Exception Handling 326425bb815Sopenharmony_ci 327425bb815Sopenharmony_ciIn order to implement a sense of exception handling, the return values of JerryScript functions are able to indicate their faulty or "exceptional" operation. The return values are ECMA values (see section [Data Representation](#data-representation)) and if an erroneous operation occurred the ECMA_VALUE_ERROR simple value is returned. 328425bb815Sopenharmony_ci 329425bb815Sopenharmony_ci### Value Management and Ownership 330425bb815Sopenharmony_ci 331425bb815Sopenharmony_ciEvery ECMA value stored by the engine is associated with a virtual "ownership", that defines how to manage the value: when to free it when it is not needed anymore and how to pass the value to an other function. 332425bb815Sopenharmony_ci 333425bb815Sopenharmony_ciInitially, value is allocated by its owner (i.e. with ownership). The owner has the responsibility for freeing the allocated value. When the value is passed to a function as an argument, the ownership of it will not pass, the called function have to make an own copy of the value. However, as long as a function returns a value, the ownership will pass, thus the caller will be responsible for freeing it. 334