From 94caafa5fdfa0938972cb7340a64eb13e5885208 Mon Sep 17 00:00:00 2001 From: lhc Date: Thu, 17 Jul 2025 09:49:33 +0800 Subject: [PATCH 1/2] Resolve build issues Issues: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICMV0P?from=project-issue Signed-off-by: lhc Change-Id: I0bf5b566ba5fca2a97b32a8d0fca1ef273628990 --- compiler_service/test/BUILD.gn | 18 +++++++++--------- .../aotcompilerargsprepare_fuzzer/BUILD.gn | 1 - .../compilerinterfacestub_fuzzer/BUILD.gn | 1 - .../aotcompilerargshandler_unit/BUILD.gn | 1 - .../unittest/aotcompilerclient_unit/BUILD.gn | 1 - .../aotcompilererrorutils_unit/BUILD.gn | 1 - .../unittest/aotcompilerimpl_unit/BUILD.gn | 1 - .../unittest/aotcompilerproxy_unit/BUILD.gn | 1 - .../unittest/aotcompilerservice_unit/BUILD.gn | 1 - .../unittest/aotcompilerstub_unit/BUILD.gn | 1 - 10 files changed, 9 insertions(+), 18 deletions(-) diff --git a/compiler_service/test/BUILD.gn b/compiler_service/test/BUILD.gn index 933eb0eae8..f457e8ad7f 100644 --- a/compiler_service/test/BUILD.gn +++ b/compiler_service/test/BUILD.gn @@ -14,20 +14,20 @@ group("compiler_service_unittest") { testonly = true deps = [ - #"unittest/aotcompilerargshandler_unit:AotCompilerArgsHandlerUnitTest", - #"unittest/aotcompilerclient_unit:AotCompilerClientUnitTest", - #"unittest/aotcompilererrorutils_unit:AotCompilerErrorUtilsUnitTest", - #"unittest/aotcompilerimpl_unit:AotCompilerImplUnitTest", - #"unittest/aotcompilerproxy_unit:AotCompilerProxyUnitTest", - #"unittest/aotcompilerservice_unit:AotCompilerServiceUnitTest", - #"unittest/aotcompilerstub_unit:AotCompilerStubUnitTest", + "unittest/aotcompilerargshandler_unit:AotCompilerArgsHandlerUnitTest", + "unittest/aotcompilerclient_unit:AotCompilerClientUnitTest", + "unittest/aotcompilererrorutils_unit:AotCompilerErrorUtilsUnitTest", + "unittest/aotcompilerimpl_unit:AotCompilerImplUnitTest", + "unittest/aotcompilerproxy_unit:AotCompilerProxyUnitTest", + "unittest/aotcompilerservice_unit:AotCompilerServiceUnitTest", + "unittest/aotcompilerstub_unit:AotCompilerStubUnitTest", ] } group("compiler_service_fuzztest") { testonly = true deps = [ - #"fuzztest/aotcompilerargsprepare_fuzzer:AotCompilerArgsPrepareFuzzTest", - #"fuzztest/compilerinterfacestub_fuzzer:CompilerInterfaceStubFuzzTest", + "fuzztest/aotcompilerargsprepare_fuzzer:AotCompilerArgsPrepareFuzzTest", + "fuzztest/compilerinterfacestub_fuzzer:CompilerInterfaceStubFuzzTest", ] } diff --git a/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn b/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn index 6270be63b0..59e3407cf1 100644 --- a/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn +++ b/compiler_service/test/fuzztest/aotcompilerargsprepare_fuzzer/BUILD.gn @@ -31,7 +31,6 @@ ohos_fuzztest("AotCompilerArgsPrepareFuzzTest") { ] configs = [ "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn b/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn index 9fe719bfbe..4f40c24150 100644 --- a/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn +++ b/compiler_service/test/fuzztest/compilerinterfacestub_fuzzer/BUILD.gn @@ -31,7 +31,6 @@ ohos_fuzztest("CompilerInterfaceStubFuzzTest") { ] configs = [ "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn index 328a9661ac..1a8f27f921 100644 --- a/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerargshandler_unit/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("AotCompilerArgsHandlerUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn index 3c928442ca..5299c50d77 100644 --- a/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerclient_unit/BUILD.gn @@ -29,7 +29,6 @@ ohos_unittest("AotCompilerClientUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn index 0dc8b62f61..0648707e85 100644 --- a/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilererrorutils_unit/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("AotCompilerErrorUtilsUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn index 544ca59542..5ac62e3f41 100644 --- a/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerimpl_unit/BUILD.gn @@ -29,7 +29,6 @@ ohos_unittest("AotCompilerImplUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn index 7d92ac28ac..d530ab7299 100644 --- a/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("AotCompilerProxyUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn index c8517a6fe2..9db3234f84 100644 --- a/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn @@ -29,7 +29,6 @@ ohos_unittest("AotCompilerServiceUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ diff --git a/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn index c451bf646a..a417cf0a97 100644 --- a/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("AotCompilerStubUnitTest") { configs = [ ":module_private_config", "$js_root:ark_jsruntime_public_config", - "$js_root:ark_jsruntime_common_config", ] version_script = "${compiler_service_root}/libaot_compiler_service.map" sources = [ -- Gitee From 410298df54c79bfb5439b385afc9302f6cdb0d40 Mon Sep 17 00:00:00 2001 From: lhc Date: Mon, 21 Jul 2025 20:02:58 +0800 Subject: [PATCH 2/2] Test modify2 Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICNTED?from=project-issue Signed-off-by: lhc Change-Id: Ief530a11a714b1bdd72c5d8c61ff9e92768fed74 --- BUILD.gn | 11 +- ecmascript/cross_vm/builtins_gc_hybrid.cpp | 32 ++++ ecmascript/cross_vm/builtins_gc_hybrid.h | 26 ++++ ecmascript/cross_vm/cross_vm_operator.cpp | 4 +- ecmascript/cross_vm/daemon_task_hybrid.h | 38 +++++ .../cross_vm/ecma_global_storage_hybrid.h | 40 +++++ ecmascript/cross_vm/ecma_vm_hybrid.h | 46 ++++++ .../cross_vm/global_env_constants_hybrid.h | 27 ++++ ecmascript/cross_vm/heap_hybrid.cpp | 84 ++++++++++ ecmascript/cross_vm/heap_hybrid.h | 55 +++++++ ecmascript/cross_vm/js_hclass_hybrid.h | 26 ++++ ecmascript/cross_vm/js_tagged_value_hybrid.h | 28 ++++ ecmascript/cross_vm/js_thread_hybrid.h | 45 ++++++ ecmascript/cross_vm/jsnapi_expo_hybrid.cpp | 145 ++++++++++++++++++ ecmascript/cross_vm/jsnapi_expo_hybrid.h | 78 ++++++++++ ecmascript/cross_vm/jsnapi_hybrid.h | 73 +++++++++ ecmascript/cross_vm/object_factory_hybrid.cpp | 26 ++++ ecmascript/cross_vm/object_factory_hybrid.h | 24 +++ .../unified_gc/unified_gc.cpp | 5 +- .../{mem => cross_vm}/unified_gc/unified_gc.h | 0 .../unified_gc/unified_gc_marker-inl.h | 3 +- .../unified_gc/unified_gc_marker.cpp | 2 +- .../unified_gc/unified_gc_marker.h | 0 ecmascript/cross_vm/work_manager_hybrid-inl.h | 35 +++++ ecmascript/cross_vm/work_manager_hybrid.h | 23 +++ ecmascript/js_thread.cpp | 24 +-- ecmascript/js_thread.h | 31 +--- ecmascript/mem/heap-inl.h | 7 - ecmascript/mem/heap.cpp | 73 ++------- ecmascript/mem/heap.h | 33 +--- ecmascript/mem/verification.h | 1 - ecmascript/mem/work_manager-inl.h | 15 -- ecmascript/mem/work_manager.h | 5 +- ecmascript/napi/include/jsnapi.h | 61 +------- ecmascript/napi/include/jsnapi_expo.h | 45 ++---- ecmascript/napi/jsnapi_expo.cpp | 116 -------------- ecmascript/object_factory.cpp | 7 - ecmascript/object_factory.h | 3 +- ecmascript/tests/unified_gc_test.cpp | 2 +- 39 files changed, 920 insertions(+), 379 deletions(-) create mode 100644 ecmascript/cross_vm/builtins_gc_hybrid.cpp create mode 100644 ecmascript/cross_vm/builtins_gc_hybrid.h create mode 100644 ecmascript/cross_vm/daemon_task_hybrid.h create mode 100644 ecmascript/cross_vm/ecma_global_storage_hybrid.h create mode 100644 ecmascript/cross_vm/ecma_vm_hybrid.h create mode 100644 ecmascript/cross_vm/global_env_constants_hybrid.h create mode 100644 ecmascript/cross_vm/heap_hybrid.cpp create mode 100644 ecmascript/cross_vm/heap_hybrid.h create mode 100644 ecmascript/cross_vm/js_hclass_hybrid.h create mode 100644 ecmascript/cross_vm/js_tagged_value_hybrid.h create mode 100644 ecmascript/cross_vm/js_thread_hybrid.h create mode 100644 ecmascript/cross_vm/jsnapi_expo_hybrid.cpp create mode 100644 ecmascript/cross_vm/jsnapi_expo_hybrid.h create mode 100644 ecmascript/cross_vm/jsnapi_hybrid.h create mode 100644 ecmascript/cross_vm/object_factory_hybrid.cpp create mode 100644 ecmascript/cross_vm/object_factory_hybrid.h rename ecmascript/{mem => cross_vm}/unified_gc/unified_gc.cpp (96%) rename ecmascript/{mem => cross_vm}/unified_gc/unified_gc.h (100%) rename ecmascript/{mem => cross_vm}/unified_gc/unified_gc_marker-inl.h (97%) rename ecmascript/{mem => cross_vm}/unified_gc/unified_gc_marker.cpp (97%) rename ecmascript/{mem => cross_vm}/unified_gc/unified_gc_marker.h (100%) create mode 100644 ecmascript/cross_vm/work_manager_hybrid-inl.h create mode 100644 ecmascript/cross_vm/work_manager_hybrid.h diff --git a/BUILD.gn b/BUILD.gn index 2dec2fe271..af65466ab0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1042,8 +1042,6 @@ ecma_source = [ "ecmascript/mem/shared_heap/shared_full_gc.cpp", "ecmascript/mem/shared_heap/shared_gc_marker.cpp", "ecmascript/mem/shared_heap/shared_space.cpp", - "ecmascript/mem/unified_gc/unified_gc.cpp", - "ecmascript/mem/unified_gc/unified_gc_marker.cpp", "ecmascript/mem/space.cpp", "ecmascript/mem/sparse_space.cpp", "ecmascript/mem/tagged_object.cpp", @@ -1180,6 +1178,15 @@ if (enable_next_optimization) { ecma_source += [ "ecmascript/base/json_stringifier.cpp" ] } +ecma_source += [ + "ecmascript/cross_vm/unified_gc/unified_gc.cpp", + "ecmascript/cross_vm/unified_gc/unified_gc_marker.cpp", + "ecmascript/cross_vm/builtins_gc_hybrid.cpp", + "ecmascript/cross_vm/heap_hybrid.cpp", + "ecmascript/cross_vm/jsnapi_expo_hybrid.cpp", + "ecmascript/cross_vm/object_factory_hybrid.cpp", +] + hitrace_scope_source = [] if (is_ohos && is_standard_system && enable_hitrace) { hitrace_scope_source += [ "ecmascript/jobs/hitrace_scope.cpp" ] diff --git a/ecmascript/cross_vm/builtins_gc_hybrid.cpp b/ecmascript/cross_vm/builtins_gc_hybrid.cpp new file mode 100644 index 0000000000..27bbef6263 --- /dev/null +++ b/ecmascript/cross_vm/builtins_gc_hybrid.cpp @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "ecmascript/builtins/builtins_gc.h" +#include "ecmascript/builtins/builtins_ark_tools.h" + +namespace panda::ecmascript::builtins { + +JSTaggedValue BuiltinsGc::ClearWeakRefForTest(EcmaRuntimeCallInfo *info) +{ + RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); + ASSERT(info); + JSThread *thread = info->GetThread(); + if (!((thread)->GetEcmaVM()->GetJSOptions().IsOpenArkTools())) { + return JSTaggedValue::Undefined(); + } + EcmaVM::ClearKeptObjects(thread); + return JSTaggedValue::Undefined(); +} +} // namespace panda::ecmascript::builtins diff --git a/ecmascript/cross_vm/builtins_gc_hybrid.h b/ecmascript/cross_vm/builtins_gc_hybrid.h new file mode 100644 index 0000000000..7d2446899f --- /dev/null +++ b/ecmascript/cross_vm/builtins_gc_hybrid.h @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_BUILTINS_GC_HYBRID_H +#define ECMASCRIPT_CROSS_VM_BUILTINS_GC_HYBRID_H + +namespace panda::ecmascript::builtins { +#define BUILDINS_GC_HYBRID_EXTENSION \ + static JSTaggedValue ClearWeakRefForTest(EcmaRuntimeCallInfo *info); + +#define BUILTINS_GC_HYBRID_FUNCTION_ENTRY \ + BUILTINS_GC_FUNCTION_ENTRY("clearWeakRefForTest", ClearWeakRefForTest, 1, INVALID) + +} // namespace panda::ecmascript::builtins +#endif // ECMASCRIPT_CROSS_VM_BUILTINS_GC_HYBRID_H \ No newline at end of file diff --git a/ecmascript/cross_vm/cross_vm_operator.cpp b/ecmascript/cross_vm/cross_vm_operator.cpp index 1d71b59f50..9dce9fa560 100644 --- a/ecmascript/cross_vm/cross_vm_operator.cpp +++ b/ecmascript/cross_vm/cross_vm_operator.cpp @@ -17,8 +17,8 @@ #include "ecmascript/ecma_vm.h" #include "ecmascript/mem/heap-inl.h" -#include "ecmascript/mem/unified_gc/unified_gc.h" -#include "ecmascript/mem/unified_gc/unified_gc_marker.h" +#include "ecmascript/cross_vm/unified_gc/unified_gc.h" +#include "ecmascript/cross_vm/unified_gc/unified_gc_marker.h" namespace panda::ecmascript { diff --git a/ecmascript/cross_vm/daemon_task_hybrid.h b/ecmascript/cross_vm/daemon_task_hybrid.h new file mode 100644 index 0000000000..1965c6fd1c --- /dev/null +++ b/ecmascript/cross_vm/daemon_task_hybrid.h @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_DAEMON_TASK_HYBRID_H +#define ECMASCRIPT_CROSS_VM_DAEMON_TASK_HYBRID_H + +namespace panda::ecmascript { +#define DAEMON_TASK_HYBRID_DEF_EXTENSION \ +template \ +void TriggerUnifiedGCMarkTaskRunner() \ +{ \ + SharedHeap::GetInstance()->StartUnifiedGCMark(gcType, gcReason); \ +} \ +template \ +TriggerUnifiedGCMarkTask::TriggerUnifiedGCMarkTask(JSThread *thread) \ + : DaemonTask(thread, DaemonTaskType::TRIGGER_UNIFIED_GC_MARK, DaemonTaskGroup::GC_GROUP, \ + &TriggerUnifiedGCMarkTaskRunner) {} + + +#define DAEMON_TASK_HYBRID_DECL_EXTENSION \ + template \ + class TriggerUnifiedGCMarkTask : public DaemonTask { \ + public: \ + explicit TriggerUnifiedGCMarkTask(JSThread *thread); \ + }; +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_DAEMON_TASK_HYBRID_H diff --git a/ecmascript/cross_vm/ecma_global_storage_hybrid.h b/ecmascript/cross_vm/ecma_global_storage_hybrid.h new file mode 100644 index 0000000000..47241298f9 --- /dev/null +++ b/ecmascript/cross_vm/ecma_global_storage_hybrid.h @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_ECMA_GLOBAL_STORAGE_HYBRID_H +#define ECMASCRIPT_CROSS_VM_ECMA_GLOBAL_STORAGE_HYBRID_H + +namespace panda::ecmascript { +// todo liuhongchen +enum class NodeKind : uint8_t { + NORMAL_NODE, + UNIFIED_NODE, +}; + +#define ECMA_GLOBAL_STORAGE_HYBRID_EXTENSION \ + void SetNodeKind(NodeKind nodeKind) \ + { \ + nodeKind_ = nodeKind; \ + } \ + NodeKind GetNodeKind() \ + { \ + return nodeKind_; \ + } \ +private: \ + NodeKind nodeKind_ {NodeKind::NORMAL_NODE}; \ + NodeList *topXRefGlobalNodes_ {nullptr}; \ + NodeList *lastXRefGlobalNodes_ {nullptr}; \ + NodeList *xRefFreeListNodes_ {nullptr}; +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_ECMA_GLOBAL_STORAGE_HYBRID_H diff --git a/ecmascript/cross_vm/ecma_vm_hybrid.h b/ecmascript/cross_vm/ecma_vm_hybrid.h new file mode 100644 index 0000000000..c5d556218f --- /dev/null +++ b/ecmascript/cross_vm/ecma_vm_hybrid.h @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_ECMA_VM_HYBRID_H +#define ECMASCRIPT_CROSS_VM_ECMA_VM_HYBRID_H + +namespace panda::ecmascript { +// #define ECMA_VM_HYBRID_EXTENSION \ +// #ifdef PANDA_JS_ETS_HYBRID_MODE \ +// CrossVMOperator* GetCrossVMOperator() const \ +// { \ +// /* if (Runtime::GetInstance()->IsHybridVm()) */ \ +// return crossVMOperator_; \ +// } \ +// #endif /* PANDA_JS_ETS_HYBRID_MODE */ \ +// private: \ +// #ifdef PANDA_JS_ETS_HYBRID_MODE \ +// CrossVMOperator* crossVMOperator_ {nullptr}; \ +// #endif /* PANDA_JS_ETS_HYBRID_MODE */ \ +// protected: \ +// void PrintJSErrorInfo(const JSHandle &exceptionInfo) const; + + +#define ECMA_VM_HYBRID_GET_CROSS_VM_OP_EXTENSION \ + CrossVMOperator* GetCrossVMOperator() const \ + { \ + /* if (Runtime::GetInstance()->IsHybridVm()) */ \ + return crossVMOperator_; \ + } + + +#define ECMA_VM_HYBRID_GET_CROSS_VM_OP_DECL_EXTENSION \ + CrossVMOperator* crossVMOperator_ {nullptr}; +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_ECMA_VM_HYBRID_H diff --git a/ecmascript/cross_vm/global_env_constants_hybrid.h b/ecmascript/cross_vm/global_env_constants_hybrid.h new file mode 100644 index 0000000000..53aed16458 --- /dev/null +++ b/ecmascript/cross_vm/global_env_constants_hybrid.h @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_GLOBAL_ENV_CONSTANTS_HYBRID_H +#define ECMASCRIPT_CROSS_VM_GLOBAL_ENV_CONSTANTS_HYBRID_H + +namespace panda::ecmascript { +#define SHARED_GLOBAL_ENV_CONSTANT_STRING_HYBRID(V) \ + V(ProxyNapiWrapperString, PROXY_NAPI_WRAPPER_INDEX, "_proxynapiwrapper") \ + V(UnifiedGcCause, UNIFIED_GC_CAUSE, "unified") + +#define GLOBAL_ENV_CONSTANT_CLASS_HYBRID(V) \ + V(JSTaggedValue, XRefObjectClass, XREF_OBJECT_HCLASS_INDEX, ecma_roots_class) + +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_GLOBAL_ENV_CONSTANTS_HYBRID_H diff --git a/ecmascript/cross_vm/heap_hybrid.cpp b/ecmascript/cross_vm/heap_hybrid.cpp new file mode 100644 index 0000000000..5a4c324984 --- /dev/null +++ b/ecmascript/cross_vm/heap_hybrid.cpp @@ -0,0 +1,84 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "ecmascript/mem/heap.h" +#include "ecmascript/checkpoint/thread_state_transition.h" +#include "ecmascript/cross_vm/unified_gc/unified_gc.h" +#include "ecmascript/mem/concurrent_sweeper.h" +#include "ecmascript/mem/verification.h" + +namespace panda::ecmascript { +void SharedHeap::StartUnifiedGCMark([[maybe_unused]]TriggerGCType gcType, [[maybe_unused]]GCReason gcReason) +{ + ASSERT(gcType == TriggerGCType::UNIFIED_GC && gcReason == GCReason::CROSSREF_CAUSE); + ASSERT(JSThread::GetCurrent() == dThread_); + { + ThreadManagedScope runningScope(dThread_); + SuspendAllScope scope(dThread_); + Runtime *runtime = Runtime::GetInstance(); + std::vector recurScopes; + // The approximate size is enough, because even if some thread creates and registers after here, it will keep + // waiting in transition to RUNNING state before JSThread::SetReadyForGCIterating. + recurScopes.reserve(runtime->ApproximateThreadListSize()); + runtime->GCIterateThreadList([&recurScopes](JSThread *thread) { + Heap *heap = const_cast(thread->GetEcmaVM()->GetHeap()); + recurScopes.emplace_back(heap, HeapType::LOCAL_HEAP); + }); +#ifdef PANDA_JS_ETS_HYBRID_MODE + if (!unifiedGC_->StartXGCBarrier()) { + unifiedGC_->SetInterruptUnifiedGC(false); + dThread_->FinishRunningTask(); + return; + } +#endif // PANDA_JS_ETS_HYBRID_MODE + runtime->GCIterateThreadList([gcType](JSThread *thread) { + Heap *heap = const_cast(thread->GetEcmaVM()->GetHeap()); + if (UNLIKELY(heap->ShouldVerifyHeap())) { // LCOV_EXCL_BR_LINE + // pre unified gc heap verify + LOG_ECMA(DEBUG) << "pre unified gc heap verify"; + heap->ProcessSharedGCRSetWorkList(); + Verification(heap, VerifyKind::VERIFY_PRE_GC).VerifyAll(); + } + heap->SetGCType(gcType); + }); + unifiedGC_->RunPhases(); + runtime->GCIterateThreadList([](JSThread *thread) { + Heap *heap = const_cast(thread->GetEcmaVM()->GetHeap()); + if (UNLIKELY(heap->ShouldVerifyHeap())) { // LCOV_EXCL_BR_LINE + // post unified gc heap verify + LOG_ECMA(DEBUG) << "post unified gc heap verify"; + Verification(heap, VerifyKind::VERIFY_POST_GC).VerifyAll(); + } + }); +#ifdef PANDA_JS_ETS_HYBRID_MODE + unifiedGC_->FinishXGCBarrier(); +#endif // PANDA_JS_ETS_HYBRID_MODE + } +} + + +void Heap::UnifiedGCPrepare() +{ + WaitRunningTaskFinished(); + sweeper_->EnsureAllTaskFinished(); + WaitClearTaskFinished(); +} + +uint32_t BaseHeap::GetRunningTaskCount() +{ + LockHolder holder(waitTaskFinishedMutex_); + return runningTaskCount_; +} +} // namespace panda::ecmascript diff --git a/ecmascript/cross_vm/heap_hybrid.h b/ecmascript/cross_vm/heap_hybrid.h new file mode 100644 index 0000000000..23db9d782a --- /dev/null +++ b/ecmascript/cross_vm/heap_hybrid.h @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_HEAP_HYBRID_H +#define ECMASCRIPT_CROSS_VM_HEAP_HYBRID_H + +namespace panda::ecmascript { +#define HEAP_HYBRID_BASE_HEAP_EXTENSION \ + void SetGCType(TriggerGCType gcType) \ + { \ + gcType_ = gcType; \ + } \ + uint32_t GetRunningTaskCount(); + +#define HEAP_HYBRID_SHARED_HEAP_EXTENSION \ + UnifiedGC *GetUnifiedGC() const \ + { \ + return unifiedGC_; \ + } \ + template \ + bool TriggerUnifiedGCMark(JSThread *thread) const \ + { \ + ASSERT(gcType == TriggerGCType::UNIFIED_GC && gcReason == GCReason::CROSSREF_CAUSE); \ + return DaemonThread::GetInstance()->CheckAndPostTask(TriggerUnifiedGCMarkTask(thread)); \ + } \ + void StartUnifiedGCMark(TriggerGCType gcType, GCReason gcReason); \ +private: \ + UnifiedGC *unifiedGC_ {nullptr}; + + +#define HEAP_HYBRID_EXTENSION \ + void UnifiedGCPrepare(); \ + UnifiedGCMarker *GetUnifiedGCMarker() const \ + { \ + return unifiedGCMarker_; \ + } \ + bool IsUnifiedGC() const \ + { \ + return gcType_ == TriggerGCType::UNIFIED_GC; \ + } \ +private: \ + UnifiedGCMarker *unifiedGCMarker_ {nullptr}; +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_HEAP_HYBRID_H diff --git a/ecmascript/cross_vm/js_hclass_hybrid.h b/ecmascript/cross_vm/js_hclass_hybrid.h new file mode 100644 index 0000000000..90ca3b7dac --- /dev/null +++ b/ecmascript/cross_vm/js_hclass_hybrid.h @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_JS_HCLASS_HYBRID_H +#define ECMASCRIPT_CROSS_VM_JS_HCLASS_HYBRID_H + +namespace panda::ecmascript { +#define JS_HCLASS_HYBRID_EXTENSION \ + inline bool IsJSXRefObject() const \ + { \ + return GetObjectType() == JSType::JS_XREF_OBJECT; \ + } + +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_JS_HCLASS_HYBRID_H diff --git a/ecmascript/cross_vm/js_tagged_value_hybrid.h b/ecmascript/cross_vm/js_tagged_value_hybrid.h new file mode 100644 index 0000000000..faa3864a60 --- /dev/null +++ b/ecmascript/cross_vm/js_tagged_value_hybrid.h @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_JS_TAGGED_VALUE_HYBRID_H +#define ECMASCRIPT_CROSS_VM_JS_TAGGED_VALUE_HYBRID_H + +namespace panda::ecmascript { +#define JS_TAGGED_VALUE_HYBRID_DEF_EXTENSION \ + inline bool JSTaggedValue::IsJSXRefObject() const \ + { \ + return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSXRefObject(); \ + } + +#define JS_TAGGED_VALUE_HYBRID_DECL_EXTENSION \ + bool IsJSXRefObject() const; +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_JS_HCLASS_HYBRID_H diff --git a/ecmascript/cross_vm/js_thread_hybrid.h b/ecmascript/cross_vm/js_thread_hybrid.h new file mode 100644 index 0000000000..a34b667d0d --- /dev/null +++ b/ecmascript/cross_vm/js_thread_hybrid.h @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_JS_THREAD_HYBRID_H +#define ECMASCRIPT_CROSS_VM_JS_THREAD_HYBRID_H + +namespace panda::ecmascript { +#define JS_THREAD_HYBRID_EXTENSION \ +inline uintptr_t NewXRefGlobalHandle(JSTaggedType value) \ +{ \ + return newXRefGlobalHandle_(value); \ +} \ +inline void DisposeXRefGlobalHandle(uintptr_t nodeAddr) \ +{ \ + disposeXRefGlobalHandle_(nodeAddr); \ +} \ +inline void SetNodeKind(NodeKind nodeKind) \ +{ \ + setNodeKind_(nodeKind); \ +} \ +void SetStackStart(uint64_t stackStart) \ +{ \ + glueData_.stackStart_ = stackStart; \ +} \ +void SetStackLimit(uint64_t stackLimit) \ +{ \ + glueData_.stackLimit_ = stackLimit; \ +} \ +private: \ + std::function newXRefGlobalHandle_; \ + std::function disposeXRefGlobalHandle_; \ + std::function setNodeKind_; +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_JS_THREAD_HYBRID_H \ No newline at end of file diff --git a/ecmascript/cross_vm/jsnapi_expo_hybrid.cpp b/ecmascript/cross_vm/jsnapi_expo_hybrid.cpp new file mode 100644 index 0000000000..f6cda9418a --- /dev/null +++ b/ecmascript/cross_vm/jsnapi_expo_hybrid.cpp @@ -0,0 +1,145 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "ecmascript/napi/include/jsnapi_expo.h" +#include "ecmascript/napi/jsnapi_helper.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "ecmascript/checkpoint/thread_state_transition.h" +#include "ecmascript/ecma_global_storage.h" +#include "ecmascript/module/napi_module_loader.h" +#include "ecmascript/module/module_path_helper.h" + +namespace panda { +using ecmascript::JSTaggedValue; +template +using JSHandle = ecmascript::JSHandle; + +using ModulePathHelper = ecmascript::ModulePathHelper; +using ecmascript::ObjectFactory; + +Local StringRef::GetProxyNapiWrapperString(const EcmaVM *vm) +{ + // Omit exception check because ark calls here may not + // cause side effect even pending exception exists. + CROSS_THREAD_CHECK(vm); + ecmascript::ThreadManagedScope managedScope(thread); + JSHandle proxyNapiWapperString = thread->GlobalConstants()->GetHandledProxyNapiWrapperString(); + return JSNApiHelper::ToLocal(proxyNapiWapperString); +} + +Local ObjectRef::NewJSXRefObject(const EcmaVM *vm) +{ + CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); + ecmascript::ThreadManagedScope managedScope(thread); + ObjectFactory *factory = vm->GetFactory(); + JSHandle object(factory->NewJSXRefObject()); + return JSNApiHelper::ToLocal(object); +} + +void JSNApi::SetStackInfo(const EcmaVM *vm, const panda::StackInfo &info) +{ + JSThread *thread = vm->GetJSThread(); + thread->SetStackStart(info.stackStart); + thread->SetStackLimit(info.stackStart - info.stackSize); +} + +panda::StackInfo JSNApi::GetStackInfo(const EcmaVM *vm) +{ + JSThread *thread = vm->GetJSThread(); + size_t stackStart = thread->GetStackStart(); + size_t stackSize = stackStart - thread->GetStackLimit(); + return {stackStart, stackSize}; +} + +uintptr_t JSNApi::GetXRefGlobalHandleAddr(const EcmaVM *vm, uintptr_t localAddress) +{ + CROSS_THREAD_CHECK(vm); + if (localAddress == 0) { + return 0; + } + ecmascript::ThreadManagedScope scope(thread); + JSTaggedType value = *(reinterpret_cast(localAddress)); + return thread->NewXRefGlobalHandle(value); +} + + +void JSNApi::DisposeXRefGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr) +{ + CROSS_THREAD_CHECK(vm); + if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { + return; + } + thread->DisposeXRefGlobalHandle(addr); +} + +#ifdef PANDA_JS_ETS_HYBRID_MODE +void JSNApi::MarkFromObject(const EcmaVM *vm, uintptr_t addr, std::function &visitor) +{ + if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { + return; + } + JSTaggedType value = *(reinterpret_cast(addr)); + vm->GetCrossVMOperator()->MarkFromObject(value, visitor); +} + +void JSNApi::MarkFromObject(const EcmaVM *vm, uintptr_t addr) +{ + if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { + return; + } + JSTaggedType value = *(reinterpret_cast(addr)); + vm->GetCrossVMOperator()->MarkFromObject(value); +} + +bool JSNApi::IsObjectAlive(const EcmaVM *vm, uintptr_t addr) +{ + if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { + return false; + } + JSTaggedType value = *(reinterpret_cast(addr)); + return vm->GetCrossVMOperator()->IsObjectAlive(value); +} + +bool JSNApi::IsValidHeapObject(const EcmaVM *vm, uintptr_t addr) +{ + if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { + return false; + } + JSTaggedType value = *(reinterpret_cast(addr)); + return vm->GetCrossVMOperator()->IsValidHeapObject(value); +} +#endif // PANDA_JS_ETS_HYBRID_MODE + +Local JSNApi::GetModuleNameSpaceWithPath(const EcmaVM *vm, const char *path) +{ + CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); + auto [filePath, recordName] = ModulePathHelper::ResolvePath(path); + ecmascript::ThreadManagedScope managedScope(thread); + JSHandle moduleNamespace = + ecmascript::NapiModuleLoader::LoadModuleNameSpaceFromFile(thread, recordName, filePath); + return JSNApiHelper::ToLocal(moduleNamespace); +} + +std::pair JSNApi::ResolveOhmUrl(std::string ohmUrl) +{ + return ModulePathHelper::ResolveOhmUrl(ohmUrl); +} + +#ifdef PANDA_JS_ETS_HYBRID_MODE +void HandshakeHelper::DoHandshake([[maybe_unused]] EcmaVM *vm, void *stsIface, void **ecmaIface) +{ + ecmascript::CrossVMOperator::DoHandshake(vm, stsIface, ecmaIface); +} +#endif // PANDA_JS_ETS_HYBRID_MODE +} // namespace panda diff --git a/ecmascript/cross_vm/jsnapi_expo_hybrid.h b/ecmascript/cross_vm/jsnapi_expo_hybrid.h new file mode 100644 index 0000000000..076c54f568 --- /dev/null +++ b/ecmascript/cross_vm/jsnapi_expo_hybrid.h @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_JS_NAPI_EXPO_HYBRID_H +#define ECMASCRIPT_CROSS_VM_JS_NAPI_EXPO_HYBRID_H + +namespace panda { +// #define JS_NAPI_EXPO_HYBRID_EXTENSION \ +// struct StackInfo { \ +// size_t stackStart; \ +// size_t stackSize; \ +// }; \ +// #ifdef PANDA_JS_ETS_HYBRID_MODE \ +// class PUBLIC_API HandshakeHelper final { \ +// public: \ +// static void DoHandshake(EcmaVM *vm, void *stsiface, void **ecmaiface); \ +// }; \ +// #endif // PANDA_JS_ETS_HYBRID_MODE + +#define JS_NAPI_EXPO_HYBRID_STACK_INFO_EXTENSION \ + struct StackInfo { \ + size_t stackStart; \ + size_t stackSize; \ + }; + +#define JS_NAPI_EXPO_HYBRID_HAND_SHAKE_HELPER_EXTENSION \ + class PUBLIC_API HandshakeHelper final { \ + public: \ + static void DoHandshake(EcmaVM *vm, void *stsiface, void **ecmaiface); \ + }; + + +#define JS_NAPI_EXPO_HYBRID_GLOBAL_EXTENSION \ + template \ + void CreateXRefGloablReference(const EcmaVM *vm, const Local ¤t); \ + /* This method must be called before Global is released.*/ \ + void FreeGlobalHandleAddr(); \ + void FreeXRefGlobalHandleAddr(); \ + void MarkFromObject(std::function &visitor); \ + void MarkFromObject(); \ + bool IsObjectAlive() const; \ + bool IsValidHeapObject() const; + +#define JS_NAPI_EXPO_HYBRID_OBJECT_REF_EXTENSION \ + static Local NewJSXRefObject(const EcmaVM *vm); + +#define JS_NAPI_EXPO_HYBRID_STRING_REF_EXTENSION \ + static Local GetProxyNapiWrapperString(const EcmaVM *vm); + +#define JS_NAPI_EXPO_HYBRID_JS_NAPI_EXTENSION \ + static void SetStackInfo(const EcmaVM *vm, const panda::StackInfo &info); \ + static panda::StackInfo GetStackInfo(const EcmaVM *vm); \ + static Local GetModuleNameSpaceWithPath(const EcmaVM *vm, const char *path); \ + static std::pair ResolveOhmUrl(std::string ohmUrl); \ + static void SetHostResolveBufferTracker(EcmaVM *vm, std::function cb); \ + static bool IsObjectAlive(const EcmaVM *vm, uintptr_t addr); \ + static bool IsValidHeapObject(const EcmaVM *vm, uintptr_t addr); \ +private: \ + static uintptr_t GetXRefGlobalHandleAddr(const EcmaVM *vm, uintptr_t localAddress); \ + static void DisposeXRefGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr); + +#define JS_NAPI_EXPO_HYBRID_JS_NAPI_MARK_FROM_OBJ_EXTENSION \ + static void MarkFromObject(const EcmaVM *vm, uintptr_t addr, std::function &visitor); \ + static void MarkFromObject(const EcmaVM *vm, uintptr_t addr); +} // namespace panda +#endif // ECMASCRIPT_CROSS_VM_JS_NAPI_EXPO_HYBRID_H diff --git a/ecmascript/cross_vm/jsnapi_hybrid.h b/ecmascript/cross_vm/jsnapi_hybrid.h new file mode 100644 index 0000000000..bc1e5f8890 --- /dev/null +++ b/ecmascript/cross_vm/jsnapi_hybrid.h @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_JS_NAPI_HYBRID_H +#define ECMASCRIPT_CROSS_VM_JS_NAPI_HYBRID_H + +namespace panda::ecmascript { +#define JS_NAPI_HYBRID_EXTENSION \ + template \ + template \ + void Global::CreateXRefGloablReference(const EcmaVM *vm, const Local ¤t) \ + { \ + vm_ = vm; \ + if (!current.IsEmpty()) { \ + address_ = JSNApi::GetXRefGlobalHandleAddr(vm_, reinterpret_cast(*current));\ + } \ + } \ + template \ + void Global::FreeXRefGlobalHandleAddr() \ + { \ + if (address_ == 0) { \ + return; \ + } \ + JSNApi::DisposeXRefGlobalHandleAddr(vm_, address_); \ + address_ = 0; \ + } + +#define JS_NAPI_HYBRID_MODE_MIC_EXTENSION \ + template \ + void Global::MarkFromObject(std::function &visitor) \ + { \ + if (address_ == 0) { \ + return; \ + } \ + JSNApi::MarkFromObject(vm_, address_, visitor); \ + } \ + template \ + void Global::MarkFromObject() \ + { \ + if (address_ == 0) { \ + return; \ + } \ + JSNApi::MarkFromObject(vm_, address_); \ + } \ + template \ + bool Global::IsObjectAlive() const \ + { \ + if (address_ == 0) { \ + return false ; \ + } \ + return JSNApi::IsObjectAlive(vm_, address_); \ + } \ + template \ + bool Global::IsValidHeapObject() const \ + { \ + if (address_ == 0) { \ + return false; \ + } \ + return JSNApi::IsValidHeapObject(vm_, address_); \ + } +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_JS_NAPI_HYBRID_H diff --git a/ecmascript/cross_vm/object_factory_hybrid.cpp b/ecmascript/cross_vm/object_factory_hybrid.cpp new file mode 100644 index 0000000000..ee20863947 --- /dev/null +++ b/ecmascript/cross_vm/object_factory_hybrid.cpp @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "ecmascript/object_factory.h" +#include "ecmascript/global_env_constants.h" +#include "ecmascript/dfx/native_module_failure_info.h" + +namespace panda::ecmascript { +JSHandle ObjectFactory::NewJSXRefObject() +{ + JSHandle jsXRefHClass = JSHandle::Cast(thread_->GlobalConstants()->GetHandledXRefObjectClass()); + JSHandle object(NewJSObject(jsXRefHClass)); + return object; +} +} // namespace panda::ecmascript diff --git a/ecmascript/cross_vm/object_factory_hybrid.h b/ecmascript/cross_vm/object_factory_hybrid.h new file mode 100644 index 0000000000..ebee95ceaf --- /dev/null +++ b/ecmascript/cross_vm/object_factory_hybrid.h @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_OBJECT_FACTORY_HYBRID_H +#define ECMASCRIPT_CROSS_VM_OBJECT_FACTORY_HYBRID_H + +namespace panda::ecmascript { + +#define OBJECT_FACTORY_HYBRID_EXTENSION \ + JSHandle PUBLIC_API NewJSXRefObject(); + +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_OBJECT_FACTORY_HYBRID_H diff --git a/ecmascript/mem/unified_gc/unified_gc.cpp b/ecmascript/cross_vm/unified_gc/unified_gc.cpp similarity index 96% rename from ecmascript/mem/unified_gc/unified_gc.cpp rename to ecmascript/cross_vm/unified_gc/unified_gc.cpp index 11939a04a3..386d24dc80 100644 --- a/ecmascript/mem/unified_gc/unified_gc.cpp +++ b/ecmascript/cross_vm/unified_gc/unified_gc.cpp @@ -13,11 +13,12 @@ * limitations under the License. */ -#include "ecmascript/mem/unified_gc/unified_gc.h" +#include "ecmascript/cross_vm/unified_gc/unified_gc.h" #include "ecmascript/mem/concurrent_marker.h" -#include "ecmascript/mem/unified_gc/unified_gc_marker.h" +#include "ecmascript/cross_vm/unified_gc/unified_gc_marker.h" #include "ecmascript/mem/verification.h" +#include "ecmascript/mem/heap.h" namespace panda::ecmascript { #ifdef PANDA_JS_ETS_HYBRID_MODE diff --git a/ecmascript/mem/unified_gc/unified_gc.h b/ecmascript/cross_vm/unified_gc/unified_gc.h similarity index 100% rename from ecmascript/mem/unified_gc/unified_gc.h rename to ecmascript/cross_vm/unified_gc/unified_gc.h diff --git a/ecmascript/mem/unified_gc/unified_gc_marker-inl.h b/ecmascript/cross_vm/unified_gc/unified_gc_marker-inl.h similarity index 97% rename from ecmascript/mem/unified_gc/unified_gc_marker-inl.h rename to ecmascript/cross_vm/unified_gc/unified_gc_marker-inl.h index 8be85b1753..31ee16f590 100644 --- a/ecmascript/mem/unified_gc/unified_gc_marker-inl.h +++ b/ecmascript/cross_vm/unified_gc/unified_gc_marker-inl.h @@ -16,10 +16,11 @@ #ifndef ECMASCRIPT_MEM_UNIFIED_GC_UNIFIED_GC_MARKER_INL_H #define ECMASCRIPT_MEM_UNIFIED_GC_UNIFIED_GC_MARKER_INL_H -#include "ecmascript/mem/unified_gc/unified_gc_marker.h" +#include "ecmascript/cross_vm/unified_gc/unified_gc_marker.h" #include "ecmascript/layout_info.h" #include "ecmascript/mem/work_manager-inl.h" +#include "ecmascript/cross_vm/work_manager_hybrid-inl.h" namespace panda::ecmascript { diff --git a/ecmascript/mem/unified_gc/unified_gc_marker.cpp b/ecmascript/cross_vm/unified_gc/unified_gc_marker.cpp similarity index 97% rename from ecmascript/mem/unified_gc/unified_gc_marker.cpp rename to ecmascript/cross_vm/unified_gc/unified_gc_marker.cpp index 188c4b1e09..f1ffc13a44 100644 --- a/ecmascript/mem/unified_gc/unified_gc_marker.cpp +++ b/ecmascript/cross_vm/unified_gc/unified_gc_marker.cpp @@ -15,7 +15,7 @@ #include "ecmascript/checkpoint/thread_state_transition.h" #include "ecmascript/mem/concurrent_marker.h" -#include "ecmascript/mem/unified_gc/unified_gc_marker-inl.h" +#include "ecmascript/cross_vm/unified_gc/unified_gc_marker-inl.h" #include "ecmascript/mem/verification.h" namespace panda::ecmascript { diff --git a/ecmascript/mem/unified_gc/unified_gc_marker.h b/ecmascript/cross_vm/unified_gc/unified_gc_marker.h similarity index 100% rename from ecmascript/mem/unified_gc/unified_gc_marker.h rename to ecmascript/cross_vm/unified_gc/unified_gc_marker.h diff --git a/ecmascript/cross_vm/work_manager_hybrid-inl.h b/ecmascript/cross_vm/work_manager_hybrid-inl.h new file mode 100644 index 0000000000..fdeafddf76 --- /dev/null +++ b/ecmascript/cross_vm/work_manager_hybrid-inl.h @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_WORK_MANAGER_INL_H +#define ECMASCRIPT_CROSS_VM_WORK_MANAGER_INL_H + +#include "ecmascript/mem/work_manager.h" + +#include "ecmascript/mem/incremental_marker.h" +#include "ecmascript/mem/tlab_allocator-inl.h" + +namespace panda::ecmascript { + void WorkManager::PushObjectToGlobal(TaggedObject *object) + { + WorkNode *tempNode = AllocateWorkNode(); + ASSERT(tempNode != nullptr); + tempNode->PushObject(ToUintPtr(object)); + workStack_.Push(tempNode); + if (heap_->IsParallelGCEnabled() && heap_->CheckCanDistributeTask() && !heap_->IsMarking()) { + heap_->PostParallelGCTask(parallelGCTaskPhase_); + } + } +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_WORK_MANAGER_HYBRID_H diff --git a/ecmascript/cross_vm/work_manager_hybrid.h b/ecmascript/cross_vm/work_manager_hybrid.h new file mode 100644 index 0000000000..f01a6b3455 --- /dev/null +++ b/ecmascript/cross_vm/work_manager_hybrid.h @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef ECMASCRIPT_CROSS_VM_WORK_MANAGER_HYBRID_H +#define ECMASCRIPT_CROSS_VM_WORK_MANAGER_HYBRID_H + +namespace panda::ecmascript { +#define WORK_MANAGER_HYBRID_DECL_EXTENSION \ + void PushObjectToGlobal(TaggedObject *object); + +} // namespace panda::ecmascript +#endif // ECMASCRIPT_CROSS_VM_WORK_MANAGER_HYBRID_H diff --git a/ecmascript/js_thread.cpp b/ecmascript/js_thread.cpp index a1eb03517d..ce73e30226 100644 --- a/ecmascript/js_thread.cpp +++ b/ecmascript/js_thread.cpp @@ -166,43 +166,47 @@ JSThread::JSThread(EcmaVM *vm) : id_(os::thread::GetCurrentThreadId()), vm_(vm) newGlobalHandle_ = [this](JSTaggedType value) { return globalStorage_->NewGlobalHandle(value); }; - newXRefGlobalHandle_ = [this](JSTaggedType value) { - return globalStorage_->NewGlobalHandle(value); - }; disposeGlobalHandle_ = [this](uintptr_t nodeAddr) { globalStorage_->DisposeGlobalHandle(nodeAddr); }; + // if (Runtime::GetInstance()->IsHybridVm()) { + newXRefGlobalHandle_ = [this](JSTaggedType value) { + return globalStorage_->NewGlobalHandle(value); + }; disposeXRefGlobalHandle_ = [this](uintptr_t nodeAddr) { globalStorage_->DisposeGlobalHandle(nodeAddr); }; + setNodeKind_ = [this](NodeKind nodeKind) { globalStorage_->SetNodeKind(nodeKind); }; + // } setWeak_ = [this](uintptr_t nodeAddr, void *ref, WeakClearCallback freeGlobalCallBack, WeakClearCallback nativeFinalizeCallBack) { return globalStorage_->SetWeak(nodeAddr, ref, freeGlobalCallBack, nativeFinalizeCallBack); }; clearWeak_ = [this](uintptr_t nodeAddr) { return globalStorage_->ClearWeak(nodeAddr); }; isWeak_ = [this](uintptr_t addr) { return globalStorage_->IsWeak(addr); }; - setNodeKind_ = [this](NodeKind nodeKind) { globalStorage_->SetNodeKind(nodeKind); }; } else { globalDebugStorage_ = chunk->New>(this, vm->GetNativeAreaAllocator()); newGlobalHandle_ = [this](JSTaggedType value) { return globalDebugStorage_->NewGlobalHandle(value); }; - newXRefGlobalHandle_ = [this](JSTaggedType value) { - return globalDebugStorage_->NewGlobalHandle(value); - }; disposeGlobalHandle_ = [this](uintptr_t nodeAddr) { globalDebugStorage_->DisposeGlobalHandle(nodeAddr); }; - disposeXRefGlobalHandle_ = [this](uintptr_t nodeAddr) { - globalDebugStorage_->DisposeGlobalHandle(nodeAddr); - }; setWeak_ = [this](uintptr_t nodeAddr, void *ref, WeakClearCallback freeGlobalCallBack, WeakClearCallback nativeFinalizeCallBack) { return globalDebugStorage_->SetWeak(nodeAddr, ref, freeGlobalCallBack, nativeFinalizeCallBack); }; clearWeak_ = [this](uintptr_t nodeAddr) { return globalDebugStorage_->ClearWeak(nodeAddr); }; isWeak_ = [this](uintptr_t addr) { return globalDebugStorage_->IsWeak(addr); }; + // if (Runtime::GetInstance()->IsHybridVm()) { + newXRefGlobalHandle_ = [this](JSTaggedType value) { + return globalDebugStorage_->NewGlobalHandle(value); + }; + disposeXRefGlobalHandle_ = [this](uintptr_t nodeAddr) { + globalDebugStorage_->DisposeGlobalHandle(nodeAddr); + }; setNodeKind_ = [this](NodeKind nodeKind) { globalDebugStorage_->SetNodeKind(nodeKind); }; + // } } vmThreadControl_ = new VmThreadControl(this); SetBCStubStatus(BCStubStatus::NORMAL_BC_STUB); diff --git a/ecmascript/js_thread.h b/ecmascript/js_thread.h index 7f57eb5ebb..6cf9784d76 100644 --- a/ecmascript/js_thread.h +++ b/ecmascript/js_thread.h @@ -40,6 +40,7 @@ #include "common_interfaces/base_runtime.h" #include "common_interfaces/thread/base_thread.h" #include "common_interfaces/thread/thread_holder.h" +#include "ecmascript/cross_vm/js_thread_hybrid.h" #if defined(ENABLE_FFRT_INTERFACES) #include "ffrt.h" @@ -908,21 +909,11 @@ public: return newGlobalHandle_(value); } - inline uintptr_t NewXRefGlobalHandle(JSTaggedType value) - { - return newXRefGlobalHandle_(value); - } - inline void DisposeGlobalHandle(uintptr_t nodeAddr) { disposeGlobalHandle_(nodeAddr); } - inline void DisposeXRefGlobalHandle(uintptr_t nodeAddr) - { - disposeXRefGlobalHandle_(nodeAddr); - } - inline uintptr_t SetWeak(uintptr_t nodeAddr, void *ref = nullptr, WeakClearCallback freeGlobalCallBack = nullptr, WeakClearCallback nativeFinalizeCallBack = nullptr) { @@ -939,11 +930,6 @@ public: return isWeak_(addr); } - inline void SetNodeKind(NodeKind nodeKind) - { - setNodeKind_(nodeKind); - } - void EnableCrossThreadExecution() { glueData_.allowCrossThreadExecution_ = true; @@ -1537,16 +1523,6 @@ public: }; STATIC_ASSERT_EQ_ARCH(sizeof(GlueData), GlueData::SizeArch32, GlueData::SizeArch64); - void SetStackStart(uint64_t stackStart) - { - glueData_.stackStart_ = stackStart; - } - - void SetStackLimit(uint64_t stackLimit) - { - glueData_.stackLimit_ = stackLimit; - } - JSTaggedValue GetSingleCharTable() const { ASSERT(glueData_.globalConst_->GetSingleCharTable() != JSTaggedValue::Hole()); @@ -1924,7 +1900,7 @@ public: << "---------------------------------------------------------"; ClearMegaStat(); } - + JS_THREAD_HYBRID_EXTENSION protected: void SetThreadId() { @@ -1997,14 +1973,11 @@ private: EcmaGlobalStorage *globalDebugStorage_ {nullptr}; int32_t stackTraceFd_ {-1}; std::function newGlobalHandle_; - std::function newXRefGlobalHandle_; std::function disposeGlobalHandle_; - std::function disposeXRefGlobalHandle_; std::function setWeak_; std::function clearWeak_; std::function isWeak_; - std::function setNodeKind_; NativePointerTaskCallback asyncCleanTaskCb_ {nullptr}; WeakFinalizeTaskCallback finalizeTaskCallback_ {nullptr}; uint32_t globalNumberCount_ {0}; diff --git a/ecmascript/mem/heap-inl.h b/ecmascript/mem/heap-inl.h index 0eb2948131..6d94b92f39 100644 --- a/ecmascript/mem/heap-inl.h +++ b/ecmascript/mem/heap-inl.h @@ -1258,13 +1258,6 @@ void SharedHeap::PostGCTaskForTest(JSThread *thread) } } -template -bool SharedHeap::TriggerUnifiedGCMark(JSThread *thread) const -{ - ASSERT(gcType == TriggerGCType::UNIFIED_GC && gcReason == GCReason::CROSSREF_CAUSE); - return DaemonThread::GetInstance()->CheckAndPostTask(TriggerUnifiedGCMarkTask(thread)); -} - static void SwapBackAndPop(CVector& vec, CVector::iterator& iter) { *iter = vec.back(); diff --git a/ecmascript/mem/heap.cpp b/ecmascript/mem/heap.cpp index cd603ad5b1..d94ef9e380 100644 --- a/ecmascript/mem/heap.cpp +++ b/ecmascript/mem/heap.cpp @@ -30,8 +30,8 @@ #include "ecmascript/mem/shared_heap/shared_gc.h" #include "ecmascript/mem/shared_heap/shared_full_gc.h" #include "ecmascript/mem/shared_heap/shared_concurrent_marker.h" -#include "ecmascript/mem/unified_gc/unified_gc.h" -#include "ecmascript/mem/unified_gc/unified_gc_marker.h" +#include "ecmascript/cross_vm/unified_gc/unified_gc.h" +#include "ecmascript/cross_vm/unified_gc/unified_gc_marker.h" #include "ecmascript/mem/verification.h" #include "ecmascript/runtime_call_id.h" #include "ecmascript/jit/jit.h" @@ -310,6 +310,7 @@ void SharedHeap::Destroy() delete sharedMemController_; sharedMemController_ = nullptr; } + // if (Runtime::GetInstance()->IsHybridVm() && if (unifiedGC_ != nullptr) { delete unifiedGC_; unifiedGC_ = nullptr; @@ -333,7 +334,9 @@ void SharedHeap::PostInitialization(const GlobalEnvConstants *globalEnvConstants sharedGC_ = new SharedGC(this); sEvacuator_ = new SharedGCEvacuator(this); sharedFullGC_ = new SharedFullGC(this); + // if (Runtime::GetInstance()->IsHybridVm()) { unifiedGC_ = new UnifiedGC(); + // } } void SharedHeap::PostGCMarkingTask(SharedParallelMarkPhase sharedTaskPhase) @@ -840,54 +843,6 @@ void SharedHeap::DumpHeapSnapshotBeforeOOM([[maybe_unused]]bool isFullGC, [[mayb #endif // ECMASCRIPT_SUPPORT_SNAPSHOT } -void SharedHeap::StartUnifiedGCMark([[maybe_unused]]TriggerGCType gcType, [[maybe_unused]]GCReason gcReason) -{ - ASSERT(gcType == TriggerGCType::UNIFIED_GC && gcReason == GCReason::CROSSREF_CAUSE); - ASSERT(JSThread::GetCurrent() == dThread_); - { - ThreadManagedScope runningScope(dThread_); - SuspendAllScope scope(dThread_); - Runtime *runtime = Runtime::GetInstance(); - std::vector recurScopes; - // The approximate size is enough, because even if some thread creates and registers after here, it will keep - // waiting in transition to RUNNING state before JSThread::SetReadyForGCIterating. - recurScopes.reserve(runtime->ApproximateThreadListSize()); - runtime->GCIterateThreadList([&recurScopes](JSThread *thread) { - Heap *heap = const_cast(thread->GetEcmaVM()->GetHeap()); - recurScopes.emplace_back(heap, HeapType::LOCAL_HEAP); - }); -#ifdef PANDA_JS_ETS_HYBRID_MODE - if (!unifiedGC_->StartXGCBarrier()) { - unifiedGC_->SetInterruptUnifiedGC(false); - dThread_->FinishRunningTask(); - return; - } -#endif // PANDA_JS_ETS_HYBRID_MODE - runtime->GCIterateThreadList([gcType](JSThread *thread) { - Heap *heap = const_cast(thread->GetEcmaVM()->GetHeap()); - if (UNLIKELY(heap->ShouldVerifyHeap())) { // LCOV_EXCL_BR_LINE - // pre unified gc heap verify - LOG_ECMA(DEBUG) << "pre unified gc heap verify"; - heap->ProcessSharedGCRSetWorkList(); - Verification(heap, VerifyKind::VERIFY_PRE_GC).VerifyAll(); - } - heap->SetGCType(gcType); - }); - unifiedGC_->RunPhases(); - runtime->GCIterateThreadList([](JSThread *thread) { - Heap *heap = const_cast(thread->GetEcmaVM()->GetHeap()); - if (UNLIKELY(heap->ShouldVerifyHeap())) { // LCOV_EXCL_BR_LINE - // post unified gc heap verify - LOG_ECMA(DEBUG) << "post unified gc heap verify"; - Verification(heap, VerifyKind::VERIFY_POST_GC).VerifyAll(); - } - }); -#ifdef PANDA_JS_ETS_HYBRID_MODE - unifiedGC_->FinishXGCBarrier(); -#endif // PANDA_JS_ETS_HYBRID_MODE - } -} - Heap::Heap(EcmaVM *ecmaVm) : BaseHeap(ecmaVm->GetEcmaParamConfiguration()), ecmaVm_(ecmaVm), thread_(ecmaVm->GetJSThread()), sHeap_(SharedHeap::GetInstance()) {} @@ -977,7 +932,9 @@ void Heap::Initialize() EnableConcurrentMarkType::CONFIG_DISABLE); nonMovableMarker_ = new NonMovableMarker(this); compressGCMarker_ = new CompressGCMarker(this); + // if (Runtime::GetInstance()->IsHybridVm()) { unifiedGCMarker_ = new UnifiedGCMarker(this); + // } evacuator_ = new ParallelEvacuator(this); incrementalMarker_ = new IncrementalMarker(this); gcListeners_.reserve(16U); @@ -1180,6 +1137,7 @@ void Heap::Destroy() delete compressGCMarker_; compressGCMarker_ = nullptr; } + // if (Runtime::GetInstance()->IsHybridVm() && if (unifiedGCMarker_ != nullptr) { delete unifiedGCMarker_; unifiedGCMarker_ = nullptr; @@ -1198,13 +1156,6 @@ void Heap::Prepare() WaitClearTaskFinished(); } -void Heap::UnifiedGCPrepare() -{ - WaitRunningTaskFinished(); - sweeper_->EnsureAllTaskFinished(); - WaitClearTaskFinished(); -} - void Heap::GetHeapPrepare() { // Ensure local and shared heap prepared. @@ -2898,7 +2849,9 @@ void Heap::UpdateWorkManager(WorkManager *workManager) incrementalMarker_->workManager_ = workManager; nonMovableMarker_->workManager_ = workManager; compressGCMarker_->workManager_ = workManager; + // if (Runtime::GetInstance()->IsHybridVm()) { unifiedGCMarker_->workManager_ = workManager; + // } partialGC_->workManager_ = workManager; } @@ -3054,12 +3007,6 @@ void BaseHeap::WaitRunningTaskFinished() } } -uint32_t BaseHeap::GetRunningTaskCount() -{ - LockHolder holder(waitTaskFinishedMutex_); - return runningTaskCount_; -} - bool BaseHeap::CheckCanDistributeTask() { LockHolder holder(waitTaskFinishedMutex_); diff --git a/ecmascript/mem/heap.h b/ecmascript/mem/heap.h index 6907dc5ca9..a0a7bf7803 100644 --- a/ecmascript/mem/heap.h +++ b/ecmascript/mem/heap.h @@ -29,6 +29,7 @@ #include "ecmascript/mem/visitor.h" #include "ecmascript/mem/work_manager.h" #include "ecmascript/napi/include/jsnapi_expo.h" +#include "ecmascript/cross_vm/heap_hybrid.h" namespace panda::test { class GCTest_CallbackTask_Test; @@ -219,11 +220,6 @@ public: return markType_ == MarkType::MARK_FULL; } - void SetGCType(TriggerGCType gcType) - { - gcType_ = gcType; - } - TriggerGCType GetGCType() const { return gcType_; @@ -356,7 +352,6 @@ public: void IncreaseTaskCount(); void ReduceTaskCount(); void WaitRunningTaskFinished(); - uint32_t GetRunningTaskCount(); void WaitClearTaskFinished(); void ThrowOutOfMemoryError(JSThread *thread, size_t size, std::string functionName, bool NonMovableObjNearOOM = false); @@ -379,6 +374,8 @@ public: } #endif + HEAP_HYBRID_BASE_HEAP_EXTENSION + protected: void FatalOutOfMemoryError(size_t size, std::string functionName); @@ -657,11 +654,6 @@ public: return sSweeper_; } - UnifiedGC *GetUnifiedGC() const - { - return unifiedGC_; - } - bool IsParallelGCEnabled() const { return parallelGC_; @@ -915,11 +907,10 @@ public: void CheckInHeapProfiler(); - void StartUnifiedGCMark(TriggerGCType gcType, GCReason gcReason); - template - bool TriggerUnifiedGCMark(JSThread *thread) const; void SetGCThreadRssPriority(common::RssPriorityType type); + HEAP_HYBRID_SHARED_HEAP_EXTENSION + private: void ProcessAllGCListeners(); void CollectGarbageFinish(bool inDaemon, TriggerGCType gcType); @@ -981,7 +972,6 @@ private: SharedGCMarker *sharedGCMarker_ {nullptr}; SharedGCMovableMarker *sharedGCMovableMarker_ {nullptr}; SharedMemController *sharedMemController_ {nullptr}; - UnifiedGC *unifiedGC_ {nullptr}; size_t growingFactor_ {0}; size_t growingStep_ {0}; size_t incNativeSizeTriggerSharedCM_ {0}; @@ -1003,7 +993,6 @@ public: void Initialize(); void Destroy() override; void Prepare(); - void UnifiedGCPrepare(); void GetHeapPrepare(); void ResetLargeCapacity(); void Resume(TriggerGCType gcType); @@ -1134,11 +1123,6 @@ public: return compressGCMarker_; } - UnifiedGCMarker *GetUnifiedGCMarker() const - { - return unifiedGCMarker_; - } - EcmaVM *GetEcmaVM() const { return ecmaVm_; @@ -1679,11 +1663,6 @@ public: return gcType_ == TriggerGCType::YOUNG_GC; } - bool IsUnifiedGC() const - { - return gcType_ == TriggerGCType::UNIFIED_GC; - } - void CheckNonMovableSpaceOOM(); void DumpHeapSnapshotBeforeOOM(bool isFullGC = true); std::tuple CalCallSiteInfo(uintptr_t retAddr) const; @@ -1712,6 +1691,7 @@ public: } void UpdateHeapStatsAfterGC(TriggerGCType gcType) override; + HEAP_HYBRID_EXTENSION \ private: void CollectGarbageImpl(TriggerGCType gcType, GCReason reason = GCReason::OTHER); @@ -1912,7 +1892,6 @@ private: */ Marker *nonMovableMarker_ {nullptr}; Marker *compressGCMarker_ {nullptr}; - UnifiedGCMarker *unifiedGCMarker_ {nullptr}; // Work manager managing the tasks mostly generated in the GC mark phase. WorkManager *workManager_ {nullptr}; diff --git a/ecmascript/mem/verification.h b/ecmascript/mem/verification.h index 5218f31c93..c370f92048 100644 --- a/ecmascript/mem/verification.h +++ b/ecmascript/mem/verification.h @@ -75,7 +75,6 @@ private: void VerifyMarkYoung(TaggedObject *obj, ObjectSlot slot, TaggedObject *value) const; void VerifyEvacuateYoung(TaggedObject *obj, ObjectSlot slot, TaggedObject *value) const; void VerifyMarkFull(TaggedObject *obj, ObjectSlot slot, TaggedObject *value) const; - void VerifyMarkUnified(TaggedObject *obj, ObjectSlot slot, TaggedObject *value) const; void VerifyEvacuateOld(TaggedObject *obj, ObjectSlot slot, TaggedObject *value) const; void VerifyEvacuateFull(TaggedObject *obj, ObjectSlot slot, TaggedObject *value) const; void VerifySharedRSetPostFullGC(TaggedObject *obj, ObjectSlot slot, TaggedObject *value) const; diff --git a/ecmascript/mem/work_manager-inl.h b/ecmascript/mem/work_manager-inl.h index 16dea09e02..fda5db67e5 100644 --- a/ecmascript/mem/work_manager-inl.h +++ b/ecmascript/mem/work_manager-inl.h @@ -217,21 +217,6 @@ WorkManager::~WorkManager() } } -// PushObjectToGlobal should be called by MarkFromObejct in STS GC thread. To avoid data race with ArkTS GC -// thread(DaemonThread), new a WorkNode and push it to global work stack. Other GC thread(in Taskpool) and -// DaemonThread will get node from global work stack and continue mark. Global work stack have mutex in push -// and pop, so it will not have data race. -void WorkManager::PushObjectToGlobal(TaggedObject *object) -{ - WorkNode *tempNode = AllocateWorkNode(); - ASSERT(tempNode != nullptr); - tempNode->PushObject(ToUintPtr(object)); - workStack_.Push(tempNode); - if (heap_->IsParallelGCEnabled() && heap_->CheckCanDistributeTask() && !heap_->IsMarking()) { - heap_->PostParallelGCTask(parallelGCTaskPhase_); - } -} - size_t WorkManager::Finish() { size_t aliveSize = 0; diff --git a/ecmascript/mem/work_manager.h b/ecmascript/mem/work_manager.h index 51b6ae59a6..eb7cc63bc2 100644 --- a/ecmascript/mem/work_manager.h +++ b/ecmascript/mem/work_manager.h @@ -20,6 +20,7 @@ #include "ecmascript/mem/mark_stack.h" #include "ecmascript/mem/slots.h" #include "ecmascript/mem/work_space_chunk.h" +#include "ecmascript/cross_vm/work_manager_hybrid.h" namespace panda::ecmascript { using SlotNeedUpdate = std::pair; @@ -261,8 +262,6 @@ public: inline size_t Finish() override; inline void Finish(size_t &aliveSize, size_t &promotedSize); - inline void PushObjectToGlobal(TaggedObject *object); - inline uint32_t GetTotalThreadNum() { return threadNum_; @@ -277,7 +276,7 @@ public: { return &works_.at(threadId); } - + WORK_MANAGER_HYBRID_DECL_EXTENSION private: NO_COPY_SEMANTIC(WorkManager); NO_MOVE_SEMANTIC(WorkManager); diff --git a/ecmascript/napi/include/jsnapi.h b/ecmascript/napi/include/jsnapi.h index 0734368ad2..7ebbc251cc 100644 --- a/ecmascript/napi/include/jsnapi.h +++ b/ecmascript/napi/include/jsnapi.h @@ -30,6 +30,7 @@ #include "ecmascript/base/aligned_struct.h" #include "ecmascript/base/config.h" #include "ecmascript/napi/include/jsnapi_expo.h" +#include "ecmascript/cross_vm/jsnapi_hybrid.h" #ifndef NDEBUG #include "libpandabase/utils/debug.h" #endif @@ -473,64 +474,10 @@ private: bool enableWarmStartupSmartGC_ {false}; friend JSNApi; }; - -template -template -void Global::CreateXRefGloablReference(const EcmaVM *vm, const Local ¤t) -{ - vm_ = vm; - if (!current.IsEmpty()) { - address_ = JSNApi::GetXRefGlobalHandleAddr(vm_, reinterpret_cast(*current)); - } -} - -template -void Global::FreeXRefGlobalHandleAddr() -{ - if (address_ == 0) { - return; - } - JSNApi::DisposeXRefGlobalHandleAddr(vm_, address_); - address_ = 0; -} - +JS_NAPI_HYBRID_EXTENSION #ifdef PANDA_JS_ETS_HYBRID_MODE - template - void Global::MarkFromObject(std::function &visitor) - { - if (address_ == 0) { - return; - } - JSNApi::MarkFromObject(vm_, address_, visitor); - } - - template - void Global::MarkFromObject() - { - if (address_ == 0) { - return; - } - JSNApi::MarkFromObject(vm_, address_); - } - - template - bool Global::IsObjectAlive() const - { - if (address_ == 0) { - return false ; - } - return JSNApi::IsObjectAlive(vm_, address_); - } - - template - bool Global::IsValidHeapObject() const - { - if (address_ == 0) { - return false; - } - return JSNApi::IsValidHeapObject(vm_, address_); - } -#endif // PANDA_JS_ETS_HYBRID_MODE + JS_NAPI_HYBRID_MODE_MIC_EXTENSION +#endif // PANDA_JS_ETS_HYBRID_MODE } // namespace panda #endif // ECMASCRIPT_NAPI_INCLUDE_JSNAPI_H diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index 9bb3095020..39865b005b 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -31,6 +31,7 @@ #include "ecmascript/common.h" #include "ecmascript/module/js_module_execute_type.h" #include "ecmascript/napi/include/jsnapi_internals.h" +#include "ecmascript/cross_vm/jsnapi_expo_hybrid.h" #ifndef NDEBUG #include "libpandabase/utils/debug.h" @@ -101,10 +102,7 @@ struct HmsMap { uint32_t sinceVersion; }; -struct StackInfo { - size_t stackStart; - size_t stackSize; -}; +JS_NAPI_EXPO_HYBRID_STACK_INFO_EXTENSION using WeakRefClearCallBack = void (*)(void *); using WeakFinalizeTaskCallback = std::function; @@ -473,16 +471,8 @@ public: address_ = 0; } - template - void CreateXRefGloablReference(const EcmaVM *vm, const Local ¤t); - // This method must be called before Global is released. - void FreeGlobalHandleAddr(); - void FreeXRefGlobalHandleAddr(); - void MarkFromObject(std::function &visitor); - void MarkFromObject(); - bool IsObjectAlive() const; - bool IsValidHeapObject() const; + JS_NAPI_EXPO_HYBRID_GLOBAL_EXTENSION inline T *operator*() const { @@ -845,7 +835,6 @@ public: } static Local New(const EcmaVM *vm); static uintptr_t NewObject(const EcmaVM *vm); - static Local NewJSXRefObject(const EcmaVM *vm); static Local NewS(const EcmaVM *vm); static Local NewWithProperties(const EcmaVM *vm, size_t propertyCount, const Local *keys, const PropertyAttribute *attributes); @@ -900,6 +889,7 @@ public: void *nativePointer = nullptr, NativePointerCallback callBack = nullptr, void *data = nullptr, size_t nativeBindingsize = 0); + JS_NAPI_EXPO_HYBRID_OBJECT_REF_EXTENSION }; using FunctionCallback = Local(*)(JsiRuntimeCallInfo*); @@ -1061,8 +1051,8 @@ public: uint32_t WriteLatin1(const EcmaVM *vm, char *buffer, uint32_t length); uint32_t WriteLatin1WithoutSwitchState(const EcmaVM *vm, char *buffer, uint32_t length); static Local GetNapiWrapperString(const EcmaVM *vm); - static Local GetProxyNapiWrapperString(const EcmaVM *vm); Local EncodeIntoUint8Array(const EcmaVM *vm); + JS_NAPI_EXPO_HYBRID_STRING_REF_EXTENSION }; class PUBLIC_API PromiseRejectInfo { @@ -1690,8 +1680,6 @@ public: static EcmaVM *CreateJSVM(const RuntimeOption &option); static void DestroyJSVM(EcmaVM *ecmaVm); - static void SetStackInfo(const EcmaVM *vm, const panda::StackInfo &info); - static panda::StackInfo GetStackInfo(const EcmaVM *vm); static void RegisterUncatchableErrorHandler(EcmaVM *ecmaVm, const UncatchableErrorHandler &handler); // aot load @@ -1731,8 +1719,6 @@ public: const std::string &module_path); static Local GetModuleNameSpaceWithModuleInfoForHybridApp(EcmaVM *vm, const std::string &file, const std::string &module_path); - static Local GetModuleNameSpaceWithPath(const EcmaVM *vm, const char *path); - static std::pair ResolveOhmUrl(std::string ohmUrl); /* * Execute panda file from secure mem. secure memory lifecycle managed externally. @@ -1824,8 +1810,6 @@ public: static void SetCancelTimerCallback(EcmaVM *vm, CancelTimerCallback callback); static void NotifyEnvInitialized(EcmaVM *vm); static void SetReleaseSecureMemCallback(EcmaVM *vm, ReleaseSecureMemCallback releaseSecureMemFunc); - static void SetHostResolveBufferTracker(EcmaVM *vm, std::function cb); static void PandaFileSerialize(const EcmaVM *vm); static void ModuleSerialize(const EcmaVM *vm); static void ModuleDeserialize(EcmaVM *vm, const uint32_t appVersion); @@ -1923,8 +1907,6 @@ public: static void NotifyTaskFinished(const EcmaVM *vm); static bool IsMultiThreadCheckEnabled(const EcmaVM *vm); static uint32_t GetCurrentThreadId(); - static bool IsObjectAlive(const EcmaVM *vm, uintptr_t addr); - static bool IsValidHeapObject(const EcmaVM *vm, uintptr_t addr); //set VM apiVersion static void SetVMAPIVersion(EcmaVM *vm, const int32_t apiVersion); @@ -1941,7 +1923,8 @@ public: // 1.2runtime interface info static Local GetImplements(const EcmaVM *vm, Local instance); static void InitHybridVMEnv(const EcmaVM *vm); - + + JS_NAPI_EXPO_HYBRID_JS_NAPI_EXTENSION private: static bool isForked_; static bool CreateRuntime(const RuntimeOption &option); @@ -1950,7 +1933,6 @@ private: static uintptr_t GetHandleAddr(const EcmaVM *vm, uintptr_t localAddress); static uintptr_t GetGlobalHandleAddr(const EcmaVM *vm, uintptr_t localAddress); - static uintptr_t GetXRefGlobalHandleAddr(const EcmaVM *vm, uintptr_t localAddress); static uintptr_t SetWeak(const EcmaVM *vm, uintptr_t localAddress); static uintptr_t SetWeakCallback(const EcmaVM *vm, uintptr_t localAddress, void *ref, WeakRefClearCallBack freeGlobalCallBack, @@ -1958,11 +1940,6 @@ private: static uintptr_t ClearWeak(const EcmaVM *vm, uintptr_t localAddress); static bool IsWeak(const EcmaVM *vm, uintptr_t localAddress); static void DisposeGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr); - static void DisposeXRefGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr); -#ifdef PANDA_JS_ETS_HYBRID_MODE - static void MarkFromObject(const EcmaVM *vm, uintptr_t addr, std::function &visitor); - static void MarkFromObject(const EcmaVM *vm, uintptr_t addr); -#endif // PANDA_JS_ETS_HYBRID_MODE static bool IsSerializationTimeoutCheckEnabled(const EcmaVM *vm); static void GenerateTimeoutTraceIfNeeded(const EcmaVM *vm, std::chrono::system_clock::time_point &start, @@ -1975,6 +1952,9 @@ private: template friend class Local; friend class test::JSNApiTests; +#ifdef PANDA_JS_ETS_HYBRID_MODE + JS_NAPI_EXPO_HYBRID_JS_NAPI_MARK_FROM_OBJ_EXTENSION +#endif // PANDA_JS_ETS_HYBRID_MODE }; class PUBLIC_API ProxyRef : public ObjectRef { @@ -2194,10 +2174,7 @@ Local::Local(const EcmaVM *vm, const Global ¤t) } #ifdef PANDA_JS_ETS_HYBRID_MODE -class PUBLIC_API HandshakeHelper final { - public: - static void DoHandshake(EcmaVM *vm, void *stsiface, void **ecmaiface); -}; + JS_NAPI_EXPO_HYBRID_HAND_SHAKE_HELPER_EXTENSION #endif // PANDA_JS_ETS_HYBRID_MODE } // namespace panda #endif diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 19cf7f2542..79e9b1fecc 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -2358,17 +2358,6 @@ Local StringRef::GetNapiWrapperString(const EcmaVM *vm) return JSNApiHelper::ToLocal(napiWrapperString); } -Local StringRef::GetProxyNapiWrapperString(const EcmaVM *vm) -{ - // Omit exception check because ark calls here may not - // cause side effect even pending exception exists. - CROSS_THREAD_CHECK(vm); - ecmascript::ThreadManagedScope managedScope(thread); - JSHandle proxyNapiWapperString = thread->GlobalConstants()->GetHandledProxyNapiWrapperString(); - return JSNApiHelper::ToLocal(proxyNapiWapperString); -} - - Local StringRef::EncodeIntoUint8Array(const EcmaVM *vm) { CROSS_THREAD_CHECK(vm); @@ -2612,15 +2601,6 @@ Local ObjectRef::New(const EcmaVM *vm) return JSNApiHelper::ToLocal(object); } -Local ObjectRef::NewJSXRefObject(const EcmaVM *vm) -{ - CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); - ecmascript::ThreadManagedScope managedScope(thread); - ObjectFactory *factory = vm->GetFactory(); - JSHandle object(factory->NewJSXRefObject()); - return JSNApiHelper::ToLocal(object); -} - uintptr_t ObjectRef::NewObject(const EcmaVM *vm) { CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, @@ -4843,21 +4823,6 @@ void JSNApi::DestroyJSVM(EcmaVM *ecmaVm) EcmaVM::Destroy(ecmaVm); } -void JSNApi::SetStackInfo(const EcmaVM *vm, const panda::StackInfo &info) -{ - JSThread *thread = vm->GetJSThread(); - thread->SetStackStart(info.stackStart); - thread->SetStackLimit(info.stackStart - info.stackSize); -} - -panda::StackInfo JSNApi::GetStackInfo(const EcmaVM *vm) -{ - JSThread *thread = vm->GetJSThread(); - size_t stackStart = thread->GetStackStart(); - size_t stackSize = stackStart - thread->GetStackLimit(); - return {stackStart, stackSize}; -} - void JSNApi::RegisterUncatchableErrorHandler(EcmaVM *ecmaVm, const UncatchableErrorHandler &handler) { ecmaVm->RegisterUncatchableErrorHandler(handler); @@ -5912,17 +5877,6 @@ uintptr_t JSNApi::GetGlobalHandleAddr(const EcmaVM *vm, uintptr_t localAddress) return thread->NewGlobalHandle(value); } -uintptr_t JSNApi::GetXRefGlobalHandleAddr(const EcmaVM *vm, uintptr_t localAddress) -{ - CROSS_THREAD_CHECK(vm); - if (localAddress == 0) { - return 0; - } - ecmascript::ThreadManagedScope scope(thread); - JSTaggedType value = *(reinterpret_cast(localAddress)); - return thread->NewXRefGlobalHandle(value); -} - int JSNApi::GetStartRealTime(const EcmaVM *vm) { ecmascript::ThreadManagedScope scope(vm->GetJSThread()); @@ -6043,53 +5997,6 @@ void JSNApi::DisposeGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr) thread->DisposeGlobalHandle(addr); } -void JSNApi::DisposeXRefGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr) -{ - CROSS_THREAD_CHECK(vm); - if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { - return; - } - thread->DisposeXRefGlobalHandle(addr); -} - -#ifdef PANDA_JS_ETS_HYBRID_MODE -void JSNApi::MarkFromObject(const EcmaVM *vm, uintptr_t addr, std::function &visitor) -{ - if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { - return; - } - JSTaggedType value = *(reinterpret_cast(addr)); - vm->GetCrossVMOperator()->MarkFromObject(value, visitor); -} - -void JSNApi::MarkFromObject(const EcmaVM *vm, uintptr_t addr) -{ - if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { - return; - } - JSTaggedType value = *(reinterpret_cast(addr)); - vm->GetCrossVMOperator()->MarkFromObject(value); -} - -bool JSNApi::IsObjectAlive(const EcmaVM *vm, uintptr_t addr) -{ - if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { - return false; - } - JSTaggedType value = *(reinterpret_cast(addr)); - return vm->GetCrossVMOperator()->IsObjectAlive(value); -} - -bool JSNApi::IsValidHeapObject(const EcmaVM *vm, uintptr_t addr) -{ - if (addr == 0 || !reinterpret_cast(addr)->IsUsing()) { - return false; - } - JSTaggedType value = *(reinterpret_cast(addr)); - return vm->GetCrossVMOperator()->IsValidHeapObject(value); -} -#endif // PANDA_JS_ETS_HYBRID_MODE - void *JSNApi::InterOpSerializeValue([[maybe_unused]] const EcmaVM *vm, [[maybe_unused]] Local value, [[maybe_unused]] Local transfer, [[maybe_unused]] Local cloneList, [[maybe_unused]] bool defaultTransfer, [[maybe_unused]] bool defaultCloneShared) @@ -6671,21 +6578,6 @@ Local JSNApi::GetModuleNameSpaceWithModuleInfoForHybridApp(EcmaVM *vm return JSNApi::GetModuleNameSpaceWithModuleInfo(vm, file, module_path); } -Local JSNApi::GetModuleNameSpaceWithPath(const EcmaVM *vm, const char *path) -{ - CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); - auto [filePath, recordName] = ModulePathHelper::ResolvePath(path); - ecmascript::ThreadManagedScope managedScope(thread); - JSHandle moduleNamespace = - ecmascript::NapiModuleLoader::LoadModuleNameSpaceFromFile(thread, recordName, filePath); - return JSNApiHelper::ToLocal(moduleNamespace); -} - -std::pair JSNApi::ResolveOhmUrl(std::string ohmUrl) -{ - return ModulePathHelper::ResolveOhmUrl(ohmUrl); -} - // ---------------------------------- Promise ------------------------------------- Local PromiseRef::Catch(const EcmaVM *vm, Local handler) { @@ -7093,12 +6985,4 @@ bool ExternalStringCache::HasCachedString([[maybe_unused]] const EcmaVM *vm, uin return instance->HasCachedString(propertyIndex); } -#ifdef PANDA_JS_ETS_HYBRID_MODE -void HandshakeHelper::DoHandshake([[maybe_unused]] EcmaVM *vm, void *stsIface, void **ecmaIface) -{ - ecmascript::CrossVMOperator::DoHandshake(vm, stsIface, ecmaIface); -} -#endif // PANDA_JS_ETS_HYBRID_MODE - - } // namespace panda diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index ea7210c553..1b624ac0f6 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -510,13 +510,6 @@ JSHandle ObjectFactory::NewJSObject(const JSHandle &jshclass return obj; } -JSHandle ObjectFactory::NewJSXRefObject() -{ - JSHandle jsXRefHClass = JSHandle::Cast(thread_->GlobalConstants()->GetHandledXRefObjectClass()); - JSHandle object(NewJSObject(jsXRefHClass)); - return object; -} - JSHandle ObjectFactory::CloneProperties(const JSHandle &old) { uint32_t newLength = old->GetLength(); diff --git a/ecmascript/object_factory.h b/ecmascript/object_factory.h index bd7d60fc32..3d686e909d 100644 --- a/ecmascript/object_factory.h +++ b/ecmascript/object_factory.h @@ -36,6 +36,7 @@ #include "ecmascript/tagged_array.h" #include "ecmascript/byte_array.h" #include "ecmascript/pgo_profiler/pgo_extra_profiler.h" +#include "ecmascript/cross_vm/object_factory_hybrid.h" namespace panda::ecmascript { struct MethodLiteral; @@ -666,7 +667,7 @@ public: JSHandle PUBLIC_API NewJSObject(const JSHandle &jshclass); // used for creating JSXRefObject - JSHandle PUBLIC_API NewJSXRefObject(); + OBJECT_FACTORY_HYBRID_EXTENSION // used for creating jshclass in Builtins, Function, Class_Linker JSHandle NewEcmaHClass(uint32_t size, JSType type, const JSHandle &prototype); diff --git a/ecmascript/tests/unified_gc_test.cpp b/ecmascript/tests/unified_gc_test.cpp index 7bc01f392d..f9251f0a27 100644 --- a/ecmascript/tests/unified_gc_test.cpp +++ b/ecmascript/tests/unified_gc_test.cpp @@ -16,7 +16,7 @@ #include "ecmascript/tests/unified_gc_test_helper.h" #include "ecmascript/mem/concurrent_marker.h" #include "ecmascript/mem/region-inl.h" -#include "ecmascript/mem/unified_gc/unified_gc_marker.h" +#include "ecmascript/cross_vm/unified_gc/unified_gc_marker.h" using namespace panda::ecmascript; -- Gitee