< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -27,48 +27,65 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Observable;
 import java.util.Observer;
 import sun.jvm.hotspot.debugger.Address;
+import sun.jvm.hotspot.debugger.OopHandle;
 import sun.jvm.hotspot.gc.shared.CompactibleSpace;
 import sun.jvm.hotspot.memory.MemRegion;
 import sun.jvm.hotspot.runtime.VM;
+import sun.jvm.hotspot.runtime.VMObjectFactory;
 import sun.jvm.hotspot.types.AddressField;
 import sun.jvm.hotspot.types.CIntegerField;
 import sun.jvm.hotspot.types.Type;
 import sun.jvm.hotspot.types.TypeDataBase;
+import sun.jvm.hotspot.utilities.Assert;
 
 // Mirror class for HeapRegion. Currently we don't actually include
 // any of its fields but only iterate over it.
 
 public class HeapRegion extends CompactibleSpace {
     // static int GrainBytes;
     static private CIntegerField grainBytesField;
     static private AddressField topField;
+    private static long typeFieldOffset;
+    private static long pointerSize;
+
+    private HeapRegionType type;
 
     static {
         VM.registerVMInitializedObserver(new Observer() {
                 public void update(Observable o, Object data) {
                     initialize(VM.getVM().getTypeDataBase());
                 }
             });
     }
 
     static private synchronized void initialize(TypeDataBase db) {
-        Type type = db.lookupType("HeapRegion");
+        Type t = db.lookupType("HeapRegion");
 
-        grainBytesField = type.getCIntegerField("GrainBytes");
-        topField = type.getAddressField("_top");
+        grainBytesField = t.getCIntegerField("GrainBytes");
+        topField = t.getAddressField("_top");
+        typeFieldOffset = t.getField("_type").getOffset();
 
+        pointerSize = db.lookupType("HeapRegion*").getSize();
     }
 
     static public long grainBytes() {
         return grainBytesField.getValue();
     }
 
     public HeapRegion(Address addr) {
         super(addr);
+
+        if (Assert.ASSERTS_ENABLED) {
+            Assert.that(addr instanceof OopHandle, "addr should be OopHandle");
+        }
+
+        Address typeAddr = addr.addOffsetToAsOopHandle(typeFieldOffset);
+        type = (HeapRegionType)VMObjectFactory.newObject(
+                                                HeapRegionType.class, typeAddr);
     }
 
     public Address top() {
         return topField.getValue(addr);
     }

@@ -87,6 +104,30 @@
 
     @Override
     public long free() {
         return end().minus(top());
     }
+
+    public boolean isFree() {
+        return type.isFree();
+    }
+
+    public boolean isYoung() {
+        return type.isYoung();
+    }
+
+    public boolean isHumongous() {
+        return type.isHumongous();
+    }
+
+    public boolean isPinned() {
+        return type.isPinned();
+    }
+
+    public boolean isOld() {
+        return type.isOld();
+    }
+
+    public static long getPointerSize() {
+        return pointerSize;
+    }
 }
< prev index next >