1# JSVM-API Overview 2 3## Introduction 4 5The OpenHarmony JSVM-API provides a set of stable APIs based on the standard JavaScript (JS) engine. It provides complete JS engine capabilities, including creating and destroying a JS engine, executing JS code, and implementing interaction between JS and C/C++ modules. 6 7OpenHarmony JSVM-API provides a set of APIs written in C programming language that complies with C99. 8 9JSVM-API allows dynamically loaded JS code segment to be directly run during application runtime. With JSVM-API, you can also use C/C++ to implement core functionalities that demand high performance or closely rely on underlying system invocation, register C++ methods in JS code, and directly call the JS code to improve the execution speed. 10 11Unless otherwise specified, JSVM-API in this document refers to OpenHarmony JSVM-API. 12 13 14## JSVM-API Architecture 15 16**Figure 1** JSVM-API architecture 17 18 19 20- Native Module: module developed using JSVM-API in C/C++. 21 22- VM Life Cycle Manager: manages the JSVM_VM lifecycle. 23 24- JS Context Manager: manages the JSVM_Env lifecycle. 25 26- Context Snapshot: manages context snapshots to shorten the time used to create JS context. 27 28- JS Code Execute: executes JS code. 29 30- JS/C++ Interaction: implements interaction between JS and C++. 31 32- Code Cache: caches the JS code to shorten the startup time for JS code execution. 33 34- Debugger: debugs JS code. 35 36- CPU Profiler: records the JS code execution time and helps analyze the JS code performance bottlenecks. 37 38- Heap Snapshot: helps you perform JS heap memory analysis, identify memory issues, and make improvements. 39 40- Heap Statistics: provides JS heap statistics, including the memory size and context count. 41 42- Memory Adjustment: adjusts the external memory size and VM memory pressure to accelerate GC triggering. 43 44- VM Information: manages JSVM_VM information. 45 46- Standard JS Engine: standard JS engine. 47 48## JSVM-API Interaction Process 49 50**Figure 2** Key interaction process of JSVM-API 51 52 53 54The interaction between JSVM-API and a native module is as follows: 55 561. **Initialization**: Initialize the JSVM and JS context on the native module and register native functions in JS code. The native functions are hooked to **GlobalThis**, which is the global context of the JS execution environment. 57 582. **Invocation**: Call JS APIs to invoke the native functions that are registered in **GlobalThis** using JSVM-API. The JS engine calls the corresponding C/C++ functions. 59