1 /* 2 * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 package sun.jvm.hotspot.gc_implementation.shenandoah; 25 26 import sun.jvm.hotspot.memory.ContiguousSpace; 27 import sun.jvm.hotspot.types.CIntegerField; 28 import sun.jvm.hotspot.runtime.VM; 29 import sun.jvm.hotspot.types.Type; 30 import sun.jvm.hotspot.types.TypeDataBase; 31 import sun.jvm.hotspot.debugger.Address; 32 33 import java.util.Observable; 34 import java.util.Observer; 35 36 37 public class ShenandoahHeapRegion extends ContiguousSpace { 38 // static int RegionSizeBytes; 39 private static CIntegerField RegionSizeBytes; 40 private static CIntegerField State; 41 private static CIntegerField regionNumber; 42 43 private static int empty_uncommitted; 44 private static int empty_committed; 45 private static int regular; 46 private static int humongous_start; 47 private static int humongous_cont; 48 private static int pinned_humongous_start; 49 private static int cset; 50 private static int pinned; 51 private static int pinned_cset; 52 private static int trash; 53 54 static { 55 VM.registerVMInitializedObserver(new Observer() { 56 public void update(Observable o, Object data) { 57 initialize(VM.getVM().getTypeDataBase()); 58 } 59 }); 60 } 61 62 static private synchronized void initialize(TypeDataBase db) { 63 Type type = db.lookupType("ShenandoahHeapRegion"); 64 65 RegionSizeBytes = type.getCIntegerField("RegionSizeBytes"); 66 State = type.getCIntegerField("_state"); 67 regionNumber = type.getCIntegerField("_region_number"); 68 69 empty_uncommitted = db.lookupIntConstant("ShenandoahHeapRegion::_empty_uncommitted"); 70 empty_committed = db.lookupIntConstant("ShenandoahHeapRegion::_empty_committed"); 71 regular = db.lookupIntConstant("ShenandoahHeapRegion::_regular"); 72 humongous_start = db.lookupIntConstant("ShenandoahHeapRegion::_humongous_start"); 73 humongous_cont = db.lookupIntConstant("ShenandoahHeapRegion::_humongous_cont"); 74 pinned_humongous_start = db.lookupIntConstant("ShenandoahHeapRegion::_pinned_humongous_start"); 75 cset = db.lookupIntConstant("ShenandoahHeapRegion::_cset"); 76 pinned_cset = db.lookupIntConstant("ShenandoahHeapRegion::_pinned_cset"); 77 trash = db.lookupIntConstant("ShenandoahHeapRegion::_trash"); 78 } 79 80 public static long regionSizeBytes() { return RegionSizeBytes.getValue(); } 81 82 public long regionNumber() { return regionNumber.getValue(addr); } 83 84 public boolean isUncommitted() { return state() == empty_uncommitted; } 85 public boolean isEmpty() { return state() == empty_committed; } 86 public boolean isRegular() { return state() == regular; } 87 public boolean isHumongousStart() { return state() == humongous_start; } 88 public boolean isHumongousCont() { return state() == humongous_cont; } 89 public boolean isPinnedHumongous() { return state() == pinned_humongous_start; } 90 public boolean isCSet() { return state() == cset; } 91 public boolean isPinned() { return state() == pinned; } 92 public boolean isPinnedCset() { return state() == pinned_cset; } 93 public boolean isTrash() { return state() == trash; } 94 95 public ShenandoahHeapRegion(Address addr) { 96 super(addr); 97 } 98 99 public int state() { return (int)State.getValue(addr); } 100 }