8219003: SA: Refactor live regions iteration in preparation for JDK-8218922
Reviewed-by: eosterlund, ysuenaga
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/cms/CompactibleFreeListSpace.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/cms/CompactibleFreeListSpace.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, 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
@@ -35,7 +35,7 @@
import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.*;
-public class CompactibleFreeListSpace extends CompactibleSpace {
+public class CompactibleFreeListSpace extends CompactibleSpace implements LiveRegionsProvider {
private static AddressField collectorField;
private static AddressField indexedFreeListField;
private static AddressField dictionaryField;
@@ -93,10 +93,10 @@
}
public long used0() {
- List regions = getLiveRegions();
+ List<MemRegion> regions = getLiveRegions();
long usedSize = 0L;
- for (Iterator itr = regions.iterator(); itr.hasNext();) {
- MemRegion mr = (MemRegion) itr.next();
+ for (Iterator<MemRegion> itr = regions.iterator(); itr.hasNext();) {
+ MemRegion mr = itr.next();
usedSize += mr.byteSize();
}
return usedSize;
@@ -154,8 +154,9 @@
return addr;
}
- public List/*<MemRegion>*/ getLiveRegions() {
- List res = new ArrayList(); // List<MemRegion>
+ @Override
+ public List<MemRegion> getLiveRegions() {
+ List<MemRegion> res = new ArrayList<>();
VM vm = VM.getVM();
Debugger dbg = vm.getDebugger();
ObjectHeap heap = vm.getObjectHeap();
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/cms/ConcurrentMarkSweepGeneration.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/cms/ConcurrentMarkSweepGeneration.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, 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
@@ -66,6 +66,9 @@
public void spaceIterate(SpaceClosure blk, boolean usedOnly) {
blk.doSpace(cmsSpace());
}
+ public void liveRegionsIterate(LiveRegionsClosure closure) {
+ closure.doLiveRegions(cmsSpace());
+ }
public Generation.Name kind() {
return Generation.Name.CONCURRENT_MARK_SWEEP;
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/epsilon/EpsilonHeap.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/epsilon/EpsilonHeap.java Tue Feb 19 10:03:41 2019 +0100
@@ -81,6 +81,11 @@
}
@Override
+ public void liveRegionsIterate(LiveRegionsClosure closure) {
+ closure.doLiveRegions(space());
+ }
+
+ @Override
public void printOn(PrintStream tty) {
MemRegion mr = reservedRegion();
tty.println("Epsilon heap");
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/G1CollectedHeap.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/G1CollectedHeap.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, 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
@@ -32,8 +32,9 @@
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.gc.shared.CollectedHeap;
import sun.jvm.hotspot.gc.shared.CollectedHeapName;
+import sun.jvm.hotspot.gc.shared.LiveRegionsClosure;
+import sun.jvm.hotspot.gc.shared.PrintRegionClosure;
import sun.jvm.hotspot.gc.shared.SpaceClosure;
-import sun.jvm.hotspot.gc.shared.PrintRegionClosure;
import sun.jvm.hotspot.memory.MemRegion;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.runtime.VMObjectFactory;
@@ -138,6 +139,15 @@
}
@Override
+ public void liveRegionsIterate(LiveRegionsClosure closure) {
+ Iterator<HeapRegion> iter = heapRegionIterator();
+ while (iter.hasNext()) {
+ HeapRegion hr = iter.next();
+ closure.doLiveRegions(hr);
+ }
+ }
+
+ @Override
public void printOn(PrintStream tty) {
MemRegion mr = reservedRegion();
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/HeapRegion.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/HeapRegion.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, 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
@@ -32,6 +32,7 @@
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.OopHandle;
import sun.jvm.hotspot.gc.shared.CompactibleSpace;
+import sun.jvm.hotspot.gc.shared.LiveRegionsProvider;
import sun.jvm.hotspot.memory.MemRegion;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.runtime.VMObjectFactory;
@@ -43,7 +44,7 @@
// Mirror class for HeapRegion. Currently we don't actually include
// any of its fields but only iterate over it.
-public class HeapRegion extends CompactibleSpace {
+public class HeapRegion extends CompactibleSpace implements LiveRegionsProvider {
// static int GrainBytes;
static private CIntegerField grainBytesField;
static private AddressField topField;
@@ -86,8 +87,8 @@
}
@Override
- public List getLiveRegions() {
- List res = new ArrayList();
+ public List<MemRegion> getLiveRegions() {
+ List<MemRegion> res = new ArrayList<>();
res.add(new MemRegion(bottom(), top()));
return res;
}
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/parallel/ImmutableSpace.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/parallel/ImmutableSpace.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, 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
@@ -73,7 +73,7 @@
}
/** returns all MemRegions where live objects are */
- public abstract List/*<MemRegion>*/ getLiveRegions();
+ public abstract List<MemRegion> getLiveRegions();
/** Returned value is in bytes */
public long capacity() { return end().minus(bottom()); }
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/parallel/MutableSpace.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/parallel/MutableSpace.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, 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
@@ -62,8 +62,8 @@
}
/** returns all MemRegions where live objects are */
- public List/*<MemRegion>*/ getLiveRegions() {
- List res = new ArrayList();
+ public List<MemRegion> getLiveRegions() {
+ List<MemRegion> res = new ArrayList<>();
res.add(new MemRegion(bottom(), top()));
return res;
}
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/parallel/ParallelScavengeHeap.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/parallel/ParallelScavengeHeap.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, 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
@@ -29,6 +29,7 @@
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.gc.shared.*;
+import sun.jvm.hotspot.memory.MemRegion;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.types.*;
@@ -88,6 +89,35 @@
return CollectedHeapName.PARALLEL;
}
+ // Simple wrapper to provide toString() usable for debugging.
+ private class LiveRegionProviderImpl implements LiveRegionsProvider {
+ private String name;
+ private MutableSpace space;
+
+ public LiveRegionProviderImpl(String name, MutableSpace space) {
+ this.name = name;
+ this.space = space;
+ }
+
+ @Override
+ public List<MemRegion> getLiveRegions() {
+ return space.getLiveRegions();
+ }
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+
+ public void liveRegionsIterate(LiveRegionsClosure closure) {
+ // Add eden space
+ closure.doLiveRegions(new LiveRegionProviderImpl("eden", youngGen().edenSpace()));
+ // Add from-space but not to-space
+ closure.doLiveRegions(new LiveRegionProviderImpl("from", youngGen().fromSpace()));
+
+ closure.doLiveRegions(new LiveRegionProviderImpl("old ", oldGen().objectSpace()));
+ }
+
public void printOn(PrintStream tty) {
tty.print("ParallelScavengeHeap [ ");
youngGen().printOn(tty);
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/serial/DefNewGeneration.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/serial/DefNewGeneration.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, 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
@@ -94,6 +94,11 @@
}
}
+ public void liveRegionsIterate(LiveRegionsClosure closure) {
+ closure.doLiveRegions(eden());
+ closure.doLiveRegions(from());
+ }
+
public void printOn(PrintStream tty) {
tty.print(" eden");
eden().printOn(tty);
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/serial/TenuredGeneration.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/serial/TenuredGeneration.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, 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
@@ -76,6 +76,10 @@
blk.doSpace(theSpace());
}
+ public void liveRegionsIterate(LiveRegionsClosure closure) {
+ closure.doLiveRegions(theSpace());
+ }
+
public void printOn(PrintStream tty) {
tty.print(" old ");
theSpace().printOn(tty);
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeap.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeap.java Tue Feb 19 10:03:41 2019 +0100
@@ -28,6 +28,7 @@
import java.util.*;
import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.gc.shared.*;
import sun.jvm.hotspot.memory.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.types.*;
@@ -77,6 +78,8 @@
public abstract CollectedHeapName kind();
+ public abstract void liveRegionsIterate(LiveRegionsClosure closure);
+
public String oopAddressDescription(OopHandle handle) {
return handle.toString();
}
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/ContiguousSpace.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/ContiguousSpace.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, 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
@@ -32,7 +32,7 @@
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.types.*;
-public class ContiguousSpace extends CompactibleSpace {
+public class ContiguousSpace extends CompactibleSpace implements LiveRegionsProvider {
private static AddressField topField;
static {
@@ -79,8 +79,8 @@
}
/** Returns regions of Space where live objects live */
- public List/*<MemRegion>*/ getLiveRegions() {
- List res = new ArrayList();
+ public List<MemRegion> getLiveRegions() {
+ List<MemRegion> res = new ArrayList<>();
res.add(new MemRegion(bottom(), top()));
return res;
}
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/GenCollectedHeap.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/GenCollectedHeap.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, 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
@@ -28,6 +28,7 @@
import java.util.*;
import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.gc.shared.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.*;
@@ -134,6 +135,14 @@
}
}
+ public void liveRegionsIterate(LiveRegionsClosure closure) {
+ // Run through all generations, obtaining bottom-top pairs.
+ for (int i = 0; i < nGens(); i++) {
+ Generation gen = getGen(i);
+ gen.liveRegionsIterate(closure);
+ }
+ }
+
public void printOn(PrintStream tty) {
for (int i = 0; i < nGens(); i++) {
tty.print("Gen " + i + ": ");
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/Generation.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/Generation.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, 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
@@ -184,6 +184,7 @@
/** Iteration - do not use for time critical operations */
public abstract void spaceIterate(SpaceClosure blk, boolean usedOnly);
+ public abstract void liveRegionsIterate(LiveRegionsClosure closure);
public void print() { printOn(System.out); }
public abstract void printOn(PrintStream tty);
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/GenerationFactory.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/GenerationFactory.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, 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
@@ -65,6 +65,8 @@
}
public void spaceIterate(SpaceClosure blk, boolean usedOnly) {
}
+ public void liveRegionsIterate(LiveRegionsClosure closure) {
+ }
public void printOn(java.io.PrintStream tty) {
tty.println("unknown subtype of Generation @ " + getAddress() + " (" +
virtualSpace().low() + "," + virtualSpace().high() + ")");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/LiveRegionsClosure.java Tue Feb 19 10:03:41 2019 +0100
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2019, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.gc.shared;
+
+public interface LiveRegionsClosure {
+ public void doLiveRegions(LiveRegionsProvider lrp);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/LiveRegionsProvider.java Tue Feb 19 10:03:41 2019 +0100
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2019, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.gc.shared;
+
+import java.util.List;
+
+import sun.jvm.hotspot.memory.MemRegion;
+
+public interface LiveRegionsProvider {
+ public List<MemRegion> getLiveRegions();
+}
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/Space.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/Space.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, 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
@@ -89,9 +89,6 @@
return handle.addOffsetToAsOopHandle(size);
}
- /** returns all MemRegions where live objects are */
- public abstract List/*<MemRegion>*/ getLiveRegions();
-
/** Returned value is in bytes */
public long capacity() { return end().minus(bottom()); }
/** Returned value is in bytes */
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeap.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeap.java Tue Feb 19 10:03:41 2019 +0100
@@ -25,6 +25,7 @@
import sun.jvm.hotspot.gc.shared.CollectedHeap;
import sun.jvm.hotspot.gc.shared.CollectedHeapName;
+import sun.jvm.hotspot.gc.shared.LiveRegionsClosure;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.types.Type;
@@ -78,6 +79,12 @@
}
@Override
+ public void liveRegionsIterate(LiveRegionsClosure closure) {
+ // Operation (currently) not supported with Shenandoah GC.
+ System.err.println("Warning: Operation not supported with Shenandoah GC");
+ }
+
+ @Override
public void printOn(PrintStream tty) {
MemRegion mr = reservedRegion();
tty.print("Shenandoah heap");
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZCollectedHeap.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZCollectedHeap.java Tue Feb 19 10:03:41 2019 +0100
@@ -30,6 +30,7 @@
import sun.jvm.hotspot.debugger.OopHandle;
import sun.jvm.hotspot.gc.shared.CollectedHeap;
import sun.jvm.hotspot.gc.shared.CollectedHeapName;
+import sun.jvm.hotspot.gc.shared.LiveRegionsClosure;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.runtime.VMObjectFactory;
import sun.jvm.hotspot.types.Type;
@@ -39,7 +40,6 @@
// Mirror class for ZCollectedHeap.
public class ZCollectedHeap extends CollectedHeap {
-
private static long zHeapFieldOffset;
static {
@@ -120,6 +120,13 @@
}
@Override
+ public void liveRegionsIterate(LiveRegionsClosure closure) {
+ // Operation (currently) not supported with ZGC. Print
+ // a warning and leave the list of live regions empty.
+ System.err.println("Warning: Operation not supported with ZGC");
+ }
+
+ @Override
public BitMapInterface createBitMap(long size) {
// Ignores the size
return new ZExternalBitMap(this);
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java Tue Feb 19 10:03:29 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java Tue Feb 19 10:03:41 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, 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
@@ -304,87 +304,48 @@
visitor.epilogue();
}
- private void addLiveRegions(String name, List input, List output) {
- for (Iterator itr = input.iterator(); itr.hasNext();) {
- MemRegion reg = (MemRegion) itr.next();
+ private static class LiveRegionsCollector implements LiveRegionsClosure {
+ LiveRegionsCollector(List<Address> l) {
+ liveRegions = l;
+ }
+
+ @Override
+ public void doLiveRegions(LiveRegionsProvider lrp) {
+ for (MemRegion reg : lrp.getLiveRegions()) {
Address top = reg.end();
Address bottom = reg.start();
if (Assert.ASSERTS_ENABLED) {
- Assert.that(top != null, "top address in a live region should not be null");
+ Assert.that(top != null, "top address in a live region should not be null");
}
if (Assert.ASSERTS_ENABLED) {
- Assert.that(bottom != null, "bottom address in a live region should not be null");
+ Assert.that(bottom != null, "bottom address in a live region should not be null");
}
- output.add(top);
- output.add(bottom);
+ liveRegions.add(top);
+ liveRegions.add(bottom);
if (DEBUG) {
- System.err.println("Live region: " + name + ": " + bottom + ", " + top);
- }
- }
+ System.err.println("Live region: " + lrp + ": " + bottom + ", " + top);
+ }
+ }
}
- private class LiveRegionsCollector implements SpaceClosure {
- LiveRegionsCollector(List l) {
- liveRegions = l;
- }
-
- public void doSpace(Space s) {
- addLiveRegions(s.toString(), s.getLiveRegions(), liveRegions);
- }
- private List liveRegions;
+ private List<Address> liveRegions;
}
// Returns a List<Address> where the addresses come in pairs. These
// designate the live regions of the heap.
- private List collectLiveRegions() {
+ private List<Address> collectLiveRegions() {
// We want to iterate through all live portions of the heap, but
// do not want to abort the heap traversal prematurely if we find
// a problem (like an allocated but uninitialized object at the
// top of a generation). To do this we enumerate all generations'
// bottom and top regions, and factor in TLABs if necessary.
- // List<Address>. Addresses come in pairs.
- List liveRegions = new ArrayList();
+ // Addresses come in pairs.
+ List<Address> liveRegions = new ArrayList<>();
LiveRegionsCollector lrc = new LiveRegionsCollector(liveRegions);
CollectedHeap heap = VM.getVM().getUniverse().heap();
-
- if (heap instanceof GenCollectedHeap) {
- GenCollectedHeap genHeap = (GenCollectedHeap) heap;
- // Run through all generations, obtaining bottom-top pairs.
- for (int i = 0; i < genHeap.nGens(); i++) {
- Generation gen = genHeap.getGen(i);
- gen.spaceIterate(lrc, true);
- }
- } else if (heap instanceof ParallelScavengeHeap) {
- ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
- PSYoungGen youngGen = psh.youngGen();
- // Add eden space
- addLiveRegions("eden", youngGen.edenSpace().getLiveRegions(), liveRegions);
- // Add from-space but not to-space
- addLiveRegions("from", youngGen.fromSpace().getLiveRegions(), liveRegions);
- PSOldGen oldGen = psh.oldGen();
- addLiveRegions("old ", oldGen.objectSpace().getLiveRegions(), liveRegions);
- } else if (heap instanceof G1CollectedHeap) {
- G1CollectedHeap g1h = (G1CollectedHeap) heap;
- g1h.heapRegionIterate(lrc);
- } else if (heap instanceof ShenandoahHeap) {
- // Operation (currently) not supported with Shenandoah GC. Print
- // a warning and leave the list of live regions empty.
- System.err.println("Warning: Operation not supported with Shenandoah GC");
- } else if (heap instanceof ZCollectedHeap) {
- // Operation (currently) not supported with ZGC. Print
- // a warning and leave the list of live regions empty.
- System.err.println("Warning: Operation not supported with ZGC");
- } else if (heap instanceof EpsilonHeap) {
- EpsilonHeap eh = (EpsilonHeap) heap;
- liveRegions.add(eh.space().top());
- liveRegions.add(eh.space().bottom());
- } else {
- if (Assert.ASSERTS_ENABLED) {
- Assert.that(false, "Unexpected CollectedHeap type: " + heap.getClass().getName());
- }
- }
+ heap.liveRegionsIterate(lrc);
// If UseTLAB is enabled, snip out regions associated with TLABs'
// dead regions. Note that TLABs can be present in any generation.
@@ -440,11 +401,9 @@
return liveRegions;
}
- private void sortLiveRegions(List liveRegions) {
- Collections.sort(liveRegions, new Comparator() {
- public int compare(Object o1, Object o2) {
- Address a1 = (Address) o1;
- Address a2 = (Address) o2;
+ private void sortLiveRegions(List<Address> liveRegions) {
+ Collections.sort(liveRegions, new Comparator<Address>() {
+ public int compare(Address a1, Address a2) {
if (AddressOps.lt(a1, a2)) {
return -1;
} else if (AddressOps.gt(a1, a2)) {