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_G1ALLOCATOR_HPP
26 #define SHARE_GC_G1_G1ALLOCATOR_HPP
27
28 #include "gc/g1/g1AllocRegion.hpp"
29 #include "gc/g1/g1HeapRegionAttr.hpp"
30 #include "gc/shared/collectedHeap.hpp"
31 #include "gc/shared/plab.hpp"
32
33 class G1EvacuationInfo;
34
35 // Interface to keep track of which regions G1 is currently allocating into. Provides
36 // some accessors (e.g. allocating into them, or getting their occupancy).
37 // Also keeps track of retained regions across GCs.
38 class G1Allocator : public CHeapObj<mtGC> {
39 friend class VMStructs;
40
41 private:
42 G1CollectedHeap* _g1h;
43
44 bool _survivor_is_full;
45 bool _old_is_full;
46
47 // Alloc region used to satisfy mutator allocation requests.
48 MutatorAllocRegion _mutator_alloc_region;
49
50 // Alloc region used to satisfy allocation requests by the GC for
51 // survivor objects.
52 SurvivorGCAllocRegion _survivor_gc_alloc_region;
53
54 // Alloc region used to satisfy allocation requests by the GC for
55 // old objects.
56 OldGCAllocRegion _old_gc_alloc_region;
57
58 HeapRegion* _retained_old_gc_alloc_region;
59
60 bool survivor_is_full() const;
61 bool old_is_full() const;
62
63 void set_survivor_full();
64 void set_old_full();
65
66 void reuse_retained_old_region(G1EvacuationInfo& evacuation_info,
67 OldGCAllocRegion* old,
68 HeapRegion** retained);
69
70 // Accessors to the allocation regions.
71 inline MutatorAllocRegion* mutator_alloc_region();
72 inline SurvivorGCAllocRegion* survivor_gc_alloc_region();
73 inline OldGCAllocRegion* old_gc_alloc_region();
74
75 // Allocation attempt during GC for a survivor object / PLAB.
76 HeapWord* survivor_attempt_allocation(size_t min_word_size,
77 size_t desired_word_size,
78 size_t* actual_word_size);
79
80 // Allocation attempt during GC for an old object / PLAB.
81 HeapWord* old_attempt_allocation(size_t min_word_size,
82 size_t desired_word_size,
83 size_t* actual_word_size);
84 public:
85 G1Allocator(G1CollectedHeap* heap);
86
87 #ifdef ASSERT
88 // Do we currently have an active mutator region to allocate into?
89 bool has_mutator_alloc_region() { return mutator_alloc_region()->get() != NULL; }
90 #endif
91
92 void init_mutator_alloc_region();
93 void release_mutator_alloc_region();
94
95 void init_gc_alloc_regions(G1EvacuationInfo& evacuation_info);
96 void release_gc_alloc_regions(G1EvacuationInfo& evacuation_info);
97 void abandon_gc_alloc_regions();
98 bool is_retained_old_region(HeapRegion* hr);
99
100 // Allocate blocks of memory during mutator time.
101
102 inline HeapWord* attempt_allocation(size_t min_word_size,
103 size_t desired_word_size,
104 size_t* actual_word_size);
105 inline HeapWord* attempt_allocation_locked(size_t word_size);
106 inline HeapWord* attempt_allocation_force(size_t word_size);
107
108 size_t unsafe_max_tlab_alloc();
109 size_t used_in_alloc_regions();
110
111 // Allocate blocks of memory during garbage collection. Will ensure an
112 // allocation region, either by picking one or expanding the
113 // heap, and then allocate a block of the given size. The block
|
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_G1ALLOCATOR_HPP
26 #define SHARE_GC_G1_G1ALLOCATOR_HPP
27
28 #include "gc/g1/g1AllocRegion.hpp"
29 #include "gc/g1/g1HeapRegionAttr.hpp"
30 #include "gc/shared/collectedHeap.hpp"
31 #include "gc/shared/plab.hpp"
32
33 class G1EvacuationInfo;
34 class G1NUMA;
35
36 // Interface to keep track of which regions G1 is currently allocating into. Provides
37 // some accessors (e.g. allocating into them, or getting their occupancy).
38 // Also keeps track of retained regions across GCs.
39 class G1Allocator : public CHeapObj<mtGC> {
40 friend class VMStructs;
41
42 private:
43 G1CollectedHeap* _g1h;
44 G1NUMA* _numa;
45
46 bool _survivor_is_full;
47 bool _old_is_full;
48
49 // The number of MutatorAllocRegions used, one per memory node.
50 size_t _num_alloc_regions;
51
52 // Alloc region used to satisfy mutator allocation requests.
53 MutatorAllocRegion* _mutator_alloc_regions;
54
55 // Alloc region used to satisfy allocation requests by the GC for
56 // survivor objects.
57 SurvivorGCAllocRegion _survivor_gc_alloc_region;
58
59 // Alloc region used to satisfy allocation requests by the GC for
60 // old objects.
61 OldGCAllocRegion _old_gc_alloc_region;
62
63 HeapRegion* _retained_old_gc_alloc_region;
64
65 bool survivor_is_full() const;
66 bool old_is_full() const;
67
68 void set_survivor_full();
69 void set_old_full();
70
71 void reuse_retained_old_region(G1EvacuationInfo& evacuation_info,
72 OldGCAllocRegion* old,
73 HeapRegion** retained);
74
75 // Accessors to the allocation regions.
76 inline MutatorAllocRegion* mutator_alloc_region(uint node_index);
77 inline SurvivorGCAllocRegion* survivor_gc_alloc_region();
78 inline OldGCAllocRegion* old_gc_alloc_region();
79
80 // Allocation attempt during GC for a survivor object / PLAB.
81 HeapWord* survivor_attempt_allocation(size_t min_word_size,
82 size_t desired_word_size,
83 size_t* actual_word_size);
84
85 // Allocation attempt during GC for an old object / PLAB.
86 HeapWord* old_attempt_allocation(size_t min_word_size,
87 size_t desired_word_size,
88 size_t* actual_word_size);
89
90 // Node index of current thread.
91 inline uint current_node_index() const;
92
93 public:
94 G1Allocator(G1CollectedHeap* heap);
95 ~G1Allocator();
96
97 #ifdef ASSERT
98 // Do we currently have an active mutator region to allocate into?
99 bool has_mutator_alloc_region();
100 #endif
101
102 void init_mutator_alloc_regions();
103 void release_mutator_alloc_regions();
104
105 void init_gc_alloc_regions(G1EvacuationInfo& evacuation_info);
106 void release_gc_alloc_regions(G1EvacuationInfo& evacuation_info);
107 void abandon_gc_alloc_regions();
108 bool is_retained_old_region(HeapRegion* hr);
109
110 // Allocate blocks of memory during mutator time.
111
112 inline HeapWord* attempt_allocation(size_t min_word_size,
113 size_t desired_word_size,
114 size_t* actual_word_size);
115 inline HeapWord* attempt_allocation_locked(size_t word_size);
116 inline HeapWord* attempt_allocation_force(size_t word_size);
117
118 size_t unsafe_max_tlab_alloc();
119 size_t used_in_alloc_regions();
120
121 // Allocate blocks of memory during garbage collection. Will ensure an
122 // allocation region, either by picking one or expanding the
123 // heap, and then allocate a block of the given size. The block
|