Skip to content

Commit 5c87d3e

Browse files
committed
[Refactor][DevTool] Split JS engine related logic.
1. Added `JSDebugProxy` to create all objects dependent on the JS engine. 2. Added a singleton `JSDebugHelper` to manage the pointer to `JSDebugProxy`. (Android only) 3. Extracted `JSDebugProxy` and JS engine related logic from lynxdevtool.so into a separate lynxdevtool_js_bridge.so, so that lynxdevtool.so no longer depends directly on the JS engines. 4. Load lynxdevtool_js_bridge.so only when `ILynxDevToolService.getLoadJsBridge()` returns true. SkipChecks: macro
1 parent d07be3f commit 5c87d3e

File tree

23 files changed

+509
-142
lines changed

23 files changed

+509
-142
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ deps = {
145145
'build': {
146146
"type": "git",
147147
"url": "https://github.com/lynx-family/buildroot.git",
148-
"commit": "01f8665ff78d9f55c56b56db86106eba1ba81bad",
148+
"commit": "6ed90b3a313371623499ae052416009830a95e92",
149149
"ignore_in_git": True,
150150
"condition": system in ['linux', 'darwin', 'windows']
151151
},

build_overrides/darwin.gni

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ JSDebug_deps = rebase_path(
103103
"../devtool/lynx_devtool/js_debug:devtool_common_js_debug",
104104
"../devtool/lynx_devtool/js_debug:devtool_js_debug",
105105
"../devtool/lynx_devtool/js_debug:devtool_quickjs_debug",
106-
"../devtool/lynx_devtool/js_debug/:devtool_lepus_debug_sources",
106+
"../devtool/lynx_devtool/js_debug:devtool_lepus_debug",
107+
"../devtool/lynx_devtool/js_debug:devtool_lepus_debug_manager",
108+
"../devtool/lynx_devtool/js_debug:js_debug_bridge",
107109
])
108110

109111
js_debug_dependency = [

devtool/lynx_devtool/agent/BUILD.gn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,11 @@ devtool_source_set("agent") {
110110
"../../../base/src:base_log_headers",
111111
"//third_party/zlib",
112112
]
113+
public_configs = [ ":common_config" ]
114+
}
115+
116+
config("common_config") {
117+
if (enable_unittests) {
118+
defines = [ "ENABLE_UNITTESTS" ]
119+
}
113120
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2025 The Lynx Authors. All rights reserved.
2+
// Licensed under the Apache License Version 2.0 that can be found in the
3+
// LICENSE file in the root directory of this source tree.
4+
5+
#include <jni.h>
6+
7+
#include <memory>
8+
9+
#include "devtool/lynx_devtool/js_debug/helper/js_debug_helper.h"
10+
#include "devtool/lynx_devtool/js_debug/helper/js_debug_proxy_impl.h"
11+
12+
namespace lynx {
13+
namespace devtool {
14+
15+
extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
16+
auto proxy = std::make_unique<JSDebugProxyImpl>();
17+
JSDebugHelper::GetInstance()->SetJSDebugProxy(std::move(proxy));
18+
19+
return JNI_VERSION_1_6;
20+
}
21+
22+
} // namespace devtool
23+
} // namespace lynx

devtool/lynx_devtool/js_debug/BUILD.gn

Lines changed: 87 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import("../../../core/runtime/jsi/v8/v8.gni")
55
import("../../../testing/test.gni")
66
import("../devtool.gni")
77

8+
if (is_android) {
9+
import("../../../platform/android/lynx_android/LynxAndroid.gni")
10+
}
11+
812
devtool_common_js_debug_sources = [
13+
"helper/js_debug_helper.cc",
14+
"helper/js_debug_helper.h",
15+
"helper/js_debug_proxy.h",
916
"inspector_client_delegate_impl.cc",
1017
"inspector_client_delegate_impl.h",
1118
"inspector_const_extend.h",
@@ -97,39 +104,23 @@ devtool_source_set("devtool_js_debug") {
97104
":devtool_common_js_debug",
98105
"../../../base/src:base_log_headers",
99106
]
100-
if (!enable_unittests) {
101-
deps += [ ":devtool_quickjs_debug" ]
102-
if (is_android || jsengine_type == "v8") {
103-
deps += [ ":devtool_v8_debug" ]
104-
include_dirs = [ v8_headers_search_path ]
105-
}
106-
}
107-
public_configs = [ ":common_config" ]
108107
}
109108

110-
devtool_source_set("devtool_lepus_debug_sources") {
109+
devtool_source_set("devtool_lepus_debug_manager") {
110+
sources = [
111+
"lepus/manager/lepus_inspector_manager_impl.cc",
112+
"lepus/manager/lepus_inspector_manager_impl.h",
113+
]
114+
deps = [ "../../js_inspect/lepus:lepus_debug" ]
115+
}
116+
117+
devtool_source_set("devtool_lepus_debug") {
111118
sources = devtool_lepus_debug_sources
112119
deps = [
113120
":devtool_common_js_debug",
114121
"../../../base/src:base_log_headers",
115122
"../recorder:recorder",
116123
]
117-
118-
if (!enable_unittests) {
119-
sources += [
120-
"lepus/manager/lepus_inspector_manager_impl.cc",
121-
"lepus/manager/lepus_inspector_manager_impl.h",
122-
]
123-
}
124-
125-
public_configs = [ ":common_config" ]
126-
}
127-
128-
devtool_source_set("devtool_lepus_debug") {
129-
deps = [ ":devtool_lepus_debug_sources" ]
130-
if (!enable_unittests) {
131-
deps += [ "../../js_inspect/lepus:lepus_debug" ]
132-
}
133124
}
134125

135126
devtool_source_set("js_debug") {
@@ -138,11 +129,26 @@ devtool_source_set("js_debug") {
138129
":devtool_lepus_debug",
139130
"../../../third_party/rapidjson:rapidjson",
140131
]
132+
if (!is_android && !enable_unittests) {
133+
deps += [ ":js_debug_bridge" ]
134+
}
141135
}
142136

143-
config("common_config") {
144-
if (enable_unittests) {
145-
defines = [ "ENABLE_UNITTESTS" ]
137+
devtool_source_set("js_debug_bridge") {
138+
sources = [
139+
"helper/js_debug_proxy_impl.cc",
140+
"helper/js_debug_proxy_impl.h",
141+
]
142+
if (is_android) {
143+
sources += [ "../android/devtool_js_bridge.cc" ]
144+
}
145+
deps = [
146+
":devtool_lepus_debug_manager",
147+
":devtool_quickjs_debug",
148+
]
149+
if (is_android || jsengine_type == "v8") {
150+
deps += [ ":devtool_v8_debug" ]
151+
include_dirs = [ v8_headers_search_path ]
146152
}
147153
}
148154

@@ -174,3 +180,56 @@ group("js_debug_unit_test") {
174180
testonly = true
175181
deps = [ ":js_debug_unittest_exec" ]
176182
}
183+
184+
if (is_android) {
185+
cmake_target("lynxdevtool_js_bridge") {
186+
is_only_sub_cmake = true
187+
cmake_version = "3.4.1"
188+
target_type = "shared_library"
189+
output_name = "lynxdevtool_js_bridge"
190+
deps = [
191+
":lynxdevtool_js_bridge_lib",
192+
"../../../platform/android/lynx_android:lynx_android",
193+
"../../../platform/android/lynx_devtool:lynxdevtool",
194+
]
195+
196+
lib_dirs = [
197+
"${primjs_native_lib_dir}",
198+
"${v8_native_lib_dir}",
199+
]
200+
libs = [
201+
"android",
202+
"dl",
203+
"log",
204+
"quick",
205+
"v8_libfull.cr",
206+
]
207+
208+
if (enable_napi_binding) {
209+
libs += [
210+
"napi",
211+
"napi_v8",
212+
]
213+
}
214+
215+
configs = [
216+
"../../../platform/android/lynx_devtool:devtool_common_defines",
217+
"../../../platform/android/lynx_devtool:devtool_flag_config",
218+
"../../../platform/android/lynx_devtool:devtool_ldflag_config",
219+
"../../../platform/android:16kb_page",
220+
]
221+
}
222+
223+
devtool_source_set("lynxdevtool_js_bridge_lib") {
224+
public_deps = [
225+
":js_debug_bridge",
226+
":v8_profile_devtool",
227+
"../../../core/build:build",
228+
]
229+
230+
# jsbridge source file
231+
if (enable_napi_binding) {
232+
public_deps += [ "../../../core/runtime/bindings/napi:napi_binding_v8" ]
233+
}
234+
}
235+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Set the minimum version of CMAKE that is required
2+
cmake_minimum_required(VERSION 3.4.1)
3+
4+
# According to the build variant,
5+
# import the CMakeLists-impl.cmake file to compile the native methods.
6+
include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists_impl/${FLAVOR_NAME}${BUILD_TYPE}${ANDROID_ABI}/CMakeLists.txt)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2025 The Lynx Authors. All rights reserved.
2+
// Licensed under the Apache License Version 2.0 that can be found in the
3+
// LICENSE file in the root directory of this source tree.
4+
5+
#include "devtool/lynx_devtool/js_debug/helper/js_debug_helper.h"
6+
7+
namespace lynx {
8+
namespace devtool {
9+
10+
JSDebugHelper* JSDebugHelper::GetInstance() {
11+
static JSDebugHelper instance_;
12+
return &instance_;
13+
}
14+
15+
std::unique_ptr<piper::RuntimeInspectorManager>
16+
JSDebugHelper::CreateRuntimeInspectorManager(const std::string& vm_type) {
17+
if (proxy_ == nullptr) {
18+
return nullptr;
19+
}
20+
return proxy_->CreateRuntimeInspectorManager(vm_type);
21+
}
22+
23+
std::unique_ptr<lepus::LepusInspectorManager>
24+
JSDebugHelper::CreateLepusInspectorManager() {
25+
if (proxy_ == nullptr) {
26+
return nullptr;
27+
}
28+
return proxy_->CreateLepusInspectorManager();
29+
}
30+
31+
void JSDebugHelper::RegisterNapiRuntimeProxy() {
32+
if (proxy_ == nullptr) {
33+
return;
34+
}
35+
proxy_->RegisterNapiRuntimeProxy();
36+
}
37+
38+
std::shared_ptr<piper::Runtime> JSDebugHelper::MakeRuntime(
39+
const std::string& vm_type) {
40+
if (proxy_ == nullptr) {
41+
return nullptr;
42+
}
43+
return proxy_->MakeRuntime(vm_type);
44+
}
45+
46+
#if ENABLE_TRACE_PERFETTO
47+
std::shared_ptr<profile::RuntimeProfiler> JSDebugHelper::MakeRuntimeProfiler(
48+
std::shared_ptr<piper::JSIContext> js_context, const std::string& vm_type) {
49+
if (proxy_ == nullptr) {
50+
return nullptr;
51+
}
52+
return proxy_->MakeRuntimeProfiler(js_context, vm_type);
53+
}
54+
#endif
55+
56+
} // namespace devtool
57+
} // namespace lynx
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2025 The Lynx Authors. All rights reserved.
2+
// Licensed under the Apache License Version 2.0 that can be found in the
3+
// LICENSE file in the root directory of this source tree.
4+
5+
#ifndef DEVTOOL_LYNX_DEVTOOL_JS_DEBUG_HELPER_JS_DEBUG_HELPER_H_
6+
#define DEVTOOL_LYNX_DEVTOOL_JS_DEBUG_HELPER_JS_DEBUG_HELPER_H_
7+
8+
#include <memory>
9+
#include <string>
10+
11+
#include "base/include/base_export.h"
12+
#include "core/inspector/lepus_inspector_manager.h"
13+
#include "core/inspector/runtime_inspector_manager.h"
14+
#include "core/runtime/jsi/jsi.h"
15+
#include "core/runtime/profile/runtime_profiler.h"
16+
#include "devtool/lynx_devtool/js_debug/helper/js_debug_proxy.h"
17+
18+
namespace lynx {
19+
namespace devtool {
20+
21+
class JSDebugHelper {
22+
public:
23+
BASE_EXPORT static JSDebugHelper* GetInstance();
24+
25+
BASE_EXPORT void SetJSDebugProxy(std::unique_ptr<JSDebugProxy> proxy) {
26+
proxy_ = std::move(proxy);
27+
}
28+
29+
bool IsHelperAvailable() const { return proxy_ != nullptr; }
30+
31+
std::unique_ptr<piper::RuntimeInspectorManager> CreateRuntimeInspectorManager(
32+
const std::string& vm_type);
33+
std::unique_ptr<lepus::LepusInspectorManager> CreateLepusInspectorManager();
34+
35+
void RegisterNapiRuntimeProxy();
36+
std::shared_ptr<piper::Runtime> MakeRuntime(const std::string& vm_type);
37+
#if ENABLE_TRACE_PERFETTO
38+
std::shared_ptr<profile::RuntimeProfiler> MakeRuntimeProfiler(
39+
std::shared_ptr<piper::JSIContext> js_context,
40+
const std::string& vm_type);
41+
#endif
42+
43+
JSDebugHelper(const JSDebugHelper&) = delete;
44+
JSDebugHelper& operator=(const JSDebugHelper&) = delete;
45+
JSDebugHelper(JSDebugHelper&&) = delete;
46+
JSDebugHelper& operator=(JSDebugHelper&&) = delete;
47+
48+
private:
49+
JSDebugHelper() = default;
50+
51+
std::unique_ptr<JSDebugProxy> proxy_;
52+
};
53+
54+
} // namespace devtool
55+
} // namespace lynx
56+
57+
#endif // DEVTOOL_LYNX_DEVTOOL_JS_DEBUG_HELPER_JS_DEBUG_HELPER_H_
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2025 The Lynx Authors. All rights reserved.
2+
// Licensed under the Apache License Version 2.0 that can be found in the
3+
// LICENSE file in the root directory of this source tree.
4+
5+
#ifndef DEVTOOL_LYNX_DEVTOOL_JS_DEBUG_HELPER_JS_DEBUG_PROXY_H_
6+
#define DEVTOOL_LYNX_DEVTOOL_JS_DEBUG_HELPER_JS_DEBUG_PROXY_H_
7+
8+
#include <memory>
9+
#include <string>
10+
11+
namespace lynx {
12+
13+
namespace profile {
14+
class RuntimeProfiler;
15+
} // namespace profile
16+
17+
namespace piper {
18+
class Runtime;
19+
class JSIContext;
20+
class RuntimeInspectorManager;
21+
} // namespace piper
22+
23+
namespace lepus {
24+
class LepusInspectorManager;
25+
} // namespace lepus
26+
27+
namespace devtool {
28+
29+
class JSDebugProxy {
30+
public:
31+
JSDebugProxy() = default;
32+
virtual ~JSDebugProxy() = default;
33+
34+
virtual std::unique_ptr<piper::RuntimeInspectorManager>
35+
CreateRuntimeInspectorManager(const std::string& vm_type) {
36+
return nullptr;
37+
}
38+
virtual std::unique_ptr<lepus::LepusInspectorManager>
39+
CreateLepusInspectorManager() {
40+
return nullptr;
41+
}
42+
43+
virtual void RegisterNapiRuntimeProxy() {}
44+
virtual std::shared_ptr<piper::Runtime> MakeRuntime(
45+
const std::string& vm_type) {
46+
return nullptr;
47+
}
48+
#if ENABLE_TRACE_PERFETTO
49+
virtual std::shared_ptr<profile::RuntimeProfiler> MakeRuntimeProfiler(
50+
std::shared_ptr<piper::JSIContext> js_context,
51+
const std::string& vm_type) {
52+
return nullptr;
53+
}
54+
#endif
55+
};
56+
} // namespace devtool
57+
} // namespace lynx
58+
59+
#endif // DEVTOOL_LYNX_DEVTOOL_JS_DEBUG_HELPER_JS_DEBUG_PROXY_H_

0 commit comments

Comments
 (0)