< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/HeapRegion.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 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.g1;
  26 
  27 import java.io.PrintStream;
  28 import java.util.ArrayList;
  29 import java.util.List;
  30 import java.util.Observable;
  31 import java.util.Observer;
  32 import sun.jvm.hotspot.debugger.Address;
  33 import sun.jvm.hotspot.debugger.OopHandle;
  34 import sun.jvm.hotspot.gc.shared.CompactibleSpace;

  35 import sun.jvm.hotspot.memory.MemRegion;
  36 import sun.jvm.hotspot.runtime.VM;
  37 import sun.jvm.hotspot.runtime.VMObjectFactory;
  38 import sun.jvm.hotspot.types.AddressField;
  39 import sun.jvm.hotspot.types.CIntegerField;
  40 import sun.jvm.hotspot.types.Type;
  41 import sun.jvm.hotspot.types.TypeDataBase;
  42 
  43 // Mirror class for HeapRegion. Currently we don't actually include
  44 // any of its fields but only iterate over it.
  45 
  46 public class HeapRegion extends CompactibleSpace {
  47     // static int GrainBytes;
  48     static private CIntegerField grainBytesField;
  49     static private AddressField topField;
  50     private static long typeFieldOffset;
  51     private static long pointerSize;
  52 
  53     private HeapRegionType type;
  54 
  55     static {
  56         VM.registerVMInitializedObserver(new Observer() {
  57                 public void update(Observable o, Object data) {
  58                     initialize(VM.getVM().getTypeDataBase());
  59                 }
  60             });
  61     }
  62 
  63     static private synchronized void initialize(TypeDataBase db) {
  64         Type type = db.lookupType("HeapRegion");
  65 
  66         grainBytesField = type.getCIntegerField("GrainBytes");


  69 
  70         pointerSize = db.lookupType("HeapRegion*").getSize();
  71     }
  72 
  73     static public long grainBytes() {
  74         return grainBytesField.getValue();
  75     }
  76 
  77     public HeapRegion(Address addr) {
  78         super(addr);
  79         Address typeAddr = (addr instanceof OopHandle) ? addr.addOffsetToAsOopHandle(typeFieldOffset)
  80                                                        : addr.addOffsetTo(typeFieldOffset);
  81         type = (HeapRegionType)VMObjectFactory.newObject(HeapRegionType.class, typeAddr);
  82     }
  83 
  84     public Address top() {
  85         return topField.getValue(addr);
  86     }
  87 
  88     @Override
  89     public List getLiveRegions() {
  90         List res = new ArrayList();
  91         res.add(new MemRegion(bottom(), top()));
  92         return res;
  93     }
  94 
  95     @Override
  96     public long used() {
  97         return top().minus(bottom());
  98     }
  99 
 100     @Override
 101     public long free() {
 102         return end().minus(top());
 103     }
 104 
 105     public boolean isFree() {
 106         return type.isFree();
 107     }
 108 
 109     public boolean isYoung() {
 110         return type.isYoung();


   1 /*
   2  * Copyright (c) 2011, 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.g1;
  26 
  27 import java.io.PrintStream;
  28 import java.util.ArrayList;
  29 import java.util.List;
  30 import java.util.Observable;
  31 import java.util.Observer;
  32 import sun.jvm.hotspot.debugger.Address;
  33 import sun.jvm.hotspot.debugger.OopHandle;
  34 import sun.jvm.hotspot.gc.shared.CompactibleSpace;
  35 import sun.jvm.hotspot.gc.shared.LiveRegionsProvider;
  36 import sun.jvm.hotspot.memory.MemRegion;
  37 import sun.jvm.hotspot.runtime.VM;
  38 import sun.jvm.hotspot.runtime.VMObjectFactory;
  39 import sun.jvm.hotspot.types.AddressField;
  40 import sun.jvm.hotspot.types.CIntegerField;
  41 import sun.jvm.hotspot.types.Type;
  42 import sun.jvm.hotspot.types.TypeDataBase;
  43 
  44 // Mirror class for HeapRegion. Currently we don't actually include
  45 // any of its fields but only iterate over it.
  46 
  47 public class HeapRegion extends CompactibleSpace implements LiveRegionsProvider {
  48     // static int GrainBytes;
  49     static private CIntegerField grainBytesField;
  50     static private AddressField topField;
  51     private static long typeFieldOffset;
  52     private static long pointerSize;
  53 
  54     private HeapRegionType type;
  55 
  56     static {
  57         VM.registerVMInitializedObserver(new Observer() {
  58                 public void update(Observable o, Object data) {
  59                     initialize(VM.getVM().getTypeDataBase());
  60                 }
  61             });
  62     }
  63 
  64     static private synchronized void initialize(TypeDataBase db) {
  65         Type type = db.lookupType("HeapRegion");
  66 
  67         grainBytesField = type.getCIntegerField("GrainBytes");


  70 
  71         pointerSize = db.lookupType("HeapRegion*").getSize();
  72     }
  73 
  74     static public long grainBytes() {
  75         return grainBytesField.getValue();
  76     }
  77 
  78     public HeapRegion(Address addr) {
  79         super(addr);
  80         Address typeAddr = (addr instanceof OopHandle) ? addr.addOffsetToAsOopHandle(typeFieldOffset)
  81                                                        : addr.addOffsetTo(typeFieldOffset);
  82         type = (HeapRegionType)VMObjectFactory.newObject(HeapRegionType.class, typeAddr);
  83     }
  84 
  85     public Address top() {
  86         return topField.getValue(addr);
  87     }
  88 
  89     @Override
  90     public List<MemRegion> getLiveRegions() {
  91         List<MemRegion> res = new ArrayList<>();
  92         res.add(new MemRegion(bottom(), top()));
  93         return res;
  94     }
  95 
  96     @Override
  97     public long used() {
  98         return top().minus(bottom());
  99     }
 100 
 101     @Override
 102     public long free() {
 103         return end().minus(top());
 104     }
 105 
 106     public boolean isFree() {
 107         return type.isFree();
 108     }
 109 
 110     public boolean isYoung() {
 111         return type.isYoung();


< prev index next >