1 /** 2 * Copyright (c) 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 PANDA_PLUGINS_ETS_RUNTIME_PLATFORM_TYPES_H_ 17 #define PANDA_PLUGINS_ETS_RUNTIME_PLATFORM_TYPES_H_ 18 19 #include "plugins/ets/runtime/ets_coroutine.h" 20 21 namespace ark::ets { 22 23 class EtsClass; 24 class EtsMethod; 25 class EtsCoroutine; 26 template <typename T> 27 class EtsTypedObjectArray; 28 29 // A set of types defined and used in platform implementation, owned by the VM 30 // NOLINTBEGIN(misc-non-private-member-variables-in-classes) 31 class PANDA_PUBLIC_API EtsPlatformTypes { 32 public: 33 static constexpr uint32_t ASCII_CHAR_TABLE_SIZE = 128; 34 EtsClass *coreString {}; // IsStringClass 35 EtsClass *coreBoolean; 36 EtsClass *coreByte; 37 EtsClass *coreChar; 38 EtsClass *coreShort; 39 EtsClass *coreInt; 40 EtsClass *coreLong; 41 EtsClass *coreFloat; 42 EtsClass *coreDouble; 43 44 EtsClass *coreObject; 45 46 EtsClass *escompatBigint; 47 EtsClass *coreFunction; 48 49 EtsClass *escompatError; 50 EtsClass *coreOutOfMemoryError; 51 EtsClass *coreException; 52 53 EtsClass *coreStringBuilder; 54 55 EtsClass *corePromise; 56 EtsClass *coreJob; 57 EtsMethod *corePromiseSubscribeOnAnotherPromise; 58 EtsClass *corePromiseRef; 59 EtsClass *coreWaitersList; 60 EtsClass *coreMutex; 61 EtsClass *coreEvent; 62 EtsClass *coreCondVar; 63 EtsClass *coreQueueSpinlock; 64 65 EtsClass *escompatArray; 66 EtsClass *escompatArrayBuffer; 67 EtsClass *containersArrayAsListInt; 68 69 EtsClass *interopJSValue; 70 71 EtsClass *coreTupleN; 72 73 EtsClass *coreStackTraceElement; 74 75 EtsClass *coreFinalizableWeakRef; 76 EtsClass *coreFinalizationRegistry; 77 EtsMethod *coreFinalizationRegistryExecCleanup; 78 79 EtsClass *coreRuntimeLinker; 80 EtsClass *coreBootRuntimeLinker; 81 EtsClass *coreAbcRuntimeLinker; 82 EtsClass *memoryRuntimeLinker; 83 EtsClass *coreAbcFile; 84 85 EtsClass *coreField; 86 EtsClass *coreMethod; 87 EtsClass *coreParameter; 88 89 EtsClass *escompatRecord; 90 EtsMethod *escompatRecordGetter; 91 EtsMethod *escompatRecordSetter; 92 93 EtsClass *escompatProcess; 94 EtsMethod *escompatProcessListUnhandledJobs; 95 EtsMethod *escompatProcessListUnhandledPromises; 96 97 EtsClass *coreTuple; 98 EtsClass *escompatRegExpExecArray; 99 EtsClass *escompatJsonReplacer; 100 101 /* Internal Caches */ 102 void CreateAndInitializeCaches(); 103 void VisitRoots(const GCRootVisitor &visitor) const; 104 void UpdateCachesVmRefs(const GCRootUpdater &updater) const; GetAsciiCacheTable()105 EtsTypedObjectArray<EtsString> *GetAsciiCacheTable() const 106 { 107 return asciiCharCache_; 108 } 109 110 private: 111 friend class EtsClassLinkerExtension; 112 friend class mem::Allocator; 113 mutable EtsTypedObjectArray<EtsString> *asciiCharCache_ {nullptr}; 114 explicit EtsPlatformTypes(EtsCoroutine *coro); 115 }; 116 // NOLINTEND(misc-non-private-member-variables-in-classes) 117 118 // Obtain EtsPlatformTypes pointer cached in the coroutine PlatformTypes(EtsCoroutine * coro)119ALWAYS_INLINE inline EtsPlatformTypes const *PlatformTypes(EtsCoroutine *coro) 120 { 121 ASSERT(coro != nullptr); 122 return coro->GetLocalStorage().Get<EtsCoroutine::DataIdx::ETS_PLATFORM_TYPES_PTR, EtsPlatformTypes *>(); 123 } 124 125 // Obtain EtsPlatfromTypes pointer from the VM 126 EtsPlatformTypes const *PlatformTypes(PandaEtsVM *vm); 127 128 // Obtain EtsPlatfromTypes pointer from the current VM 129 EtsPlatformTypes const *PlatformTypes(); 130 131 } // namespace ark::ets 132 133 #endif // !PANDA_PLUGINS_ETS_RUNTIME_PLATFORM_TYPES_H_ 134