• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 ark::mem {
26 
27 // forward declarations:
28 class GC;
29 
30 class GCScopedPhase {
31 public:
32     GCScopedPhase(GC *gc, GCPhase newPhase);
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:
58                 return "Sweep()";
59             case GCPhase::GC_PHASE_CLEANUP:
60                 return "Cleanup()";
61             default:
62                 return "UnknownPhase";
63         }
64     }
65 
GetPhaseAbbr(GCPhase phase)66     static const char *GetPhaseAbbr(GCPhase phase)
67     {
68         switch (phase) {
69             case GCPhase::GC_PHASE_IDLE:
70                 return "Idle";
71             case GCPhase::GC_PHASE_RUNNING:
72                 return "RunPhases";
73             case GCPhase::GC_PHASE_COLLECT_ROOTS:
74                 return "ColRoots";
75             case GCPhase::GC_PHASE_INITIAL_MARK:
76                 return "InitMark";
77             case GCPhase::GC_PHASE_MARK:
78                 return "Mark";
79             case GCPhase::GC_PHASE_MARK_YOUNG:
80                 return "MarkY";
81             case GCPhase::GC_PHASE_REMARK:
82                 return "YRemark";
83             case GCPhase::GC_PHASE_COLLECT_YOUNG_AND_MOVE:
84                 return "ColYAndMove";
85             case GCPhase::GC_PHASE_SWEEP:
86                 return "Sweep";
87             case GCPhase::GC_PHASE_CLEANUP:
88                 return "Cleanup";
89             default:
90                 return "UnknownPhase";
91         }
92     }
93 
94 private:
95     GCPhase phase_;
96     GCPhase oldPhase_;
97     GC *gc_;
98 
99     PandaString GetGCName();
100 };
101 
102 }  // namespace ark::mem
103 
104 #endif  // GC_SCOPED_PHASE_H
105