1 /* 2 * Copyright (c) 2021 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_SNAPSHOT_MEM_CONSTANTS_H 17 #define ECMASCRIPT_SNAPSHOT_MEM_CONSTANTS_H 18 19 // slot bit 20 static constexpr int OBJECT_INDEX_BIT_NUMBER = 13; // object index 21 static constexpr int OBJECT_TO_STRING_FLAG_NUMBER = 1; // 1 : reference to string 22 static constexpr int OBJECT_IN_CONSTANTS_INDEX_NUMBER = 8; // index 23 static constexpr int OBJECT_TYPE_BIT_NUMBER = 7; // js_type 24 static constexpr int OBJECT_SIZE_BIT_NUMBER = 18; // 4M 25 static constexpr int OBJECT_SPECIAL = 1; // special 26 static constexpr int IS_REFERENCE_SLOT_BIT_NUMBER = 16; // [0x0000] is reference 27 28 static constexpr int MAX_C_POINTER_INDEX = 1024 * 8 - 1; 29 static constexpr int MAX_OBJECT_INDEX = 8192; 30 static constexpr int MAX_OBJECT_SIZE_INDEX = 1024 * 256 - 1; 31 32 // object or space align up 33 static constexpr size_t PAGE_SIZE_ALIGN_UP = 4096; 34 static constexpr size_t MAX_UINT_32 = 0xFFFFFFFF; 35 36 // builtins native method encode 37 // builtins deserialize: nativeMehtods_ + getter/setter; program deserialize: getter/setter + programFunctionMethods 38 static constexpr size_t PROGRAM_NATIVE_METHOD_BEGIN = 6; 39 40 // address slot size 41 static constexpr int ADDRESS_SIZE = sizeof(uintptr_t); 42 43 // serialize use constants 44 static constexpr uint8_t MASK_METHOD_SPACE_BEGIN = 0x7F; 45 static constexpr int OBJECT_SIZE_EXTEND_PAGE = 512; 46 static constexpr int NATIVE_METHOD_SIZE = 427; 47 48 static constexpr size_t MANAGED_OBJECT_OFFSET = 16; 49 50 #endif // ECMASCRIPT_SNAPSHOT_MEM_CONSTANTS_H 51