Java Code Examples for java.lang.management.MemoryType#HEAP

The following examples show how to use java.lang.management.MemoryType#HEAP . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hbase   File: MemorySizeUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return Pair of global memstore size and memory type(ie. on heap or off heap).
 */
public static Pair<Long, MemoryType> getGlobalMemStoreSize(Configuration conf) {
  long offheapMSGlobal = conf.getLong(OFFHEAP_MEMSTORE_SIZE_KEY, 0);// Size in MBs
  if (offheapMSGlobal > 0) {
    // Off heap memstore size has not relevance when MSLAB is turned OFF. We will go with making
    // this entire size split into Chunks and pooling them in MemstoreLABPoool. We dont want to
    // create so many on demand off heap chunks. In fact when this off heap size is configured, we
    // will go with 100% of this size as the pool size
    if (MemStoreLAB.isEnabled(conf)) {
      // We are in offheap Memstore use
      long globalMemStoreLimit = (long) (offheapMSGlobal * 1024 * 1024); // Size in bytes
      return new Pair<>(globalMemStoreLimit, MemoryType.NON_HEAP);
    } else {
      // Off heap max memstore size is configured with turning off MSLAB. It makes no sense. Do a
      // warn log and go with on heap memstore percentage. By default it will be 40% of Xmx
      LOG.warn("There is no relevance of configuring '" + OFFHEAP_MEMSTORE_SIZE_KEY + "' when '"
          + MemStoreLAB.USEMSLAB_KEY + "' is turned off."
          + " Going with on heap global memstore size ('" + MEMSTORE_SIZE_KEY + "')");
    }
  }
  return new Pair<>(getOnheapGlobalMemStoreSize(conf), MemoryType.HEAP);
}
 
Example 2
Source Project: ranger   File: RangerMetricsUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * collect the pool division of java
 */
protected Map<String, Object> getPoolDivision() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> RangerJVMMetricUtil.getPoolDivision()");
    }

    Map<String, Object> poolDivisionValues = new LinkedHashMap<>();
    for (MemoryPoolMXBean mpBean : ManagementFactory.getMemoryPoolMXBeans()) {
        if (mpBean.getType() == MemoryType.HEAP) {
            poolDivisionValues.put(mpBean.getName(), mpBean.getUsage());
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== RangerJVMMetricUtil.getPoolDivision()" + poolDivisionValues);
    }

    return poolDivisionValues;
}
 
Example 3
Source Project: gemfirexd-oss   File: HeapMemoryMonitor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the name of the memory pool MXBean provided matches a list of
 * known young generation pool names.
 * 
 * @param memoryPoolMXBean
 *          The memory pool MXBean to check.
 * @return True if the pool name matches a known young generation pool name,
 *         false otherwise.
 */
static boolean isEden(MemoryPoolMXBean memoryPoolMXBean) {
  if (memoryPoolMXBean.getType() != MemoryType.HEAP) {
    return false;
  }

  String name = memoryPoolMXBean.getName();

  return name.equals("Par Eden Space")  // Oracle ParNew with Concurrent Mark Sweep GC
      || name.equals("PS Eden Space")   // Oracle Parallel GC
      || name.equals("G1 Eden")         // Oracle G1 GC
      //|| name.equals("Nursery")       // BEA JRockit 1.5, 1.6 GC
      || name.equals("Eden Space")      // Hitachi 1.5 GC
      // Allow an unknown pool name to monitor
      || (HEAP_EDEN_POOL != null && name.equals(HEAP_EDEN_POOL));
}
 
Example 4
Source Project: dremio-oss   File: HeapMonitorThread.java    License: Apache License 2.0 6 votes vote down vote up
private void registerForNotifications() {
  // Register the listener with MemoryMXBean
  NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
  emitter.addNotificationListener(listener, null, null);

  // set collection usage threshold.
  for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
    if (pool.getType() == MemoryType.HEAP &&
      pool.isUsageThresholdSupported() &&
      pool.isCollectionUsageThresholdSupported()) {

      long threshold = (pool.getUsage().getMax() * thresholdPercentage) / 100;
      logger.info("setting collection threshold for " + pool.getName() +
        " with max " + pool.getUsage().getMax() +
        " to " + threshold);

      pool.setCollectionUsageThreshold(threshold);
      monitoredPools.put(pool.getName(), pool.getCollectionUsageThresholdCount());
    } else {
      logger.info("skip monitoring for pool " + pool.getName());
    }
  }
}
 
Example 5
Source Project: hbase   File: RegionServerAccounting.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return true if we're above the low watermark
 */
public FlushType isAboveLowWaterMark() {
  // for onheap memstore we check if the global memstore size and the
  // global heap overhead is greater than the global memstore lower mark limit
  if (memType == MemoryType.HEAP) {
    if (getGlobalMemStoreHeapSize() >= globalMemStoreLimitLowMark) {
      return FlushType.ABOVE_ONHEAP_LOWER_MARK;
    }
  } else {
    if (getGlobalMemStoreOffHeapSize() >= globalMemStoreLimitLowMark) {
      // Indicates that the offheap memstore's size is greater than the global memstore
      // lower limit
      return FlushType.ABOVE_OFFHEAP_LOWER_MARK;
    } else if (getGlobalMemStoreHeapSize() >= globalOnHeapMemstoreLimitLowMark) {
      // Indicates that the offheap memstore's heap overhead is greater than the global memstore
      // onheap lower limit
      return FlushType.ABOVE_ONHEAP_LOWER_MARK;
    }
  }
  return FlushType.NORMAL;
}
 
Example 6
private MemoryUsage getMemoryUsage(MemoryType type) {
    if (type == MemoryType.HEAP) {
        return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    } else {
        return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    }
}
 
Example 7
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 8
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 9
private MemoryUsage getMemoryUsage(MemoryType type) {
    if (type == MemoryType.HEAP) {
        return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    } else {
        return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    }
}
 
Example 10
Source Project: hbase   File: RegionServerAccounting.java    License: Apache License 2.0 5 votes vote down vote up
void setGlobalMemStoreLimits(long newGlobalMemstoreLimit) {
  if (this.memType == MemoryType.HEAP) {
    this.globalMemStoreLimit = newGlobalMemstoreLimit;
    this.globalMemStoreLimitLowMark =
        (long) (this.globalMemStoreLimit * this.globalMemStoreLimitLowMarkPercent);
  } else {
    this.globalOnHeapMemstoreLimit = newGlobalMemstoreLimit;
    this.globalOnHeapMemstoreLimitLowMark =
        (long) (this.globalOnHeapMemstoreLimit * this.globalMemStoreLimitLowMarkPercent);
  }
}
 
Example 11
private MemoryUsage getMemoryUsage(MemoryType type) {
    if (type == MemoryType.HEAP) {
        return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    } else {
        return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    }
}
 
Example 12
private static MemoryPoolMXBean findTenuredGenPool() {
    for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
        if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
            return pool;
        }
    }
    throw new AssertionError("could not find tenured space");
}
 
Example 13
Source Project: atlas   File: AtlasMetricJVMUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * collect the pool division of java
 */
private static void pooldivision(Map<String, Object> memory) {
    Map<String, Object> poolDivisionValues = new LinkedHashMap<>();
    for (MemoryPoolMXBean mpBean : ManagementFactory.getMemoryPoolMXBeans()) {
        if (mpBean.getType() == MemoryType.HEAP) {
            poolDivisionValues.put(mpBean.getName(), mpBean.getUsage());
        }
    }
    memory.put("memory_pool_usages", poolDivisionValues);
}
 
Example 14
/**
 * Tenured Space Pool can be determined by it being of type HEAP and by it
 * being possible to set the usage threshold.
 *
 * @return MXBean for the Tenured Space Pool
 */
private static MemoryPoolMXBean findTenuredGenPool() {
    // I don't know whether this approach is better, or whether
    // we should rather check for the pool name "Tenured Gen"?
    for (final MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans())
        if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
            return pool;
        }
    throw new AssertionError("Could not find tenured space");
}
 
Example 15
private MemoryUsage getMemoryUsage(MemoryType type) {
    if (type == MemoryType.HEAP) {
        return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    } else {
        return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    }
}
 
Example 16
Source Project: gemfirexd-oss   File: HeapMemoryMonitor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Determines if the name of the memory pool MXBean provided matches a list of
 * known survivor space pool names.
 * 
 * @param memoryPoolMXBean
 *          The memory pool MXBean to check.
 * @return True if the pool name matches a known survivor space pool name,
 *         false otherwise.
 */
static boolean isSurvivor(MemoryPoolMXBean memoryPoolMXBean) {
  if (memoryPoolMXBean.getType() != MemoryType.HEAP) {
    return false;
  }

  String name = memoryPoolMXBean.getName();

  return name.equals("Par Survivor Space")  // Oracle Concurrent Mark Sweep GC
      || name.equals("PS Survivor Space")   // Oracle Parallel GC
      || name.equals("G1 Survivor")         // Oracle G1 GC
      || name.equals("Survivor Space")      // Hitachi 1.5 GC
      // Allow an unknown pool name to monitor
      || (HEAP_SURVIVOR_POOL != null && name.equals(HEAP_SURVIVOR_POOL));
}
 
Example 17
/**
 * Tenured Space Pool can be determined by it being of type HEAP and by it
 * being possible to set the usage threshold.
 */
private static MemoryPoolMXBean findTenuredGenPool() {
	for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
		// I don't know whether this approach is better, or whether
		// we should rather check for the pool name "Tenured Gen"?
		if (pool.getType() == MemoryType.HEAP
				&& pool.isUsageThresholdSupported()) {
			return pool;
		}
	}
	throw new AssertionError("Could not find tenured space");
}
 
Example 18
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 19
private MemoryUsage getMemoryUsage(MemoryType type) {
    if (type == MemoryType.HEAP) {
        return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    } else {
        return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    }
}
 
Example 20
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}