1 /* 2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 package sun.jvm.hotspot.gc.z; 26 27 import java.io.PrintStream; 28 29 import sun.jvm.hotspot.debugger.Address; 30 import sun.jvm.hotspot.debugger.OopHandle; 31 import sun.jvm.hotspot.gc.shared.CollectedHeap; 32 import sun.jvm.hotspot.gc.shared.CollectedHeapName; 33 import sun.jvm.hotspot.gc.shared.LiveRegionsClosure; 34 import sun.jvm.hotspot.runtime.VM; 35 import sun.jvm.hotspot.runtime.VMObjectFactory; 36 import sun.jvm.hotspot.types.Type; 37 import sun.jvm.hotspot.types.TypeDataBase; 38 import sun.jvm.hotspot.utilities.BitMapInterface; 39 40 // Mirror class for ZCollectedHeap. 41 42 public class ZCollectedHeap extends CollectedHeap { 43 private static long zHeapFieldOffset; 44 45 static { 46 VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); 47 } 48 49 private static synchronized void initialize(TypeDataBase db) { 50 Type type = db.lookupType("ZCollectedHeap"); 51 52 zHeapFieldOffset = type.getAddressField("_heap").getOffset(); 53 } 54 55 public ZHeap heap() { 56 Address heapAddr = addr.addOffsetTo(zHeapFieldOffset); 57 return (ZHeap)VMObjectFactory.newObject(ZHeap.class, heapAddr); 58 } 59 60 @Override 61 public CollectedHeapName kind() { 62 return CollectedHeapName.Z; 63 } 64 65 @Override 66 public void printOn(PrintStream tty) { 67 heap().printOn(tty); 68 } 69 70 public ZCollectedHeap(Address addr) { 71 super(addr); 72 } 73 74 @Override 75 public long capacity() { 76 return heap().capacity(); 77 } 78 79 @Override 80 public long used() { 81 return heap().used(); 82 } 83 84 85 86 private OopHandle oop_load_barrier(Address oopAddress) { 87 oopAddress = ZBarrier.weak_barrier(oopAddress); 88 if (oopAddress == null) { 89 return null; 90 } 91 92 return oopAddress.addOffsetToAsOopHandle(0); 93 } 94 95 @Override 96 public OopHandle oop_load_at(OopHandle handle, long offset) { 97 assert(!VM.getVM().isCompressedOopsEnabled()); 98 99 Address oopAddress = handle.getAddressAt(offset); 100 101 return oop_load_barrier(oopAddress); 102 } 103 104 // addr can be either in heap or in native 105 @Override 106 public OopHandle oop_load_in_native(Address addr) { 107 Address oopAddress = addr.getAddressAt(0); 108 109 return oop_load_barrier(oopAddress); 110 } 111 112 public String oopAddressDescription(OopHandle handle) { 113 Address origOop = ZOop.to_address(handle); 114 Address loadBarrieredOop = ZBarrier.weak_barrier(origOop); 115 if (!origOop.equals(loadBarrieredOop)) { 116 return origOop + " (" + loadBarrieredOop.toString() + ")"; 117 } else { 118 return handle.toString(); 119 } 120 } 121 122 @Override 123 public void liveRegionsIterate(LiveRegionsClosure closure) { 124 // Operation (currently) not supported with ZGC. Print 125 // a warning and leave the list of live regions empty. 126 System.err.println("Warning: Operation not supported with ZGC"); 127 } 128 129 @Override 130 public BitMapInterface createBitMap(long size) { 131 // Ignores the size 132 return new ZExternalBitMap(this); 133 } 134 }