hotspot/src/share/vm/gc/g1/g1Allocator.hpp
author sjohanss
Wed, 07 Dec 2016 13:51:20 +0100
changeset 46285 5b673a9fa682
parent 34146 42523f0da397
child 46810 7dad333205cd
permissions -rw-r--r--
8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator Reviewed-by: tschatzl, kbarrett
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
/*
46285
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
     2
 * Copyright (c) 2014, 2017, 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
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    25
#ifndef SHARE_VM_GC_G1_G1ALLOCATOR_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    26
#define SHARE_VM_GC_G1_G1ALLOCATOR_HPP
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    28
#include "gc/g1/g1AllocRegion.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    29
#include "gc/g1/g1AllocationContext.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    30
#include "gc/g1/g1InCSetState.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    31
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    32
#include "gc/shared/plab.hpp"
30175
543725014c9d 8076457: Fix includes of inline.hpp in GC code
stefank
parents: 29327
diff changeset
    33
543725014c9d 8076457: Fix includes of inline.hpp in GC code
stefank
parents: 29327
diff changeset
    34
class EvacuationInfo;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    35
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    36
// Interface to keep track of which regions G1 is currently allocating into. Provides
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    37
// some accessors (e.g. allocating into them, or getting their occupancy).
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    38
// Also keeps track of retained regions across GCs.
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    39
class G1Allocator : public CHeapObj<mtGC> {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    40
  friend class VMStructs;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    41
protected:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    42
  G1CollectedHeap* _g1h;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    43
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    44
  virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) = 0;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    45
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
    46
  virtual bool survivor_is_full(AllocationContext_t context) const = 0;
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
    47
  virtual bool old_is_full(AllocationContext_t context) const = 0;
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
    48
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
    49
  virtual void set_survivor_full(AllocationContext_t context) = 0;
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
    50
  virtual void set_old_full(AllocationContext_t context) = 0;
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
    51
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    52
  // Accessors to the allocation regions.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    53
  virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    54
  virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) = 0;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    55
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    56
  // Allocation attempt during GC for a survivor object / PLAB.
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
    57
  inline HeapWord* survivor_attempt_allocation(size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
    58
                                               size_t desired_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
    59
                                               size_t* actual_word_size,
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    60
                                               AllocationContext_t context);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    61
  // Allocation attempt during GC for an old object / PLAB.
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
    62
  inline HeapWord* old_attempt_allocation(size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
    63
                                          size_t desired_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
    64
                                          size_t* actual_word_size,
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    65
                                          AllocationContext_t context);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    66
public:
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
    67
  G1Allocator(G1CollectedHeap* heap) : _g1h(heap) { }
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    68
  virtual ~G1Allocator() { }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    69
31848
65b917637e4f 8131166: Remove additional whitespace in G1Allocator
tschatzl
parents: 31632
diff changeset
    70
  static G1Allocator* create_allocator(G1CollectedHeap* g1h);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    71
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    72
#ifdef ASSERT
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    73
  // Do we currently have an active mutator region to allocate into?
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    74
  bool has_mutator_alloc_region(AllocationContext_t context) { return mutator_alloc_region(context)->get() != NULL; }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    75
#endif
31848
65b917637e4f 8131166: Remove additional whitespace in G1Allocator
tschatzl
parents: 31632
diff changeset
    76
  virtual void init_mutator_alloc_region() = 0;
65b917637e4f 8131166: Remove additional whitespace in G1Allocator
tschatzl
parents: 31632
diff changeset
    77
  virtual void release_mutator_alloc_region() = 0;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    78
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
    79
  virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
31848
65b917637e4f 8131166: Remove additional whitespace in G1Allocator
tschatzl
parents: 31632
diff changeset
    80
  virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
65b917637e4f 8131166: Remove additional whitespace in G1Allocator
tschatzl
parents: 31632
diff changeset
    81
  virtual void abandon_gc_alloc_regions() = 0;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    82
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    83
  // Management of retained regions.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    84
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    85
  virtual bool is_retained_old_region(HeapRegion* hr) = 0;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    86
  void reuse_retained_old_region(EvacuationInfo& evacuation_info,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    87
                                 OldGCAllocRegion* old,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    88
                                 HeapRegion** retained);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    89
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    90
  // Allocate blocks of memory during mutator time.
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    91
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    92
  inline HeapWord* attempt_allocation(size_t word_size, AllocationContext_t context);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    93
  inline HeapWord* attempt_allocation_locked(size_t word_size, AllocationContext_t context);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    94
  inline HeapWord* attempt_allocation_force(size_t word_size, AllocationContext_t context);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    95
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    96
  size_t unsafe_max_tlab_alloc(AllocationContext_t context);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    97
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    98
  // Allocate blocks of memory during garbage collection. Will ensure an
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
    99
  // allocation region, either by picking one or expanding the
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   100
  // heap, and then allocate a block of the given size. The block
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   101
  // may not be a humongous - it must fit into a single heap region.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   102
  HeapWord* par_allocate_during_gc(InCSetState dest,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   103
                                   size_t word_size,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   104
                                   AllocationContext_t context);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   105
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   106
  HeapWord* par_allocate_during_gc(InCSetState dest,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   107
                                   size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   108
                                   size_t desired_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   109
                                   size_t* actual_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   110
                                   AllocationContext_t context);
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   111
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   112
  virtual size_t used_in_alloc_regions() = 0;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   113
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   114
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   115
// The default allocation region manager for G1. Provides a single mutator, survivor
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   116
// and old generation allocation region.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   117
// Can retain the (single) old generation allocation region across GCs.
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   118
class G1DefaultAllocator : public G1Allocator {
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
   119
private:
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
   120
  bool _survivor_is_full;
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
   121
  bool _old_is_full;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   122
protected:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   123
  // Alloc region used to satisfy mutator allocation requests.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   124
  MutatorAllocRegion _mutator_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   125
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   126
  // Alloc region used to satisfy allocation requests by the GC for
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   127
  // survivor objects.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   128
  SurvivorGCAllocRegion _survivor_gc_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   129
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   130
  // Alloc region used to satisfy allocation requests by the GC for
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   131
  // old objects.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   132
  OldGCAllocRegion _old_gc_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   133
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   134
  HeapRegion* _retained_old_gc_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   135
public:
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   136
  G1DefaultAllocator(G1CollectedHeap* heap);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   137
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
   138
  virtual bool survivor_is_full(AllocationContext_t context) const;
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
   139
  virtual bool old_is_full(AllocationContext_t context) const ;
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
   140
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
   141
  virtual void set_survivor_full(AllocationContext_t context);
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
   142
  virtual void set_old_full(AllocationContext_t context);
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33105
diff changeset
   143
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   144
  virtual void init_mutator_alloc_region();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   145
  virtual void release_mutator_alloc_region();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   146
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   147
  virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31592
diff changeset
   148
  virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   149
  virtual void abandon_gc_alloc_regions();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   150
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   151
  virtual bool is_retained_old_region(HeapRegion* hr) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   152
    return _retained_old_gc_alloc_region == hr;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   153
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   154
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   155
  virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   156
    return &_mutator_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   157
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   158
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   159
  virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   160
    return &_survivor_gc_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   161
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   162
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   163
  virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   164
    return &_old_gc_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   165
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   166
31975
1e8d389159cb 8131319: Move G1Allocator::_summary_bytes_used back to G1CollectedHeap
ehelin
parents: 31848
diff changeset
   167
  virtual size_t used_in_alloc_regions() {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   168
    assert(Heap_lock->owner() != NULL,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   169
           "Should be owned on this thread's behalf.");
31975
1e8d389159cb 8131319: Move G1Allocator::_summary_bytes_used back to G1CollectedHeap
ehelin
parents: 31848
diff changeset
   170
    size_t result = 0;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   171
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   172
    // Read only once in case it is set to NULL concurrently
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   173
    HeapRegion* hr = mutator_alloc_region(AllocationContext::current())->get();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   174
    if (hr != NULL) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   175
      result += hr->used();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   176
    }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   177
    return result;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   178
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   179
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   180
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   181
class G1PLAB: public PLAB {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   182
private:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   183
  bool _retired;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   184
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   185
public:
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   186
  G1PLAB(size_t gclab_word_size);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   187
  virtual ~G1PLAB() {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   188
    guarantee(_retired, "Allocation buffer has not been retired");
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   189
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   190
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   191
  // The amount of space in words wasted within the PLAB including
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   192
  // waste due to refills and alignment.
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   193
  size_t wasted() const { return _wasted; }
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   194
32383
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   195
  virtual void set_buf(HeapWord* buf, size_t word_size) {
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   196
    PLAB::set_buf(buf, word_size);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   197
    _retired = false;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   198
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   199
29327
b539902e30f8 8073466: Remove buffer retaining functionality and clean up in ParGCAllocBuffer
tschatzl
parents: 28213
diff changeset
   200
  virtual void retire() {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   201
    if (_retired) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   202
      return;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   203
    }
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   204
    PLAB::retire();
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   205
    _retired = true;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   206
  }
30278
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   207
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   208
  virtual void flush_and_retire_stats(PLABStats* stats) {
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   209
    PLAB::flush_and_retire_stats(stats);
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   210
    _retired = true;
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   211
  }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   212
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   213
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   214
// Manages the PLABs used during garbage collection. Interface for allocation from PLABs.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   215
// Needs to handle multiple contexts, extra alignment in any "survivor" area and some
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   216
// statistics.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   217
class G1PLABAllocator : public CHeapObj<mtGC> {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   218
  friend class G1ParScanThreadState;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   219
protected:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   220
  G1CollectedHeap* _g1h;
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   221
  G1Allocator* _allocator;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   222
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   223
  // The survivor alignment in effect in bytes.
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   224
  // == 0 : don't align survivors
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   225
  // != 0 : align survivors to that alignment
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   226
  // These values were chosen to favor the non-alignment case since some
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   227
  // architectures have a special compare against zero instructions.
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   228
  const uint _survivor_alignment_bytes;
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   229
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   230
  // Number of words allocated directly (not counting PLAB allocation).
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   231
  size_t _direct_allocated[InCSetState::Num];
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   232
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   233
  virtual void flush_and_retire_stats() = 0;
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   234
  virtual G1PLAB* alloc_buffer(InCSetState dest, AllocationContext_t context) = 0;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   235
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   236
  // Calculate the survivor space object alignment in bytes. Returns that or 0 if
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   237
  // there are no restrictions on survivor alignment.
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   238
  static uint calc_survivor_alignment_bytes() {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   239
    assert(SurvivorAlignmentInBytes >= ObjectAlignmentInBytes, "sanity");
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   240
    if (SurvivorAlignmentInBytes == ObjectAlignmentInBytes) {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   241
      // No need to align objects in the survivors differently, return 0
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   242
      // which means "survivor alignment is not used".
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   243
      return 0;
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   244
    } else {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   245
      assert(SurvivorAlignmentInBytes > 0, "sanity");
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   246
      return SurvivorAlignmentInBytes;
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   247
    }
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   248
  }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   249
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   250
  HeapWord* allocate_new_plab(InCSetState dest,
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   251
                              size_t word_sz,
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   252
                              AllocationContext_t context);
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   253
32383
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   254
  bool may_throw_away_buffer(size_t const allocation_word_sz, size_t const buffer_size) const;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   255
public:
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   256
  G1PLABAllocator(G1Allocator* allocator);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   257
  virtual ~G1PLABAllocator() { }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   258
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   259
  static G1PLABAllocator* create_allocator(G1Allocator* allocator);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   260
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   261
  virtual void waste(size_t& wasted, size_t& undo_wasted) = 0;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   262
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   263
  // Allocate word_sz words in dest, either directly into the regions or by
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   264
  // allocating a new PLAB. Returns the address of the allocated memory, NULL if
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   265
  // not successful. Plab_refill_failed indicates whether an attempt to refill the
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   266
  // PLAB failed or not.
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   267
  HeapWord* allocate_direct_or_new_plab(InCSetState dest,
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   268
                                        size_t word_sz,
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   269
                                        AllocationContext_t context,
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   270
                                        bool* plab_refill_failed);
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   271
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   272
  // Allocate word_sz words in the PLAB of dest.  Returns the address of the
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   273
  // allocated memory, NULL if not successful.
32378
8dd0e7359751 8133470: Uses of Atomic methods in plab.hpp should be moved to .inline.hpp file
tschatzl
parents: 32377
diff changeset
   274
  inline HeapWord* plab_allocate(InCSetState dest,
8dd0e7359751 8133470: Uses of Atomic methods in plab.hpp should be moved to .inline.hpp file
tschatzl
parents: 32377
diff changeset
   275
                                 size_t word_sz,
8dd0e7359751 8133470: Uses of Atomic methods in plab.hpp should be moved to .inline.hpp file
tschatzl
parents: 32377
diff changeset
   276
                                 AllocationContext_t context);
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   277
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   278
  HeapWord* allocate(InCSetState dest,
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   279
                     size_t word_sz,
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   280
                     AllocationContext_t context,
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   281
                     bool* refill_failed) {
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   282
    HeapWord* const obj = plab_allocate(dest, word_sz, context);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   283
    if (obj != NULL) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   284
      return obj;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   285
    }
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32185
diff changeset
   286
    return allocate_direct_or_new_plab(dest, word_sz, context, refill_failed);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   287
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   288
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   289
  void undo_allocation(InCSetState dest, HeapWord* obj, size_t word_sz, AllocationContext_t context);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   290
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   291
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   292
// The default PLAB allocator for G1. Keeps the current (single) PLAB for survivor
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   293
// and old generation allocation.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   294
class G1DefaultPLABAllocator : public G1PLABAllocator {
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   295
  G1PLAB  _surviving_alloc_buffer;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   296
  G1PLAB  _tenured_alloc_buffer;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   297
  G1PLAB* _alloc_buffers[InCSetState::Num];
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   298
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   299
public:
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31975
diff changeset
   300
  G1DefaultPLABAllocator(G1Allocator* _allocator);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   301
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   302
  virtual G1PLAB* alloc_buffer(InCSetState dest, AllocationContext_t context) {
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   303
    assert(dest.is_valid(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
   304
           "Allocation buffer index out-of-bounds: " CSETSTATE_FORMAT, dest.value());
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   305
    assert(_alloc_buffers[dest.value()] != NULL,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32389
diff changeset
   306
           "Allocation buffer is NULL: " CSETSTATE_FORMAT, dest.value());
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   307
    return _alloc_buffers[dest.value()];
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   308
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   309
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32378
diff changeset
   310
  virtual void flush_and_retire_stats();
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   311
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30278
diff changeset
   312
  virtual void waste(size_t& wasted, size_t& undo_wasted);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   313
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   314
46285
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   315
// G1ArchiveRegionMap is a boolean array used to mark G1 regions as
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   316
// archive regions.  This allows a quick check for whether an object
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   317
// should not be marked because it is in an archive region.
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   318
class G1ArchiveRegionMap : public G1BiasedMappedArray<bool> {
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   319
protected:
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   320
  bool default_value() const { return false; }
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   321
};
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   322
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   323
// G1ArchiveAllocator is used to allocate memory in archive
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   324
// regions. Such regions are not modifiable by GC, being neither
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   325
// scavenged nor compacted, or even marked in the object header.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   326
// They can contain no pointers to non-archive heap regions,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   327
class G1ArchiveAllocator : public CHeapObj<mtGC> {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   328
protected:
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   329
  G1CollectedHeap* _g1h;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   330
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   331
  // The current allocation region
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   332
  HeapRegion* _allocation_region;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   333
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   334
  // Regions allocated for the current archive range.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   335
  GrowableArray<HeapRegion*> _allocated_regions;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   336
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   337
  // The number of bytes used in the current range.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   338
  size_t _summary_bytes_used;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   339
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   340
  // Current allocation window within the current region.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   341
  HeapWord* _bottom;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   342
  HeapWord* _top;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   343
  HeapWord* _max;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   344
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   345
  // Allocate a new region for this archive allocator.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   346
  // Allocation is from the top of the reserved heap downward.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   347
  bool alloc_new_region();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   348
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   349
public:
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   350
  G1ArchiveAllocator(G1CollectedHeap* g1h) :
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   351
    _g1h(g1h),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   352
    _allocation_region(NULL),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   353
    _allocated_regions((ResourceObj::set_allocation_type((address) &_allocated_regions,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   354
                                                         ResourceObj::C_HEAP),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   355
                        2), true /* C_Heap */),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   356
    _summary_bytes_used(0),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   357
    _bottom(NULL),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   358
    _top(NULL),
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   359
    _max(NULL) { }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   360
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   361
  virtual ~G1ArchiveAllocator() {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   362
    assert(_allocation_region == NULL, "_allocation_region not NULL");
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   363
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   364
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   365
  static G1ArchiveAllocator* create_allocator(G1CollectedHeap* g1h);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   366
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   367
  // Allocate memory for an individual object.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   368
  HeapWord* archive_mem_allocate(size_t word_size);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   369
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   370
  // Return the memory ranges used in the current archive, after
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   371
  // aligning to the requested alignment.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   372
  void complete_archive(GrowableArray<MemRegion>* ranges,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   373
                        size_t end_alignment_in_bytes);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   374
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   375
  // The number of bytes allocated by this allocator.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   376
  size_t used() {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   377
    return _summary_bytes_used;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   378
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   379
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   380
  // Clear the count of bytes allocated in prior G1 regions. This
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   381
  // must be done when recalculate_use is used to reset the counter
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   382
  // for the generic allocator, since it counts bytes in all G1
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   383
  // regions, including those still associated with this allocator.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   384
  void clear_used() {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   385
    _summary_bytes_used = 0;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   386
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   387
46285
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   388
  // Create the _archive_region_map which is used to identify archive objects.
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   389
  static inline void enable_archive_object_check();
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   390
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   391
  // Set the regions containing the specified address range as archive/non-archive.
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   392
  static inline void set_range_archive(MemRegion range, bool is_archive);
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   393
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   394
  static inline bool is_archive_object(oop object);
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   395
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   396
private:
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   397
  static bool _archive_check_enabled;
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   398
  static G1ArchiveRegionMap  _archive_region_map;
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   399
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   400
  // Check if an object is in an archive region using the _archive_region_map.
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   401
  static inline bool in_archive_range(oop object);
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   402
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   403
  // Check if archive object checking is enabled, to avoid calling in_archive_range
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   404
  // unnecessarily.
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 34146
diff changeset
   405
  static inline bool archive_check_enabled();
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   406
};
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   407
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
   408
#endif // SHARE_VM_GC_G1_G1ALLOCATOR_HPP