1 /**
2 * Copyright (c) 2021-2022 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/gc_task.h"
17
18 #include "runtime/mem/gc/gc.h"
19
20 namespace panda {
21
Run(mem::GC & gc)22 void GCTask::Run(mem::GC &gc)
23 {
24 gc.WaitForGC(*this);
25 gc.SetCanAddGCTask(true);
26 }
27
Release(mem::InternalAllocatorPtr allocator)28 void GCTask::Release(mem::InternalAllocatorPtr allocator)
29 {
30 allocator->Delete(this);
31 }
32
UpdateGCCollectionType(GCCollectionType collection_type)33 void GCTask::UpdateGCCollectionType(GCCollectionType collection_type)
34 {
35 ASSERT(collection_type != GCCollectionType::NONE);
36 if (collection_type <= collection_type_) {
37 return;
38 }
39 collection_type_ = collection_type;
40 }
41
operator <<(std::ostream & os,const GCTaskCause & cause)42 std::ostream &operator<<(std::ostream &os, const GCTaskCause &cause)
43 {
44 switch (cause) {
45 case GCTaskCause::INVALID_CAUSE:
46 os << "Invalid";
47 break;
48 case GCTaskCause::PYGOTE_FORK_CAUSE:
49 os << "PygoteFork";
50 break;
51 case GCTaskCause::STARTUP_COMPLETE_CAUSE:
52 os << "StartupComplete";
53 break;
54 case GCTaskCause::NATIVE_ALLOC_CAUSE:
55 os << "NativeAlloc";
56 break;
57 case GCTaskCause::EXPLICIT_CAUSE:
58 os << "Explicit";
59 break;
60 case GCTaskCause::HEAP_USAGE_THRESHOLD_CAUSE:
61 os << "Threshold";
62 break;
63 case GCTaskCause::YOUNG_GC_CAUSE:
64 os << "Young";
65 break;
66 case GCTaskCause::OOM_CAUSE:
67 os << "OOM";
68 break;
69 default:
70 LOG(FATAL, GC) << "Unknown gc cause";
71 break;
72 }
73 return os;
74 }
75
operator <<(std::ostream & os,const GCCollectionType & collection_type_)76 std::ostream &operator<<(std::ostream &os, const GCCollectionType &collection_type_)
77 {
78 switch (collection_type_) {
79 case GCCollectionType::NONE:
80 os << "NONE";
81 break;
82 case GCCollectionType::YOUNG:
83 os << "YOUNG";
84 break;
85 case GCCollectionType::TENURED:
86 os << "TENURED";
87 break;
88 case GCCollectionType::MIXED:
89 os << "MIXED";
90 break;
91 case GCCollectionType::FULL:
92 os << "FULL";
93 break;
94 default:
95 LOG(FATAL, GC) << "Unknown collection type";
96 break;
97 }
98 return os;
99 }
100
101 } // namespace panda
102