hotspot/src/share/vm/gc/g1/g1AllocRegion.hpp
author david
Tue, 29 Sep 2015 11:02:08 +0200
changeset 33105 294e48b4f704
parent 32389 626f27450e12
child 37171 b968bbc6291c
permissions -rw-r--r--
8080775: Better argument formatting for assert() and friends Reviewed-by: kbarrett, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26837
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     4
 *
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     8
 *
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    13
 * accompanied this code).
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    14
 *
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    18
 *
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    21
 * questions.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    22
 *
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    23
 */
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    24
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26837
diff changeset
    25
#ifndef SHARE_VM_GC_G1_G1ALLOCREGION_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26837
diff changeset
    26
#define SHARE_VM_GC_G1_G1ALLOCREGION_HPP
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26837
diff changeset
    28
#include "gc/g1/heapRegion.hpp"
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
    29
#include "gc/g1/g1EvacStats.hpp"
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
    30
#include "gc/g1/g1InCSetState.hpp"
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    31
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    32
class G1CollectedHeap;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    33
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    34
// 0 -> no tracing, 1 -> basic tracing, 2 -> basic + allocation tracing
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    35
#define G1_ALLOC_REGION_TRACING 0
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    36
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    37
// A class that holds a region that is active in satisfying allocation
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    38
// requests, potentially issued in parallel. When the active region is
10243
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    39
// full it will be retired and replaced with a new one. The
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    40
// implementation assumes that fast-path allocations will be lock-free
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    41
// and a lock will need to be taken when the active region needs to be
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    42
// replaced.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    43
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    44
class G1AllocRegion VALUE_OBJ_CLASS_SPEC {
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    45
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    46
private:
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    47
  // The active allocating region we are currently allocating out
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    48
  // of. The invariant is that if this object is initialized (i.e.,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    49
  // init() has been called and release() has not) then _alloc_region
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    50
  // is either an active allocating region or the dummy region (i.e.,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    51
  // it can never be NULL) and this object can be used to satisfy
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    52
  // allocation requests. If this object is not initialized
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    53
  // (i.e. init() has not been called or release() has been called)
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    54
  // then _alloc_region is NULL and this object should not be used to
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    55
  // satisfy allocation requests (it was done this way to force the
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    56
  // correct use of init() and release()).
21119
ca1c9dd0e277 8025728: Missing volatile specifier for field G1AllocRegion::_alloc_region
tschatzl
parents: 12381
diff changeset
    57
  HeapRegion* volatile _alloc_region;
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    58
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
    59
  // Allocation context associated with this alloc region.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
    60
  AllocationContext_t _allocation_context;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
    61
10243
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    62
  // It keeps track of the distinct number of regions that are used
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    63
  // for allocation in the active interval of this object, i.e.,
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    64
  // between a call to init() and a call to release(). The count
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    65
  // mostly includes regions that are freshly allocated, as well as
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    66
  // the region that is re-used using the set() method. This count can
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    67
  // be used in any heuristics that might want to bound how many
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    68
  // distinct regions this object can used during an active interval.
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 10243
diff changeset
    69
  uint _count;
10243
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    70
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    71
  // When we set up a new active region we save its used bytes in this
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    72
  // field so that, when we retire it, we can calculate how much space
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    73
  // we allocated in it.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    74
  size_t _used_bytes_before;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    75
10243
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    76
  // When true, indicates that allocate calls should do BOT updates.
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
    77
  const bool _bot_updates;
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    78
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    79
  // Useful for debugging and tracing.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    80
  const char* _name;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    81
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    82
  // A dummy region (i.e., it's been allocated specially for this
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    83
  // purpose and it is not part of the heap) that is full (i.e., top()
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    84
  // == end()). When we don't have a valid active region we make
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    85
  // _alloc_region point to this. This allows us to skip checking
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    86
  // whether the _alloc_region is NULL or not.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    87
  static HeapRegion* _dummy_region;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    88
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    89
  // Some of the methods below take a bot_updates parameter. Its value
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    90
  // should be the same as the _bot_updates field. The idea is that
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    91
  // the parameter will be a constant for a particular alloc region
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    92
  // and, given that these methods will be hopefully inlined, the
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    93
  // compiler should compile out the test.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    94
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    95
  // Perform a non-MT-safe allocation out of the given region.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    96
  static inline HeapWord* allocate(HeapRegion* alloc_region,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    97
                                   size_t word_size,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    98
                                   bool bot_updates);
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
    99
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   100
  // Perform a MT-safe allocation out of the given region.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   101
  static inline HeapWord* par_allocate(HeapRegion* alloc_region,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   102
                                       size_t word_size,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   103
                                       bool bot_updates);
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   104
  // Perform a MT-safe allocation out of the given region, with the given
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   105
  // minimum and desired size. Returns the actual size allocated (between
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   106
  // minimum and desired size) in actual_word_size if the allocation has been
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   107
  // successful.
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   108
  static inline HeapWord* par_allocate(HeapRegion* alloc_region,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   109
                                       size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   110
                                       size_t desired_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   111
                                       size_t* actual_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   112
                                       bool bot_updates);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   113
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   114
  // Ensure that the region passed as a parameter has been filled up
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   115
  // so that noone else can allocate out of it any more.
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   116
  // Returns the number of bytes that have been wasted by filled up
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   117
  // the space.
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   118
  static size_t fill_up_remaining_space(HeapRegion* alloc_region,
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   119
                                        bool bot_updates);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   120
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   121
  // After a region is allocated by alloc_new_region, this
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   122
  // method is used to set it as the active alloc_region
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   123
  void update_alloc_region(HeapRegion* alloc_region);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   124
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   125
  // Allocate a new active region and use it to perform a word_size
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   126
  // allocation. The force parameter will be passed on to
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   127
  // G1CollectedHeap::allocate_new_alloc_region() and tells it to try
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   128
  // to allocate a new region even if the max has been reached.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   129
  HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force);
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   130
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   131
protected:
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   132
  // Retire the active allocating region. If fill_up is true then make
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   133
  // sure that the region is full before we retire it so that no one
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   134
  // else can allocate out of it.
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   135
  // Returns the number of bytes that have been filled up during retire.
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   136
  virtual size_t retire(bool fill_up);
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   137
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   138
  // For convenience as subclasses use it.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   139
  static G1CollectedHeap* _g1h;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   140
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   141
  virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   142
  virtual void retire_region(HeapRegion* alloc_region,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   143
                             size_t allocated_bytes) = 0;
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   144
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   145
  G1AllocRegion(const char* name, bool bot_updates);
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   146
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   147
public:
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   148
  static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   149
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   150
  HeapRegion* get() const {
21119
ca1c9dd0e277 8025728: Missing volatile specifier for field G1AllocRegion::_alloc_region
tschatzl
parents: 12381
diff changeset
   151
    HeapRegion * hr = _alloc_region;
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   152
    // Make sure that the dummy region does not escape this class.
21119
ca1c9dd0e277 8025728: Missing volatile specifier for field G1AllocRegion::_alloc_region
tschatzl
parents: 12381
diff changeset
   153
    return (hr == _dummy_region) ? NULL : hr;
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   154
  }
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   155
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   156
  void set_allocation_context(AllocationContext_t context) { _allocation_context = context; }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   157
  AllocationContext_t  allocation_context() { return _allocation_context; }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   158
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 10243
diff changeset
   159
  uint count() { return _count; }
10243
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
   160
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   161
  // The following two are the building blocks for the allocation method.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   162
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   163
  // First-level allocation: Should be called without holding a
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   164
  // lock. It will try to allocate lock-free out of the active region,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   165
  // or return NULL if it was unable to.
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   166
  inline HeapWord* attempt_allocation(size_t word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   167
                                      bool bot_updates);
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   168
  // Perform an allocation out of the current allocation region, with the given
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   169
  // minimum and desired size. Returns the actual size allocated (between
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   170
  // minimum and desired size) in actual_word_size if the allocation has been
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   171
  // successful.
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   172
  // Should be called without holding a lock. It will try to allocate lock-free
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   173
  // out of the active region, or return NULL if it was unable to.
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   174
  inline HeapWord* attempt_allocation(size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   175
                                      size_t desired_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   176
                                      size_t* actual_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   177
                                      bool bot_updates);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   178
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   179
  // Second-level allocation: Should be called while holding a
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   180
  // lock. It will try to first allocate lock-free out of the active
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   181
  // region or, if it's unable to, it will try to replace the active
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   182
  // alloc region with a new one. We require that the caller takes the
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   183
  // appropriate lock before calling this so that it is easier to make
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   184
  // it conform to its locking protocol.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   185
  inline HeapWord* attempt_allocation_locked(size_t word_size,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   186
                                             bool bot_updates);
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   187
  // Same as attempt_allocation_locked(size_t, bool), but allowing specification
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   188
  // of minimum word size of the block in min_word_size, and the maximum word
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   189
  // size of the allocation in desired_word_size. The actual size of the block is
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   190
  // returned in actual_word_size.
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   191
  inline HeapWord* attempt_allocation_locked(size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   192
                                             size_t desired_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   193
                                             size_t* actual_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   194
                                             bool bot_updates);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   195
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   196
  // Should be called to allocate a new region even if the max of this
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   197
  // type of regions has been reached. Should only be called if other
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   198
  // allocation attempts have failed and we are not holding a valid
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   199
  // active region.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   200
  inline HeapWord* attempt_allocation_force(size_t word_size,
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   201
                                            bool bot_updates);
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   202
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   203
  // Should be called before we start using this object.
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   204
  void init();
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   205
10243
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
   206
  // This can be used to set the active region to a specific
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
   207
  // region. (Use Example: we try to retain the last old GC alloc
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
   208
  // region that we've used during a GC and we can use set() to
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
   209
  // re-instate it at the beginning of the next GC.)
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
   210
  void set(HeapRegion* alloc_region);
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 8928
diff changeset
   211
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   212
  // Should be called when we want to release the active region which
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   213
  // is returned after it's been retired.
26159
6033a6fc63cc 8044406: JVM crash with JDK8 (build 1.8.0-b132) with G1 GC
poonam
parents: 24424
diff changeset
   214
  virtual HeapRegion* release();
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   215
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   216
#if G1_ALLOC_REGION_TRACING
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   217
  void trace(const char* str,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   218
             size_t min_word_size = 0,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   219
             size_t desired_word_size = 0,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   220
             size_t actual_word_size = 0,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   221
             HeapWord* result = NULL);
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   222
#else // G1_ALLOC_REGION_TRACING
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   223
  void trace(const char* str,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   224
             size_t min_word_size = 0,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   225
             size_t desired_word_size = 0,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   226
             size_t actual_word_size = 0,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32379
diff changeset
   227
             HeapWord* result = NULL) { }
8928
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   228
#endif // G1_ALLOC_REGION_TRACING
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   229
};
e5c53268bef5 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
   230
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   231
class MutatorAllocRegion : public G1AllocRegion {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   232
protected:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   233
  virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   234
  virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   235
public:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   236
  MutatorAllocRegion()
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   237
    : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */) { }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   238
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   239
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   240
// Common base class for allocation regions used during GC.
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   241
class G1GCAllocRegion : public G1AllocRegion {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   242
protected:
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   243
  G1EvacStats* _stats;
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   244
  InCSetState::in_cset_state_t _purpose;
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   245
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   246
  virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   247
  virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   248
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   249
  virtual size_t retire(bool fill_up);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   250
public:
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   251
  G1GCAllocRegion(const char* name, bool bot_updates, G1EvacStats* stats, InCSetState::in_cset_state_t purpose)
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   252
  : G1AllocRegion(name, bot_updates), _stats(stats), _purpose(purpose) {
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   253
    assert(stats != NULL, "Must pass non-NULL PLAB statistics");
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   254
  }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   255
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   256
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   257
class SurvivorGCAllocRegion : public G1GCAllocRegion {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   258
public:
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   259
  SurvivorGCAllocRegion(G1EvacStats* stats)
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   260
  : G1GCAllocRegion("Survivor GC Alloc Region", false /* bot_updates */, stats, InCSetState::Young) { }
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   261
};
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   262
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   263
class OldGCAllocRegion : public G1GCAllocRegion {
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   264
public:
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   265
  OldGCAllocRegion(G1EvacStats* stats)
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 30764
diff changeset
   266
  : G1GCAllocRegion("Old GC Alloc Region", true /* bot_updates */, stats, InCSetState::Old) { }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   267
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   268
  // This specialization of release() makes sure that the last card that has
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   269
  // been allocated into has been completely filled by a dummy object.  This
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   270
  // avoids races when remembered set scanning wants to update the BOT of the
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   271
  // last card in the retained old gc alloc region, and allocation threads
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   272
  // allocating into that card at the same time.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   273
  virtual HeapRegion* release();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   274
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents: 26159
diff changeset
   275
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26837
diff changeset
   276
#endif // SHARE_VM_GC_G1_G1ALLOCREGION_HPP