1 /**
2 * Copyright (c) 2025 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 #include "runtime/include/object_header.h"
17 #include "runtime/mem/gc/cmc-gc-adapter/cmc-allocator-adapter.h"
18 #include "runtime/mem/runslots_allocator-inl.h"
19 #if defined(ARK_HYBRID)
20 #include "heap/heap_allocator.h"
21 #include "objects/base_state_word.h"
22 #endif
23
24 namespace ark::mem {
25
26 template <MTModeT MT_MODE>
CMCObjectAllocatorAdapter(MemStatsType * memStats,bool createPygoteSpaceAllocator)27 CMCObjectAllocatorAdapter<MT_MODE>::CMCObjectAllocatorAdapter(MemStatsType *memStats, bool createPygoteSpaceAllocator)
28 : ObjectAllocatorNoGen<MT_MODE>(memStats, createPygoteSpaceAllocator)
29 {
30 }
31
32 template <MTModeT MT_MODE>
Allocate(size_t size,Alignment align,ark::ManagedThread * thread,ObjectAllocatorBase::ObjMemInitPolicy objInit,bool pinned)33 void *CMCObjectAllocatorAdapter<MT_MODE>::Allocate([[maybe_unused]] size_t size, [[maybe_unused]] Alignment align,
34 [[maybe_unused]] ark::ManagedThread *thread,
35 [[maybe_unused]] ObjectAllocatorBase::ObjMemInitPolicy objInit,
36 [[maybe_unused]] bool pinned)
37 {
38 #if defined(ARK_HYBRID)
39 return reinterpret_cast<void *>(panda::HeapAllocator::Allocate(size, panda::Language::STATIC));
40 #else
41 return nullptr;
42 #endif
43 }
44
45 template <MTModeT MT_MODE>
AllocateNonMovable(size_t size,Alignment align,ark::ManagedThread * thread,ObjectAllocatorBase::ObjMemInitPolicy objInit)46 void *CMCObjectAllocatorAdapter<MT_MODE>::AllocateNonMovable(
47 [[maybe_unused]] size_t size, [[maybe_unused]] Alignment align, // CC-OFF(G.FMT.06) project code style
48 [[maybe_unused]] ark::ManagedThread *thread, // CC-OFF(G.FMT.06) project code style
49 [[maybe_unused]] ObjectAllocatorBase::ObjMemInitPolicy objInit) // CC-OFF(G.FMT.06) project code style
50 {
51 #if defined(ARK_HYBRID)
52 return reinterpret_cast<ObjectHeader *>(panda::HeapAllocator::AllocateInNonmove(size, panda::Language::STATIC));
53 #else
54 return nullptr;
55 #endif
56 }
57
58 template class CMCObjectAllocatorAdapter<MT_MODE_SINGLE>;
59 template class CMCObjectAllocatorAdapter<MT_MODE_MULTI>;
60 template class CMCObjectAllocatorAdapter<MT_MODE_TASK>;
61
62 } // namespace ark::mem
63