ARK-Runtime-Subsystem.md 5.4 KB
Newer Older
G
Gloria 已提交
1
# ArkCompiler Runtime
W
wusongqing 已提交
2

W
wusongqing 已提交
3
## Introduction
W
wusongqing 已提交
4

G
Gloria 已提交
5
ArkCompiler is a unified compilation and runtime platform that supports joint compilation and running across programming languages and chip platforms. It supports a variety of dynamic and static programming languages such as JS, TS, and ArkTS. It is the compilation and runtime base that enables OpenHarmony to run on multiple device forms such as mobile phones, PCs, tablets, TVs, automobiles, and wearables.
W
wusongqing 已提交
6

G
Gloria 已提交
7
ArkCompiler consists of two parts: compiler toolchain and runtime.
W
wusongqing 已提交
8

G
Gloria 已提交
9
**Figure 1** Architecture of the compiler toolchain
W
wusongqing 已提交
10 11
![](figures/en-us_image_ark_frontend.png)

G
Gloria 已提交
12
The compiler toolchain compiles ArkTS, TS, and JS source code into abc files, that is, ArkCompiler bytecode.
W
wusongqing 已提交
13

G
Gloria 已提交
14
**Figure 2** Runtime architecture
W
wusongqing 已提交
15

G
Gloria 已提交
16
![](figures/en-us_image_ark-ts-arch.png)
W
wusongqing 已提交
17

G
Gloria 已提交
18
The runtime runs the abc files to implement the corresponding semantic logic.
W
wusongqing 已提交
19

G
Gloria 已提交
20
The ArkCompiler runtime consists of four subsystems:
W
wusongqing 已提交
21

22
-   Core subsystem
W
wusongqing 已提交
23

G
Gloria 已提交
24
    The core subsystem consists of basic language-irrelevant runtime libraries, including File, Tooling, and Base. File provides bytecode. Tooling supports Debugger. Base implements system calls.
W
wusongqing 已提交
25

G
Gloria 已提交
26
-   Execution subsystem
W
wusongqing 已提交
27

G
Gloria 已提交
28
    The execution subsystem consists of the interpreter for executing bytecode, the inline caching, and the profiler for capturing runtime information.
W
wusongqing 已提交
29

G
Gloria 已提交
30
-   Compiler subsystem
W
wusongqing 已提交
31

G
Gloria 已提交
32
    The compiler subsystem consists of the stub compiler, circuit framework, and Ahead-of-Time (AOT) compiler.
W
wusongqing 已提交
33

G
Gloria 已提交
34
-   Runtime subsystem
35

G
Gloria 已提交
36
    The runtime subsystem contains modules related to the running of ArkTS, TS, and JS code.
W
wusongqing 已提交
37 38 39 40 41 42
    - Memory management: object allocator and garbage collector (CMS-GC and Partial-Compressing-GC for concurrent marking and partial memory compression)
    - Analysis tools: DFX tool and CPU and heap profiling tool
    - Concurrency management: abc file manager in the actor concurrency model
    - Standard library: standard library defined by ECMAScript, efficient container library, and object model
    - Others: asynchronous work queues, TypeScript (TS) type loading, and JS native APIs (JSNAPIs) for interacting with C++ interfaces

G
Gloria 已提交
43
**Design features of ArkCompiler eTS Runtime**
W
wusongqing 已提交
44

G
Gloria 已提交
45
- Native support for type information
W
wusongqing 已提交
46

G
Gloria 已提交
47
   Currently, mainstream engines in the industry convert TS source code into JS source code and then run the JS source code to complete semantic logic. However, the ArkCompiler compiler toolchain analyzes and deduces the TS type information when compiling the TS source code and transfers the information to the runtime. The runtime uses the TS type information to pre-generate an inline cache before running, speeding up bytecode execution. The TS AOT compiler directly compiles and generates machine code based on the TS type information in the abc file, so that an application can directly run the optimized machine code, thereby greatly improving the running performance.
W
wusongqing 已提交
48

G
Gloria 已提交
49
- Optimized concurrency model and concurrency APIs
W
wusongqing 已提交
50

G
Gloria 已提交
51
  The ArkCompiler eTS runtime statically pre-compiles ArkTS programs into ArkCompiler bytecode (with static type information) to reduce the overhead caused by compilation and type information collection during runtime. To ensure security and performance, the ArkCompiler eTS runtime selects the code that supports strict but not eval.
W
wusongqing 已提交
52

G
Gloria 已提交
53 54 55 56
- Native support for TS
  
  The ECMAScript specification does not include concurrency semantic representation. Engines in the industry, such as browser or Node.js, usually provide the Worker APIs for multi-thread development based on the Actor concurrency model. In this model, executors do not share data objects or communicate with each other using the messaging mechanism. The worker thread of the web engine or Node.js engine has defects such as slow startup and high memory usage.  To address these defects, the ArkCompiler runtime supports sharing of immutable objects (methods and bytecode) in Actor instances, greatly optimizing Actor startup performance and startup memory.
  In addition to the Worker APIs, the ArkCompiler runtime provides TaskPool, a task pool function library that supports priority-based scheduling and automatic scaling of worker threads. With TaskPool, you do not need to care about the lifecycle of concurrent instances or create or destroy concurrent instances upon task load changes. This greatly simplifies the development of high-performance multithreaded OpenHarmony applications.
W
wusongqing 已提交
57 58


G
Gloria 已提交
59 60 61
- Security
  
  The ArkCompiler compiler toolchain statically precompiles ArkTS, TS, and JS code into ArkCompiler bytecode and enhances the multi-obfuscation capability, effectively improving the security of your code assets. For security purposes, ArkCompiler does not support JS code in sloppy mode or functions such as eval for running dynamic strings.
W
wusongqing 已提交
62 63

## Directory Structure
W
wusongqing 已提交
64 65

```
G
Gloria 已提交
66 67
/arkcompiler
├── ets_runtime       # ArkTS runtime module
G
Gloria 已提交
68
├── runtime_core      # Runtime core subsystem
G
Gloria 已提交
69 70
├── ets_frontend      # ArkTS frontend tool
└── toolchain         # ArkTS toolchain
W
wusongqing 已提交
71 72
```

G
Gloria 已提交
73
## Usage
W
wusongqing 已提交
74

G
Gloria 已提交
75
[Ark Runtime User Guide](https://gitee.com/openharmony/arkcompiler_ets_runtime/blob/master/docs/ARK-Runtime-Usage-Guide.md)
W
wusongqing 已提交
76

W
wusongqing 已提交
77
## Repositories Involved
W
wusongqing 已提交
78

G
Gloria 已提交
79
[arkcompiler\_runtime\_core](https://gitee.com/openharmony/arkcompiler_runtime_core)
W
wusongqing 已提交
80

G
Gloria 已提交
81
[arkcompiler\_ets\_runtime](https://gitee.com/openharmony/arkcompiler_ets_runtime)
W
wusongqing 已提交
82

G
Gloria 已提交
83
[arkcompiler\_ets\_frontend](https://gitee.com/openharmony/arkcompiler_ets_frontend)
G
Gloria 已提交
84 85

[arkcompiler\_toolchain](https://gitee.com/openharmony/arkcompiler_toolchain)