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/generational-gc-base.h" 17 #include "runtime/include/runtime.h" 18 #include "runtime/include/runtime_notification.h" 19 #include "runtime/include/panda_vm.h" 20 21 namespace panda::mem { 22 23 template <class LanguageConfig> ShouldRunTenuredGC(const GCTask & task)24bool GenerationalGC<LanguageConfig>::ShouldRunTenuredGC([[maybe_unused]] const GCTask &task) 25 { 26 static size_t young_gc_count = 0; 27 young_gc_count++; 28 bool run_tenured = false; 29 if (young_gc_count >= GenerationalGC<LanguageConfig>::GetMajorPeriod()) { 30 young_gc_count = 0; 31 run_tenured = true; 32 } 33 LOG_DEBUG_GC << "GenGC::ShouldRunTenuredGC = " << run_tenured; 34 return run_tenured; 35 } 36 37 template <class LanguageConfig> WaitForGC(const GCTask & task)38void GenerationalGC<LanguageConfig>::WaitForGC(const GCTask &task) 39 { 40 Runtime::GetCurrent()->GetNotificationManager()->GarbageCollectorStartEvent(); 41 auto old_counter = this->gc_counter_.load(std::memory_order_acquire); 42 this->GetPandaVm()->GetRendezvous()->SafepointBegin(); 43 44 auto new_counter = this->gc_counter_.load(std::memory_order_acquire); 45 if (new_counter > old_counter && this->last_cause_.load() >= task.reason_) { 46 this->GetPandaVm()->GetRendezvous()->SafepointEnd(); 47 return; 48 } 49 this->RunPhases(task); 50 this->GetPandaVm()->GetRendezvous()->SafepointEnd(); 51 Runtime::GetCurrent()->GetNotificationManager()->GarbageCollectorFinishEvent(); 52 this->GetPandaVm()->HandleGCFinished(); 53 this->GetPandaVm()->HandleEnqueueReferences(); 54 } 55 56 template <class LanguageConfig> Dump()57PandaString GenerationalGC<LanguageConfig>::MemStats::Dump() 58 { 59 PandaStringStream statistic; 60 statistic << "Young freed " << young_free_object_count_ << "(" << helpers::MemoryConverter(young_free_object_size_) 61 << ") Young moved " << young_move_object_count_ << "(" 62 << helpers::MemoryConverter(young_move_object_count_) << ")"; 63 if (tenured_free_object_size_ > 0U) { 64 statistic << " Tenured freed " << tenured_free_object_size_ << "(" 65 << helpers::MemoryConverter(tenured_free_object_size_) << ")"; 66 } 67 return statistic.str(); 68 } 69 70 template class GenerationalGC<PandaAssemblyLanguageConfig>; 71 } // namespace panda::mem 72