72 OldGCAllocRegion* old, |
72 OldGCAllocRegion* old, |
73 HeapRegion** retained); |
73 HeapRegion** retained); |
74 |
74 |
75 // Accessors to the allocation regions. |
75 // Accessors to the allocation regions. |
76 inline MutatorAllocRegion* mutator_alloc_region(uint node_index); |
76 inline MutatorAllocRegion* mutator_alloc_region(uint node_index); |
77 inline SurvivorGCAllocRegion* survivor_gc_alloc_region(); |
77 inline SurvivorGCAllocRegion* survivor_gc_alloc_region(uint node_index); |
78 inline OldGCAllocRegion* old_gc_alloc_region(); |
78 inline OldGCAllocRegion* old_gc_alloc_region(); |
79 |
79 |
80 // Allocation attempt during GC for a survivor object / PLAB. |
80 // Allocation attempt during GC for a survivor object / PLAB. |
81 HeapWord* survivor_attempt_allocation(size_t min_word_size, |
81 HeapWord* survivor_attempt_allocation(size_t min_word_size, |
82 size_t desired_word_size, |
82 size_t desired_word_size, |
83 size_t* actual_word_size); |
83 size_t* actual_word_size, |
|
84 uint node_index); |
84 |
85 |
85 // Allocation attempt during GC for an old object / PLAB. |
86 // Allocation attempt during GC for an old object / PLAB. |
86 HeapWord* old_attempt_allocation(size_t min_word_size, |
87 HeapWord* old_attempt_allocation(size_t min_word_size, |
87 size_t desired_word_size, |
88 size_t desired_word_size, |
88 size_t* actual_word_size); |
89 size_t* actual_word_size); |
121 // Allocate blocks of memory during garbage collection. Will ensure an |
124 // Allocate blocks of memory during garbage collection. Will ensure an |
122 // allocation region, either by picking one or expanding the |
125 // allocation region, either by picking one or expanding the |
123 // heap, and then allocate a block of the given size. The block |
126 // heap, and then allocate a block of the given size. The block |
124 // may not be a humongous - it must fit into a single heap region. |
127 // may not be a humongous - it must fit into a single heap region. |
125 HeapWord* par_allocate_during_gc(G1HeapRegionAttr dest, |
128 HeapWord* par_allocate_during_gc(G1HeapRegionAttr dest, |
126 size_t word_size); |
129 size_t word_size, |
|
130 uint node_index); |
127 |
131 |
128 HeapWord* par_allocate_during_gc(G1HeapRegionAttr dest, |
132 HeapWord* par_allocate_during_gc(G1HeapRegionAttr dest, |
129 size_t min_word_size, |
133 size_t min_word_size, |
130 size_t desired_word_size, |
134 size_t desired_word_size, |
131 size_t* actual_word_size); |
135 size_t* actual_word_size, |
|
136 uint node_index); |
132 }; |
137 }; |
133 |
138 |
134 // Manages the PLABs used during garbage collection. Interface for allocation from PLABs. |
139 // Manages the PLABs used during garbage collection. Interface for allocation from PLABs. |
135 // Needs to handle multiple contexts, extra alignment in any "survivor" area and some |
140 // Needs to handle multiple contexts, extra alignment in any "survivor" area and some |
136 // statistics. |
141 // statistics. |
137 class G1PLABAllocator : public CHeapObj<mtGC> { |
142 class G1PLABAllocator : public CHeapObj<mtGC> { |
138 friend class G1ParScanThreadState; |
143 friend class G1ParScanThreadState; |
139 private: |
144 private: |
|
145 typedef G1HeapRegionAttr::region_type_t region_type_t; |
|
146 |
140 G1CollectedHeap* _g1h; |
147 G1CollectedHeap* _g1h; |
141 G1Allocator* _allocator; |
148 G1Allocator* _allocator; |
142 |
149 |
143 PLAB _surviving_alloc_buffer; |
150 PLAB** _alloc_buffers[G1HeapRegionAttr::Num]; |
144 PLAB _tenured_alloc_buffer; |
|
145 PLAB* _alloc_buffers[G1HeapRegionAttr::Num]; |
|
146 |
151 |
147 // The survivor alignment in effect in bytes. |
152 // The survivor alignment in effect in bytes. |
148 // == 0 : don't align survivors |
153 // == 0 : don't align survivors |
149 // != 0 : align survivors to that alignment |
154 // != 0 : align survivors to that alignment |
150 // These values were chosen to favor the non-alignment case since some |
155 // These values were chosen to favor the non-alignment case since some |
153 |
158 |
154 // Number of words allocated directly (not counting PLAB allocation). |
159 // Number of words allocated directly (not counting PLAB allocation). |
155 size_t _direct_allocated[G1HeapRegionAttr::Num]; |
160 size_t _direct_allocated[G1HeapRegionAttr::Num]; |
156 |
161 |
157 void flush_and_retire_stats(); |
162 void flush_and_retire_stats(); |
158 inline PLAB* alloc_buffer(G1HeapRegionAttr dest); |
163 inline PLAB* alloc_buffer(G1HeapRegionAttr dest, uint node_index) const; |
|
164 inline PLAB* alloc_buffer(region_type_t dest, uint node_index) const; |
|
165 |
|
166 // Returns the number of allocation buffers for the given dest. |
|
167 // There is only 1 buffer for Old while Young may have multiple buffers depending on |
|
168 // active NUMA nodes. |
|
169 inline uint alloc_buffers_length(region_type_t dest) const; |
159 |
170 |
160 // Calculate the survivor space object alignment in bytes. Returns that or 0 if |
171 // Calculate the survivor space object alignment in bytes. Returns that or 0 if |
161 // there are no restrictions on survivor alignment. |
172 // there are no restrictions on survivor alignment. |
162 static uint calc_survivor_alignment_bytes(); |
173 static uint calc_survivor_alignment_bytes(); |
163 |
174 |
164 bool may_throw_away_buffer(size_t const allocation_word_sz, size_t const buffer_size) const; |
175 bool may_throw_away_buffer(size_t const allocation_word_sz, size_t const buffer_size) const; |
165 public: |
176 public: |
166 G1PLABAllocator(G1Allocator* allocator); |
177 G1PLABAllocator(G1Allocator* allocator); |
|
178 ~G1PLABAllocator(); |
167 |
179 |
168 size_t waste() const; |
180 size_t waste() const; |
169 size_t undo_waste() const; |
181 size_t undo_waste() const; |
170 |
182 |
171 // Allocate word_sz words in dest, either directly into the regions or by |
183 // Allocate word_sz words in dest, either directly into the regions or by |
172 // allocating a new PLAB. Returns the address of the allocated memory, NULL if |
184 // allocating a new PLAB. Returns the address of the allocated memory, NULL if |
173 // not successful. Plab_refill_failed indicates whether an attempt to refill the |
185 // not successful. Plab_refill_failed indicates whether an attempt to refill the |
174 // PLAB failed or not. |
186 // PLAB failed or not. |
175 HeapWord* allocate_direct_or_new_plab(G1HeapRegionAttr dest, |
187 HeapWord* allocate_direct_or_new_plab(G1HeapRegionAttr dest, |
176 size_t word_sz, |
188 size_t word_sz, |
177 bool* plab_refill_failed); |
189 bool* plab_refill_failed, |
|
190 uint node_index); |
178 |
191 |
179 // Allocate word_sz words in the PLAB of dest. Returns the address of the |
192 // Allocate word_sz words in the PLAB of dest. Returns the address of the |
180 // allocated memory, NULL if not successful. |
193 // allocated memory, NULL if not successful. |
181 inline HeapWord* plab_allocate(G1HeapRegionAttr dest, |
194 inline HeapWord* plab_allocate(G1HeapRegionAttr dest, |
182 size_t word_sz); |
195 size_t word_sz, |
|
196 uint node_index); |
183 |
197 |
184 inline HeapWord* allocate(G1HeapRegionAttr dest, |
198 inline HeapWord* allocate(G1HeapRegionAttr dest, |
185 size_t word_sz, |
199 size_t word_sz, |
186 bool* refill_failed); |
200 bool* refill_failed, |
187 |
201 uint node_index); |
188 void undo_allocation(G1HeapRegionAttr dest, HeapWord* obj, size_t word_sz); |
202 |
|
203 void undo_allocation(G1HeapRegionAttr dest, HeapWord* obj, size_t word_sz, uint node_index); |
189 }; |
204 }; |
190 |
205 |
191 // G1ArchiveRegionMap is a boolean array used to mark G1 regions as |
206 // G1ArchiveRegionMap is a boolean array used to mark G1 regions as |
192 // archive regions. This allows a quick check for whether an object |
207 // archive regions. This allows a quick check for whether an object |
193 // should not be marked because it is in an archive region. |
208 // should not be marked because it is in an archive region. |