hotspot/src/share/vm/gc/g1/g1Allocator.cpp
author tschatzl
Fri, 07 Aug 2015 15:37:07 +0200
changeset 32193 862a68285b1e
parent 32185 49a57ff2c3cb
child 32377 5ee15c417d02
permissions -rw-r--r--
8133042: Remove some direct accesses of G1Allocator to G1CollectedHeap members Summary: Remove direct access to private members of G1CollectedHeap from G1Allocator and G1ArchiveAllocator. Allows removal of friend delcarations. Reviewed-by: kbarrett, jmasa, jwilhelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     1
/*
29327
b539902e30f8 8073466: Remove buffer retaining functionality and clean up in ParGCAllocBuffer
tschatzl
parents: 28375
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     4
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     7
 * published by the Free Software Foundation.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     8
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    13
 * accompanied this code).
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    14
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    18
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    21
 * questions.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    22
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    23
 */
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    24
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    25
#include "precompiled.hpp"
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
    26
#include "gc/g1/g1Allocator.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    27
#include "gc/g1/g1CollectedHeap.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    28
#include "gc/g1/g1CollectorPolicy.hpp"
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
    29
#include "gc/g1/g1MarkSweep.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    30
#include "gc/g1/heapRegion.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    31
#include "gc/g1/heapRegionSet.inline.hpp"
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    32
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    33
void G1DefaultAllocator::init_mutator_alloc_region() {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    34
  assert(_mutator_alloc_region.get() == NULL, "pre-condition");
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    35
  _mutator_alloc_region.init();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    36
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    37
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    38
void G1DefaultAllocator::release_mutator_alloc_region() {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    39
  _mutator_alloc_region.release();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    40
  assert(_mutator_alloc_region.get() == NULL, "post-condition");
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    41
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    42
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    43
void G1Allocator::reuse_retained_old_region(EvacuationInfo& evacuation_info,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    44
                                            OldGCAllocRegion* old,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    45
                                            HeapRegion** retained_old) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    46
  HeapRegion* retained_region = *retained_old;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    47
  *retained_old = NULL;
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
    48
  assert(retained_region == NULL || !retained_region->is_archive(),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
    49
         err_msg("Archive region should not be alloc region (index %u)", retained_region->hrm_index()));
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    50
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    51
  // We will discard the current GC alloc region if:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    52
  // a) it's in the collection set (it can happen!),
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    53
  // b) it's already full (no point in using it),
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    54
  // c) it's empty (this means that it was emptied during
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    55
  // a cleanup and it should be on the free list now), or
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    56
  // d) it's humongous (this means that it was emptied
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    57
  // during a cleanup and was added to the free list, but
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    58
  // has been subsequently used to allocate a humongous
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    59
  // object that may be less than the region size).
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    60
  if (retained_region != NULL &&
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    61
      !retained_region->in_collection_set() &&
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    62
      !(retained_region->top() == retained_region->end()) &&
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    63
      !retained_region->is_empty() &&
26846
7d4376f8560e 8058495: G1: normalize names for isHumongous() and friends
tonyp
parents: 26837
diff changeset
    64
      !retained_region->is_humongous()) {
27889
7d50f95e0076 8065358: Refactor G1s usage of save_marks and reduce related races
mgerdin
parents: 26846
diff changeset
    65
    retained_region->record_timestamp();
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    66
    // The retained region was added to the old region set when it was
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    67
    // retired. We have to remove it now, since we don't allow regions
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    68
    // we allocate to in the region sets. We'll re-add it later, when
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    69
    // it's retired again.
32193
862a68285b1e 8133042: Remove some direct accesses of G1Allocator to G1CollectedHeap members
tschatzl
parents: 32185
diff changeset
    70
    _g1h->old_set_remove(retained_region);
31331
a7c714b6cfb3 7097567: G1: abstract and encapsulate collector phases and transitions between them
drwhite
parents: 30764
diff changeset
    71
    bool during_im = _g1h->collector_state()->during_initial_mark_pause();
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    72
    retained_region->note_start_of_copying(during_im);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    73
    old->set(retained_region);
32193
862a68285b1e 8133042: Remove some direct accesses of G1Allocator to G1CollectedHeap members
tschatzl
parents: 32185
diff changeset
    74
    _g1h->hr_printer()->reuse(retained_region);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    75
    evacuation_info.set_alloc_regions_used_before(retained_region->used());
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    76
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    77
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    78
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    79
void G1DefaultAllocator::init_gc_alloc_regions(EvacuationInfo& evacuation_info) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    80
  assert_at_safepoint(true /* should_be_vm_thread */);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    81
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    82
  _survivor_gc_alloc_region.init();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    83
  _old_gc_alloc_region.init();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    84
  reuse_retained_old_region(evacuation_info,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    85
                            &_old_gc_alloc_region,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    86
                            &_retained_old_gc_alloc_region);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    87
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    88
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31346
diff changeset
    89
void G1DefaultAllocator::release_gc_alloc_regions(EvacuationInfo& evacuation_info) {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    90
  AllocationContext_t context = AllocationContext::current();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    91
  evacuation_info.set_allocation_regions(survivor_gc_alloc_region(context)->count() +
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    92
                                         old_gc_alloc_region(context)->count());
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    93
  survivor_gc_alloc_region(context)->release();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    94
  // If we have an old GC alloc region to release, we'll save it in
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    95
  // _retained_old_gc_alloc_region. If we don't
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    96
  // _retained_old_gc_alloc_region will become NULL. This is what we
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    97
  // want either way so no reason to check explicitly for either
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    98
  // condition.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    99
  _retained_old_gc_alloc_region = old_gc_alloc_region(context)->release();
27889
7d50f95e0076 8065358: Refactor G1s usage of save_marks and reduce related races
mgerdin
parents: 26846
diff changeset
   100
  if (_retained_old_gc_alloc_region != NULL) {
7d50f95e0076 8065358: Refactor G1s usage of save_marks and reduce related races
mgerdin
parents: 26846
diff changeset
   101
    _retained_old_gc_alloc_region->record_retained_region();
7d50f95e0076 8065358: Refactor G1s usage of save_marks and reduce related races
mgerdin
parents: 26846
diff changeset
   102
  }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   103
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   104
  if (ResizePLAB) {
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31346
diff changeset
   105
    _g1h->alloc_buffer_stats(InCSetState::Young)->adjust_desired_plab_sz();
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31346
diff changeset
   106
    _g1h->alloc_buffer_stats(InCSetState::Old)->adjust_desired_plab_sz();
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   107
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   108
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   109
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   110
void G1DefaultAllocator::abandon_gc_alloc_regions() {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   111
  assert(survivor_gc_alloc_region(AllocationContext::current())->get() == NULL, "pre-condition");
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   112
  assert(old_gc_alloc_region(AllocationContext::current())->get() == NULL, "pre-condition");
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   113
  _retained_old_gc_alloc_region = NULL;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   114
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   115
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   116
G1PLAB::G1PLAB(size_t gclab_word_size) :
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   117
  PLAB(gclab_word_size), _retired(true) { }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   118
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   119
size_t G1Allocator::unsafe_max_tlab_alloc(AllocationContext_t context) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   120
  // Return the remaining space in the cur alloc region, but not less than
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   121
  // the min TLAB size.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   122
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   123
  // Also, this value can be at most the humongous object threshold,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   124
  // since we can't allow tlabs to grow big enough to accommodate
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   125
  // humongous objects.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   126
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   127
  HeapRegion* hr = mutator_alloc_region(context)->get();
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   128
  size_t max_tlab = _g1h->max_tlab_size() * wordSize;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   129
  if (hr == NULL) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   130
    return max_tlab;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   131
  } else {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   132
    return MIN2(MAX2(hr->free(), (size_t) MinTLABSize), max_tlab);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   133
  }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   134
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   135
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   136
HeapWord* G1Allocator::par_allocate_during_gc(InCSetState dest,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   137
                                              size_t word_size,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   138
                                              AllocationContext_t context) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   139
  switch (dest.value()) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   140
    case InCSetState::Young:
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   141
      return survivor_attempt_allocation(word_size, context);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   142
    case InCSetState::Old:
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   143
      return old_attempt_allocation(word_size, context);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   144
    default:
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   145
      ShouldNotReachHere();
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   146
      return NULL; // Keep some compilers happy
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   147
  }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   148
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   149
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   150
HeapWord* G1Allocator::survivor_attempt_allocation(size_t word_size,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   151
                                                   AllocationContext_t context) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   152
  assert(!_g1h->is_humongous(word_size),
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   153
         "we should not be seeing humongous-size allocations in this path");
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   154
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   155
  HeapWord* result = survivor_gc_alloc_region(context)->attempt_allocation(word_size,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   156
                                                                           false /* bot_updates */);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   157
  if (result == NULL) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   158
    MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   159
    result = survivor_gc_alloc_region(context)->attempt_allocation_locked(word_size,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   160
                                                                          false /* bot_updates */);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   161
  }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   162
  if (result != NULL) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   163
    _g1h->dirty_young_block(result, word_size);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   164
  }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   165
  return result;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   166
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   167
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   168
HeapWord* G1Allocator::old_attempt_allocation(size_t word_size,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   169
                                              AllocationContext_t context) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   170
  assert(!_g1h->is_humongous(word_size),
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   171
         "we should not be seeing humongous-size allocations in this path");
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   172
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   173
  HeapWord* result = old_gc_alloc_region(context)->attempt_allocation(word_size,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   174
                                                                      true /* bot_updates */);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   175
  if (result == NULL) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   176
    MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   177
    result = old_gc_alloc_region(context)->attempt_allocation_locked(word_size,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   178
                                                                     true /* bot_updates */);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   179
  }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   180
  return result;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   181
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   182
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   183
G1PLABAllocator::G1PLABAllocator(G1Allocator* allocator) :
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   184
  _g1h(G1CollectedHeap::heap()),
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   185
  _allocator(allocator),
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   186
  _survivor_alignment_bytes(calc_survivor_alignment_bytes()) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   187
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   188
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   189
HeapWord* G1PLABAllocator::allocate_direct_or_new_plab(InCSetState dest,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   190
                                                       size_t word_sz,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   191
                                                       AllocationContext_t context) {
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   192
  size_t gclab_word_size = _g1h->desired_plab_sz(dest);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   193
  if (word_sz * 100 < gclab_word_size * ParallelGCBufferWastePct) {
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   194
    G1PLAB* alloc_buf = alloc_buffer(dest, context);
29327
b539902e30f8 8073466: Remove buffer retaining functionality and clean up in ParGCAllocBuffer
tschatzl
parents: 28375
diff changeset
   195
    alloc_buf->retire();
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   196
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   197
    HeapWord* buf = _allocator->par_allocate_during_gc(dest, gclab_word_size, context);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   198
    if (buf == NULL) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   199
      return NULL; // Let caller handle allocation failure.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   200
    }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   201
    // Otherwise.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   202
    alloc_buf->set_word_size(gclab_word_size);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   203
    alloc_buf->set_buf(buf);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   204
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   205
    HeapWord* const obj = alloc_buf->allocate(word_sz);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   206
    assert(obj != NULL, "buffer was definitely big enough...");
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   207
    return obj;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   208
  } else {
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   209
    return _allocator->par_allocate_during_gc(dest, word_sz, context);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   210
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   211
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   212
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   213
void G1PLABAllocator::undo_allocation(InCSetState dest, HeapWord* obj, size_t word_sz, AllocationContext_t context) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   214
  alloc_buffer(dest, context)->undo_allocation(obj, word_sz);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   215
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   216
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   217
G1DefaultPLABAllocator::G1DefaultPLABAllocator(G1Allocator* allocator) :
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   218
  G1PLABAllocator(allocator),
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   219
  _surviving_alloc_buffer(_g1h->desired_plab_sz(InCSetState::Young)),
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   220
  _tenured_alloc_buffer(_g1h->desired_plab_sz(InCSetState::Old)) {
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   221
  for (uint state = 0; state < InCSetState::Num; state++) {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   222
    _alloc_buffers[state] = NULL;
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   223
  }
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   224
  _alloc_buffers[InCSetState::Young] = &_surviving_alloc_buffer;
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   225
  _alloc_buffers[InCSetState::Old]  = &_tenured_alloc_buffer;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   226
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   227
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   228
void G1DefaultPLABAllocator::retire_alloc_buffers() {
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   229
  for (uint state = 0; state < InCSetState::Num; state++) {
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   230
    G1PLAB* const buf = _alloc_buffers[state];
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   231
    if (buf != NULL) {
29327
b539902e30f8 8073466: Remove buffer retaining functionality and clean up in ParGCAllocBuffer
tschatzl
parents: 28375
diff changeset
   232
      buf->flush_and_retire_stats(_g1h->alloc_buffer_stats(state));
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   233
    }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   234
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   235
}
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   236
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   237
void G1DefaultPLABAllocator::waste(size_t& wasted, size_t& undo_wasted) {
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   238
  wasted = 0;
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   239
  undo_wasted = 0;
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   240
  for (uint state = 0; state < InCSetState::Num; state++) {
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   241
    G1PLAB * const buf = _alloc_buffers[state];
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   242
    if (buf != NULL) {
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   243
      wasted += buf->waste();
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   244
      undo_wasted += buf->undo_waste();
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   245
    }
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   246
  }
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   247
}
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   248
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   249
G1ArchiveAllocator* G1ArchiveAllocator::create_allocator(G1CollectedHeap* g1h) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   250
  // Create the archive allocator, and also enable archive object checking
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   251
  // in mark-sweep, since we will be creating archive regions.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   252
  G1ArchiveAllocator* result =  new G1ArchiveAllocator(g1h);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   253
  G1MarkSweep::enable_archive_object_check();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   254
  return result;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   255
}
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   256
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   257
bool G1ArchiveAllocator::alloc_new_region() {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   258
  // Allocate the highest free region in the reserved heap,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   259
  // and add it to our list of allocated regions. It is marked
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   260
  // archive and added to the old set.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   261
  HeapRegion* hr = _g1h->alloc_highest_free_region();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   262
  if (hr == NULL) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   263
    return false;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   264
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   265
  assert(hr->is_empty(), err_msg("expected empty region (index %u)", hr->hrm_index()));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   266
  hr->set_archive();
32193
862a68285b1e 8133042: Remove some direct accesses of G1Allocator to G1CollectedHeap members
tschatzl
parents: 32185
diff changeset
   267
  _g1h->old_set_add(hr);
862a68285b1e 8133042: Remove some direct accesses of G1Allocator to G1CollectedHeap members
tschatzl
parents: 32185
diff changeset
   268
  _g1h->hr_printer()->alloc(hr, G1HRPrinter::Archive);
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   269
  _allocated_regions.append(hr);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   270
  _allocation_region = hr;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   271
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   272
  // Set up _bottom and _max to begin allocating in the lowest
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   273
  // min_region_size'd chunk of the allocated G1 region.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   274
  _bottom = hr->bottom();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   275
  _max = _bottom + HeapRegion::min_region_size_in_words();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   276
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   277
  // Tell mark-sweep that objects in this region are not to be marked.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   278
  G1MarkSweep::mark_range_archive(MemRegion(_bottom, HeapRegion::GrainWords));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   279
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   280
  // Since we've modified the old set, call update_sizes.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   281
  _g1h->g1mm()->update_sizes();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   282
  return true;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   283
}
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   284
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   285
HeapWord* G1ArchiveAllocator::archive_mem_allocate(size_t word_size) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   286
  assert(word_size != 0, "size must not be zero");
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   287
  if (_allocation_region == NULL) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   288
    if (!alloc_new_region()) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   289
      return NULL;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   290
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   291
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   292
  HeapWord* old_top = _allocation_region->top();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   293
  assert(_bottom >= _allocation_region->bottom(),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   294
         err_msg("inconsistent allocation state: " PTR_FORMAT " < " PTR_FORMAT,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   295
                 p2i(_bottom), p2i(_allocation_region->bottom())));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   296
  assert(_max <= _allocation_region->end(),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   297
         err_msg("inconsistent allocation state: " PTR_FORMAT " > " PTR_FORMAT,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   298
                 p2i(_max), p2i(_allocation_region->end())));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   299
  assert(_bottom <= old_top && old_top <= _max,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   300
         err_msg("inconsistent allocation state: expected "
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   301
                 PTR_FORMAT " <= " PTR_FORMAT " <= " PTR_FORMAT,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   302
                 p2i(_bottom), p2i(old_top), p2i(_max)));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   303
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   304
  // Allocate the next word_size words in the current allocation chunk.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   305
  // If allocation would cross the _max boundary, insert a filler and begin
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   306
  // at the base of the next min_region_size'd chunk. Also advance to the next
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   307
  // chunk if we don't yet cross the boundary, but the remainder would be too
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   308
  // small to fill.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   309
  HeapWord* new_top = old_top + word_size;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   310
  size_t remainder = pointer_delta(_max, new_top);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   311
  if ((new_top > _max) ||
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   312
      ((new_top < _max) && (remainder < CollectedHeap::min_fill_size()))) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   313
    if (old_top != _max) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   314
      size_t fill_size = pointer_delta(_max, old_top);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   315
      CollectedHeap::fill_with_object(old_top, fill_size);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   316
      _summary_bytes_used += fill_size * HeapWordSize;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   317
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   318
    _allocation_region->set_top(_max);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   319
    old_top = _bottom = _max;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   320
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   321
    // Check if we've just used up the last min_region_size'd chunk
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   322
    // in the current region, and if so, allocate a new one.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   323
    if (_bottom != _allocation_region->end()) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   324
      _max = _bottom + HeapRegion::min_region_size_in_words();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   325
    } else {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   326
      if (!alloc_new_region()) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   327
        return NULL;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   328
      }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   329
      old_top = _allocation_region->bottom();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   330
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   331
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   332
  _allocation_region->set_top(old_top + word_size);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   333
  _summary_bytes_used += word_size * HeapWordSize;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   334
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   335
  return old_top;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   336
}
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   337
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   338
void G1ArchiveAllocator::complete_archive(GrowableArray<MemRegion>* ranges,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   339
                                          size_t end_alignment_in_bytes) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   340
  assert((end_alignment_in_bytes >> LogHeapWordSize) < HeapRegion::min_region_size_in_words(),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   341
          err_msg("alignment " SIZE_FORMAT " too large", end_alignment_in_bytes));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   342
  assert(is_size_aligned(end_alignment_in_bytes, HeapWordSize),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   343
         err_msg("alignment " SIZE_FORMAT " is not HeapWord (%u) aligned", end_alignment_in_bytes, HeapWordSize));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   344
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   345
  // If we've allocated nothing, simply return.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   346
  if (_allocation_region == NULL) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   347
    return;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   348
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   349
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   350
  // If an end alignment was requested, insert filler objects.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   351
  if (end_alignment_in_bytes != 0) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   352
    HeapWord* currtop = _allocation_region->top();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   353
    HeapWord* newtop = (HeapWord*)align_pointer_up(currtop, end_alignment_in_bytes);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   354
    size_t fill_size = pointer_delta(newtop, currtop);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   355
    if (fill_size != 0) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   356
      if (fill_size < CollectedHeap::min_fill_size()) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   357
        // If the required fill is smaller than we can represent,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   358
        // bump up to the next aligned address. We know we won't exceed the current
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   359
        // region boundary because the max supported alignment is smaller than the min
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   360
        // region size, and because the allocation code never leaves space smaller than
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   361
        // the min_fill_size at the top of the current allocation region.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   362
        newtop = (HeapWord*)align_pointer_up(currtop + CollectedHeap::min_fill_size(),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   363
                                             end_alignment_in_bytes);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   364
        fill_size = pointer_delta(newtop, currtop);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   365
      }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   366
      HeapWord* fill = archive_mem_allocate(fill_size);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   367
      CollectedHeap::fill_with_objects(fill, fill_size);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   368
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   369
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   370
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   371
  // Loop through the allocated regions, and create MemRegions summarizing
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   372
  // the allocated address range, combining contiguous ranges. Add the
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   373
  // MemRegions to the GrowableArray provided by the caller.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   374
  int index = _allocated_regions.length() - 1;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   375
  assert(_allocated_regions.at(index) == _allocation_region,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   376
         err_msg("expected region %u at end of array, found %u",
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   377
                 _allocation_region->hrm_index(), _allocated_regions.at(index)->hrm_index()));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   378
  HeapWord* base_address = _allocation_region->bottom();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   379
  HeapWord* top = base_address;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   380
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   381
  while (index >= 0) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   382
    HeapRegion* next = _allocated_regions.at(index);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   383
    HeapWord* new_base = next->bottom();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   384
    HeapWord* new_top = next->top();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   385
    if (new_base != top) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   386
      ranges->append(MemRegion(base_address, pointer_delta(top, base_address)));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   387
      base_address = new_base;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   388
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   389
    top = new_top;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   390
    index = index - 1;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   391
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   392
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   393
  assert(top != base_address, err_msg("zero-sized range, address " PTR_FORMAT, p2i(base_address)));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   394
  ranges->append(MemRegion(base_address, pointer_delta(top, base_address)));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   395
  _allocated_regions.clear();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   396
  _allocation_region = NULL;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   397
};