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 PANDA_RUNTIME_MEM_GC_GC_SCOPED_PHASE_H_ 17 #define PANDA_RUNTIME_MEM_GC_GC_SCOPED_PHASE_H_ 18 19 #include "libpandabase/macros.h" 20 #include "libpandabase/utils/logger.h" 21 #include "runtime/include/mem/panda_string.h" 22 #include "runtime/mem/gc/gc_phase.h" 23 #include "runtime/mem/mem_stats_additional_info.h" 24 #include "runtime/mem/mem_stats_default.h" 25 26 namespace panda::mem { 27 28 // forward declarations: 29 class GC; 30 31 class GCScopedPhase { 32 public: 33 GCScopedPhase(MemStatsType *mem_stats, GC *gc, GCPhase new_phase); 34 NO_COPY_SEMANTIC(GCScopedPhase); 35 NO_MOVE_SEMANTIC(GCScopedPhase); 36 37 ~GCScopedPhase(); 38 GetPhaseName(GCPhase phase)39 static PandaString GetPhaseName(GCPhase phase) 40 { 41 switch (phase) { 42 case GCPhase::GC_PHASE_IDLE: 43 return "Idle"; 44 case GCPhase::GC_PHASE_RUNNING: 45 return "RunPhases()"; 46 case GCPhase::GC_PHASE_COLLECT_ROOTS: 47 return "CollectRoots()"; 48 case GCPhase::GC_PHASE_INITIAL_MARK: 49 return "InitialMark"; 50 case GCPhase::GC_PHASE_MARK: 51 return "MarkAll()"; 52 case GCPhase::GC_PHASE_MARK_YOUNG: 53 return "MarkYoung()"; 54 case GCPhase::GC_PHASE_REMARK: 55 return "YoungRemark()"; 56 case GCPhase::GC_PHASE_COLLECT_YOUNG_AND_MOVE: 57 return "CollectYoungAndMove()"; 58 case GCPhase::GC_PHASE_SWEEP_STRING_TABLE: 59 return "SweepStringTable()"; 60 case GCPhase::GC_PHASE_SWEEP_STRING_TABLE_YOUNG: 61 return "SweepStringTableYoung()"; 62 case GCPhase::GC_PHASE_SWEEP: 63 return "Sweep()"; 64 case GCPhase::GC_PHASE_CLEANUP: 65 return "Cleanup()"; 66 default: 67 return "UnknownPhase"; 68 } 69 } 70 GetPhaseAbbr(GCPhase phase)71 static PandaString GetPhaseAbbr(GCPhase phase) 72 { 73 switch (phase) { 74 case GCPhase::GC_PHASE_IDLE: 75 return "Idle"; 76 case GCPhase::GC_PHASE_RUNNING: 77 return "RunPhases"; 78 case GCPhase::GC_PHASE_COLLECT_ROOTS: 79 return "ColRoots"; 80 case GCPhase::GC_PHASE_INITIAL_MARK: 81 return "InitMark"; 82 case GCPhase::GC_PHASE_MARK: 83 return "Mark"; 84 case GCPhase::GC_PHASE_MARK_YOUNG: 85 return "MarkY"; 86 case GCPhase::GC_PHASE_REMARK: 87 return "YRemark"; 88 case GCPhase::GC_PHASE_COLLECT_YOUNG_AND_MOVE: 89 return "ColYAndMove"; 90 case GCPhase::GC_PHASE_SWEEP_STRING_TABLE: 91 return "SweepStrT"; 92 case GCPhase::GC_PHASE_SWEEP_STRING_TABLE_YOUNG: 93 return "SweepStrTY()"; 94 case GCPhase::GC_PHASE_SWEEP: 95 return "Sweep"; 96 case GCPhase::GC_PHASE_CLEANUP: 97 return "Cleanup"; 98 default: 99 return "UnknownPhase"; 100 } 101 } 102 103 private: 104 GCPhase phase_; 105 GCPhase old_phase_; 106 GC *gc_; 107 MemStatsType *mem_stats_; 108 109 PandaString GetGCName(); 110 }; 111 112 } // namespace panda::mem 113 114 #endif // PANDA_RUNTIME_MEM_GC_GC_SCOPED_PHASE_H_ 115