< prev index next >

src/java.management/share/classes/com/sun/management/GcInfo.java

Print this page




  35 import java.util.Map;
  36 import java.util.List;
  37 import sun.management.GcInfoCompositeData;
  38 import sun.management.GcInfoBuilder;
  39 
  40 /**
  41  * Garbage collection information.  It contains the following
  42  * information for one garbage collection as well as GC-specific
  43  * attributes:
  44  * <blockquote>
  45  * <ul>
  46  *   <li>Start time</li>
  47  *   <li>End time</li>
  48  *   <li>Duration</li>
  49  *   <li>Memory usage before the collection starts</li>
  50  *   <li>Memory usage after the collection ends</li>
  51  * </ul>
  52  * </blockquote>
  53  *
  54  * <p>
  55  * <tt>GcInfo</tt> is a {@link CompositeData CompositeData}
  56  * The GC-specific attributes can be obtained via the CompositeData
  57  * interface.  This is a historical relic, and other classes should
  58  * not copy this pattern.  Use {@link CompositeDataView} instead.
  59  *
  60  * <h4>MXBean Mapping</h4>
  61  * <tt>GcInfo</tt> is mapped to a {@link CompositeData CompositeData}
  62  * with attributes as specified in the {@link #from from} method.
  63  *
  64  * @author  Mandy Chung
  65  * @since   1.5
  66  */
  67 @jdk.Exported
  68 public class GcInfo implements CompositeData, CompositeDataView {
  69     private final long index;
  70     private final long startTime;
  71     private final long endTime;
  72     private final Map<String, MemoryUsage> usageBeforeGc;
  73     private final Map<String, MemoryUsage> usageAfterGc;
  74     private final Object[] extAttributes;
  75     private final CompositeData cdata;
  76     private final GcInfoBuilder builder;
  77 
  78     private GcInfo(GcInfoBuilder builder,
  79                    long index, long startTime, long endTime,
  80                    MemoryUsage[] muBeforeGc,
  81                    MemoryUsage[] muAfterGc,


 135      *
 136      * @return the end time of this GC.
 137      */
 138     public long getEndTime() {
 139         return endTime;
 140     }
 141 
 142     /**
 143      * Returns the elapsed time of this GC in milliseconds.
 144      *
 145      * @return the elapsed time of this GC in milliseconds.
 146      */
 147     public long getDuration() {
 148         return endTime - startTime;
 149     }
 150 
 151     /**
 152      * Returns the memory usage of all memory pools
 153      * at the beginning of this GC.
 154      * This method returns
 155      * a <tt>Map</tt> of the name of a memory pool
 156      * to the memory usage of the corresponding
 157      * memory pool before GC starts.
 158      *
 159      * @return a <tt>Map</tt> of memory pool names to the memory
 160      * usage of a memory pool before GC starts.
 161      */
 162     public Map<String, MemoryUsage> getMemoryUsageBeforeGc() {
 163         return Collections.unmodifiableMap(usageBeforeGc);
 164     }
 165 
 166     /**
 167      * Returns the memory usage of all memory pools
 168      * at the end of this GC.
 169      * This method returns
 170      * a <tt>Map</tt> of the name of a memory pool
 171      * to the memory usage of the corresponding
 172      * memory pool when GC finishes.
 173      *
 174      * @return a <tt>Map</tt> of memory pool names to the memory
 175      * usage of a memory pool when GC finishes.
 176      */
 177     public Map<String, MemoryUsage> getMemoryUsageAfterGc() {
 178         return Collections.unmodifiableMap(usageAfterGc);
 179     }
 180 
 181    /**
 182      * Returns a <tt>GcInfo</tt> object represented by the
 183      * given <tt>CompositeData</tt>. The given
 184      * <tt>CompositeData</tt> must contain
 185      * all the following attributes:
 186      *
 187      * <p>
 188      * <blockquote>
 189      * <table border>
 190      * <tr>
 191      *   <th align=left>Attribute Name</th>
 192      *   <th align=left>Type</th>
 193      * </tr>
 194      * <tr>
 195      *   <td>index</td>
 196      *   <td><tt>java.lang.Long</tt></td>
 197      * </tr>
 198      * <tr>
 199      *   <td>startTime</td>
 200      *   <td><tt>java.lang.Long</tt></td>
 201      * </tr>
 202      * <tr>
 203      *   <td>endTime</td>
 204      *   <td><tt>java.lang.Long</tt></td>
 205      * </tr>
 206      * <tr>
 207      *   <td>memoryUsageBeforeGc</td>
 208      *   <td><tt>javax.management.openmbean.TabularData</tt></td>
 209      * </tr>
 210      * <tr>
 211      *   <td>memoryUsageAfterGc</td>
 212      *   <td><tt>javax.management.openmbean.TabularData</tt></td>
 213      * </tr>
 214      * </table>
 215      * </blockquote>
 216      *
 217      * @throws IllegalArgumentException if <tt>cd</tt> does not
 218      *   represent a <tt>GcInfo</tt> object with the attributes
 219      *   described above.
 220      *
 221      * @return a <tt>GcInfo</tt> object represented by <tt>cd</tt>
 222      * if <tt>cd</tt> is not <tt>null</tt>; <tt>null</tt> otherwise.
 223      */
 224     public static GcInfo from(CompositeData cd) {
 225         if (cd == null) {
 226             return null;
 227         }
 228 
 229         if (cd instanceof GcInfoCompositeData) {
 230             return ((GcInfoCompositeData) cd).getGcInfo();
 231         } else {
 232             return new GcInfo(cd);
 233         }
 234 
 235     }
 236 
 237     // Implementation of the CompositeData interface
 238     public boolean containsKey(String key) {
 239         return cdata.containsKey(key);
 240     }
 241 
 242     public boolean containsValue(Object value) {


 255         return cdata.getAll(keys);
 256     }
 257 
 258     public CompositeType getCompositeType() {
 259         return cdata.getCompositeType();
 260     }
 261 
 262     public int hashCode() {
 263         return cdata.hashCode();
 264     }
 265 
 266     public String toString() {
 267         return cdata.toString();
 268     }
 269 
 270     public Collection<?> values() {
 271         return cdata.values();
 272     }
 273 
 274     /**
 275      * <p>Return the {@code CompositeData} representation of this
 276      * {@code GcInfo}, including any GC-specific attributes.  The
 277      * returned value will have at least all the attributes described
 278      * in the {@link #from(CompositeData) from} method, plus optionally
 279      * other attributes.
 280      *
 281      * @param ct the {@code CompositeType} that the caller expects.
 282      * This parameter is ignored and can be null.
 283      *
 284      * @return the {@code CompositeData} representation.
 285      */
 286     public CompositeData toCompositeData(CompositeType ct) {
 287         return cdata;
 288     }
 289 }


  35 import java.util.Map;
  36 import java.util.List;
  37 import sun.management.GcInfoCompositeData;
  38 import sun.management.GcInfoBuilder;
  39 
  40 /**
  41  * Garbage collection information.  It contains the following
  42  * information for one garbage collection as well as GC-specific
  43  * attributes:
  44  * <blockquote>
  45  * <ul>
  46  *   <li>Start time</li>
  47  *   <li>End time</li>
  48  *   <li>Duration</li>
  49  *   <li>Memory usage before the collection starts</li>
  50  *   <li>Memory usage after the collection ends</li>
  51  * </ul>
  52  * </blockquote>
  53  *
  54  * <p>
  55  * {@code GcInfo} is a {@link CompositeData CompositeData}
  56  * The GC-specific attributes can be obtained via the CompositeData
  57  * interface.  This is a historical relic, and other classes should
  58  * not copy this pattern.  Use {@link CompositeDataView} instead.
  59  *
  60  * <h4>MXBean Mapping</h4>
  61  * {@code GcInfo} is mapped to a {@link CompositeData CompositeData}
  62  * with attributes as specified in the {@link #from from} method.
  63  *
  64  * @author  Mandy Chung
  65  * @since   1.5
  66  */
  67 @jdk.Exported
  68 public class GcInfo implements CompositeData, CompositeDataView {
  69     private final long index;
  70     private final long startTime;
  71     private final long endTime;
  72     private final Map<String, MemoryUsage> usageBeforeGc;
  73     private final Map<String, MemoryUsage> usageAfterGc;
  74     private final Object[] extAttributes;
  75     private final CompositeData cdata;
  76     private final GcInfoBuilder builder;
  77 
  78     private GcInfo(GcInfoBuilder builder,
  79                    long index, long startTime, long endTime,
  80                    MemoryUsage[] muBeforeGc,
  81                    MemoryUsage[] muAfterGc,


 135      *
 136      * @return the end time of this GC.
 137      */
 138     public long getEndTime() {
 139         return endTime;
 140     }
 141 
 142     /**
 143      * Returns the elapsed time of this GC in milliseconds.
 144      *
 145      * @return the elapsed time of this GC in milliseconds.
 146      */
 147     public long getDuration() {
 148         return endTime - startTime;
 149     }
 150 
 151     /**
 152      * Returns the memory usage of all memory pools
 153      * at the beginning of this GC.
 154      * This method returns
 155      * a {@code Map} of the name of a memory pool
 156      * to the memory usage of the corresponding
 157      * memory pool before GC starts.
 158      *
 159      * @return a {@code Map} of memory pool names to the memory
 160      * usage of a memory pool before GC starts.
 161      */
 162     public Map<String, MemoryUsage> getMemoryUsageBeforeGc() {
 163         return Collections.unmodifiableMap(usageBeforeGc);
 164     }
 165 
 166     /**
 167      * Returns the memory usage of all memory pools
 168      * at the end of this GC.
 169      * This method returns
 170      * a {@code Map} of the name of a memory pool
 171      * to the memory usage of the corresponding
 172      * memory pool when GC finishes.
 173      *
 174      * @return a {@code Map} of memory pool names to the memory
 175      * usage of a memory pool when GC finishes.
 176      */
 177     public Map<String, MemoryUsage> getMemoryUsageAfterGc() {
 178         return Collections.unmodifiableMap(usageAfterGc);
 179     }
 180 
 181    /**
 182      * Returns a {@code GcInfo} object represented by the
 183      * given {@code CompositeData}. The given
 184      * {@code CompositeData} must contain
 185      * all the following attributes:
 186      *

 187      * <blockquote>
 188      * <table border>
 189      * <tr>
 190      *   <th align=left>Attribute Name</th>
 191      *   <th align=left>Type</th>
 192      * </tr>
 193      * <tr>
 194      *   <td>index</td>
 195      *   <td>{@code java.lang.Long}</td>
 196      * </tr>
 197      * <tr>
 198      *   <td>startTime</td>
 199      *   <td>{@code java.lang.Long}</td>
 200      * </tr>
 201      * <tr>
 202      *   <td>endTime</td>
 203      *   <td>{@code java.lang.Long}</td>
 204      * </tr>
 205      * <tr>
 206      *   <td>memoryUsageBeforeGc</td>
 207      *   <td>{@code javax.management.openmbean.TabularData}</td>
 208      * </tr>
 209      * <tr>
 210      *   <td>memoryUsageAfterGc</td>
 211      *   <td>{@code javax.management.openmbean.TabularData}</td>
 212      * </tr>
 213      * </table>
 214      * </blockquote>
 215      *
 216      * @throws IllegalArgumentException if {@code cd} does not
 217      *   represent a {@code GcInfo} object with the attributes
 218      *   described above.
 219      *
 220      * @return a {@code GcInfo} object represented by {@code cd}
 221      * if {@code cd} is not {@code null}; {@code null} otherwise.
 222      */
 223     public static GcInfo from(CompositeData cd) {
 224         if (cd == null) {
 225             return null;
 226         }
 227 
 228         if (cd instanceof GcInfoCompositeData) {
 229             return ((GcInfoCompositeData) cd).getGcInfo();
 230         } else {
 231             return new GcInfo(cd);
 232         }
 233 
 234     }
 235 
 236     // Implementation of the CompositeData interface
 237     public boolean containsKey(String key) {
 238         return cdata.containsKey(key);
 239     }
 240 
 241     public boolean containsValue(Object value) {


 254         return cdata.getAll(keys);
 255     }
 256 
 257     public CompositeType getCompositeType() {
 258         return cdata.getCompositeType();
 259     }
 260 
 261     public int hashCode() {
 262         return cdata.hashCode();
 263     }
 264 
 265     public String toString() {
 266         return cdata.toString();
 267     }
 268 
 269     public Collection<?> values() {
 270         return cdata.values();
 271     }
 272 
 273     /**
 274      * Return the {@code CompositeData} representation of this
 275      * {@code GcInfo}, including any GC-specific attributes.  The
 276      * returned value will have at least all the attributes described
 277      * in the {@link #from(CompositeData) from} method, plus optionally
 278      * other attributes.
 279      *
 280      * @param ct the {@code CompositeType} that the caller expects.
 281      * This parameter is ignored and can be null.
 282      *
 283      * @return the {@code CompositeData} representation.
 284      */
 285     public CompositeData toCompositeData(CompositeType ct) {
 286         return cdata;
 287     }
 288 }
< prev index next >