--- old/src/hotspot/share/gc/z/vmStructs_z.hpp 2018-07-19 22:49:36.582520649 +0900 +++ new/src/hotspot/share/gc/z/vmStructs_z.hpp 2018-07-19 22:49:36.377519265 +0900 @@ -68,6 +68,8 @@ \ nonstatic_field(ZPage, _type, const uint8_t) \ nonstatic_field(ZPage, _virtual, const ZVirtualMemory) \ + volatile_nonstatic_field(ZPage, _top, uintptr_t) \ + volatile_nonstatic_field(ZPage, _refcount, uint32_t) \ nonstatic_field(ZPage, _forwarding, ZForwardingTable) \ \ nonstatic_field(ZPageAllocator, _physical, ZPhysicalMemoryManager) \ @@ -101,6 +103,7 @@ declare_constant(ZAddressOffsetShift) \ declare_constant(ZAddressOffsetBits) \ declare_constant(ZAddressOffsetMask) \ + declare_constant(ZAddressOffsetMax) \ declare_constant(ZAddressSpaceStart) #define VM_TYPES_ZGC(declare_type, declare_toplevel_type, declare_integer_type) \ --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZAddress.java 2018-07-19 22:49:37.149524477 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZAddress.java 2018-07-19 22:49:36.942523079 +0900 @@ -58,7 +58,7 @@ static Address address(long value) { VM vm = VM.getVM(); if (vm.getOS().equals("solaris") && vm.getCPU().equals("sparc")) { - value |= ZGlobals.ZAddressSpaceStart; + value |= ZGlobals.ZAddressSpaceStart.asLongValue(); } return ZOop.to_address(value); --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZAddressRangeMapForPageTable.java 2018-07-19 22:49:37.734528426 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZAddressRangeMapForPageTable.java 2018-07-19 22:49:37.526527022 +0900 @@ -60,9 +60,15 @@ return index; } + Address get(long index) { + return map().getAddressAt(index * VM.getVM().getBytesPerLong()); + } + Address get(Address addr) { - long index = index_for_addr(addr); + return get(index_for_addr(addr)); + } - return map().getAddressAt(index * VM.getVM().getBytesPerLong()); + long size() { + return ZGlobals.ZAddressOffsetMax >>> ZGlobals.ZPageSizeMinShift; } } --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZGlobals.java 2018-07-19 22:49:38.305532281 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZGlobals.java 2018-07-19 22:49:38.100530897 +0900 @@ -24,6 +24,7 @@ package sun.jvm.hotspot.gc.z; +import sun.jvm.hotspot.debugger.Address; import sun.jvm.hotspot.runtime.VM; import sun.jvm.hotspot.types.Field; import sun.jvm.hotspot.types.Type; @@ -54,9 +55,10 @@ // Pointer part of address public static long ZAddressOffsetBits; public static long ZAddressOffsetMask; + public static long ZAddressOffsetMax; // Address space start/end/size - public static long ZAddressSpaceStart; + public static Address ZAddressSpaceStart; static { VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); @@ -84,8 +86,10 @@ ZAddressOffsetBits = db.lookupLongConstant("ZAddressOffsetBits").longValue(); ZAddressOffsetMask = db.lookupLongConstant("ZAddressOffsetMask").longValue(); + ZAddressOffsetMax = db.lookupLongConstant("ZAddressOffsetMax").longValue(); - ZAddressSpaceStart = db.lookupLongConstant("ZAddressSpaceStart").longValue(); + ZAddressSpaceStart = VM.getVM().getDebugger().parseAddress( + "0x" + Long.toUnsignedString(db.lookupLongConstant("ZAddressSpaceStart").longValue(), 16)); } private static ZGlobalsForVMStructs instance() { --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZHeap.java 2018-07-19 22:49:38.876536136 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZHeap.java 2018-07-19 22:49:38.668534732 +0900 @@ -60,7 +60,7 @@ return (ZPageAllocator)VMObjectFactory.newObject(ZPageAllocator.class, pageAllocatorAddr); } - ZPageTable pageTable() { + public ZPageTable pageTable() { return (ZPageTable)VMObjectFactory.newObject(ZPageTable.class, addr.addOffsetTo(pageTableFieldOffset)); } --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPage.java 2018-07-19 22:49:39.449540005 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPage.java 2018-07-19 22:49:39.242538607 +0900 @@ -35,6 +35,8 @@ public class ZPage extends VMObject { private static CIntegerField typeField; private static long virtualFieldOffset; + private static CIntegerField topField; + private static CIntegerField refcountField; private static long forwardingFieldOffset; static { @@ -46,6 +48,8 @@ typeField = type.getCIntegerField("_type"); virtualFieldOffset = type.getField("_virtual").getOffset(); + topField = type.getCIntegerField("_top"); + refcountField = type.getCIntegerField("_refcount"); forwardingFieldOffset = type.getField("_forwarding").getOffset(); } @@ -65,10 +69,18 @@ return (ZForwardingTable)VMObjectFactory.newObject(ZForwardingTable.class, addr.addOffsetTo(forwardingFieldOffset)); } - private long start() { + public long start() { return virtual().start(); } + public long top() { + return topField.getJLong(addr); + } + + public int refcount() { + return topField.getJInt(addr); + } + Address forward_object(Address from) { // Lookup address in forwarding table long from_offset = ZAddress.offset(from); --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPageTable.java 2018-07-19 22:49:40.018543846 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZPageTable.java 2018-07-19 22:49:39.813542462 +0900 @@ -24,6 +24,8 @@ package sun.jvm.hotspot.gc.z; +import java.util.function.Consumer; + import sun.jvm.hotspot.debugger.Address; import sun.jvm.hotspot.runtime.VM; import sun.jvm.hotspot.runtime.VMObject; @@ -56,6 +58,10 @@ return new ZPageTableEntry(map().get(o)); } + private ZPageTableEntry getEntry(long index) { + return new ZPageTableEntry(map().get(index)); + } + ZPage get(Address o) { return getEntry(o).page(); } @@ -63,4 +69,18 @@ boolean is_relocating(Address o) { return getEntry(o).relocating(); } + + public void pageTableIterate(Consumer consumer) { + ZPage prev = null; + for (long index = 0L; index < map().size(); index++) { + var pageEntry = getEntry(index); + if (pageEntry.entry != null) { + var page = pageEntry.page(); + if (!page.equals(prev)) { + consumer.accept(page); + prev = page; + } + } + } + } } --- old/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java 2018-07-19 22:49:40.586547681 +0900 +++ new/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java 2018-07-19 22:49:40.380546290 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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,6 +37,7 @@ import sun.jvm.hotspot.gc.epsilon.*; import sun.jvm.hotspot.gc.g1.*; import sun.jvm.hotspot.gc.parallel.*; +import sun.jvm.hotspot.gc.z.*; import sun.jvm.hotspot.memory.*; import sun.jvm.hotspot.runtime.*; import sun.jvm.hotspot.types.*; @@ -443,6 +444,14 @@ EpsilonHeap eh = (EpsilonHeap) heap; liveRegions.add(eh.space().top()); liveRegions.add(eh.space().bottom()); + } else if (heap instanceof ZCollectedHeap) { + ZCollectedHeap zh = (ZCollectedHeap) heap; + zh.heap().pageTable().pageTableIterate(p -> { + if (p.refcount() > 0 ) { + liveRegions.add(ZGlobals.ZAddressSpaceStart.addOffsetTo(p.start())); + liveRegions.add(ZGlobals.ZAddressSpaceStart.addOffsetTo(p.top())); + } + }); } else { if (Assert.ASSERTS_ENABLED) { Assert.that(false, "Unexpected CollectedHeap type: " + heap.getClass().getName());