14514f5e3Sopenharmony_ci# Overview
24514f5e3Sopenharmony_ci
34514f5e3Sopenharmony_ciArkCompiler is a built-in componentized and configurable multi-language compilation and runtime platform of OpenHarmony. It contains core components such as the compiler, toolchain, and runtime. It supports compilation and running of high-level programming languages on the multi-chip platform. ArkCompiler JS Runtime provides the capability of compiling and running the JavaScript (JS) language on the OpenHarmony operating system.
44514f5e3Sopenharmony_ci
54514f5e3Sopenharmony_ciArkCompiler JS Runtime consists of two parts: JS compiler toolchain and JS runtime. The JS compiler toolchain compiles JS source code into ArkCompiler bytecodes. The JS runtime executes the generated ArkCompiler bytecodes. Unless otherwise specified, bytecodes refer to ArkCompiler bytecodes in this document.
64514f5e3Sopenharmony_ci
74514f5e3Sopenharmony_ciFigure 1 Architecture of the JS compiler toolchain
84514f5e3Sopenharmony_ci![](figures/en-us_image_0000001197967897.png)
94514f5e3Sopenharmony_ci
104514f5e3Sopenharmony_ciThe source code compiler of ArkCompiler JS Runtime receives JS source code, based on which ts2abc generates an abc file.
114514f5e3Sopenharmony_ci
124514f5e3Sopenharmony_ciFigure 2 Architecture of ArkCompiler JS Runtime
134514f5e3Sopenharmony_ci
144514f5e3Sopenharmony_ci![](figures/en-us_image_ark-js-arch.png)
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ciArkCompiler JS Runtime runs ArkCompiler bytecode files to implement JS semantic logic.
174514f5e3Sopenharmony_ci
184514f5e3Sopenharmony_ci**ArkCompiler JS Runtime consists of four subsystems:**
194514f5e3Sopenharmony_ci
204514f5e3Sopenharmony_ci-   **Core Subsystem**
214514f5e3Sopenharmony_ci
224514f5e3Sopenharmony_ci    Core Subsystem consists of basic language-irrelevant runtime libraries, including ArkCompiler File, Tooling, and ArkCompiler Base. ArkCompiler File provides bytecodes. Tooling supports Debugger. ArkCompiler Base is responsible for implementing system calls.
234514f5e3Sopenharmony_ci
244514f5e3Sopenharmony_ci-   **JS Execution Subsystem**
254514f5e3Sopenharmony_ci
264514f5e3Sopenharmony_ci    JS Execution Subsystem consists of an interpreter that executes bytecodes, inline caching that stores hidden classes, and Profiler that analyzes and records runtime types.
274514f5e3Sopenharmony_ci
284514f5e3Sopenharmony_ci-   **JS Compiler Subsystem**
294514f5e3Sopenharmony_ci
304514f5e3Sopenharmony_ci    JS Compiler Subsystem consists of the Stub compiler, optimized compilation framework based on the Circuit IR, and code generator.
314514f5e3Sopenharmony_ci
324514f5e3Sopenharmony_ci-   **JS Runtime Subsystem**
334514f5e3Sopenharmony_ci
344514f5e3Sopenharmony_ci    JS Runtime Subsystem contains various modules related to JS runtime:
354514f5e3Sopenharmony_ci    - Memory management: object allocator and garbage collector (CMS-GC and Partial-Compressing-GC for concurrent marking and partial memory compression)
364514f5e3Sopenharmony_ci    - Analysis tools: DFX tool and CPU and heap profiling tool
374514f5e3Sopenharmony_ci    - Concurrency management: abc file manager in the actor concurrency model
384514f5e3Sopenharmony_ci    - Standard library: standard library defined by ECMAScript, efficient container library, and object model
394514f5e3Sopenharmony_ci    - Others: asynchronous work queues, TypeScript (TS) type loading, and JS native APIs (JSNAPIs) for interacting with C++ interfaces
404514f5e3Sopenharmony_ci
414514f5e3Sopenharmony_ci**Design features of ArkCompiler JS Runtime:**
424514f5e3Sopenharmony_ci
434514f5e3Sopenharmony_ci- ArkCompiler JS Runtime is designed to provide a JS/TS application execution engine for OpenHarmony rather than a JS execution engine for the browser.
444514f5e3Sopenharmony_ci
454514f5e3Sopenharmony_ci- To improve the application execution performance and security, ArkCompiler JS Runtime statically pre-compiles JS/TS 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, ArkCompiler JS Runtime selects the code that supports strict but not eval.
464514f5e3Sopenharmony_ci
474514f5e3Sopenharmony_ci- Native support for TS. The common way to process TS in the industry is to convert TS into JS and execute JS code with JS runtime. ts2abc is planned to analyze and obtain the TS type information when compiling the TS source code and send the information to ArkCompiler JS Runtime. ArkCompiler JS Runtime directly uses the type information to statically generate inline caching to accelerate bytecode execution. The TS Ahead of Time (AOT) compiler directly converts the source code into high-quality machine code based on the TS type information sent from ts2abc, which greatly improves the running performance.
484514f5e3Sopenharmony_ci
494514f5e3Sopenharmony_ci- Lightweight Actor concurrency model: ECMAScript does not provide concurrency specifications. The Actor concurrency model is commonly used in JS engines in the industry to implement concurrent processing. In this model, executors do not share data and communicate with each other using the messaging mechanism. The JS Actor model (web-worker) in the industry has defects such as slow startup and high memory usage. ArkCompiler JS Runtime is required to provide the Actor implementation that features fast startup and low memory usage to better leverage the device's multi-core feature to improve performance. Now ARK-JS is able to share immutable objects, methods, and bytecodes (built-in code blocks and constant strings in the future) in Actor instances based on the Actor memory isolation model to accelerate the startup of JS Actor, reduce memory overhead, and implement the lightweight Actor concurrency model.
504514f5e3Sopenharmony_ci
514514f5e3Sopenharmony_ci- Cross-language interaction of TS/C++: In the API implementation, it is common for C/C++ code to access and operate TS objects in OpenHarmony. ArkCompiler JS Runtime is planned to statically generate a C/C++ header file that contains the TS object layout description and the C/C++ implementation library for operating the TS object based on the class declaration and runtime conventions in the TS program. The C/C++ code usually includes the TS object layout description header file and the corresponding implementation library to implement the direct operation on the TS object. The TS type or its internal layout is not always fixed. Therefore, in the code implementation for TS object operations, type check is used. If the object type or layout changes during runtime, the common slow path is rolled back.
52