• 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_MEM_MARK_STACK_INL_H
17 #define ECMASCRIPT_MEM_MARK_STACK_INL_H
18 
19 #include "ecmascript/mem/mark_stack.h"
20 
21 #include "ecmascript/mem/native_area_allocator.h"
22 
23 namespace panda::ecmascript {
24 template<class T>
BeginMarking(Heap * heap,ContinuousStack<T> * other)25 void ContinuousStack<T>::BeginMarking(Heap *heap, ContinuousStack<T> *other)
26 {
27     heap_ = heap;
28     currentArea_ = other->currentArea_;
29     if (currentArea_ == nullptr) {
30         currentArea_ = NativeAreaAllocator::AllocateSpace(DEFAULT_MARK_STACK_SIZE);
31     }
32     ResetBegin(currentArea_->GetBegin(), currentArea_->GetEnd());
33 }
34 
35 template<class T>
FinishMarking(ContinuousStack<T> * other)36 void ContinuousStack<T>::FinishMarking(ContinuousStack<T> *other)
37 {
38     other->currentArea_ = currentArea_;
39 
40     while (!unusedList_.IsEmpty()) {
41         Area *node = unusedList_.PopBack();
42         NativeAreaAllocator::FreeSpace(node);
43     }
44 }
45 
46 template<class T>
Extend()47 void ContinuousStack<T>::Extend()
48 {
49     auto area = NativeAreaAllocator::AllocateSpace(DEFAULT_MARK_STACK_SIZE);
50     areaList_.AddNode(currentArea_);
51     currentArea_ = area;
52     ResetBegin(currentArea_->GetBegin(), currentArea_->GetEnd());
53 }
54 
55 template<class T>
Destroy()56 void ContinuousStack<T>::Destroy()
57 {
58     if (currentArea_ != nullptr) {
59         NativeAreaAllocator::FreeSpace(currentArea_);
60         currentArea_ = nullptr;
61     }
62 }
63 }  // namespace panda::ecmascript
64 
65 #endif  // ECMASCRIPT_MEM_MARK_STACK_INL_H
66