hotspot/src/share/vm/gc_implementation/g1/g1Allocator.hpp
author sjohanss
Wed, 22 Apr 2015 12:58:10 +0200
changeset 30278 928bec4e217f
parent 30275 41fef3a62cc8
child 30564 a37d98a1eb54
permissions -rw-r--r--
8077836: Make sure G1ParGCAllocBuffer are marked as retired Reviewed-by: tschatzl, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     1
/*
29327
b539902e30f8 8073466: Remove buffer retaining functionality and clean up in ParGCAllocBuffer
tschatzl
parents: 28213
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     4
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     7
 * published by the Free Software Foundation.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     8
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    13
 * accompanied this code).
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    14
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    18
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    21
 * questions.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    22
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    23
 */
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    24
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    26
#define SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    27
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    28
#include "gc_implementation/g1/g1AllocationContext.hpp"
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    29
#include "gc_implementation/g1/g1AllocRegion.hpp"
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
    30
#include "gc_implementation/g1/g1InCSetState.hpp"
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
    31
#include "gc_implementation/shared/plab.hpp"
30175
543725014c9d 8076457: Fix includes of inline.hpp in GC code
stefank
parents: 29327
diff changeset
    32
#include "gc_interface/collectedHeap.hpp"
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
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    36
// Base class for G1 allocators.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    37
class G1Allocator : public CHeapObj<mtGC> {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    38
  friend class VMStructs;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    39
protected:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    40
  G1CollectedHeap* _g1h;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    41
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    42
  // Outside of GC pauses, the number of bytes used in all regions other
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    43
  // than the current allocation region.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    44
  size_t _summary_bytes_used;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    45
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    46
public:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    47
   G1Allocator(G1CollectedHeap* heap) :
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    48
     _g1h(heap), _summary_bytes_used(0) { }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    49
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    50
   static G1Allocator* create_allocator(G1CollectedHeap* g1h);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    51
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    52
   virtual void init_mutator_alloc_region() = 0;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    53
   virtual void release_mutator_alloc_region() = 0;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    54
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    55
   virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    56
   virtual void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info) = 0;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    57
   virtual void abandon_gc_alloc_regions() = 0;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    58
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    59
   virtual MutatorAllocRegion*    mutator_alloc_region(AllocationContext_t context) = 0;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    60
   virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    61
   virtual OldGCAllocRegion*      old_gc_alloc_region(AllocationContext_t context) = 0;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    62
   virtual size_t                 used() = 0;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    63
   virtual bool                   is_retained_old_region(HeapRegion* hr) = 0;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    64
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    65
   void                           reuse_retained_old_region(EvacuationInfo& evacuation_info,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    66
                                                            OldGCAllocRegion* old,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    67
                                                            HeapRegion** retained);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    68
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    69
   size_t used_unlocked() const {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    70
     return _summary_bytes_used;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    71
   }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    72
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    73
   void increase_used(size_t bytes) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    74
     _summary_bytes_used += bytes;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    75
   }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    76
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    77
   void decrease_used(size_t bytes) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    78
     assert(_summary_bytes_used >= bytes,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    79
            err_msg("invariant: _summary_bytes_used: "SIZE_FORMAT" should be >= bytes: "SIZE_FORMAT,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    80
                _summary_bytes_used, bytes));
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    81
     _summary_bytes_used -= bytes;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    82
   }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    83
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    84
   void set_used(size_t bytes) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    85
     _summary_bytes_used = bytes;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    86
   }
26839
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26837
diff changeset
    87
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26837
diff changeset
    88
   virtual HeapRegion* new_heap_region(uint hrs_index,
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26837
diff changeset
    89
                                       G1BlockOffsetSharedArray* sharedOffsetArray,
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26837
diff changeset
    90
                                       MemRegion mr) {
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26837
diff changeset
    91
     return new HeapRegion(hrs_index, sharedOffsetArray, mr);
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26837
diff changeset
    92
   }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    93
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    94
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    95
// The default allocator for G1.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    96
class G1DefaultAllocator : public G1Allocator {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    97
protected:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    98
  // Alloc region used to satisfy mutator allocation requests.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    99
  MutatorAllocRegion _mutator_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   100
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   101
  // Alloc region used to satisfy allocation requests by the GC for
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   102
  // survivor objects.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   103
  SurvivorGCAllocRegion _survivor_gc_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   104
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   105
  // Alloc region used to satisfy allocation requests by the GC for
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   106
  // old objects.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   107
  OldGCAllocRegion _old_gc_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   108
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   109
  HeapRegion* _retained_old_gc_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   110
public:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   111
  G1DefaultAllocator(G1CollectedHeap* heap) : G1Allocator(heap), _retained_old_gc_alloc_region(NULL) { }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   112
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   113
  virtual void init_mutator_alloc_region();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   114
  virtual void release_mutator_alloc_region();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   115
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   116
  virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   117
  virtual void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   118
  virtual void abandon_gc_alloc_regions();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   119
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   120
  virtual bool is_retained_old_region(HeapRegion* hr) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   121
    return _retained_old_gc_alloc_region == hr;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   122
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   123
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   124
  virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   125
    return &_mutator_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   126
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   127
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   128
  virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   129
    return &_survivor_gc_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   130
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   131
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   132
  virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   133
    return &_old_gc_alloc_region;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   134
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   135
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   136
  virtual size_t used() {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   137
    assert(Heap_lock->owner() != NULL,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   138
           "Should be owned on this thread's behalf.");
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   139
    size_t result = _summary_bytes_used;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   140
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   141
    // Read only once in case it is set to NULL concurrently
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   142
    HeapRegion* hr = mutator_alloc_region(AllocationContext::current())->get();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   143
    if (hr != NULL) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   144
      result += hr->used();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   145
    }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   146
    return result;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   147
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   148
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   149
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   150
class G1PLAB: public PLAB {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   151
private:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   152
  bool _retired;
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
public:
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   155
  G1PLAB(size_t gclab_word_size);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   156
  virtual ~G1PLAB() {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   157
    guarantee(_retired, "Allocation buffer has not been retired");
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
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   160
  virtual void set_buf(HeapWord* buf) {
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   161
    PLAB::set_buf(buf);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   162
    _retired = false;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   163
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   164
29327
b539902e30f8 8073466: Remove buffer retaining functionality and clean up in ParGCAllocBuffer
tschatzl
parents: 28213
diff changeset
   165
  virtual void retire() {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   166
    if (_retired) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   167
      return;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   168
    }
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   169
    PLAB::retire();
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   170
    _retired = true;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   171
  }
30278
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   172
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   173
  virtual void flush_and_retire_stats(PLABStats* stats) {
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   174
    PLAB::flush_and_retire_stats(stats);
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   175
    _retired = true;
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   176
  }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   177
};
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
class G1ParGCAllocator : public CHeapObj<mtGC> {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   180
  friend class G1ParScanThreadState;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   181
protected:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   182
  G1CollectedHeap* _g1h;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   183
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   184
  // The survivor alignment in effect in bytes.
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   185
  // == 0 : don't align survivors
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   186
  // != 0 : align survivors to that alignment
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   187
  // 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
   188
  // 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
   189
  const uint _survivor_alignment_bytes;
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   190
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   191
  size_t _alloc_buffer_waste;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   192
  size_t _undo_waste;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   193
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   194
  void add_to_alloc_buffer_waste(size_t waste) { _alloc_buffer_waste += waste; }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   195
  void add_to_undo_waste(size_t waste)         { _undo_waste += waste; }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   196
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   197
  virtual void retire_alloc_buffers() = 0;
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   198
  virtual G1PLAB* alloc_buffer(InCSetState dest, AllocationContext_t context) = 0;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   199
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   200
  // 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
   201
  // there are no restrictions on survivor alignment.
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   202
  static uint calc_survivor_alignment_bytes() {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   203
    assert(SurvivorAlignmentInBytes >= ObjectAlignmentInBytes, "sanity");
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   204
    if (SurvivorAlignmentInBytes == ObjectAlignmentInBytes) {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   205
      // 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
   206
      // which means "survivor alignment is not used".
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   207
      return 0;
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   208
    } else {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   209
      assert(SurvivorAlignmentInBytes > 0, "sanity");
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   210
      return SurvivorAlignmentInBytes;
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   211
    }
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   212
  }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   213
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   214
public:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   215
  G1ParGCAllocator(G1CollectedHeap* g1h) :
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   216
    _g1h(g1h), _survivor_alignment_bytes(calc_survivor_alignment_bytes()),
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   217
    _alloc_buffer_waste(0), _undo_waste(0) {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   218
  }
30278
928bec4e217f 8077836: Make sure G1ParGCAllocBuffer are marked as retired
sjohanss
parents: 30275
diff changeset
   219
  virtual ~G1ParGCAllocator() { }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   220
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   221
  static G1ParGCAllocator* create_allocator(G1CollectedHeap* g1h);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   222
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   223
  size_t alloc_buffer_waste() { return _alloc_buffer_waste; }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   224
  size_t undo_waste() {return _undo_waste; }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   225
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   226
  // 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
   227
  // allocating a new PLAB. Returns the address of the allocated memory, NULL if
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   228
  // not successful.
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   229
  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
   230
                                        size_t word_sz,
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   231
                                        AllocationContext_t context);
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   232
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   233
  // 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
   234
  // allocated memory, NULL if not successful.
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   235
  HeapWord* plab_allocate(InCSetState dest,
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   236
                          size_t word_sz,
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   237
                          AllocationContext_t context) {
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   238
    G1PLAB* buffer = alloc_buffer(dest, context);
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   239
    if (_survivor_alignment_bytes == 0) {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   240
      return buffer->allocate(word_sz);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   241
    } else {
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   242
      return buffer->allocate_aligned(word_sz, _survivor_alignment_bytes);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   243
    }
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   244
  }
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   245
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   246
  HeapWord* allocate(InCSetState dest, size_t word_sz,
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   247
                     AllocationContext_t context) {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   248
    HeapWord* const obj = plab_allocate(dest, word_sz, context);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   249
    if (obj != NULL) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   250
      return obj;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   251
    }
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   252
    return allocate_direct_or_new_plab(dest, word_sz, context);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   253
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   254
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   255
  void undo_allocation(InCSetState dest, HeapWord* obj, size_t word_sz, AllocationContext_t context) {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   256
    if (alloc_buffer(dest, context)->contains(obj)) {
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   257
      assert(alloc_buffer(dest, context)->contains(obj + word_sz - 1),
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   258
             "should contain whole object");
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   259
      alloc_buffer(dest, context)->undo_allocation(obj, word_sz);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   260
    } else {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   261
      CollectedHeap::fill_with_object(obj, word_sz);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   262
      add_to_undo_waste(word_sz);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   263
    }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   264
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   265
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   266
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   267
class G1DefaultParGCAllocator : public G1ParGCAllocator {
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   268
  G1PLAB  _surviving_alloc_buffer;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   269
  G1PLAB  _tenured_alloc_buffer;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   270
  G1PLAB* _alloc_buffers[InCSetState::Num];
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   271
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   272
public:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   273
  G1DefaultParGCAllocator(G1CollectedHeap* g1h);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   274
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents: 30274
diff changeset
   275
  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
   276
    assert(dest.is_valid(),
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   277
           err_msg("Allocation buffer index out-of-bounds: " CSETSTATE_FORMAT, dest.value()));
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   278
    assert(_alloc_buffers[dest.value()] != NULL,
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   279
           err_msg("Allocation buffer is NULL: " CSETSTATE_FORMAT, dest.value()));
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 26839
diff changeset
   280
    return _alloc_buffers[dest.value()];
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   281
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   282
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   283
  virtual void retire_alloc_buffers() ;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   284
};
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   285
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   286
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP