xref: /aosp_15_r20/external/cronet/base/allocator/partition_allocator/src/partition_alloc/starscan/pcscan.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "partition_alloc/starscan/pcscan.h"
6 
7 #include "partition_alloc/partition_alloc_base/compiler_specific.h"
8 #include "partition_alloc/starscan/pcscan_internal.h"
9 
10 namespace partition_alloc::internal {
11 
Initialize(InitConfig config)12 void PCScan::Initialize(InitConfig config) {
13   PCScanInternal::Instance().Initialize(config);
14 }
15 
IsInitialized()16 bool PCScan::IsInitialized() {
17   return PCScanInternal::Instance().is_initialized();
18 }
19 
Disable()20 void PCScan::Disable() {
21   auto& instance = PCScan::Instance();
22   instance.scheduler().scheduling_backend().DisableScheduling();
23 }
24 
IsEnabled()25 bool PCScan::IsEnabled() {
26   auto& instance = PCScan::Instance();
27   return instance.scheduler().scheduling_backend().is_scheduling_enabled();
28 }
29 
Reenable()30 void PCScan::Reenable() {
31   auto& instance = PCScan::Instance();
32   instance.scheduler().scheduling_backend().EnableScheduling();
33 }
34 
RegisterScannableRoot(Root * root)35 void PCScan::RegisterScannableRoot(Root* root) {
36   PCScanInternal::Instance().RegisterScannableRoot(root);
37 }
38 
RegisterNonScannableRoot(Root * root)39 void PCScan::RegisterNonScannableRoot(Root* root) {
40   PCScanInternal::Instance().RegisterNonScannableRoot(root);
41 }
42 
RegisterNewSuperPage(Root * root,uintptr_t super_page_base)43 void PCScan::RegisterNewSuperPage(Root* root, uintptr_t super_page_base) {
44   PCScanInternal::Instance().RegisterNewSuperPage(root, super_page_base);
45 }
46 
PerformScan(InvocationMode invocation_mode)47 void PCScan::PerformScan(InvocationMode invocation_mode) {
48   PCScanInternal::Instance().PerformScan(invocation_mode);
49 }
50 
PerformScanIfNeeded(InvocationMode invocation_mode)51 void PCScan::PerformScanIfNeeded(InvocationMode invocation_mode) {
52   PCScanInternal::Instance().PerformScanIfNeeded(invocation_mode);
53 }
54 
PerformDelayedScan(int64_t delay_in_microseconds)55 void PCScan::PerformDelayedScan(int64_t delay_in_microseconds) {
56   PCScanInternal::Instance().PerformDelayedScan(
57       base::Microseconds(delay_in_microseconds));
58 }
59 
JoinScan()60 void PCScan::JoinScan() {
61   PCScanInternal::Instance().JoinScan();
62 }
63 
SetProcessName(const char * process_name)64 void PCScan::SetProcessName(const char* process_name) {
65   PCScanInternal::Instance().SetProcessName(process_name);
66 }
67 
EnableStackScanning()68 void PCScan::EnableStackScanning() {
69   PCScanInternal::Instance().EnableStackScanning();
70 }
DisableStackScanning()71 void PCScan::DisableStackScanning() {
72   PCScanInternal::Instance().DisableStackScanning();
73 }
IsStackScanningEnabled()74 bool PCScan::IsStackScanningEnabled() {
75   return PCScanInternal::Instance().IsStackScanningEnabled();
76 }
77 
EnableImmediateFreeing()78 void PCScan::EnableImmediateFreeing() {
79   PCScanInternal::Instance().EnableImmediateFreeing();
80 }
81 
SetClearType(ClearType clear_type)82 void PCScan::SetClearType(ClearType clear_type) {
83   PCScan& instance = Instance();
84   instance.clear_type_ = clear_type;
85 }
86 
UninitForTesting()87 void PCScan::UninitForTesting() {
88   PCScanInternal::Instance().ClearRootsForTesting();  // IN-TEST
89 }
90 
ReinitForTesting(InitConfig config)91 void PCScan::ReinitForTesting(InitConfig config) {
92   PCScanInternal::Instance().ReinitForTesting(config);  // IN-TEST
93 }
94 
FinishScanForTesting()95 void PCScan::FinishScanForTesting() {
96   PCScanInternal::Instance().FinishScanForTesting();  // IN-TEST
97 }
98 
RegisterStatsReporter(partition_alloc::StatsReporter * reporter)99 void PCScan::RegisterStatsReporter(partition_alloc::StatsReporter* reporter) {
100   PCScanInternal::Instance().RegisterStatsReporter(reporter);
101 }
102 
103 PCScan PCScan::instance_ PA_CONSTINIT;
104 
105 }  // namespace partition_alloc::internal
106