From 99014ec24983d25042476aa248dc8bede9eab961 Mon Sep 17 00:00:00 2001 From: zzhengxiang <2646125453@qq.com> Date: Fri, 20 Jun 2025 10:04:31 +0800 Subject: [PATCH] =?UTF-8?q?support=20jit=20on=20hiperf=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81v8=E5=86=85=E9=83=A8=E5=9B=9E=E6=A0=88=E5=92=8Cjit?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=20=E4=B8=BAhiperf=E6=98=BE=E7=A4=BAjit?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=8F=90=E4=BE=9B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zzhengxiang <2646125453@qq.com> --- src/js_native_api_v8.cpp | 48 ++++++++++++++++++++++++++++++++++++++++ src/jsvm_dfx.h | 27 ++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/js_native_api_v8.cpp b/src/js_native_api_v8.cpp index 70c5422..d7a235f 100644 --- a/src/js_native_api_v8.cpp +++ b/src/js_native_api_v8.cpp @@ -6000,3 +6000,51 @@ JSVM_Status OH_JSVM_PromiseRegisterHandler(JSVM_Env env, return ClearLastError(env); } + +__attribute__((visibility("default"))) int step_jsvm(void *ctx, ReadMemFunc readMem, JsvmStepParam *frame) +{ + uintptr_t preFp = 0; + readMem(ctx, *(frame->fp), &preFp); + uintptr_t prePc = 0; + readMem(ctx, *(frame->fp) + sizeof(void*), &prePc); + + *(frame->fp) = preFp; + *(frame->pc) = prePc; + *(frame->sp) = preFp; + return 0; +} + + +__attribute__((visibility("default"))) int create_jsvm_extractor(uintptr_t* extractorPptr, uint32_t pid) +{ + uintptr_t extractorPtr = 0; + if (v8::V8::CreateJSVMExtractor(extractorPtr, pid) == 0) { + *extractorPptr = extractorPtr; + return 0; + } else { + return -1; + } +} + +__attribute_((visibility)("default")) int destory_jsvm_extractor(uintptr_t extractorPtr) +{ + v8::V8::DeleteJSVMExtractor(extractorPtr); + return 0; +} + +__attribute_((visibility)("default")) int jsvm_parse_js_frame_info(uintptr_t pc, + uintptr_t jsvmExtractorPtr, + JsvmFunction* jsvmFunction) +{ + std::string codeName; + int ret = v8::V8::GetJSVMCodeName(jsvmExtractorPtr, pc, codeName); + if (ret == 0) { + size_t nameSize = codeName.size() + 1; + if (strcpy_s(jsvmFunction->functionName, nameSize, codeName.c_str()) != EOK) { + return -1; + } + return 0; + } else { + return -1; + } +} diff --git a/src/jsvm_dfx.h b/src/jsvm_dfx.h index 7aca9b4..f0c139e 100644 --- a/src/jsvm_dfx.h +++ b/src/jsvm_dfx.h @@ -122,6 +122,33 @@ private: } // namespace jsvm +constexpr uint16_t FUNCTIONNAME_MAX = 1024; + +struct JsvmStepParam { + uintptr_t *fp; + uintptr_t *sp; + uintptr_t *pc; + bool *isJsvmFrame; + + JsvmStepParam(uintptr_t *fp, uintptr_t *sp, uintptr_t *pc, bool *isJsvmFrame) + : fp(fp), sp(sp), pc(pc), isJsvmFrame(isJsvmFrame) {} +} +struct JsvmFunction { + char functionName[FUNCTIONNAME_MAX]; +} + +typedef bool (*ReadMemFunc)(void *ctx, uintptr_t addr, uintptr_t *val); + +extern "C" int step_jsvm(void *ctx, ReadMemFunc readMem, JsvmStepParam *frame); + +extern "C" int create_jsvm_extractor(uintptr_t *extractorPptr, uint32_t pid); + +extern "C" int destory_jsvm_extractor(uintptr_t extractorPtr); + +extern "C" int jsvm_parse_js_frame_info(uintptr_t pc, + uintptr_t jsvmExtractorPtr, + JsvmFunction *jsvmFunction); + #define UNREACHABLE(...) JSVM_FATAL("Unreachable code reached" __VA_OPT__(": ") __VA_ARGS__) -- Gitee