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