• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_STARSCAN_SNAPSHOT_H_
6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_STARSCAN_SNAPSHOT_H_
7 
8 #include <memory>
9 #include <utility>
10 
11 #include "base/allocator/partition_allocator/starscan/pcscan_internal.h"
12 #include "base/allocator/partition_allocator/starscan/raceful_worklist.h"
13 
14 namespace partition_alloc::internal {
15 
16 class StarScanSnapshot final : public AllocatedOnPCScanMetadataPartition {
17  public:
18   using SuperPageBase = uintptr_t;
19   using SuperPagesWorklist = RacefulWorklist<SuperPageBase>;
20 
21   class ViewBase {
22    public:
23     template <typename Function>
24     void VisitConcurrently(Function);
25 
26     template <typename Function>
27     void VisitNonConcurrently(Function);
28 
29    protected:
ViewBase(SuperPagesWorklist & worklist)30     explicit ViewBase(SuperPagesWorklist& worklist) : worklist_(worklist) {}
31 
32    private:
33     SuperPagesWorklist& worklist_;
34   };
35 
36   class ClearingView : public ViewBase {
37    public:
38     inline explicit ClearingView(StarScanSnapshot& snapshot);
39   };
40   class ScanningView : public ViewBase {
41    public:
42     inline explicit ScanningView(StarScanSnapshot& snapshot);
43   };
44   class SweepingView : public ViewBase {
45    public:
46     inline explicit SweepingView(StarScanSnapshot& snapshot);
47   };
48   class UnprotectingView : public ViewBase {
49    public:
50     inline explicit UnprotectingView(StarScanSnapshot& snapshot);
51   };
52 
53   static std::unique_ptr<StarScanSnapshot> Create(const PCScanInternal&);
54 
55   StarScanSnapshot(const StarScanSnapshot&) = delete;
56   StarScanSnapshot& operator=(const StarScanSnapshot&) = delete;
57 
58   ~StarScanSnapshot();
59 
60  private:
61   explicit StarScanSnapshot(const PCScanInternal&);
62 
63   SuperPagesWorklist clear_worklist_;
64   SuperPagesWorklist scan_worklist_;
65   SuperPagesWorklist unprotect_worklist_;
66   SuperPagesWorklist sweep_worklist_;
67 };
68 
69 template <typename Function>
VisitConcurrently(Function f)70 void StarScanSnapshot::ViewBase::VisitConcurrently(Function f) {
71   SuperPagesWorklist::RandomizedView view(worklist_);
72   view.Visit(std::move(f));
73 }
74 
75 template <typename Function>
VisitNonConcurrently(Function f)76 void StarScanSnapshot::ViewBase::VisitNonConcurrently(Function f) {
77   worklist_.VisitNonConcurrently(std::move(f));
78 }
79 
ClearingView(StarScanSnapshot & snapshot)80 StarScanSnapshot::ClearingView::ClearingView(StarScanSnapshot& snapshot)
81     : StarScanSnapshot::ViewBase(snapshot.clear_worklist_) {}
82 
ScanningView(StarScanSnapshot & snapshot)83 StarScanSnapshot::ScanningView::ScanningView(StarScanSnapshot& snapshot)
84     : StarScanSnapshot::ViewBase(snapshot.scan_worklist_) {}
85 
SweepingView(StarScanSnapshot & snapshot)86 StarScanSnapshot::SweepingView::SweepingView(StarScanSnapshot& snapshot)
87     : StarScanSnapshot::ViewBase(snapshot.sweep_worklist_) {}
88 
UnprotectingView(StarScanSnapshot & snapshot)89 StarScanSnapshot::UnprotectingView::UnprotectingView(StarScanSnapshot& snapshot)
90     : StarScanSnapshot::ViewBase(snapshot.unprotect_worklist_) {}
91 
92 }  // namespace partition_alloc::internal
93 
94 #endif  // BASE_ALLOCATOR_PARTITION_ALLOCATOR_STARSCAN_SNAPSHOT_H_
95