1 /** 2 * Copyright (c) 2021-2022 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 PANDA_RUNTIME_ETS_FFI_CLASSES_ETS_VOID_H 17 #define PANDA_RUNTIME_ETS_FFI_CLASSES_ETS_VOID_H 18 19 #include "plugins/ets/runtime/ets_panda_file_items.h" 20 #include "plugins/ets/runtime/ets_vm.h" 21 22 namespace panda::ets { 23 24 class EtsVoid : EtsObject { 25 public: 26 EtsVoid() = delete; 27 ~EtsVoid() = delete; 28 29 // NOTE: vpukhov. replace with undefined or move to TLS GetInstance()30 static EtsVoid *GetInstance() 31 { 32 EtsCoroutine *coro = EtsCoroutine::GetCurrent(); 33 EtsClassLinker *classLinker = coro->GetPandaVM()->GetClassLinker(); 34 EtsClass *voidClass = classLinker->GetVoidClass(); 35 ASSERT(voidClass->IsInitialized()); // do not trigger gc! 36 37 EtsField *instanceField = voidClass->GetStaticFieldIDByName("void_instance"); 38 return reinterpret_cast<EtsVoid *>(voidClass->GetStaticFieldObject(instanceField)); 39 } 40 Initialize()41 static void Initialize() 42 { 43 EtsCoroutine *coro = EtsCoroutine::GetCurrent(); 44 EtsClassLinker *classLinker = coro->GetPandaVM()->GetClassLinker(); 45 EtsClass *voidClass = classLinker->GetVoidClass(); 46 if (!voidClass->IsInitialized()) { 47 classLinker->InitializeClass(coro, voidClass); 48 } 49 } 50 FromEtsObject(EtsObject * obj)51 static EtsVoid *FromEtsObject(EtsObject *obj) 52 { 53 ASSERT(obj->GetClass() == EtsCoroutine::GetCurrent()->GetPandaVM()->GetClassLinker()->GetVoidClass()); 54 return static_cast<EtsVoid *>(obj); 55 } 56 57 private: 58 NO_COPY_SEMANTIC(EtsVoid); 59 NO_MOVE_SEMANTIC(EtsVoid); 60 }; 61 62 } // namespace panda::ets 63 64 #endif // PANDA_RUNTIME_ETS_FFI_CLASSES_ETS_VOID_H 65