Java Code Examples for java.lang.management.MemoryType

The following examples show how to use java.lang.management.MemoryType. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Flink-CEPplus   Source File: MemoryLogger.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the memory pool statistics from the JVM.
 *
 * @param poolBeans The collection of memory pool beans.
 * @return A string denoting the names and sizes of the memory pools.
 */
public static String getMemoryPoolStatsAsString(List<MemoryPoolMXBean> poolBeans) {
	StringBuilder bld = new StringBuilder("Off-heap pool stats: ");
	int count = 0;
	
	for (MemoryPoolMXBean bean : poolBeans) {
		if (bean.getType() == MemoryType.NON_HEAP) {
			if (count > 0) {
				bld.append(", ");
			}
			count++;

			MemoryUsage usage = bean.getUsage();
			long used = usage.getUsed() >> 20;
			long committed = usage.getCommitted() >> 20;
			long max = usage.getMax() >> 20;
			
			bld.append('[').append(bean.getName()).append(": ");
			bld.append(used).append('/').append(committed).append('/').append(max);
			bld.append(" MB (used/committed/max)]");
		}
	}

	return bld.toString();
}
 
Example 2
Source Project: flink   Source File: MemoryLogger.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the memory pool statistics from the JVM.
 *
 * @param poolBeans The collection of memory pool beans.
 * @return A string denoting the names and sizes of the memory pools.
 */
public static String getMemoryPoolStatsAsString(List<MemoryPoolMXBean> poolBeans) {
	StringBuilder bld = new StringBuilder("Off-heap pool stats: ");
	int count = 0;
	
	for (MemoryPoolMXBean bean : poolBeans) {
		if (bean.getType() == MemoryType.NON_HEAP) {
			if (count > 0) {
				bld.append(", ");
			}
			count++;

			MemoryUsage usage = bean.getUsage();
			long used = usage.getUsed() >> 20;
			long committed = usage.getCommitted() >> 20;
			long max = usage.getMax() >> 20;
			
			bld.append('[').append(bean.getName()).append(": ");
			bld.append(used).append('/').append(committed).append('/').append(max);
			bld.append(" MB (used/committed/max)]");
		}
	}

	return bld.toString();
}
 
Example 3
Source Project: Quicksql   Source File: UtilTest.java    License: MIT License 6 votes vote down vote up
/**
 * Tests the methods {@link Util#enumConstants(Class)} and
 * {@link Util#enumVal(Class, String)}.
 */
@Test public void testEnumConstants() {
  final Map<String, MemoryType> memoryTypeMap =
      Util.enumConstants(MemoryType.class);
  assertEquals(2, memoryTypeMap.size());
  assertEquals(MemoryType.HEAP, memoryTypeMap.get("HEAP"));
  assertEquals(MemoryType.NON_HEAP, memoryTypeMap.get("NON_HEAP"));
  try {
    memoryTypeMap.put("FOO", null);
    fail("expected exception");
  } catch (UnsupportedOperationException e) {
    // expected: map is immutable
  }

  assertEquals("HEAP", Util.enumVal(MemoryType.class, "HEAP").name());
  assertNull(Util.enumVal(MemoryType.class, "heap"));
  assertNull(Util.enumVal(MemoryType.class, "nonexistent"));
}
 
Example 4
Source Project: calcite   Source File: UtilTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests the methods {@link Util#enumConstants(Class)} and
 * {@link Util#enumVal(Class, String)}.
 */
@Test void testEnumConstants() {
  final Map<String, MemoryType> memoryTypeMap =
      Util.enumConstants(MemoryType.class);
  assertEquals(2, memoryTypeMap.size());
  assertEquals(MemoryType.HEAP, memoryTypeMap.get("HEAP"));
  assertEquals(MemoryType.NON_HEAP, memoryTypeMap.get("NON_HEAP"));
  try {
    memoryTypeMap.put("FOO", null);
    fail("expected exception");
  } catch (UnsupportedOperationException e) {
    // expected: map is immutable
  }

  assertEquals("HEAP", Util.enumVal(MemoryType.class, "HEAP").name());
  assertNull(Util.enumVal(MemoryType.class, "heap"));
  assertNull(Util.enumVal(MemoryType.class, "nonexistent"));
}
 
Example 5
Source Project: hbase   Source File: RegionServerAccounting.java    License: Apache License 2.0 6 votes vote down vote up
public RegionServerAccounting(Configuration conf) {
  Pair<Long, MemoryType> globalMemstoreSizePair = MemorySizeUtil.getGlobalMemStoreSize(conf);
  this.globalMemStoreLimit = globalMemstoreSizePair.getFirst();
  this.memType = globalMemstoreSizePair.getSecond();
  this.globalMemStoreLimitLowMarkPercent =
      MemorySizeUtil.getGlobalMemStoreHeapLowerMark(conf, this.memType == MemoryType.HEAP);
  // When off heap memstore in use we configure the global off heap space for memstore as bytes
  // not as % of max memory size. In such case, the lower water mark should be specified using the
  // key "hbase.regionserver.global.memstore.size.lower.limit" which says % of the global upper
  // bound and defaults to 95%. In on heap case also specifying this way is ideal. But in the past
  // we used to take lower bound also as the % of xmx (38% as default). For backward compatibility
  // for this deprecated config,we will fall back to read that config when new one is missing.
  // Only for on heap case, do this fallback mechanism. For off heap it makes no sense.
  // TODO When to get rid of the deprecated config? ie
  // "hbase.regionserver.global.memstore.lowerLimit". Can get rid of this boolean passing then.
  this.globalMemStoreLimitLowMark =
      (long) (this.globalMemStoreLimit * this.globalMemStoreLimitLowMarkPercent);
  this.globalOnHeapMemstoreLimit = MemorySizeUtil.getOnheapGlobalMemStoreSize(conf);
  this.globalOnHeapMemstoreLimitLowMark =
      (long) (this.globalOnHeapMemstoreLimit * this.globalMemStoreLimitLowMarkPercent);
  this.retainedRegionRWRequestsCnt = new ConcurrentHashMap<>();
}
 
Example 6
Source Project: hbase   Source 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 7
Source Project: consulo   Source File: LowMemoryWatcherManager.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private Future<?> initializeMXBeanListenersLater(@Nonnull ExecutorService backendExecutorService) {
  // do it in the other thread to get it out of the way during startup
  return backendExecutorService.submit(() -> {
    try {
      for (MemoryPoolMXBean bean : ManagementFactory.getMemoryPoolMXBeans()) {
        if (bean.getType() == MemoryType.HEAP && bean.isCollectionUsageThresholdSupported() && bean.isUsageThresholdSupported()) {
          long max = bean.getUsage().getMax();
          long threshold = Math.min((long)(max * getOccupiedMemoryThreshold()), max - MEM_THRESHOLD);
          if (threshold > 0) {
            bean.setUsageThreshold(threshold);
            bean.setCollectionUsageThreshold(threshold);
          }
        }
      }
      ((NotificationEmitter)ManagementFactory.getMemoryMXBean()).addNotificationListener(myLowMemoryListener, null, null);
    }
    catch (Throwable e) {
      // should not happen normally
      getLogger().info("Errors initializing LowMemoryWatcher: ", e);
    }
  });
}
 
Example 8
Source Project: kfs   Source File: MemoryMonitor.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public MemoryMonitor() {
    LOG.info("initializing");
    this.springContextId = "Unknown";
    ManagementFactory.getThreadMXBean().setThreadContentionMonitoringEnabled(true);
    ManagementFactory.getThreadMXBean().setThreadCpuTimeEnabled(true);
    lowMemoryListener = new NotificationListener() {
        public void handleNotification(Notification n, Object hb) {
            if (n.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
                Map<String, String> memoryUsageStatistics = new HashMap<String, String>();
                memoryUsageStatistics.put("MemoryMXBean: " + MemoryType.HEAP, ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().toString());
                memoryUsageStatistics.put("MemoryMXBean:" + MemoryType.NON_HEAP, ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().toString());
                for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
                    memoryUsageStatistics.put("MemoryPoolMXBean: " + pool.getType(), pool.getUsage().toString());
                }
                for (Listener listener : listeners) {
                    listener.memoryUsageLow(springContextId, memoryUsageStatistics, Arrays.toString(ManagementFactory.getThreadMXBean().findMonitorDeadlockedThreads()));
                }
            }
        }
    };
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).addNotificationListener(lowMemoryListener, null, null);
}
 
Example 9
Source Project: hbase   Source File: HRegionServer.java    License: Apache License 2.0 6 votes vote down vote up
protected void initializeMemStoreChunkCreator() {
  if (MemStoreLAB.isEnabled(conf)) {
    // MSLAB is enabled. So initialize MemStoreChunkPool
    // By this time, the MemstoreFlusher is already initialized. We can get the global limits from
    // it.
    Pair<Long, MemoryType> pair = MemorySizeUtil.getGlobalMemStoreSize(conf);
    long globalMemStoreSize = pair.getFirst();
    boolean offheap = this.regionServerAccounting.isOffheap();
    // When off heap memstore in use, take full area for chunk pool.
    float poolSizePercentage = offheap? 1.0F:
        conf.getFloat(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, MemStoreLAB.POOL_MAX_SIZE_DEFAULT);
    float initialCountPercentage = conf.getFloat(MemStoreLAB.CHUNK_POOL_INITIALSIZE_KEY,
        MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT);
    int chunkSize = conf.getInt(MemStoreLAB.CHUNK_SIZE_KEY, MemStoreLAB.CHUNK_SIZE_DEFAULT);
    // init the chunkCreator
    ChunkCreator.initialize(chunkSize, offheap, globalMemStoreSize, poolSizePercentage,
      initialCountPercentage, this.hMemManager);
  }
}
 
Example 10
Source Project: ranger   Source 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 11
Source Project: hbase   Source 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 12
Source Project: ranger   Source 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("==> RangerMetricsUtil.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("<== RangerMetricsUtil.getPoolDivision()" + poolDivisionValues);
    }

    return poolDivisionValues;
}
 
Example 13
Source Project: aws-sdk-java-v2   Source File: Memory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns a summary information about the memory pools.
 */
public static String poolSummaries() {
    // Why ? list-archive?4273859
    // How ? http://stackoverflow.com/questions/697336/how-do-i-programmatically-find-out-my-permgen-space-usage
    //       http://stackoverflow.com/questions/8356416/xxmaxpermsize-with-or-without-xxpermsize
    StringBuilder sb = new StringBuilder();
    for (MemoryPoolMXBean item : ManagementFactory.getMemoryPoolMXBeans()) {
        String name = item.getName();
        MemoryType type = item.getType();
        MemoryUsage usage = item.getUsage();
        MemoryUsage peak = item.getPeakUsage();
        MemoryUsage collections = item.getCollectionUsage();
        sb.append("Memory pool name: " + name
                  + ", type: " + type
                  + ", usage: " + usage
                  + ", peak: " + peak
                  + ", collections: " + collections
                  + "\n");
    }
    return sb.toString();
}
 
Example 14
Source Project: dremio-oss   Source 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 15
@Override
protected RegionProcedureStore createProcedureStore(Path storeDir) throws IOException {
  Pair<Long, MemoryType> pair = MemorySizeUtil.getGlobalMemStoreSize(conf);
  long globalMemStoreSize = pair.getFirst();
  boolean offheap = pair.getSecond() == MemoryType.NON_HEAP;
  float poolSizePercentage = offheap ? 1.0F :
    conf.getFloat(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, MemStoreLAB.POOL_MAX_SIZE_DEFAULT);
  float initialCountPercentage =
    conf.getFloat(MemStoreLAB.CHUNK_POOL_INITIALSIZE_KEY, MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT);
  int chunkSize = conf.getInt(MemStoreLAB.CHUNK_SIZE_KEY, MemStoreLAB.CHUNK_SIZE_DEFAULT);
  ChunkCreator.initialize(chunkSize, offheap, globalMemStoreSize, poolSizePercentage,
    initialCountPercentage, null);
  conf.setBoolean(MasterRegionFactory.USE_HSYNC_KEY, "hsync".equals(syncType));
  CommonFSUtils.setRootDir(conf, storeDir);
  MockServer server = new MockServer(conf);
  region = MasterRegionFactory.create(server);
  return new RegionProcedureStore(server, region, (fs, apth) -> {
  });
}
 
Example 16
Source Project: flink   Source File: MemoryLogger.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the memory pool statistics from the JVM.
 *
 * @param poolBeans The collection of memory pool beans.
 * @return A string denoting the names and sizes of the memory pools.
 */
public static String getMemoryPoolStatsAsString(List<MemoryPoolMXBean> poolBeans) {
	StringBuilder bld = new StringBuilder("Off-heap pool stats: ");
	int count = 0;
	
	for (MemoryPoolMXBean bean : poolBeans) {
		if (bean.getType() == MemoryType.NON_HEAP) {
			if (count > 0) {
				bld.append(", ");
			}
			count++;

			MemoryUsage usage = bean.getUsage();
			long used = usage.getUsed() >> 20;
			long committed = usage.getCommitted() >> 20;
			long max = usage.getMax() >> 20;
			
			bld.append('[').append(bean.getName()).append(": ");
			bld.append(used).append('/').append(committed).append('/').append(max);
			bld.append(" MB (used/committed/max)]");
		}
	}

	return bld.toString();
}
 
Example 17
Source Project: gemfirexd-oss   Source 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 tenured pool names.
 * 
 * Package private for testing.
 * 
 * @param memoryPoolMXBean
 *          The memory pool MXBean to check.
 * @return True if the pool name matches a known tenured pool name, false
 *         otherwise.
 */
static boolean isTenured(MemoryPoolMXBean memoryPoolMXBean) {
  if (memoryPoolMXBean.getType() != MemoryType.HEAP) {
    return false;
  }
  
  String name = memoryPoolMXBean.getName();
  
  return name.equals("CMS Old Gen")     // Sun Concurrent Mark Sweep GC
      || name.equals("PS Old Gen")      // Sun Parallel GC
      || name.equals("G1 Old Gen")      // Sun G1 GC
      || name.equals("Old Space")       // BEA JRockit 1.5, 1.6 GC
      || name.equals("Tenured Gen")     // Hitachi 1.5 GC
      || name.equals("Java heap")       // IBM 1.5, 1.6 GC
      
      // Allow an unknown pool name to monitor
      || (HEAP_POOL != null && name.equals(HEAP_POOL));
}
 
Example 18
Source Project: gemfirexd-oss   Source 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 19
Source Project: gemfirexd-oss   Source 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 tenured pool names.
 * 
 * Package private for testing.
 * 
 * @param memoryPoolMXBean
 *          The memory pool MXBean to check.
 * @return True if the pool name matches a known tenured pool name, false
 *         otherwise.
 */
static boolean isTenured(MemoryPoolMXBean memoryPoolMXBean) {
  if (memoryPoolMXBean.getType() != MemoryType.HEAP) {
    return false;
  }
  
  String name = memoryPoolMXBean.getName();
  
  return name.equals("CMS Old Gen")     // Sun Concurrent Mark Sweep GC
      || name.equals("PS Old Gen")      // Sun Parallel GC
      || name.equals("G1 Old Gen")      // Sun G1 GC
      || name.equals("Old Space")       // BEA JRockit 1.5, 1.6 GC
      || name.equals("Tenured Gen")     // Hitachi 1.5 GC
      || name.equals("Java heap")       // IBM 1.5, 1.6 GC
      
      // Allow an unknown pool name to monitor
      || (HEAP_POOL != null && name.equals(HEAP_POOL));
}
 
Example 20
Source Project: gemfirexd-oss   Source 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 21
MemoryUsage getNonHeapMemoryUsage() {
    try {
        final Map<Object, Object> m = JvmContextFactory.getUserData();

        if (m != null) {
            final MemoryUsage cached = (MemoryUsage)
                m.get(nonHeapMemoryTag);
            if (cached != null) {
                log.debug("getNonHeapMemoryUsage",
                      "jvmMemory.getNonHeapMemoryUsage found in cache.");
                return cached;
            }

            final MemoryUsage u = getMemoryUsage(MemoryType.NON_HEAP);

            //  getNonHeapMemoryUsage() never returns null.
            //
            // if (u == null) u=MemoryUsage.INVALID;

            m.put(nonHeapMemoryTag,u);
            return u;
        }
        // Should never come here.
        // Log error!
        log.trace("getNonHeapMemoryUsage",
                  "ERROR: should never come here!");
        return getMemoryUsage(MemoryType.NON_HEAP);
    } catch (RuntimeException x) {
        log.trace("getNonHeapMemoryUsage",
              "Failed to get NonHeapMemoryUsage: " + x);
        log.debug("getNonHeapMemoryUsage",x);
        throw x;
    }

}
 
Example 22
MemoryUsage getHeapMemoryUsage() {
    try {
        final Map<Object, Object> m = JvmContextFactory.getUserData();

        if (m != null) {
            final MemoryUsage cached = (MemoryUsage)m.get(heapMemoryTag);
            if (cached != null) {
                log.debug("getHeapMemoryUsage",
                      "jvmMemory.getHeapMemoryUsage found in cache.");
                return cached;
            }

            final MemoryUsage u = getMemoryUsage(MemoryType.HEAP);

            // getHeapMemoryUsage() never returns null.
            //
            // if (u == null) u=MemoryUsage.INVALID;

            m.put(heapMemoryTag,u);
            return u;
        }

        // Should never come here.
        // Log error!
        log.trace("getHeapMemoryUsage", "ERROR: should never come here!");
        return getMemoryUsage(MemoryType.HEAP);
    } catch (RuntimeException x) {
        log.trace("getHeapMemoryUsage",
              "Failed to get HeapMemoryUsage: " + x);
        log.debug("getHeapMemoryUsage",x);
        throw x;
    }
}
 
Example 23
public static EnumJvmMemPoolType jvmMemPoolType(MemoryType type)
    throws SnmpStatusException {
    if (type.equals(MemoryType.HEAP))
        return  EnumJvmMemPoolTypeHeap;
    else if (type.equals(MemoryType.NON_HEAP))
        return EnumJvmMemPoolTypeNonHeap;
    throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
}
 
Example 24
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 25
Source Project: kfs   Source File: MemoryMonitor.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public static void setPercentageUsageThreshold(double percentage) {
    for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
        if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
            if (percentage <= 0.0 || percentage > 1.0) {
                throw new IllegalArgumentException("percentage not in range");
            }
            long warningThreshold = (long) (pool.getUsage().getMax() * percentage);
            pool.setUsageThreshold(warningThreshold);
        }
    }
}
 
Example 26
Source Project: jdk8u-dev-jdk   Source File: JvmMemoryImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
private MemoryUsage getMemoryUsage(MemoryType type) {
    if (type == MemoryType.HEAP) {
        return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    } else {
        return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    }
}
 
Example 27
public static EnumJvmMemPoolType jvmMemPoolType(MemoryType type)
    throws SnmpStatusException {
    if (type.equals(MemoryType.HEAP))
        return  EnumJvmMemPoolTypeHeap;
    else if (type.equals(MemoryType.NON_HEAP))
        return EnumJvmMemPoolTypeNonHeap;
    throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
}
 
Example 28
Source Project: TencentKona-8   Source File: MemoryPoolImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 29
Source Project: jdk8u60   Source File: JvmMemoryImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
MemoryUsage getNonHeapMemoryUsage() {
    try {
        final Map<Object, Object> m = JvmContextFactory.getUserData();

        if (m != null) {
            final MemoryUsage cached = (MemoryUsage)
                m.get(nonHeapMemoryTag);
            if (cached != null) {
                log.debug("getNonHeapMemoryUsage",
                      "jvmMemory.getNonHeapMemoryUsage found in cache.");
                return cached;
            }

            final MemoryUsage u = getMemoryUsage(MemoryType.NON_HEAP);

            //  getNonHeapMemoryUsage() never returns null.
            //
            // if (u == null) u=MemoryUsage.INVALID;

            m.put(nonHeapMemoryTag,u);
            return u;
        }
        // Should never come here.
        // Log error!
        log.trace("getNonHeapMemoryUsage",
                  "ERROR: should never come here!");
        return getMemoryUsage(MemoryType.NON_HEAP);
    } catch (RuntimeException x) {
        log.trace("getNonHeapMemoryUsage",
              "Failed to get NonHeapMemoryUsage: " + x);
        log.debug("getNonHeapMemoryUsage",x);
        throw x;
    }

}
 
Example 30
Source Project: jdk8u60   Source File: JvmMemoryImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
MemoryUsage getHeapMemoryUsage() {
    try {
        final Map<Object, Object> m = JvmContextFactory.getUserData();

        if (m != null) {
            final MemoryUsage cached = (MemoryUsage)m.get(heapMemoryTag);
            if (cached != null) {
                log.debug("getHeapMemoryUsage",
                      "jvmMemory.getHeapMemoryUsage found in cache.");
                return cached;
            }

            final MemoryUsage u = getMemoryUsage(MemoryType.HEAP);

            // getHeapMemoryUsage() never returns null.
            //
            // if (u == null) u=MemoryUsage.INVALID;

            m.put(heapMemoryTag,u);
            return u;
        }

        // Should never come here.
        // Log error!
        log.trace("getHeapMemoryUsage", "ERROR: should never come here!");
        return getMemoryUsage(MemoryType.HEAP);
    } catch (RuntimeException x) {
        log.trace("getHeapMemoryUsage",
              "Failed to get HeapMemoryUsage: " + x);
        log.debug("getHeapMemoryUsage",x);
        throw x;
    }
}