1 /*
 2  * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 #ifndef SHARE_GC_G1_G1FULLGCCOMPACTIONPOINT_HPP
26 #define SHARE_GC_G1_G1FULLGCCOMPACTIONPOINT_HPP
27 
28 #include "memory/allocation.hpp"
29 #include "oops/oopsHierarchy.hpp"
30 #include "utilities/growableArray.hpp"
31 #include "utilities/pair.hpp"
32 
33 class G1FullCollector;
34 class HeapRegion;
35 class PreservedMarks;
36 
37 class G1FullGCCompactionPoint : public CHeapObj<mtGC> {
38   G1FullCollector* _collector;
39   HeapRegion* _current_region;
40   HeapWord*   _compaction_top;
41   PreservedMarks* _preserved_stack;
42   GrowableArray<HeapRegion*>* _compaction_regions;
43   GrowableArrayIterator<HeapRegion*> _compaction_region_iterator;
44 
45   bool object_will_fit(size_t size);
46   void initialize_values();
47   void switch_region();
48   HeapRegion* next_region();
49   uint find_contiguous_before(HeapRegion* hr, uint num_regions);
50 
51 public:
52   G1FullGCCompactionPoint(G1FullCollector* collector, PreservedMarks* preserved_stack);
53   ~G1FullGCCompactionPoint();
54 
55   bool has_regions();
56   bool is_initialized();
57   void initialize(HeapRegion* hr);
58   void update();
59   template <bool ALT_FWD>
60   void forward(oop object, size_t size);
61   template <bool ALT_FWD>
62   void forward_humongous(HeapRegion* hr);
63   void add(HeapRegion* hr);
64   void add_humongous(HeapRegion* hr);
65 
66   void remove_at_or_above(uint bottom);
67   HeapRegion* current_region();
68 
69   GrowableArray<HeapRegion*>* regions();
70 
71   PreservedMarks* preserved_stack() const {
72     assert(_preserved_stack != nullptr, "must be initialized");
73     return _preserved_stack;
74   }
75 
76   void set_preserved_stack(PreservedMarks* preserved_stack) {
77     assert(_preserved_stack == nullptr, "only initialize once");
78     _preserved_stack = preserved_stack;
79   }
80 };
81 
82 #endif // SHARE_GC_G1_G1FULLGCCOMPACTIONPOINT_HPP