src/hotspot/share/gc/g1/g1Allocator.hpp
changeset 49713 456e51e56ea2
parent 49323 565336327354
child 49945 9425445633cf
--- a/src/hotspot/share/gc/g1/g1Allocator.hpp	Fri Apr 06 11:37:34 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1Allocator.hpp	Fri Apr 06 11:41:21 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,82 +37,13 @@
 // Also keeps track of retained regions across GCs.
 class G1Allocator : public CHeapObj<mtGC> {
   friend class VMStructs;
-protected:
+
+private:
   G1CollectedHeap* _g1h;
 
-  virtual MutatorAllocRegion* mutator_alloc_region() = 0;
-
-  virtual bool survivor_is_full() const = 0;
-  virtual bool old_is_full() const = 0;
-
-  virtual void set_survivor_full() = 0;
-  virtual void set_old_full() = 0;
-
-  // Accessors to the allocation regions.
-  virtual SurvivorGCAllocRegion* survivor_gc_alloc_region() = 0;
-  virtual OldGCAllocRegion* old_gc_alloc_region() = 0;
-
-  // Allocation attempt during GC for a survivor object / PLAB.
-  inline HeapWord* survivor_attempt_allocation(size_t min_word_size,
-                                               size_t desired_word_size,
-                                               size_t* actual_word_size);
-  // Allocation attempt during GC for an old object / PLAB.
-  inline HeapWord* old_attempt_allocation(size_t min_word_size,
-                                          size_t desired_word_size,
-                                          size_t* actual_word_size);
-public:
-  G1Allocator(G1CollectedHeap* heap) : _g1h(heap) { }
-  virtual ~G1Allocator() { }
-
-#ifdef ASSERT
-  // Do we currently have an active mutator region to allocate into?
-  bool has_mutator_alloc_region() { return mutator_alloc_region()->get() != NULL; }
-#endif
-  virtual void init_mutator_alloc_region() = 0;
-  virtual void release_mutator_alloc_region() = 0;
-
-  virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
-  virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
-  virtual void abandon_gc_alloc_regions() = 0;
-
-  // Management of retained regions.
-
-  virtual bool is_retained_old_region(HeapRegion* hr) = 0;
-  void reuse_retained_old_region(EvacuationInfo& evacuation_info,
-                                 OldGCAllocRegion* old,
-                                 HeapRegion** retained);
-
-  // Allocate blocks of memory during mutator time.
-
-  inline HeapWord* attempt_allocation(size_t word_size);
-  inline HeapWord* attempt_allocation_locked(size_t word_size);
-  inline HeapWord* attempt_allocation_force(size_t word_size);
-
-  size_t unsafe_max_tlab_alloc();
-
-  // Allocate blocks of memory during garbage collection. Will ensure an
-  // allocation region, either by picking one or expanding the
-  // heap, and then allocate a block of the given size. The block
-  // may not be a humongous - it must fit into a single heap region.
-  HeapWord* par_allocate_during_gc(InCSetState dest,
-                                   size_t word_size);
-
-  HeapWord* par_allocate_during_gc(InCSetState dest,
-                                   size_t min_word_size,
-                                   size_t desired_word_size,
-                                   size_t* actual_word_size);
-
-  virtual size_t used_in_alloc_regions() = 0;
-};
-
-// The default allocation region manager for G1. Provides a single mutator, survivor
-// and old generation allocation region.
-// Can retain the (single) old generation allocation region across GCs.
-class G1DefaultAllocator : public G1Allocator {
-private:
   bool _survivor_is_full;
   bool _old_is_full;
-protected:
+
   // Alloc region used to satisfy mutator allocation requests.
   MutatorAllocRegion _mutator_alloc_region;
 
@@ -125,50 +56,67 @@
   OldGCAllocRegion _old_gc_alloc_region;
 
   HeapRegion* _retained_old_gc_alloc_region;
-public:
-  G1DefaultAllocator(G1CollectedHeap* heap);
+
+  bool survivor_is_full() const;
+  bool old_is_full() const;
 
-  virtual bool survivor_is_full() const;
-  virtual bool old_is_full() const ;
+  void set_survivor_full();
+  void set_old_full();
 
-  virtual void set_survivor_full();
-  virtual void set_old_full();
+  void reuse_retained_old_region(EvacuationInfo& evacuation_info,
+                                 OldGCAllocRegion* old,
+                                 HeapRegion** retained);
 
-  virtual void init_mutator_alloc_region();
-  virtual void release_mutator_alloc_region();
+  // Accessors to the allocation regions.
+  inline MutatorAllocRegion* mutator_alloc_region();
+  inline SurvivorGCAllocRegion* survivor_gc_alloc_region();
+  inline OldGCAllocRegion* old_gc_alloc_region();
 
-  virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
-  virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info);
-  virtual void abandon_gc_alloc_regions();
+  // Allocation attempt during GC for a survivor object / PLAB.
+  HeapWord* survivor_attempt_allocation(size_t min_word_size,
+                                               size_t desired_word_size,
+                                               size_t* actual_word_size);
 
-  virtual bool is_retained_old_region(HeapRegion* hr) {
-    return _retained_old_gc_alloc_region == hr;
-  }
+  // Allocation attempt during GC for an old object / PLAB.
+  HeapWord* old_attempt_allocation(size_t min_word_size,
+                                          size_t desired_word_size,
+                                          size_t* actual_word_size);
+public:
+  G1Allocator(G1CollectedHeap* heap);
 
-  virtual MutatorAllocRegion* mutator_alloc_region() {
-    return &_mutator_alloc_region;
-  }
+#ifdef ASSERT
+  // Do we currently have an active mutator region to allocate into?
+  bool has_mutator_alloc_region() { return mutator_alloc_region()->get() != NULL; }
+#endif
 
-  virtual SurvivorGCAllocRegion* survivor_gc_alloc_region() {
-    return &_survivor_gc_alloc_region;
-  }
+  void init_mutator_alloc_region();
+  void release_mutator_alloc_region();
 
-  virtual OldGCAllocRegion* old_gc_alloc_region() {
-    return &_old_gc_alloc_region;
-  }
+  void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
+  void release_gc_alloc_regions(EvacuationInfo& evacuation_info);
+  void abandon_gc_alloc_regions();
+  bool is_retained_old_region(HeapRegion* hr);
+
+  // Allocate blocks of memory during mutator time.
 
-  virtual size_t used_in_alloc_regions() {
-    assert(Heap_lock->owner() != NULL,
-           "Should be owned on this thread's behalf.");
-    size_t result = 0;
+  inline HeapWord* attempt_allocation(size_t word_size);
+  inline HeapWord* attempt_allocation_locked(size_t word_size);
+  inline HeapWord* attempt_allocation_force(size_t word_size);
+
+  size_t unsafe_max_tlab_alloc();
+  size_t used_in_alloc_regions();
 
-    // Read only once in case it is set to NULL concurrently
-    HeapRegion* hr = mutator_alloc_region()->get();
-    if (hr != NULL) {
-      result += hr->used();
-    }
-    return result;
-  }
+  // Allocate blocks of memory during garbage collection. Will ensure an
+  // allocation region, either by picking one or expanding the
+  // heap, and then allocate a block of the given size. The block
+  // may not be a humongous - it must fit into a single heap region.
+  HeapWord* par_allocate_during_gc(InCSetState dest,
+                                   size_t word_size);
+
+  HeapWord* par_allocate_during_gc(InCSetState dest,
+                                   size_t min_word_size,
+                                   size_t desired_word_size,
+                                   size_t* actual_word_size);
 };
 
 // Manages the PLABs used during garbage collection. Interface for allocation from PLABs.
@@ -176,10 +124,14 @@
 // statistics.
 class G1PLABAllocator : public CHeapObj<mtGC> {
   friend class G1ParScanThreadState;
-protected:
+private:
   G1CollectedHeap* _g1h;
   G1Allocator* _allocator;
 
+  PLAB  _surviving_alloc_buffer;
+  PLAB  _tenured_alloc_buffer;
+  PLAB* _alloc_buffers[InCSetState::Num];
+
   // The survivor alignment in effect in bytes.
   // == 0 : don't align survivors
   // != 0 : align survivors to that alignment
@@ -190,32 +142,18 @@
   // Number of words allocated directly (not counting PLAB allocation).
   size_t _direct_allocated[InCSetState::Num];
 
-  virtual void flush_and_retire_stats() = 0;
-  virtual PLAB* alloc_buffer(InCSetState dest) = 0;
+  void flush_and_retire_stats();
+  inline PLAB* alloc_buffer(InCSetState dest);
 
   // Calculate the survivor space object alignment in bytes. Returns that or 0 if
   // there are no restrictions on survivor alignment.
-  static uint calc_survivor_alignment_bytes() {
-    assert(SurvivorAlignmentInBytes >= ObjectAlignmentInBytes, "sanity");
-    if (SurvivorAlignmentInBytes == ObjectAlignmentInBytes) {
-      // No need to align objects in the survivors differently, return 0
-      // which means "survivor alignment is not used".
-      return 0;
-    } else {
-      assert(SurvivorAlignmentInBytes > 0, "sanity");
-      return SurvivorAlignmentInBytes;
-    }
-  }
-
-  HeapWord* allocate_new_plab(InCSetState dest,
-                              size_t word_sz);
+  static uint calc_survivor_alignment_bytes();
 
   bool may_throw_away_buffer(size_t const allocation_word_sz, size_t const buffer_size) const;
 public:
   G1PLABAllocator(G1Allocator* allocator);
-  virtual ~G1PLABAllocator() { }
 
-  virtual void waste(size_t& wasted, size_t& undo_wasted) = 0;
+  void waste(size_t& wasted, size_t& undo_wasted);
 
   // Allocate word_sz words in dest, either directly into the regions or by
   // allocating a new PLAB. Returns the address of the allocated memory, NULL if
@@ -230,42 +168,13 @@
   inline HeapWord* plab_allocate(InCSetState dest,
                                  size_t word_sz);
 
-  HeapWord* allocate(InCSetState dest,
-                     size_t word_sz,
-                     bool* refill_failed) {
-    HeapWord* const obj = plab_allocate(dest, word_sz);
-    if (obj != NULL) {
-      return obj;
-    }
-    return allocate_direct_or_new_plab(dest, word_sz, refill_failed);
-  }
+  inline HeapWord* allocate(InCSetState dest,
+                            size_t word_sz,
+                            bool* refill_failed);
 
   void undo_allocation(InCSetState dest, HeapWord* obj, size_t word_sz);
 };
 
-// The default PLAB allocator for G1. Keeps the current (single) PLAB for survivor
-// and old generation allocation.
-class G1DefaultPLABAllocator : public G1PLABAllocator {
-  PLAB  _surviving_alloc_buffer;
-  PLAB  _tenured_alloc_buffer;
-  PLAB* _alloc_buffers[InCSetState::Num];
-
-public:
-  G1DefaultPLABAllocator(G1Allocator* _allocator);
-
-  virtual PLAB* alloc_buffer(InCSetState dest) {
-    assert(dest.is_valid(),
-           "Allocation buffer index out-of-bounds: " CSETSTATE_FORMAT, dest.value());
-    assert(_alloc_buffers[dest.value()] != NULL,
-           "Allocation buffer is NULL: " CSETSTATE_FORMAT, dest.value());
-    return _alloc_buffers[dest.value()];
-  }
-
-  virtual void flush_and_retire_stats();
-
-  virtual void waste(size_t& wasted, size_t& undo_wasted);
-};
-
 // G1ArchiveRegionMap is a boolean array used to mark G1 regions as
 // archive regions.  This allows a quick check for whether an object
 // should not be marked because it is in an archive region.