diff --git a/ark_runtime/jsvm/jsvm.h b/ark_runtime/jsvm/jsvm.h index 39a58774c5eb7713747bc3c16501fde275eed218..35fa95c2a1e585a1e5b1e4ce7a94b86ee3899d2f 100644 --- a/ark_runtime/jsvm/jsvm.h +++ b/ark_runtime/jsvm/jsvm.h @@ -208,6 +208,17 @@ JSVM_EXTERN JSVM_Status OH_JSVM_OpenEnvScope(JSVM_Env env, JSVM_EXTERN JSVM_Status OH_JSVM_CloseEnvScope(JSVM_Env env, JSVM_EnvScope scope); +/** + * @brief This function retrieves the VM instance of the given environment. + * + * @param env: The environment that the JSVM-API call is invoked under. + * @param result: The VM instance of the environment. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetVM(JSVM_Env env, + JSVM_VM* result); + /** * @brief This function compiles a string of JavaScript code and returns the compiled script. * @@ -2108,6 +2119,90 @@ JSVM_EXTERN JSVM_Status OH_JSVM_CreateSnapshot(JSVM_VM vm, const char** blobData, size_t* blobSize); +/** + * @brief This function returns a set of statistics data of the heap of the VM. + * + * @param vm: The VM whose heap statistics are returned. + * @param result: The heap statistics data. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_GetHeapStatistics(JSVM_VM vm, + JSVM_HeapStatistics* result); + +/** + * @brief This function creates and starts a CPU profiler. + * + * @param vm: The VM to start CPU profiler for. + * @param result: The pointer to the CPU profiler. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_StartCpuProfiler(JSVM_VM vm, + JSVM_CpuProfiler* result); + +/** + * @brief This function stops the CPU profiler and output to the stream. + * + * @param vm: THe VM to start CPU profiler for. + * @param profiler: The CPU profiler to stop. + * @param stream: The output stream callback for receiving the data. + * @param streamData: Optional data to be passed to the stream callback. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_StopCpuProfiler(JSVM_VM vm, + JSVM_CpuProfiler profiler, + JSVM_OutputStream stream, + void* streamData); + +/** + * @brief This funciton takes the current heap snapshot and output to the stream. + * + * @param vm: The VM whose heap snapshot is taken. + * @param stream: The output stream callback for receiving the data. + * @param streamData: Optional data to be passed to the stream callback. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_TakeHeapSnapshot(JSVM_VM vm, + JSVM_OutputStream stream, + void* streamData); + +/** + * @brief This functiong activates insepctor on host and port. + * + * @param env: The environment that the API is invoked under. + * @param host: The host to listen to for inspector connections. + * @param port: The port to listen to for inspector connections. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_OpenInspector(JSVM_Env env, + const char* host, + uint16_t port); + +/** + * @brief This function attempts to close all remaining inspector connections. + * + * @param env: The environment that the API is invoked under. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_CloseInspector(JSVM_Env env); + +/** + * @brief This function will block until a client (existing or connected later) + * has sent Runtime.runIfWaitingForDebugger command. + * + * @param env: The environment that the API is invoked under. + * @param breakNextLine: Whether break on the next line of JavaScript code. + * @return Returns JSVM_OK if the API succeeded. + * @since 12 + */ +JSVM_EXTERN JSVM_Status OH_JSVM_WaitForDebugger(JSVM_Env env, + bool breakNextLine); + EXTERN_C_END /** @} */ diff --git a/ark_runtime/jsvm/jsvm_types.h b/ark_runtime/jsvm/jsvm_types.h index 7eb742b21d36f8cad0e537406736d57c195c903b..fadad53b152f6cf8f4f4e2c1835b68be3df2168e 100644 --- a/ark_runtime/jsvm/jsvm_types.h +++ b/ark_runtime/jsvm/jsvm_types.h @@ -92,6 +92,13 @@ typedef struct JSVM_Script__* JSVM_Script; */ typedef struct JSVM_Env__* JSVM_Env; +/** + * @brief To represent a JavaScript profiler. + * + * @since 12 + */ +typedef struct JSVM_CpuProfiler__* JSVM_CpuProfiler; + /** * @brief To represent a JavaScript VM environment. * @@ -162,6 +169,19 @@ typedef void(JSVM_CDECL* JSVM_Finalize)(JSVM_Env env, void* finalizeData, void* finalizeHint); +/** + * @brief Function pointer type for callback of ASCII output stream. The first parameter data is the data pointer. + * And the second parameter size is the data size to output. A null data pointer indicates the end of the stream. + * The third parameter streamData is the pointer passed in together with the callback to the API functions that + * generate data to the output stream. The callback returns true to indicate the stream can continue to accept + * data. Otherwise, it will abort the stream. + * + * @since 12 + */ +typedef bool(JSVM_CDECL* JSVM_OutputStream)(const char* data, + int size, + void* streamData); + /** * @brief JSVM_PropertyAttributes are flag used to control the behavior of properties set on a js object. * @@ -356,6 +376,40 @@ typedef enum { JSVM_MEMORY_PRESSURE_LEVEL_CRITICAL, } JSVM_MemoryPressureLevel; +/** + * @brief Heap statisics. + * + * @since 12 + */ +typedef struct { + /** the size of the total heap. */ + size_t totalHeapSize; + /** the executable size of the total heap. */ + size_t totalHeapSizeExecutable; + /** the physical size of the total heap. */ + size_t totalPhysicalSize; + /** the available size of the total heap. */ + size_t totalAvailableSize; + /** used size of the heap. */ + size_t usedHeapSize; + /** heap size limit. */ + size_t heapSizeLimit; + /** memory requested by the heap. */ + size_t mallocedMemory; + /** heap-requested external memory. */ + size_t externalMemory; + /** peak memory requested by the heap. */ + size_t peakMallocedMemory; + /** the number of native contexts. */ + size_t numberOfNativeContexts; + /** the number of detached contexts. */ + size_t numberOfDetachedContexts; + /** the size of the total global handles. */ + size_t totalGlobalHandlesSize; + /** the size of the used global handles. */ + size_t usedGlobalHandlesSize; +} JSVM_HeapStatistics; + /** * @brief Init the JavaScript VM with init option. * diff --git a/ark_runtime/jsvm/libjsvm.ndk.json b/ark_runtime/jsvm/libjsvm.ndk.json index 96e0e36dc5329aa8b6e60c734465cad94fd2b6f0..23ba1a5d1df75ac09a4ce230120ce7ff27405046 100644 --- a/ark_runtime/jsvm/libjsvm.ndk.json +++ b/ark_runtime/jsvm/libjsvm.ndk.json @@ -534,5 +534,37 @@ { "first_introduced": "11", "name": "OH_JSVM_CreateSnapshot" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_GetVM" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_GetHeapStatistics" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_StartCpuProfiler" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_StopCpuProfiler" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_TakeHeapSnapshot" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_OpenInspector" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_CloseInspector" + }, + { + "first_introduced": "12", + "name": "OH_JSVM_WaitForDebugger" } -] \ No newline at end of file +]