Fix image scaling on 'internals' page.

This commit is contained in:
Andrey Shitov
2015-06-15 00:01:04 +03:00
parent fa3258dfdc
commit f470c608a2
8 changed files with 26 additions and 26 deletions
+26 -26
View File
@@ -8,7 +8,7 @@ permalink: /internals/
{:toc}
# High-Level Design
![High-Level Design]({{ site.baseurl }}/img/engines_high_level_design.jpg)
![High-Level Design]({{ site.baseurl }}/img/engines_high_level_design.jpg){: class="thumbnail center-block img-responsive" }
On the diagram above is shown interaction of major components of software system: Parser and Runtime. Parser performs translation of input ECMAScript application into byte-code with specified format (refer to [Bytecode](/internals/#byte-code) and [Parser](/internals/#parser) page for details). Prepared bytecode is executed by Runtime engine that performs interpretation (refer to [Virtual Machine](/internals/#virtual-machine) and [ECMA](/internals/#ECMA) pages for details).
@@ -116,21 +116,21 @@ This component is just checks for syntax errors defined in the specification. It
# Byte-code
Every instruction of bytecode consists of opcode and up to three operands. Operand (idx) can be either a "register" or a string
literal, specifying identifier to evaluate (i.e. `var //Storage idx`). General structure of instruction is shown on the picture.
![Structure of instruction]({{ site.baseurl }}/img/bytecode_view.jpg)
![Structure of instruction]({{ site.baseurl }}/img/bytecode_view.jpg){: class="thumbnail center-block img-responsive" }
Special kinds of instructions are described below.
## Arithmetic/bitwise-logic/logic/comparison/shift
Arithmetic instruction can have the following structure:
![Arithmetic instructions]({{ site.baseurl }}/img/bytecode_arithmetic.jpg)
![Arithmetic instructions]({{ site.baseurl }}/img/bytecode_arithmetic.jpg){: class="thumbnail center-block img-responsive" }
where dst/left/right/value identify an operand.
## Control (jumps)
Control instructions utilize two bytes to encode jump location. Destination offset is contained inside `offset_high` and `offset_low` fields.
![Control instructions]({{ site.baseurl }}/img/bytecode_control.jpg)
![Control instructions]({{ site.baseurl }}/img/bytecode_control.jpg){: class="thumbnail center-block img-responsive" }
Condition jump checks `cond value` field, which identifies an operand, and performs a jump if the operand has `true` value.
@@ -138,7 +138,7 @@ Condition jump checks `cond value` field, which identifies an operand, and perfo
Assignment instructions perform assignment of immediate value (contained inside instruction) to the operand, which is marked as `idx` on the picture.
![Assignment instruction]({{ site.baseurl }}/img/bytecode_assignment.jpg)
![Assignment instruction]({{ site.baseurl }}/img/bytecode_assignment.jpg){: class="thumbnail center-block img-responsive" }
Type of the immediate value is encoded in the `type` field of instruction. The following values are supported:
- "simple value" (see ECMA types encoding)
@@ -151,7 +151,7 @@ Type of the immediate value is encoded in the `type` field of instruction. The f
Exit instruction serves to stop the execution and exit with a specified status.
![Exit instruction]({{ site.baseurl }}/img/bytecode_exit.jpg)
![Exit instruction]({{ site.baseurl }}/img/bytecode_exit.jpg){: class="thumbnail center-block img-responsive" }
Exit instruction is employed in following cases:
- at script end (exit with "succesful" stats);
@@ -161,35 +161,35 @@ Exit instruction is employed in following cases:
Native call instruction is used to call intrinsics. Arguments are not encoded directly inside this instruction, instead they follow it as special "meta" instructions (see the according section). Id of desired intrinsic is encoded in the `intrinsic id` field.
![Native call instruction]({{ site.baseurl }}/img/bytecode_native.jpg)
![Native call instruction]({{ site.baseurl }}/img/bytecode_native.jpg){: class="thumbnail center-block img-responsive" }
## Function call/Constructor call
Function/constructor call are utilized to perform calls to functions and constructors. Destination operand is encoded in `dst` field. Operand `name_idx` specifies the name of the function to call. Arguments are encoded the same way as in native call instruction.
![Function/constructor instruction]({{ site.baseurl }}/img/bytecode_fcall.jpg)
![Function/constructor instruction]({{ site.baseurl }}/img/bytecode_fcall.jpg){: class="thumbnail center-block img-responsive" }
## Function declaration
Function declarations are represented by special kind of instructions. Function name and number of arguments are located in `name_idx` and `arg_list` fields respectively.
![Function declaration instruction]({{ site.baseurl }}/img/bytecode_fdecl.jpg)
![Function declaration instruction]({{ site.baseurl }}/img/bytecode_fdecl.jpg){: class="thumbnail center-block img-responsive" }
## Function expression
Very similar to function declaration. But additionally contains destination (`dst`) field and `name` operand is optional, because anonymous functions are possible.
![Function expression instruction]({{ site.baseurl }}/img/bytecode_fexpr.jpg)
![Function expression instruction]({{ site.baseurl }}/img/bytecode_fexpr.jpg){: class="thumbnail center-block img-responsive" }
## Return from function/eval
Return instructions perfrom unconditional return from function/eval code. Return value can be specified (`idx` field).
![Return instruction]({{ site.baseurl }}/img/bytecode_ret.jpg)
![Return instruction]({{ site.baseurl }}/img/bytecode_ret.jpg){: class="thumbnail center-block img-responsive" }
## "Meta" (special marker opcode)
![Meta instruction]({{ site.baseurl }}/img/bytecode_meta.jpg)
![Meta instruction]({{ site.baseurl }}/img/bytecode_meta.jpg){: class="thumbnail center-block img-responsive" }
Meta instructions are usually utilized as continuations of other instructions. Depending on `type` field, meta instruction can have the following meaning:
@@ -204,49 +204,49 @@ Meta instructions are usually utilized as continuations of other instructions. D
JavaScript delete operator is modeled with delete instruction in the bytecode. There are two types of delete instruction, applied either to element of lexical environment or to object's property.
![Delete instructions]({{ site.baseurl }}/img/bytecode_delete.jpg)
![Delete instructions]({{ site.baseurl }}/img/bytecode_delete.jpg){: class="thumbnail center-block img-responsive" }
## This binding (evaluate "this")
This binding instruction writes value of "this" to the `dst` operand.
![This instruction]({{ site.baseurl }}/img/bytecode_binding.jpg)
![This instruction]({{ site.baseurl }}/img/bytecode_binding.jpg){: class="thumbnail center-block img-responsive" }
## typeof (typeof operation)
Typeof instruction executes JavaScript operator with the same name. Result is written to the `dst` operand.
![Typeof instruction]({{ site.baseurl }}/img/bytecode_typeof.jpg)
![Typeof instruction]({{ site.baseurl }}/img/bytecode_typeof.jpg){: class="thumbnail center-block img-responsive" }
## with block
To specify bounds of "with" block, a pair of instructions is used. "With" instruction specifies its start. Followed by a number of arbitrary instructions, the block ends with `end_with` meta instruction.
![With block instruction]({{ site.baseurl }}/img/bytecode_with.jpg)
![With block instruction]({{ site.baseurl }}/img/bytecode_with.jpg){: class="thumbnail center-block img-responsive"}
## try block
Try block consists of try instruction, followed by a number of arbitrary instructions, meta instruction `catch` or `finally` or both of them, separating catch and finally blocks respectively and meta instruction `end_try_catch_finally`, which finishes the whole construction.
![Try block instruction]({{ site.baseurl }}/img/bytecode_try.jpg)
![Try block instruction]({{ site.baseurl }}/img/bytecode_try.jpg){: class="thumbnail center-block img-responsive" }
## Object declaration
Obect declaration instruction represents object literal in JavaScript specification. It consists of `op_obj_decl` instruction, followed by a list of `prop_data`, `prop_getter` and `prop_setter` meta instructions. A series of instructions which evaluate property values can precede meta instructions. Number of meta instructions, e.g. number of properties, is specified in the `prop_num` field.
![Object declaration instruction]({{ site.baseurl }}/img/bytecode_obj.jpg)
![Object declaration instruction]({{ site.baseurl }}/img/bytecode_obj.jpg){: class="thumbnail center-block img-responsive" }
## Arguments and array declarartion
The strategy descibed in previous section is also used for encoding of arguments in function/constructor calls and elements in array declarations.
See the according pictures.
![Arguments/Array elements representation]({{ site.baseurl }}/img/bytecode_with.jpg)
![Arguments/Array elements representation]({{ site.baseurl }}/img/bytecode_with.jpg){: class="thumbnail center-block img-responsive" }
# Virtual machine
Virtual machine executes bytecode by interpreting instructions one by one. Bytecode is a continuous array of instructions, divided into blocks of fixed size. Main loop of interpreter calls `opfunc_*` for every instruction. This function returns completion value and position of the next instruction.
![Bytecode storage]({{ site.baseurl }}/img/bytecode_storage.jpg)
![Bytecode storage]({{ site.baseurl }}/img/bytecode_storage.jpg){: class="thumbnail center-block img-responsive" }
Instruction can have up to three operands which are represented by `idx` values. Meaning of `idx` value depends on opcode and can be the following:
@@ -291,7 +291,7 @@ The major structure for data representation is `ECMA_value`. Lower two bits of t
* string
* object
![ECMA value representation]({{ site.baseurl }}/img/ecma_value.jpg)
![ECMA value representation]({{ site.baseurl }}/img/ecma_value.jpg){: class="thumbnail center-block img-responsive" }
The immediate value is placed in higher bits. "Simple value" is an enumeration, which consists of the following elements:
- undefined
@@ -307,7 +307,7 @@ For other value types higher bits of `ECMA_value` structure contain compressed p
Compressed pointers were introduced to save heap space. They are possible because heap size is currently limited by 256 KB, which requires 18 bits to cover it. ECMA values in heap are aligned by 8 bytes and this allows to save three more bits, so that compressed pointer consumes 15 bits only.
![Heap and ECMA elements]({{ site.baseurl }}/img/ecma_compressed.jpg)
![Heap and ECMA elements]({{ site.baseurl }}/img/ecma_compressed.jpg){: class="thumbnail center-block img-responsive" }
ECMA data elements are allocated in pools (pools are allocated on heap)
Chunk size of the pool is 8 bytes (reduces fragmentation).
@@ -345,7 +345,7 @@ Object and lexical environment structures, 8 bytes each, have common (GC) header
Remaining fields of these structures are different and are shown on the picture.
![Object/Lexicat environment structures]({{ site.baseurl }}/img/ecma_object.jpg)
![Object/Lexicat environment structures]({{ site.baseurl }}/img/ecma_object.jpg){: class="thumbnail center-block img-responsive" }
### Property of an object / description of a lexical environment variable
@@ -359,7 +359,7 @@ All these units occupy 8 bytes and have common header:
- next property/variable in the object/lexical environment (compressed pointer)
The remaining parts are differnt:
![Object property/lexcial environment variable]({{ site.baseurl }}/img/ecma_object_property.jpg)
![Object property/lexcial environment variable]({{ site.baseurl }}/img/ecma_object_property.jpg){: class="thumbnail center-block img-responsive" }
### Collections
@@ -400,7 +400,7 @@ Chunk's layout is following:
LCache is a cache for property variable search requests.
![LCache]({{ site.baseurl }}/img/ecma_lcache.jpg)
![LCache]({{ site.baseurl }}/img/ecma_lcache.jpg){: class="thumbnail center-block img-responsive"}
Entry of LCache has the following layout:
- object pointer
@@ -426,7 +426,7 @@ However, there could be some combinations.
Many algorithms/routines described in ECMA return a value of "completion" type, that is triplet of the following form:
![ECMA completion]({{ site.baseurl }}/img/ecma_completion.jpg)
![ECMA completion]({{ site.baseurl }}/img/ecma_completion.jpg){: class="thumbnail center-block img-responsive" }
Jerry introduces two additional completion types:
- exit - produced by `exitval` opcode, indicates request to finish execution
Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 143 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 18 KiB