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