1 /*
   2  * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
   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.shenandoah;
  25 
  26 import sun.jvm.hotspot.gc.shared.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     private static CIntegerField RegionSizeBytes;
  39     private static CIntegerField State;
  40     private static CIntegerField regionNumber;
  41 
  42     private static int empty_uncommitted;
  43     private static int empty_committed;
  44     private static int regular;
  45     private static int humongous_start;
  46     private static int humongous_cont;
  47     private static int pinned_humongous_start;
  48     private static int cset;
  49     private static int pinned;
  50     private static int pinned_cset;
  51     private static int trash;
  52 
  53     static {
  54         VM.registerVMInitializedObserver(new Observer() {
  55             public void update(Observable o, Object data) {
  56                 initialize(VM.getVM().getTypeDataBase());
  57             }
  58         });
  59     }
  60 
  61     static private synchronized void initialize(TypeDataBase db) {
  62         Type type = db.lookupType("ShenandoahHeapRegion");
  63 
  64         RegionSizeBytes = type.getCIntegerField("RegionSizeBytes");
  65         State = type.getCIntegerField("_state");
  66         regionNumber = type.getCIntegerField("_region_number");
  67 
  68         empty_uncommitted = db.lookupIntConstant("ShenandoahHeapRegion::_empty_uncommitted");
  69         empty_committed = db.lookupIntConstant("ShenandoahHeapRegion::_empty_committed");
  70         regular = db.lookupIntConstant("ShenandoahHeapRegion::_regular");
  71         humongous_start = db.lookupIntConstant("ShenandoahHeapRegion::_humongous_start");
  72         humongous_cont = db.lookupIntConstant("ShenandoahHeapRegion::_humongous_cont");
  73         pinned_humongous_start = db.lookupIntConstant("ShenandoahHeapRegion::_pinned_humongous_start");
  74         cset = db.lookupIntConstant("ShenandoahHeapRegion::_cset");
  75         pinned_cset = db.lookupIntConstant("ShenandoahHeapRegion::_pinned_cset");
  76         trash = db.lookupIntConstant("ShenandoahHeapRegion::_trash");
  77     }
  78 
  79     public static long regionSizeBytes() { return RegionSizeBytes.getValue(); }
  80 
  81     public long regionNumber() { return regionNumber.getValue(addr); }
  82 
  83     public boolean isUncommitted()      { return state() == empty_uncommitted; }
  84     public boolean isEmpty()            { return state() == empty_committed; }
  85     public boolean isRegular()          { return state() == regular; }
  86     public boolean isHumongousStart()   { return state() == humongous_start; }
  87     public boolean isHumongousCont()    { return state() == humongous_cont;  }
  88     public boolean isPinnedHumongous()  { return state() == pinned_humongous_start; }
  89     public boolean isCSet()             { return state() == cset; }
  90     public boolean isPinned()           { return state() == pinned; }
  91     public boolean isPinnedCset()       { return state() == pinned_cset; }
  92     public boolean isTrash()            { return state() == trash; }
  93 
  94     public ShenandoahHeapRegion(Address addr) {
  95         super(addr);
  96     }
  97 
  98     public int state() { return (int)State.getValue(addr); }
  99 }