• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ArkCompiler Runtime
2
3## Introduction
4
5ArkCompiler 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.
6
7ArkCompiler consists of two parts: compiler toolchain and runtime.
8
9**Figure 1** Architecture of the compiler toolchain
10![](figures/en-us_image_ark_frontend.png)
11
12The compiler toolchain compiles ArkTS, TS, and JS source code into abc files, that is, ArkCompiler bytecode.
13
14**Figure 2** Runtime architecture
15
16![](figures/en-us_image_ark-ts-arch.png)
17
18The runtime runs the abc files to implement the corresponding semantic logic.
19
20The ArkCompiler runtime consists of four subsystems:
21
22-   Core subsystem
23
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.
25
26-   Execution subsystem
27
28    The execution subsystem consists of the interpreter for executing bytecode, the inline caching, and the profiler for capturing runtime information.
29
30-   Compiler subsystem
31
32    The compiler subsystem consists of the stub compiler, circuit framework, and Ahead-of-Time (AOT) compiler.
33
34-   Runtime subsystem
35
36    The runtime subsystem contains modules related to the running of ArkTS, TS, and JS code.
37    - Memory management: object allocator and garbage collector (CMS-GC and Partial-Compressing-GC for concurrent marking and partial memory compression)
38    - Analysis tools: DFX tool and CPU and heap profiling tool
39    - Concurrency management: abc file manager in the actor concurrency model
40    - Standard library: standard library defined by ECMAScript, efficient container library, and object model
41    - Others: asynchronous work queues, TypeScript (TS) type loading, and JS native APIs (JSNAPIs) for interacting with C++ interfaces
42
43**Design features of ArkCompiler eTS Runtime**
44
45- Native support for type information
46
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.
48
49- Optimized concurrency model and concurrency APIs
50
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.
52
53- Native support for TS
54
55  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.
56  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.
57
58
59- Security
60
61  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.
62
63## Directory Structure
64
65```
66/arkcompiler
67├── ets_runtime       # ArkTS runtime module
68├── runtime_core      # Runtime core subsystem
69├── ets_frontend      # ArkTS frontend tool
70└── toolchain         # ArkTS toolchain
71```
72
73## Usage
74
75[Ark Runtime User Guide](https://gitee.com/openharmony/arkcompiler_ets_runtime/blob/OpenHarmony-3.2-Release/docs/README.md)
76
77## Repositories Involved
78
79[arkcompiler\_runtime\_core](https://gitee.com/openharmony/arkcompiler_runtime_core)
80
81[arkcompiler\_ets\_runtime](https://gitee.com/openharmony/arkcompiler_ets_runtime)
82
83[arkcompiler\_ets\_frontend](https://gitee.com/openharmony/arkcompiler_ets_frontend)
84
85[arkcompiler\_toolchain](https://gitee.com/openharmony/arkcompiler_toolchain)
86