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_MEM_AREA_H 17 #define ECMASCRIPT_MEM_AREA_H 18 19 namespace panda::ecmascript { 20 class Area { 21 public: Area(uintptr_t begin,size_t capacity)22 Area(uintptr_t begin, size_t capacity) 23 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 24 : begin_(begin), end_(begin + capacity), next_(nullptr), prev_(nullptr) 25 { 26 } 27 ~Area() = default; 28 NO_COPY_SEMANTIC(Area); 29 NO_MOVE_SEMANTIC(Area); 30 GetBegin()31 uintptr_t GetBegin() const 32 { 33 return begin_; 34 } 35 GetEnd()36 uintptr_t GetEnd() const 37 { 38 return end_; 39 } 40 LinkPrev(Area * prev)41 void LinkPrev(Area *prev) 42 { 43 prev_ = prev; 44 } 45 LinkNext(Area * next)46 void LinkNext(Area *next) 47 { 48 next_ = next; 49 } 50 GetSize()51 size_t GetSize() 52 { 53 return end_ - begin_; 54 } 55 56 private: 57 template<class T> 58 friend class EcmaList; 59 friend class Worker; GetPrev()60 Area *GetPrev() const 61 { 62 return prev_; 63 } 64 GetNext()65 Area *GetNext() const 66 { 67 return next_; 68 } 69 uintptr_t begin_; 70 uintptr_t end_; 71 Area *next_; 72 Area *prev_; 73 }; 74 } // namespace panda::ecmascript 75 76 #endif // ECMASCRIPT_MEM_AREA_H 77