Skip to content

Commit 6b5b768

Browse files
wqyfavorjianliang00
authored andcommitted
[Optimize] Add debug information for VMs
To better display VM information in trace, add debug information to MTS and BTS virtual machines.
1 parent 2505d12 commit 6b5b768

14 files changed

Lines changed: 60 additions & 14 deletions

File tree

core/runtime/js/jsi/jsc/jsc_context_group_wrapper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <JavaScriptCore/JavaScript.h>
88

9+
#include <string>
910
#include <unordered_map>
1011

1112
#include "core/runtime/js/jsi/jsi.h"
@@ -17,7 +18,8 @@ class JSCContextGroupWrapper : public VMInstance {
1718
public:
1819
JSCContextGroupWrapper() = default;
1920
~JSCContextGroupWrapper() override;
20-
JSRuntimeType GetRuntimeType() override { return JSRuntimeType::jsc; }
21+
JSRuntimeType GetRuntimeType() const override { return JSRuntimeType::jsc; }
22+
std::string GetDebugDescription() const override { return "jsc"; }
2123

2224
void InitContextGroup();
2325
inline JSContextGroupRef GetContextGroup() { return group_; }

core/runtime/js/jsi/jsi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,8 @@ class VMInstance {
17341734
// static VMInstance createVM();
17351735
public:
17361736
virtual ~VMInstance() = default;
1737-
virtual JSRuntimeType GetRuntimeType() = 0;
1737+
virtual JSRuntimeType GetRuntimeType() const = 0;
1738+
virtual std::string GetDebugDescription() const = 0;
17381739
};
17391740

17401741
class HostGlobal {

core/runtime/js/jsi/jsvm/jsvm_runtime_wrapper.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <ark_runtime/jsvm.h>
88
#include <ark_runtime/jsvm_types.h>
99

10+
#include <string>
11+
1012
#include "core/runtime/js/jsi/jsi.h"
1113

1214
namespace lynx {
@@ -17,7 +19,8 @@ class JSVMRuntimeInstance : public VMInstance {
1719
JSVMRuntimeInstance() = default;
1820
~JSVMRuntimeInstance() override;
1921

20-
JSRuntimeType GetRuntimeType() override { return JSRuntimeType::jsvm; };
22+
JSRuntimeType GetRuntimeType() const override { return JSRuntimeType::jsvm; };
23+
std::string GetDebugDescription() const override { return "jsvm"; }
2124

2225
void InitInstance();
2326
JSVM_VM GetVM() const { return vm_; }

core/runtime/js/jsi/quickjs/quickjs_runtime_wrapper.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ void QuickjsRuntimeInstance::RemoveObserver(JSIObserver* obs) {
138138
obs_set_ptr_.erase(obs);
139139
}
140140

141+
std::string QuickjsRuntimeInstance::GetDebugDescription() const {
142+
if (rt_) {
143+
return std::string("quickjs(") + (LEPUS_IsGCModeRT(rt_) ? "gc)" : "rc)");
144+
} else {
145+
return "";
146+
}
147+
}
148+
141149
void QuickjsRuntimeInstance::AddToIdContainer() {
142150
GetFunctionIdContainer().insert({rt_, s_function_id_});
143151
GetObjectIdContainer().insert({rt_, s_object_id_});

core/runtime/js/jsi/quickjs/quickjs_runtime_wrapper.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ class QuickjsRuntimeInstance : public VMInstance, public GCObserver {
8686
void AddObserver(JSIObserver* obs);
8787
void RemoveObserver(JSIObserver* obs);
8888

89-
JSRuntimeType GetRuntimeType() override { return JSRuntimeType::quickjs; }
89+
JSRuntimeType GetRuntimeType() const override {
90+
return JSRuntimeType::quickjs;
91+
}
92+
std::string GetDebugDescription() const override;
9093

9194
// Must exec in use thread.
9295
void AddToIdContainer();

core/runtime/js/jsi/v8/v8_isolate_wrapper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef CORE_RUNTIME_JS_JSI_V8_V8_ISOLATE_WRAPPER_H_
55
#define CORE_RUNTIME_JS_JSI_V8_V8_ISOLATE_WRAPPER_H_
66

7+
#include <string>
78
#include <unordered_map>
89

910
#include "core/base/observer/observer_list.h"
@@ -25,7 +26,8 @@ class V8IsolateInstance : public VMInstance {
2526
// observers_.RemoveObserver(obs);
2627
// }
2728
virtual v8::Isolate* Isolate() const = 0;
28-
JSRuntimeType GetRuntimeType() { return JSRuntimeType::v8; }
29+
JSRuntimeType GetRuntimeType() const override { return JSRuntimeType::v8; }
30+
std::string GetDebugDescription() const override { return "v8"; }
2931
};
3032

3133
} // namespace js

core/runtime/lepus/vm_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class VMContext : public runtime::MTSContext {
5858
virtual runtime::ContextType Type() const override {
5959
return runtime::ContextType::VMContextType;
6060
}
61+
virtual std::string GetDebugDescription() const override { return "lepus"; }
6162

6263
void RegisterGlobalFunction(const runtime::RenderBindingFunction* funcs,
6364
size_t size) override;

core/runtime/lepusng/quick_context.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ bool QuickContext::ExecuteBinaryInternal(Value* ret_val) {
683683
return true;
684684
}
685685

686+
std::string QuickContext::GetDebugDescription() const {
687+
return std::string("quickjs(") + (LEPUS_IsGCModeRT(runtime_) ? "gc)" : "rc)");
688+
}
689+
686690
void QuickContext::TriggerVmGC() {
687691
if (!gc_flag_) return;
688692
LEPUS_TrigGC(runtime_);

core/runtime/lepusng/quick_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class QuickContext : private LEPUSRuntimeData,
108108
return runtime::ContextType::LepusNGContextType;
109109
}
110110

111+
virtual std::string GetDebugDescription() const override;
112+
111113
virtual void TriggerVmGC() override;
112114
virtual void UpdateGCTiming(bool is_start) override;
113115
virtual int64_t GetCurrentHeapSizeBytes() override;

core/runtime/mts_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class MTSContext {
7070
virtual void Initialize() = 0;
7171

7272
virtual ContextType Type() const = 0;
73+
virtual std::string GetDebugDescription() const = 0;
7374

7475
bool IsVMContext() const { return Type() == ContextType::VMContextType; }
7576
bool IsLepusNGContext() const {

0 commit comments

Comments
 (0)