1 /* 2 * Copyright (c) 2017, 2018, 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.runtime.VM; 34 import sun.jvm.hotspot.runtime.VMObjectFactory; 35 import sun.jvm.hotspot.types.Type; 36 import sun.jvm.hotspot.types.TypeDataBase; 37 38 // Mirror class for ZCollectedHeap. 39 40 public class ZCollectedHeap extends CollectedHeap { 41 42 private static long zHeapFieldOffset; 43 44 static { 45 VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase())); 46 } 47 48 private static synchronized void initialize(TypeDataBase db) { 49 Type type = db.lookupType("ZCollectedHeap"); 50 51 zHeapFieldOffset = type.getAddressField("_heap").getOffset(); 52 } 53 54 public ZHeap heap() { 55 Address heapAddr = addr.addOffsetTo(zHeapFieldOffset); 56 return (ZHeap)VMObjectFactory.newObject(ZHeap.class, heapAddr); 57 } 58 59 @Override 60 public CollectedHeapName kind() { 61 return CollectedHeapName.Z; 62 } 63 64 @Override 65 public void printOn(PrintStream tty) { 66 heap().printOn(tty); 67 } 68 69 public ZCollectedHeap(Address addr) { 70 super(addr); 71 } 72 73 public OopHandle oop_load_at(OopHandle handle, long offset) { 74 assert(!VM.getVM().isCompressedOopsEnabled()); 75 76 Address oopAddress = handle.getAddressAt(offset); 77 78 oopAddress = ZBarrier.weak_barrier(oopAddress); 79 if (oopAddress == null) { 80 return null; 81 } 82 83 return oopAddress.addOffsetToAsOopHandle(0); 84 } 85 86 public String oopAddressDescription(OopHandle handle) { 87 Address origOop = ZOop.to_address(handle); 88 Address loadBarrieredOop = ZBarrier.weak_barrier(origOop); 89 if (!origOop.equals(loadBarrieredOop)) { 90 return origOop + " (" + loadBarrieredOop.toString() + ")"; 91 } else { 92 return handle.toString(); 93 } 94 } 95 }