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 #include "precompiled.hpp"
26 #include "gc/g1/g1Allocator.inline.hpp"
27 #include "gc/g1/g1AllocRegion.inline.hpp"
28 #include "gc/g1/g1EvacStats.inline.hpp"
29 #include "gc/g1/g1CollectedHeap.inline.hpp"
30 #include "gc/g1/g1MarkSweep.hpp"
31 #include "gc/g1/heapRegion.inline.hpp"
32 #include "gc/g1/heapRegionSet.inline.hpp"
33
34 G1DefaultAllocator::G1DefaultAllocator(G1CollectedHeap* heap) :
35 G1Allocator(heap),
36 _survivor_is_full(false),
37 _old_is_full(false),
38 _retained_old_gc_alloc_region(NULL),
39 _survivor_gc_alloc_region(heap->alloc_buffer_stats(InCSetState::Young)),
40 _old_gc_alloc_region(heap->alloc_buffer_stats(InCSetState::Old)) {
41 }
42
43 void G1DefaultAllocator::init_mutator_alloc_region() {
44 assert(_mutator_alloc_region.get() == NULL, "pre-condition");
45 _mutator_alloc_region.init();
46 }
47
48 void G1DefaultAllocator::release_mutator_alloc_region() {
49 _mutator_alloc_region.release();
50 assert(_mutator_alloc_region.get() == NULL, "post-condition");
316 G1EvacStats* stats = _g1h->alloc_buffer_stats(state);
317 buf->flush_and_retire_stats(stats);
318 stats->add_direct_allocated(_direct_allocated[state]);
319 _direct_allocated[state] = 0;
320 }
321 }
322 }
323
324 void G1DefaultPLABAllocator::waste(size_t& wasted, size_t& undo_wasted) {
325 wasted = 0;
326 undo_wasted = 0;
327 for (uint state = 0; state < InCSetState::Num; state++) {
328 G1PLAB * const buf = _alloc_buffers[state];
329 if (buf != NULL) {
330 wasted += buf->waste();
331 undo_wasted += buf->undo_waste();
332 }
333 }
334 }
335
336 G1ArchiveAllocator* G1ArchiveAllocator::create_allocator(G1CollectedHeap* g1h) {
337 // Create the archive allocator, and also enable archive object checking
338 // in mark-sweep, since we will be creating archive regions.
339 G1ArchiveAllocator* result = new G1ArchiveAllocator(g1h);
340 G1MarkSweep::enable_archive_object_check();
341 return result;
342 }
343
344 bool G1ArchiveAllocator::alloc_new_region() {
345 // Allocate the highest free region in the reserved heap,
346 // and add it to our list of allocated regions. It is marked
347 // archive and added to the old set.
348 HeapRegion* hr = _g1h->alloc_highest_free_region();
349 if (hr == NULL) {
350 return false;
351 }
352 assert(hr->is_empty(), "expected empty region (index %u)", hr->hrm_index());
353 hr->set_archive();
354 _g1h->old_set_add(hr);
355 _g1h->hr_printer()->alloc(hr);
356 _allocated_regions.append(hr);
357 _allocation_region = hr;
358
359 // Set up _bottom and _max to begin allocating in the lowest
360 // min_region_size'd chunk of the allocated G1 region.
361 _bottom = hr->bottom();
362 _max = _bottom + HeapRegion::min_region_size_in_words();
363
364 // Tell mark-sweep that objects in this region are not to be marked.
365 G1MarkSweep::set_range_archive(MemRegion(_bottom, HeapRegion::GrainWords), true);
366
367 // Since we've modified the old set, call update_sizes.
368 _g1h->g1mm()->update_sizes();
369 return true;
370 }
371
372 HeapWord* G1ArchiveAllocator::archive_mem_allocate(size_t word_size) {
373 assert(word_size != 0, "size must not be zero");
374 if (_allocation_region == NULL) {
375 if (!alloc_new_region()) {
376 return NULL;
377 }
378 }
379 HeapWord* old_top = _allocation_region->top();
380 assert(_bottom >= _allocation_region->bottom(),
381 "inconsistent allocation state: " PTR_FORMAT " < " PTR_FORMAT,
382 p2i(_bottom), p2i(_allocation_region->bottom()));
383 assert(_max <= _allocation_region->end(),
384 "inconsistent allocation state: " PTR_FORMAT " > " PTR_FORMAT,
385 p2i(_max), p2i(_allocation_region->end()));
|
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 #include "precompiled.hpp"
26 #include "gc/g1/g1Allocator.inline.hpp"
27 #include "gc/g1/g1AllocRegion.inline.hpp"
28 #include "gc/g1/g1EvacStats.inline.hpp"
29 #include "gc/g1/g1CollectedHeap.inline.hpp"
30 #include "gc/g1/heapRegion.inline.hpp"
31 #include "gc/g1/heapRegionSet.inline.hpp"
32
33 G1DefaultAllocator::G1DefaultAllocator(G1CollectedHeap* heap) :
34 G1Allocator(heap),
35 _survivor_is_full(false),
36 _old_is_full(false),
37 _retained_old_gc_alloc_region(NULL),
38 _survivor_gc_alloc_region(heap->alloc_buffer_stats(InCSetState::Young)),
39 _old_gc_alloc_region(heap->alloc_buffer_stats(InCSetState::Old)) {
40 }
41
42 void G1DefaultAllocator::init_mutator_alloc_region() {
43 assert(_mutator_alloc_region.get() == NULL, "pre-condition");
44 _mutator_alloc_region.init();
45 }
46
47 void G1DefaultAllocator::release_mutator_alloc_region() {
48 _mutator_alloc_region.release();
49 assert(_mutator_alloc_region.get() == NULL, "post-condition");
315 G1EvacStats* stats = _g1h->alloc_buffer_stats(state);
316 buf->flush_and_retire_stats(stats);
317 stats->add_direct_allocated(_direct_allocated[state]);
318 _direct_allocated[state] = 0;
319 }
320 }
321 }
322
323 void G1DefaultPLABAllocator::waste(size_t& wasted, size_t& undo_wasted) {
324 wasted = 0;
325 undo_wasted = 0;
326 for (uint state = 0; state < InCSetState::Num; state++) {
327 G1PLAB * const buf = _alloc_buffers[state];
328 if (buf != NULL) {
329 wasted += buf->waste();
330 undo_wasted += buf->undo_waste();
331 }
332 }
333 }
334
335 bool G1ArchiveAllocator::_archive_check_enabled = false;
336 G1ArchiveRegionMap G1ArchiveAllocator::_archive_region_map;
337
338 G1ArchiveAllocator* G1ArchiveAllocator::create_allocator(G1CollectedHeap* g1h) {
339 // Create the archive allocator, and also enable archive object checking
340 // in mark-sweep, since we will be creating archive regions.
341 G1ArchiveAllocator* result = new G1ArchiveAllocator(g1h);
342 enable_archive_object_check();
343 return result;
344 }
345
346 bool G1ArchiveAllocator::alloc_new_region() {
347 // Allocate the highest free region in the reserved heap,
348 // and add it to our list of allocated regions. It is marked
349 // archive and added to the old set.
350 HeapRegion* hr = _g1h->alloc_highest_free_region();
351 if (hr == NULL) {
352 return false;
353 }
354 assert(hr->is_empty(), "expected empty region (index %u)", hr->hrm_index());
355 hr->set_archive();
356 _g1h->old_set_add(hr);
357 _g1h->hr_printer()->alloc(hr);
358 _allocated_regions.append(hr);
359 _allocation_region = hr;
360
361 // Set up _bottom and _max to begin allocating in the lowest
362 // min_region_size'd chunk of the allocated G1 region.
363 _bottom = hr->bottom();
364 _max = _bottom + HeapRegion::min_region_size_in_words();
365
366 // Tell mark-sweep that objects in this region are not to be marked.
367 set_range_archive(MemRegion(_bottom, HeapRegion::GrainWords), true);
368
369 // Since we've modified the old set, call update_sizes.
370 _g1h->g1mm()->update_sizes();
371 return true;
372 }
373
374 HeapWord* G1ArchiveAllocator::archive_mem_allocate(size_t word_size) {
375 assert(word_size != 0, "size must not be zero");
376 if (_allocation_region == NULL) {
377 if (!alloc_new_region()) {
378 return NULL;
379 }
380 }
381 HeapWord* old_top = _allocation_region->top();
382 assert(_bottom >= _allocation_region->bottom(),
383 "inconsistent allocation state: " PTR_FORMAT " < " PTR_FORMAT,
384 p2i(_bottom), p2i(_allocation_region->bottom()));
385 assert(_max <= _allocation_region->end(),
386 "inconsistent allocation state: " PTR_FORMAT " > " PTR_FORMAT,
387 p2i(_max), p2i(_allocation_region->end()));
|