1 /* 2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ETS_RUNTIME_ECMASCRIPT_CROSS_VM_CROSS_VM_OPERATOR_H 17 #define ETS_RUNTIME_ECMASCRIPT_CROSS_VM_CROSS_VM_OPERATOR_H 18 19 #include <memory> 20 21 #include "libpandabase/macros.h" 22 23 #include "hybrid/ecma_vm_interface.h" 24 #include "hybrid/sts_vm_interface.h" 25 26 namespace panda::ecmascript { 27 28 using JSTaggedType = uint64_t; 29 class EcmaVM; 30 31 class CrossVMOperator { 32 static_assert(PANDA_JS_ETS_HYBRID_MODE); 33 public: 34 CrossVMOperator(EcmaVM *vm); 35 ~CrossVMOperator() = default; 36 NO_COPY_SEMANTIC(CrossVMOperator); 37 NO_MOVE_SEMANTIC(CrossVMOperator); 38 39 static void DoHandshake(EcmaVM *vm, void *stsIface, void **ecmaIface); 40 GetSTSVMInterface()41 arkplatform::STSVMInterface *GetSTSVMInterface() const 42 { 43 return stsVMInterface_; 44 } 45 GetEcmaVMInterface()46 arkplatform::EcmaVMInterface *GetEcmaVMInterface() const 47 { 48 return ecmaVMInterface_.get(); 49 } 50 51 void MarkFromObject(JSTaggedType value); 52 bool IsObjectAlive(JSTaggedType value); 53 bool IsValidHeapObject(JSTaggedType value); 54 private: 55 class EcmaVMInterfaceImpl final : public arkplatform::EcmaVMInterface { 56 public: 57 NO_COPY_SEMANTIC(EcmaVMInterfaceImpl); 58 NO_MOVE_SEMANTIC(EcmaVMInterfaceImpl); EcmaVMInterfaceImpl(EcmaVM * vm)59 EcmaVMInterfaceImpl(EcmaVM *vm): vm_(vm) {}; 60 ~EcmaVMInterfaceImpl() override = default; 61 62 bool StartXRefMarking() override; 63 void NotifyXGCInterruption() override; 64 private: 65 EcmaVM *vm_ {nullptr}; 66 }; 67 68 EcmaVM *vm_ {nullptr}; 69 arkplatform::STSVMInterface *stsVMInterface_ = nullptr; 70 std::unique_ptr<arkplatform::EcmaVMInterface> ecmaVMInterface_; 71 }; 72 73 } // namespace panda::ecmascript 74 75 #endif // ETS_RUNTIME_ECMASCRIPT_CROSS_VM_CROSS_VM_OPERATOR_H