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