1 /*
   2  * Copyright (c) 2011, 2015, 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.util.Observable;
  28 import java.util.Observer;
  29 
  30 import sun.jvm.hotspot.debugger.Address;
  31 import sun.jvm.hotspot.runtime.VM;
  32 import sun.jvm.hotspot.runtime.VMObject;
  33 import sun.jvm.hotspot.types.CIntegerField;
  34 import sun.jvm.hotspot.types.Type;
  35 import sun.jvm.hotspot.types.TypeDataBase;
  36 
  37 // Mirror class for G1MonitoringSupport.
  38 
  39 public class G1MonitoringSupport extends VMObject {
  40     // size_t _eden_space_committed;
  41     static private CIntegerField edenSpaceCommittedField;
  42     // size_t _eden_space_used;
  43     static private CIntegerField edenSpaceUsedField;
  44     // size_t _survivor_space_committed;
  45     static private CIntegerField survivorSpaceCommittedField;
  46     // size_t _survivor_space_used;
  47     static private CIntegerField survivorSpaceUsedField;
  48     // size_t _old_gen_committed;
  49     static private CIntegerField oldGenCommittedField;
  50     // size_t _old_gen_used;
  51     static private CIntegerField oldGenUsedField;
  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("G1MonitoringSupport");
  63 
  64         edenSpaceCommittedField = type.getCIntegerField("_eden_space_committed");
  65         edenSpaceUsedField = type.getCIntegerField("_eden_space_used");
  66         survivorSpaceCommittedField = type.getCIntegerField("_survivor_space_committed");
  67         survivorSpaceUsedField = type.getCIntegerField("_survivor_space_used");
  68         oldGenCommittedField = type.getCIntegerField("_old_gen_committed");
  69         oldGenUsedField = type.getCIntegerField("_old_gen_used");
  70     }
  71 
  72     public long edenSpaceCommitted() {
  73         return edenSpaceCommittedField.getValue(addr);
  74     }
  75 
  76     public long edenSpaceUsed() {
  77         return edenSpaceUsedField.getValue(addr);
  78     }
  79 
  80     public long edenSpaceRegionNum() {
  81         return edenSpaceUsed() / HeapRegion.grainBytes();
  82     }
  83 
  84     public long survivorSpaceCommitted() {
  85         return survivorSpaceCommittedField.getValue(addr);
  86     }
  87 
  88     public long survivorSpaceUsed() {
  89         return survivorSpaceUsedField.getValue(addr);
  90     }
  91 
  92     public long survivorSpaceRegionNum() {
  93         return survivorSpaceUsed() / HeapRegion.grainBytes();
  94     }
  95 
  96     public long oldGenCommitted() {
  97         return oldGenCommittedField.getValue(addr);
  98     }
  99 
 100     public long oldGenUsed() {
 101         return oldGenUsedField.getValue(addr);
 102     }
 103 
 104     public G1MonitoringSupport(Address addr) {
 105         super(addr);
 106     }
 107 }