8131319: Move G1Allocator::_summary_bytes_used back to G1CollectedHeap
Summary: G1Allocator::_summary_bytes_used fits better in G1CollectedHeap since we added the archive allocator. Move it back to the original location.
Reviewed-by: mgerdin, tbenson
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/gc/g1/G1Allocator.java Thu Jul 23 08:45:25 2015 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-package sun.jvm.hotspot.gc.g1;
-
-import java.util.Observable;
-import java.util.Observer;
-
-import sun.jvm.hotspot.debugger.Address;
-import sun.jvm.hotspot.runtime.VM;
-import sun.jvm.hotspot.runtime.VMObject;
-import sun.jvm.hotspot.types.CIntegerField;
-import sun.jvm.hotspot.types.Type;
-import sun.jvm.hotspot.types.TypeDataBase;
-
-public class G1Allocator extends VMObject {
-
- //size_t _summary_bytes_used;
- static private CIntegerField summaryBytesUsedField;
-
- static {
- VM.registerVMInitializedObserver(new Observer() {
- public void update(Observable o, Object data) {
- initialize(VM.getVM().getTypeDataBase());
- }
- });
- }
-
- static private synchronized void initialize(TypeDataBase db) {
- Type type = db.lookupType("G1Allocator");
-
- summaryBytesUsedField = type.getCIntegerField("_summary_bytes_used");
- }
-
- public long getSummaryBytes() {
- return summaryBytesUsedField.getValue(addr);
- }
-
- public G1Allocator(Address addr) {
- super(addr);
-
- }
-}
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/gc/g1/G1CollectedHeap.java Thu Jul 23 08:45:25 2015 +0200
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/gc/g1/G1CollectedHeap.java Thu Jul 23 11:14:24 2015 +0200
@@ -36,6 +36,7 @@
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.runtime.VMObjectFactory;
import sun.jvm.hotspot.types.AddressField;
+import sun.jvm.hotspot.types.CIntegerField;
import sun.jvm.hotspot.types.Type;
import sun.jvm.hotspot.types.TypeDataBase;
@@ -46,8 +47,8 @@
static private long hrmFieldOffset;
// MemRegion _g1_reserved;
static private long g1ReservedFieldOffset;
- // G1Allocator* _allocator
- static private AddressField g1Allocator;
+ // size_t _summary_bytes_used;
+ static private CIntegerField summaryBytesUsedField;
// G1MonitoringSupport* _g1mm;
static private AddressField g1mmField;
// HeapRegionSet _old_set;
@@ -67,7 +68,7 @@
Type type = db.lookupType("G1CollectedHeap");
hrmFieldOffset = type.getField("_hrm").getOffset();
- g1Allocator = type.getAddressField("_allocator");
+ summaryBytesUsedField = type.getCIntegerField("_summary_bytes_used");
g1mmField = type.getAddressField("_g1mm");
oldSetFieldOffset = type.getField("_old_set").getOffset();
humongousSetFieldOffset = type.getField("_humongous_set").getOffset();
@@ -78,7 +79,7 @@
}
public long used() {
- return allocator().getSummaryBytes();
+ return summaryBytesUsedField.getValue(addr);
}
public long n_regions() {
@@ -96,11 +97,6 @@
return (G1MonitoringSupport) VMObjectFactory.newObject(G1MonitoringSupport.class, g1mmAddr);
}
- public G1Allocator allocator() {
- Address g1AllocatorAddr = g1Allocator.getValue(addr);
- return (G1Allocator) VMObjectFactory.newObject(G1Allocator.class, g1AllocatorAddr);
- }
-
public HeapRegionSetBase oldSet() {
Address oldSetAddr = addr.addOffsetTo(oldSetFieldOffset);
return (HeapRegionSetBase) VMObjectFactory.newObject(HeapRegionSetBase.class,
--- a/hotspot/src/share/vm/gc/g1/g1Allocator.hpp Thu Jul 23 08:45:25 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1Allocator.hpp Thu Jul 23 11:14:24 2015 +0200
@@ -39,13 +39,8 @@
protected:
G1CollectedHeap* _g1h;
- // Outside of GC pauses, the number of bytes used in all regions other
- // than the current allocation region.
- size_t _summary_bytes_used;
-
public:
- G1Allocator(G1CollectedHeap* heap) :
- _g1h(heap), _summary_bytes_used(0) { }
+ G1Allocator(G1CollectedHeap* heap) : _g1h(heap) { }
static G1Allocator* create_allocator(G1CollectedHeap* g1h);
@@ -59,32 +54,13 @@
virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) = 0;
virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) = 0;
- virtual size_t used() = 0;
+ virtual size_t used_in_alloc_regions() = 0;
virtual bool is_retained_old_region(HeapRegion* hr) = 0;
void reuse_retained_old_region(EvacuationInfo& evacuation_info,
OldGCAllocRegion* old,
HeapRegion** retained);
- size_t used_unlocked() const {
- return _summary_bytes_used;
- }
-
- void increase_used(size_t bytes) {
- _summary_bytes_used += bytes;
- }
-
- void decrease_used(size_t bytes) {
- assert(_summary_bytes_used >= bytes,
- err_msg("invariant: _summary_bytes_used: " SIZE_FORMAT " should be >= bytes: " SIZE_FORMAT,
- _summary_bytes_used, bytes));
- _summary_bytes_used -= bytes;
- }
-
- void set_used(size_t bytes) {
- _summary_bytes_used = bytes;
- }
-
virtual HeapRegion* new_heap_region(uint hrs_index,
G1BlockOffsetSharedArray* sharedOffsetArray,
MemRegion mr) {
@@ -133,10 +109,10 @@
return &_old_gc_alloc_region;
}
- virtual size_t used() {
+ virtual size_t used_in_alloc_regions() {
assert(Heap_lock->owner() != NULL,
"Should be owned on this thread's behalf.");
- size_t result = _summary_bytes_used;
+ size_t result = 0;
// Read only once in case it is set to NULL concurrently
HeapRegion* hr = mutator_alloc_region(AllocationContext::current())->get();
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp Thu Jul 23 08:45:25 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp Thu Jul 23 11:14:24 2015 +0200
@@ -632,7 +632,7 @@
check_bitmaps("Humongous Region Allocation", first_hr);
assert(first_hr->used() == word_size * HeapWordSize, "invariant");
- _allocator->increase_used(first_hr->used());
+ increase_used(first_hr->used());
_humongous_set.add(first_hr);
return new_obj;
@@ -998,7 +998,7 @@
if ((prev_last_region != NULL) && (start_region == prev_last_region)) {
start_address = start_region->end();
if (start_address > last_address) {
- _allocator->increase_used(word_size * HeapWordSize);
+ increase_used(word_size * HeapWordSize);
start_region->set_top(last_address + 1);
continue;
}
@@ -1012,7 +1012,7 @@
if (!_hrm.allocate_containing_regions(curr_range, &commits)) {
return false;
}
- _allocator->increase_used(word_size * HeapWordSize);
+ increase_used(word_size * HeapWordSize);
if (commits != 0) {
ergo_verbose1(ErgoHeapSizing,
"attempt heap expansion",
@@ -1104,7 +1104,7 @@
if (start_address != bottom_address) {
size_t fill_size = pointer_delta(start_address, bottom_address);
G1CollectedHeap::fill_with_objects(bottom_address, fill_size);
- _allocator->increase_used(fill_size * HeapWordSize);
+ increase_used(fill_size * HeapWordSize);
}
}
}
@@ -1930,6 +1930,7 @@
_free_regions_coming(false),
_young_list(new YoungList(this)),
_gc_time_stamp(0),
+ _summary_bytes_used(0),
_survivor_plab_stats(YoungPLABSize, PLABWeight),
_old_plab_stats(OldPLABSize, PLABWeight),
_expand_heap_after_alloc_failure(true),
@@ -2371,7 +2372,7 @@
// Computes the sum of the storage used by the various regions.
size_t G1CollectedHeap::used() const {
- size_t result = _allocator->used();
+ size_t result = _summary_bytes_used + _allocator->used_in_alloc_regions();
if (_archive_allocator != NULL) {
result += _archive_allocator->used();
}
@@ -2379,7 +2380,7 @@
}
size_t G1CollectedHeap::used_unlocked() const {
- return _allocator->used_unlocked();
+ return _summary_bytes_used;
}
class SumUsedClosure: public HeapRegionClosure {
@@ -4102,7 +4103,7 @@
_young_list->reset_auxilary_lists();
if (evacuation_failed()) {
- _allocator->set_used(recalculate_used());
+ set_used(recalculate_used());
if (_archive_allocator != NULL) {
_archive_allocator->clear_used();
}
@@ -4114,7 +4115,7 @@
} else {
// The "used" of the the collection set have already been subtracted
// when they were freed. Add in the bytes evacuated.
- _allocator->increase_used(g1_policy()->bytes_copied_during_gc());
+ increase_used(g1_policy()->bytes_copied_during_gc());
}
if (collector_state()->during_initial_mark_pause()) {
@@ -5745,7 +5746,7 @@
}
void G1CollectedHeap::decrement_summary_bytes(size_t bytes) {
- _allocator->decrease_used(bytes);
+ decrease_used(bytes);
}
class G1ParCleanupCTTask : public AbstractGangTask {
@@ -6395,6 +6396,21 @@
_hrm.remove_all_free_regions();
}
+void G1CollectedHeap::increase_used(size_t bytes) {
+ _summary_bytes_used += bytes;
+}
+
+void G1CollectedHeap::decrease_used(size_t bytes) {
+ assert(_summary_bytes_used >= bytes,
+ err_msg("invariant: _summary_bytes_used: " SIZE_FORMAT " should be >= bytes: " SIZE_FORMAT,
+ _summary_bytes_used, bytes));
+ _summary_bytes_used -= bytes;
+}
+
+void G1CollectedHeap::set_used(size_t bytes) {
+ _summary_bytes_used = bytes;
+}
+
class RebuildRegionSetsClosure : public HeapRegionClosure {
private:
bool _free_list_only;
@@ -6463,15 +6479,15 @@
heap_region_iterate(&cl);
if (!free_list_only) {
- _allocator->set_used(cl.total_used());
+ set_used(cl.total_used());
if (_archive_allocator != NULL) {
_archive_allocator->clear_used();
}
}
- assert(_allocator->used_unlocked() == recalculate_used(),
- err_msg("inconsistent _allocator->used_unlocked(), "
+ assert(used_unlocked() == recalculate_used(),
+ err_msg("inconsistent used_unlocked(), "
"value: " SIZE_FORMAT " recalculated: " SIZE_FORMAT,
- _allocator->used_unlocked(), recalculate_used()));
+ used_unlocked(), recalculate_used()));
}
void G1CollectedHeap::set_refine_cte_cl_concurrency(bool concurrent) {
@@ -6511,7 +6527,7 @@
assert(alloc_region->is_eden(), "all mutator alloc regions should be eden");
g1_policy()->add_region_to_incremental_cset_lhs(alloc_region);
- _allocator->increase_used(allocated_bytes);
+ increase_used(allocated_bytes);
_hr_printer.retire(alloc_region);
// We update the eden sizes here, when the region is retired,
// instead of when it's allocated, since this is the point that its
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp Thu Jul 23 08:45:25 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp Thu Jul 23 11:14:24 2015 +0200
@@ -251,6 +251,15 @@
// Class that handles the different kinds of allocations.
G1Allocator* _allocator;
+ // Outside of GC pauses, the number of bytes used in all regions other
+ // than the current allocation region(s).
+ size_t _summary_bytes_used;
+
+ void increase_used(size_t bytes);
+ void decrease_used(size_t bytes);
+
+ void set_used(size_t bytes);
+
// Class that handles archive allocation ranges.
G1ArchiveAllocator* _archive_allocator;
--- a/hotspot/src/share/vm/gc/g1/vmStructs_g1.hpp Thu Jul 23 08:45:25 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/vmStructs_g1.hpp Thu Jul 23 11:14:24 2015 +0200
@@ -45,13 +45,11 @@
nonstatic_field(HeapRegionManager, _regions, G1HeapRegionTable) \
nonstatic_field(HeapRegionManager, _num_committed, uint) \
\
- nonstatic_field(G1Allocator, _summary_bytes_used, size_t) \
- \
+ nonstatic_field(G1CollectedHeap, _summary_bytes_used, size_t) \
nonstatic_field(G1CollectedHeap, _hrm, HeapRegionManager) \
nonstatic_field(G1CollectedHeap, _g1mm, G1MonitoringSupport*) \
nonstatic_field(G1CollectedHeap, _old_set, HeapRegionSetBase) \
nonstatic_field(G1CollectedHeap, _humongous_set, HeapRegionSetBase) \
- nonstatic_field(G1CollectedHeap, _allocator, G1Allocator*) \
\
nonstatic_field(G1MonitoringSupport, _eden_committed, size_t) \
nonstatic_field(G1MonitoringSupport, _eden_used, size_t) \
@@ -78,12 +76,10 @@
declare_toplevel_type(HeapRegionSetBase) \
declare_toplevel_type(HeapRegionSetCount) \
declare_toplevel_type(G1MonitoringSupport) \
- declare_toplevel_type(G1Allocator) \
\
declare_toplevel_type(G1CollectedHeap*) \
declare_toplevel_type(HeapRegion*) \
declare_toplevel_type(G1MonitoringSupport*) \
- declare_toplevel_type(G1Allocator*) \
#endif // SHARE_VM_GC_G1_VMSTRUCTS_G1_HPP