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