--- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeapName.java 2018-11-30 10:22:09.608812474 +0100 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeapName.java 2018-11-30 10:22:09.458814113 +0100 @@ -37,6 +37,7 @@ public static final CollectedHeapName G1 = new CollectedHeapName("G1"); public static final CollectedHeapName EPSILON = new CollectedHeapName("Epsilon"); public static final CollectedHeapName Z = new CollectedHeapName("Z"); + public static final CollectedHeapName SHENANDOAH = new CollectedHeapName("Shenandoah"); public String toString() { return name; --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeap.java 2018-11-30 10:22:09.672811775 +0100 @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * 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.shenandoah; + +import sun.jvm.hotspot.gc.shared.CollectedHeap; +import sun.jvm.hotspot.gc.shared.CollectedHeapName; +import sun.jvm.hotspot.debugger.Address; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.runtime.VMObjectFactory; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; +import sun.jvm.hotspot.memory.MemRegion; +import sun.jvm.hotspot.types.CIntegerField; +import sun.jvm.hotspot.types.AddressField; +import sun.jvm.hotspot.gc.shared.SpaceClosure; +import java.io.PrintStream; +import java.util.Iterator; +import java.util.Observable; +import java.util.Observer; + +public class ShenandoahHeap extends CollectedHeap { + static private CIntegerField numRegions; + static private CIntegerField usedRegions; + static private CIntegerField committedRegions; + static private AddressField regionsField; + 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("ShenandoahHeap"); + numRegions = type.getCIntegerField("_num_regions"); + usedRegions = type.getCIntegerField("_used"); + committedRegions = type.getCIntegerField("_committed"); + + regionsField = type.getAddressField("_regions"); + } + + @Override + public CollectedHeapName kind() { + return CollectedHeapName.SHENANDOAH; + } + + public long numOfRegions() { + return numRegions.getValue(addr); + } + + public long used() { + return usedRegions.getValue(addr); + } + + public long committed() { + return committedRegions.getValue(addr); + } + + public void heapRegionIterate(sun.jvm.hotspot.gc.shared.SpaceClosure scl) { + int numRgns = (int)numRegions.getValue(addr); + for (int index = 0; index < numRgns; index ++) { + ShenandoahHeapRegion r = getRegion(index); + + // Walk live regions + if (!r.isTrash() && !r.isUncommitted() && !r.isEmpty()) { + scl.doSpace(r); + } + } + } + + @Override + public void printOn(PrintStream tty) { + MemRegion mr = reservedRegion(); + tty.print("Shenandoah heap"); + tty.print(" [" + mr.start() + ", " + mr.end() + "]"); + tty.println(" region size " + ShenandoahHeapRegion.regionSizeBytes() / 1024 + " K"); + } + + private ShenandoahHeapRegion getRegion(int index) { + Address regsAddr = regionsField.getValue(addr); + return (ShenandoahHeapRegion) VMObjectFactory.newObject(ShenandoahHeapRegion.class, + regsAddr.getAddressAt(index * VM.getVM().getAddressSize())); + } + + public ShenandoahHeap(Address addr) { + super(addr); + } +} --- /dev/null 2018-11-30 10:10:44.238550338 +0100 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shenandoah/ShenandoahHeapRegion.java 2018-11-30 10:22:09.917809099 +0100 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. + * + * 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.shenandoah; + +import sun.jvm.hotspot.gc.shared.ContiguousSpace; +import sun.jvm.hotspot.types.CIntegerField; +import sun.jvm.hotspot.runtime.VM; +import sun.jvm.hotspot.types.Type; +import sun.jvm.hotspot.types.TypeDataBase; +import sun.jvm.hotspot.debugger.Address; + +import java.util.Observable; +import java.util.Observer; + + +public class ShenandoahHeapRegion extends ContiguousSpace { + private static CIntegerField RegionSizeBytes; + private static CIntegerField State; + private static CIntegerField regionNumber; + + private static int empty_uncommitted; + private static int empty_committed; + private static int regular; + private static int humongous_start; + private static int humongous_cont; + private static int pinned_humongous_start; + private static int cset; + private static int pinned; + private static int pinned_cset; + private static int trash; + + 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("ShenandoahHeapRegion"); + + RegionSizeBytes = type.getCIntegerField("RegionSizeBytes"); + State = type.getCIntegerField("_state"); + regionNumber = type.getCIntegerField("_region_number"); + + empty_uncommitted = db.lookupIntConstant("ShenandoahHeapRegion::_empty_uncommitted"); + empty_committed = db.lookupIntConstant("ShenandoahHeapRegion::_empty_committed"); + regular = db.lookupIntConstant("ShenandoahHeapRegion::_regular"); + humongous_start = db.lookupIntConstant("ShenandoahHeapRegion::_humongous_start"); + humongous_cont = db.lookupIntConstant("ShenandoahHeapRegion::_humongous_cont"); + pinned_humongous_start = db.lookupIntConstant("ShenandoahHeapRegion::_pinned_humongous_start"); + cset = db.lookupIntConstant("ShenandoahHeapRegion::_cset"); + pinned_cset = db.lookupIntConstant("ShenandoahHeapRegion::_pinned_cset"); + trash = db.lookupIntConstant("ShenandoahHeapRegion::_trash"); + } + + public static long regionSizeBytes() { return RegionSizeBytes.getValue(); } + + public long regionNumber() { return regionNumber.getValue(addr); } + + public boolean isUncommitted() { return state() == empty_uncommitted; } + public boolean isEmpty() { return state() == empty_committed; } + public boolean isRegular() { return state() == regular; } + public boolean isHumongousStart() { return state() == humongous_start; } + public boolean isHumongousCont() { return state() == humongous_cont; } + public boolean isPinnedHumongous() { return state() == pinned_humongous_start; } + public boolean isCSet() { return state() == cset; } + public boolean isPinned() { return state() == pinned; } + public boolean isPinnedCset() { return state() == pinned_cset; } + public boolean isTrash() { return state() == trash; } + + public ShenandoahHeapRegion(Address addr) { + super(addr); + } + + public int state() { return (int)State.getValue(addr); } +} --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java 2018-11-30 10:22:10.314804761 +0100 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java 2018-11-30 10:22:10.157806477 +0100 @@ -36,6 +36,7 @@ import sun.jvm.hotspot.gc.parallel.ParallelScavengeHeap; import sun.jvm.hotspot.gc.serial.SerialHeap; import sun.jvm.hotspot.gc.shared.CollectedHeap; +import sun.jvm.hotspot.gc.shenandoah.ShenandoahHeap; import sun.jvm.hotspot.gc.z.ZCollectedHeap; import sun.jvm.hotspot.oops.Oop; import sun.jvm.hotspot.runtime.BasicType; @@ -100,6 +101,7 @@ addHeapTypeIfInDB(db, G1CollectedHeap.class); addHeapTypeIfInDB(db, EpsilonHeap.class); addHeapTypeIfInDB(db, ZCollectedHeap.class); + addHeapTypeIfInDB(db, ShenandoahHeap.class); mainThreadGroupField = type.getOopField("_main_thread_group"); systemThreadGroupField = type.getOopField("_system_thread_group"); --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java 2018-11-30 10:22:10.529802412 +0100 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java 2018-11-30 10:22:10.379804051 +0100 @@ -36,6 +36,7 @@ import sun.jvm.hotspot.gc.shared.*; import sun.jvm.hotspot.gc.epsilon.*; import sun.jvm.hotspot.gc.g1.*; +import sun.jvm.hotspot.gc.shenandoah.*; import sun.jvm.hotspot.gc.parallel.*; import sun.jvm.hotspot.gc.z.*; import sun.jvm.hotspot.memory.*; @@ -367,6 +368,10 @@ } 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. --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapSummary.java 2018-11-30 10:22:10.746800042 +0100 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapSummary.java 2018-11-30 10:22:10.595801691 +0100 @@ -29,6 +29,7 @@ import sun.jvm.hotspot.gc.g1.*; import sun.jvm.hotspot.gc.parallel.*; import sun.jvm.hotspot.gc.serial.*; +import sun.jvm.hotspot.gc.shenandoah.*; import sun.jvm.hotspot.gc.shared.*; import sun.jvm.hotspot.gc.z.*; import sun.jvm.hotspot.debugger.JVMDebugger; @@ -83,7 +84,11 @@ printValMB("MetaspaceSize = ", getFlagValue("MetaspaceSize", flagMap)); printValMB("CompressedClassSpaceSize = ", getFlagValue("CompressedClassSpaceSize", flagMap)); printValMB("MaxMetaspaceSize = ", getFlagValue("MaxMetaspaceSize", flagMap)); - printValMB("G1HeapRegionSize = ", HeapRegion.grainBytes()); + if (heap instanceof ShenandoahHeap) { + printValMB("ShenandoahRegionSize = ", ShenandoahHeapRegion.regionSizeBytes()); + } else { + printValMB("G1HeapRegionSize = ", HeapRegion.grainBytes()); + } System.out.println(); System.out.println("Heap Usage:"); @@ -126,6 +131,14 @@ printValMB("used = ", oldGen.used()); printValMB("free = ", oldFree); System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used"); + } else if (heap instanceof ShenandoahHeap) { + ShenandoahHeap sh = (ShenandoahHeap) heap; + long num_regions = sh.numOfRegions(); + System.out.println("Shenandoah Heap:"); + System.out.println(" regions = " + num_regions); + printValMB("capacity = ", num_regions * ShenandoahHeapRegion.regionSizeBytes()); + printValMB("used = ", sh.used()); + printValMB("committed = ", sh.committed()); } else if (heap instanceof EpsilonHeap) { EpsilonHeap eh = (EpsilonHeap) heap; printSpace(eh.space());