java.lang.management.MemoryType Java Examples

The following examples show how to use java.lang.management.MemoryType. 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 File: RegionProcedureStorePerformanceEvaluation.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: UtilTest.java    From calcite with 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 #3
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with 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 File: UtilTest.java    From Quicksql with 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 #5
Source File: RegionServerAccounting.java    From hbase with 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 File: RegionServerAccounting.java    From hbase with 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 File: MemoryLogger.java    From flink with 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 #8
Source File: MemoryLogger.java    From Flink-CEPplus with 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 #9
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with 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 #10
Source File: LowMemoryWatcherManager.java    From consulo with 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 #11
Source File: RangerMetricsUtil.java    From ranger with 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 #12
Source File: HRegionServer.java    From hbase with 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 #13
Source File: HeapMonitorThread.java    From dremio-oss with 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 #14
Source File: Memory.java    From aws-sdk-java-v2 with 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 #15
Source File: RangerMetricsUtil.java    From ranger with 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 #16
Source File: MemorySizeUtil.java    From hbase with 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 #17
Source File: MemoryLogger.java    From flink with 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 #18
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with 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 #19
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with 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 #20
Source File: MemoryMonitor.java    From kfs with 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 #21
Source File: JvmMemoryImpl.java    From jdk8u-jdk with 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 #22
Source File: JvmMemoryImpl.java    From jdk8u-jdk with 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;
    }
}
 
Example #23
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with 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 #24
Source File: JvmMemoryImpl.java    From jdk8u-jdk with 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 #25
Source File: JvmMemoryImpl.java    From jdk8u-dev-jdk with 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;
    }
}
 
Example #26
Source File: JvmMemoryImpl.java    From openjdk-8-source with 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;
    }
}
 
Example #27
Source File: RegionServerAccounting.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Return true if we are above the memstore high water mark
 * @return the flushtype
 */
public FlushType isAboveHighWaterMark() {
  // for onheap memstore we check if the global memstore size and the
  // global heap overhead is greater than the global memstore limit
  if (memType == MemoryType.HEAP) {
    if (getGlobalMemStoreHeapSize() >= globalMemStoreLimit) {
      return FlushType.ABOVE_ONHEAP_HIGHER_MARK;
    }
  } else {
    // If the configured memstore is offheap, check for two things
    // 1) If the global memstore off-heap size is greater than the configured
    // 'hbase.regionserver.offheap.global.memstore.size'
    // 2) If the global memstore heap size is greater than the configured onheap
    // global memstore limit 'hbase.regionserver.global.memstore.size'.
    // We do this to avoid OOME incase of scenarios where the heap is occupied with
    // lot of onheap references to the cells in memstore
    if (getGlobalMemStoreOffHeapSize() >= globalMemStoreLimit) {
      // Indicates that global memstore size is above the configured
      // 'hbase.regionserver.offheap.global.memstore.size'
      return FlushType.ABOVE_OFFHEAP_HIGHER_MARK;
    } else if (getGlobalMemStoreHeapSize() >= this.globalOnHeapMemstoreLimit) {
      // Indicates that the offheap memstore's heap overhead is greater than the
      // configured 'hbase.regionserver.global.memstore.size'.
      return FlushType.ABOVE_ONHEAP_HIGHER_MARK;
    }
  }
  return FlushType.NORMAL;
}
 
Example #28
Source File: RegionServerAccounting.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @return the flush pressure of all stores on this regionserver. The value should be greater than
 *         or equal to 0.0, and any value greater than 1.0 means we enter the emergency state that
 *         global memstore size already exceeds lower limit.
 */
public double getFlushPressure() {
  if (memType == MemoryType.HEAP) {
    return (getGlobalMemStoreHeapSize()) * 1.0 / globalMemStoreLimitLowMark;
  } else {
    return Math.max(getGlobalMemStoreOffHeapSize() * 1.0 / globalMemStoreLimitLowMark,
        getGlobalMemStoreHeapSize() * 1.0 / globalOnHeapMemstoreLimitLowMark);
  }
}
 
Example #29
Source File: JvmMemoryImpl.java    From hottub with 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;
    }
}
 
Example #30
Source File: JvmMemoryImpl.java    From openjdk-8-source with 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;
    }

}