1 /* 2 * Copyright (c) 2024 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 ECMASCRIPT_BUILTINS_BUILTINS_GC_H 17 #define ECMASCRIPT_BUILTINS_BUILTINS_GC_H 18 19 #include "ecmascript/base/builtins_base.h" 20 #include "ecmascript/js_thread.h" 21 22 // List of functions in ArkTools.GC, extension of JS engine. 23 // V(name, func, length, stubIndex) 24 // where BuiltinsGc::func refers to the native implementation of GC[name]. 25 // kungfu::BuiltinsStubCSigns::stubIndex refers to the builtin stub index, or INVALID if no stub available. 26 #define BUILTIN_GC_FUNCTIONS(V) \ 27 V("getFreeHeapSize", GetFreeHeapSize, 0, INVALID) \ 28 V("getReservedHeapSize", GetReservedHeapSize, 0, INVALID) \ 29 V("getUsedHeapSize", GetUsedHeapSize, 0, INVALID) \ 30 V("getObjectAddress", GetObjectAddress, 1, INVALID) \ 31 V("getObjectSpaceType", GetObjectSpaceType, 1, INVALID) \ 32 V("registerNativeAllocation", RegisterNativeAllocation, 1, INVALID) \ 33 V("registerNativeFree", RegisterNativeFree, 1, INVALID) 34 35 namespace panda::ecmascript::builtins { 36 class BuiltinsGc : public base::BuiltinsBase { 37 public: 38 static JSTaggedValue GetFreeHeapSize(EcmaRuntimeCallInfo *info); 39 40 static JSTaggedValue GetReservedHeapSize(EcmaRuntimeCallInfo *info); 41 42 static JSTaggedValue GetUsedHeapSize(EcmaRuntimeCallInfo *info); 43 44 static JSTaggedValue GetObjectAddress(EcmaRuntimeCallInfo *info); 45 46 static JSTaggedValue GetObjectSpaceType(EcmaRuntimeCallInfo *info); 47 48 static JSTaggedValue RegisterNativeAllocation(EcmaRuntimeCallInfo *info); 49 50 static JSTaggedValue RegisterNativeFree(EcmaRuntimeCallInfo *info); 51 GetGcFunctions()52 static Span<const base::BuiltinFunctionEntry> GetGcFunctions() 53 { 54 return Span<const base::BuiltinFunctionEntry>(GC_FUNCTIONS); 55 } 56 57 private: 58 #define BUILTINS_GC_FUNCTION_ENTRY(name, method, length, id) \ 59 base::BuiltinFunctionEntry::Create(name, BuiltinsGc::method, length, kungfu::BuiltinsStubCSigns::id), 60 61 static constexpr std::array GC_FUNCTIONS = { 62 BUILTIN_GC_FUNCTIONS(BUILTINS_GC_FUNCTION_ENTRY) 63 }; 64 #undef BUILTINS_GC_FUNCTION_ENTRY 65 }; 66 } // namespace panda::ecmascript::builtins 67 68 #endif // ECMASCRIPT_BUILTINS_BUILTINS_GC_H 69