• 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_TLAB_ALLOCATOR_H
17 #define ECMASCRIPT_MEM_TLAB_ALLOCATOR_H
18 
19 #include "ecmascript/mem/allocator-inl.h"
20 
21 namespace panda::ecmascript {
22 class Heap;
23 
24 class TlabAllocator {
25 public:
26     TlabAllocator() = delete;
27     inline explicit TlabAllocator(Heap *heap);
~TlabAllocator()28     ~TlabAllocator()
29     {
30         delete localSpace_;
31     }
32 
33     NO_COPY_SEMANTIC(TlabAllocator);
34     NO_MOVE_SEMANTIC(TlabAllocator);
35 
36     inline void Finalize();
37 
38     inline uintptr_t Allocate(size_t size, MemSpaceType space);
39 
40 private:
41     inline uintptr_t AllocateInYoungSpace(size_t size);
42     inline uintptr_t AllocateInOldSpace(size_t size);
43     inline uintptr_t AllocateInCompressSpace(size_t size);
44 
45     inline bool ExpandYoung();
46     inline bool ExpandCompressFromOld(size_t size);
47 
48     Heap *heap_;
49 
50     bool enableExpandYoung_;
51     BumpPointerAllocator youngAllocator_;
52 
53     LocalSpace *localSpace_;
54 };
55 }  // namespace panda::ecmascript
56 
57 #endif  // ECMASCRIPT_MEM_TLAB_ALLOCATOR_H
58