1 /** 2 * Copyright (c) 2021-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 PANDA_RUNTIME_MEM_FREE_OBJECT 17 #define PANDA_RUNTIME_MEM_FREE_OBJECT 18 19 #include "runtime/include/coretypes/tagged_value.h" 20 #include "runtime/include/object_header.h" 21 #include "runtime/include/object_accessor.h" 22 #include "libpandabase/macros.h" 23 24 namespace ark::mem { 25 class FreeObject : public ObjectHeader { 26 public: GetSize()27 uint32_t GetSize() const 28 { 29 auto raw = ObjectAccessor::GetPrimitive<coretypes::TaggedType>(this, GetTaggedSizeOffset()); 30 return coretypes::TaggedValue::UnpackPrimitiveData(raw); 31 } 32 GetNext()33 FreeObject *GetNext() const 34 { 35 auto raw = ObjectAccessor::GetPrimitive<coretypes::TaggedType>(this, GetTaggedNextOffset()); 36 return reinterpret_cast<FreeObject *>(static_cast<uintptr_t>(coretypes::TaggedValue::UnpackPrimitiveData(raw))); 37 } 38 GetTaggedNextOffset()39 static constexpr size_t GetTaggedNextOffset() 40 { 41 return MEMBER_OFFSET(FreeObject, taggedNext_); 42 } 43 GetTaggedSizeOffset()44 static constexpr size_t GetTaggedSizeOffset() 45 { 46 return MEMBER_OFFSET(FreeObject, taggedSize_); 47 } 48 49 private: 50 // There should be primitive fields, but that's not friendly to concurrent marker 51 coretypes::TaggedType taggedNext_ FIELD_UNUSED; 52 coretypes::TaggedType taggedSize_ FIELD_UNUSED; 53 }; 54 } // namespace ark::mem 55 56 #endif // PANDA_RUNTIME_MEM_FREE_OBJECT 57