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 #include "common_components/heap/collector/collector_proxy.h"
16
17 namespace common {
Init(const RuntimeParam & param)18 void CollectorProxy::Init(const RuntimeParam& param)
19 {
20 arkCollector_.Init(param);
21
22 if (currentCollector_ == nullptr) {
23 currentCollector_ = &arkCollector_;
24 }
25 }
26
Fini()27 void CollectorProxy::Fini() { arkCollector_.Fini(); }
28
RunGarbageCollection(uint64_t gcIndex,GCReason reason,GCType gcType)29 void CollectorProxy::RunGarbageCollection(uint64_t gcIndex, GCReason reason, GCType gcType)
30 {
31 switch (reason) {
32 case GC_REASON_HEU:
33 case GC_REASON_YOUNG:
34 case GC_REASON_BACKUP:
35 currentCollector_ = &arkCollector_;
36 break;
37 case GC_REASON_OOM:
38 case GC_REASON_FORCE:
39 currentCollector_ = &arkCollector_;
40 break;
41 default:
42 currentCollector_ = &arkCollector_;
43 break;
44 }
45 currentCollector_->MarkGCStart();
46 currentCollector_->RunGarbageCollection(gcIndex, reason, gcType);
47 }
48 } // namespace common
49