001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package gnu.java.lang.management;
014
015import java.lang.management.MemoryUsage;
016
017import org.jikesrvm.mm.mminterface.JMXSupport;
018
019final class VMMemoryMXBeanImpl {
020
021  /**
022   * Return the sum of the usage in all heap-based
023   * pools.
024   *
025   * @return the memory usage for heap-based pools.
026   */
027  static MemoryUsage getHeapMemoryUsage() {
028    return getUsage(false);
029  }
030
031  /**
032   * Return the sum of the usage in all non-heap-based
033   * pools.
034   *
035   * @return the memory usage for non-heap-based pools.
036   */
037  static MemoryUsage getNonHeapMemoryUsage() {
038    return getUsage(true);
039  }
040
041  /**
042   * Return the number of objects waiting for finalization.
043   *
044   * @return the number of finalizable objects.
045   */
046  static int getObjectPendingFinalizationCount() {
047    return JMXSupport.getObjectPendingFinalizationCount();
048  }
049
050  /**
051   * Returns true if some level of verbosity is on.
052   *
053   * @return {@code true} if verbosity is greater than 0.
054   */
055  static boolean isVerbose() {
056    return JMXSupport.isMMTkVerbose();
057  }
058
059  /**
060   * Turns on or off verbosity.  MMTk has a more detailed
061   * level of verbosity, so we simply map true to level 1.
062   *
063   * @param verbose the new verbosity setting.
064   */
065  static void setVerbose(boolean verbose) {
066    JMXSupport.setMMTkVerbose(verbose);
067  }
068
069  /**
070   * Totals the memory usage from all the pools that are either
071   * mortal or immortal.
072   * <p>
073   * Non-heap pools are immortal, heap pools are non-immortal.
074   *
075   * @param immortal true if the spaces counted should be immortal.
076   * @return the memory usage overall.
077   */
078  private static MemoryUsage getUsage(boolean immortal) {
079    return JMXSupport.getUsage(immortal);
080  }
081
082}