• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FREE_OBJECT_H
17 #define ECMASCRIPT_FREE_OBJECT_H
18 
19 #include "ecmascript/js_hclass.h"
20 #include "ecmascript/mem/barriers.h"
21 #include "ecmascript/mem/tagged_object-inl.h"
22 
23 namespace panda::ecmascript {
24 class FreeObject : public TaggedObject {
25 public:
Cast(uintptr_t object)26     static FreeObject *Cast(uintptr_t object)
27     {
28         return reinterpret_cast<FreeObject *>(object);
29     }
30     static FreeObject *FillFreeObject(EcmaVM *vm, uintptr_t address, size_t size);
31 
IsEmpty()32     inline bool IsEmpty() const
33     {
34         return Available() == 0;
35     }
36 
GetBegin()37     inline uintptr_t GetBegin() const
38     {
39         return reinterpret_cast<uintptr_t>(this);
40     }
41 
GetEnd()42     inline uintptr_t GetEnd() const
43     {
44         return reinterpret_cast<uintptr_t>(this) + Available();
45     }
46 
SetAvailable(uint32_t size)47     inline void SetAvailable(uint32_t size)
48     {
49         if (size >= SIZE) {
50             SetSize(JSTaggedValue(size));
51         }
52     }
53 
Available()54     inline uint32_t Available() const
55     {
56         auto hclass = GetClass();
57         if (hclass->IsFreeObjectWithShortField()) {
58             return hclass->GetObjectSize();
59         }
60         ASSERT(GetSize().IsInt());
61         return GetSize().GetInt();
62     }
63 
IsFreeObject()64     inline bool IsFreeObject() const
65     {
66         return GetClass()->IsFreeObject();
67     }
68 
69     static constexpr size_t NEXT_OFFSET = TaggedObjectSize();
70     ACCESSORS_FIXED_SIZE_FIELD(Next, FreeObject *, JSTaggedType, NEXT_OFFSET, SIZE_OFFSET)
71     // TaggedArray visitor may be error while concurrent marking
72     ACCESSORS(Size, SIZE_OFFSET, SIZE)
73 };
74 
75 static_assert((FreeObject::SIZE % static_cast<uint8_t>(MemAlignment::MEM_ALIGN_OBJECT)) == 0);
76 }  // namespace panda::ecmascript
77 
78 #endif  // ECMASCRIPT_MEM_FREE_OBJECT_H
79