• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "runtime/mem/gc/gc_scoped_phase.h"
17 
18 #include "runtime/mem/gc/gc.h"
19 
20 namespace panda::mem {
21 
GCScopedPhase(MemStatsType * mem_stats,GC * gc,GCPhase new_phase)22 GCScopedPhase::GCScopedPhase(MemStatsType *mem_stats, GC *gc, GCPhase new_phase) : mem_stats_(mem_stats)
23 {
24     ASSERT(mem_stats != nullptr);
25     ASSERT(gc != nullptr);
26     gc_ = gc;
27     gc_->BeginTracePoint(GetPhaseName(new_phase));
28     phase_ = new_phase;
29     old_phase_ = gc_->GetGCPhase();
30     gc_->SetGCPhase(phase_);
31     LOG(DEBUG, GC) << "== " << GetGCName() << "::" << GetPhaseName(phase_) << " started ==";
32     mem_stats_->RecordGCPhaseStart(phase_);
33 }
34 
~GCScopedPhase()35 GCScopedPhase::~GCScopedPhase()
36 {
37     mem_stats_->RecordGCPhaseEnd();
38     gc_->SetGCPhase(old_phase_);
39     gc_->EndTracePoint();
40     LOG(DEBUG, GC) << "== " << GetGCName() << "::" << GetPhaseName(phase_) << " finished ==";
41     mem_stats_->RecordGCPhaseStart(old_phase_);
42 }
43 
GetGCName()44 PandaString GCScopedPhase::GetGCName()
45 {
46     GCType type = gc_->GetType();
47     switch (type) {
48         case GCType::EPSILON_GC:
49             return "EpsilonGC";
50         case GCType::STW_GC:
51             return "StwGC";
52         case GCType::GEN_GC:
53             return "GenGC";
54         default:
55             return "GC";
56     }
57 }
58 
59 }  // namespace panda::mem
60