Java 类java.lang.management.MemoryType 实例源码

项目:monarch    文件:HeapMemoryMonitor.java   
/**
 * 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
      || name.equals("GenPauseless Old Gen") // azul C4/GPGC collector

      // Allow an unknown pool name to monitor
      || (HEAP_POOL != null && name.equals(HEAP_POOL));
}
项目:ChronoBike    文件:CodeManager.java   
public static void initCodeSizeLimits(int nMaxSizeMemPoolCodeCache, int nMaxSizeMemPoolPermGen)
{
    // PJD remove ibm JMV
    List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean p: pools)
    {
        if(p.getType().compareTo(MemoryType.NON_HEAP) == 0)
        {
            String cs = p.getName();
            if(cs.equalsIgnoreCase("Code Cache"))
                p.setUsageThreshold((long)nMaxSizeMemPoolCodeCache * 1024L * 1024L);
            else if(cs.equalsIgnoreCase("Perm Gen"))
                p.setUsageThreshold((long)nMaxSizeMemPoolPermGen * 1024L * 1024L);
        }
    }
}
项目:ChronoBike    文件:ThreadStatementGC.java   
private void setMemThreshold()
{
    m_bMaxPermanentHeap_MoSet = false;

    List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean p: pools)
    {
        if(p.getType().compareTo(MemoryType.HEAP) == 0)
        {
            String cs = p.getName();
            if(cs.equalsIgnoreCase("Tenured gen"))
            {
                long l = 1024L * 1024L * (long)m_nMaxPermanentHeap_Mo;
                p.setUsageThreshold(l);
                m_tenuredPool = p;
            }               
        }
    }
}
项目:aws-sdk-java-v2    文件:Memory.java   
/**
 * 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();
    Iterator<MemoryPoolMXBean> iter =
            ManagementFactory.getMemoryPoolMXBeans().iterator();
    while (iter.hasNext()) {
        MemoryPoolMXBean item = iter.next();
        String name = item.getName();
        MemoryType type = item.getType();
        MemoryUsage usage = item.getUsage();
        MemoryUsage peak = item.getPeakUsage();
        MemoryUsage collections = item.getCollectionUsage();
        sb.append(String.format("Memory pool name: " + name
                                + ", type: " + type
                                + ", usage: " + usage
                                + ", peak: " + peak
                                + ", collections: " + collections
                                + "\n"));
    }
    return sb.toString();
}
项目:gemfirexd-oss    文件:HeapMemoryMonitor.java   
/**
 * 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));
}
项目:gemfirexd-oss    文件:HeapMemoryMonitor.java   
/**
 * 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));
}
项目:demidovii    文件:MemoryChecker.java   
private static MemoryPoolMXBean getMemoryBean(){
  System.gc();

  List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
  long curMax = 0;
  MemoryPoolMXBean heap = null;

  for (MemoryPoolMXBean pool : pools) {
    if (pool.getType() != MemoryType.HEAP) {
      continue;
    }
    MemoryUsage memusage = pool.getUsage();
    long max = memusage.getMax();
    if(max > curMax)
      heap = pool;
  }
  return heap;
}
项目:flink    文件:MemoryLogger.java   
/**
 * 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();
}
项目:gemfirexd-oss    文件:HeapMemoryMonitor.java   
/**
 * 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));
}
项目:gemfirexd-oss    文件:HeapMemoryMonitor.java   
/**
 * 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));
}
项目:SOMns    文件:ActorExecutionTrace.java   
public static void reportPeakMemoryUsage() {
  List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
  long totalHeap = 0;
  long totalNonHeap = 0;
  long gcTime = 0;
  for (MemoryPoolMXBean memoryPoolMXBean : pools) {
    long peakUsed = memoryPoolMXBean.getPeakUsage().getUsed();
    if (memoryPoolMXBean.getType() == MemoryType.HEAP) {
      totalHeap += peakUsed;
    } else if (memoryPoolMXBean.getType() == MemoryType.NON_HEAP) {
      totalNonHeap += peakUsed;
    }
  }
  for (GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) {
    gcTime += garbageCollectorMXBean.getCollectionTime();
  }
  VM.println("[Memstat] Heap: " + totalHeap + "B\tNonHeap: " + totalNonHeap
      + "B\tCollected: " + collectedMemory + "B\tGC-Time: " + gcTime + "ms");
}
项目:galago-git    文件:MemoryChecker.java   
private static MemoryPoolMXBean getMemoryBean(){
  System.gc();

  List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
  long curMax = 0;
  MemoryPoolMXBean heap = null;

  for (MemoryPoolMXBean pool : pools) {
    if (pool.getType() != MemoryType.HEAP) {
      continue;
    }
    MemoryUsage memusage = pool.getUsage();
    long max = memusage.getMax();
    if(max > curMax)
      heap = pool;
  }
  return heap;
}
项目:Lucee4    文件:MemoryControler.java   
public synchronized static void init(ConfigServer cs){
      if(init) return;
        // set level
      for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
          types.put(pool.getName(), pool.getType());
        // 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()) {
              long maxMemory = pool.getUsage().getMax();
              long warningThreshold = (long) (maxMemory * 0.9);
              //long warningThreshold = maxMemory -(10*1024*1024);
              pool.setUsageThreshold(warningThreshold);
          }
      }

      MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
      NotificationEmitter emitter = (NotificationEmitter) mbean;
      MemoryNotificationListener listener = new MemoryNotificationListener(types);
      emitter.addNotificationListener(listener, null, cs);
      init=true;
}
项目:Lucee4    文件:SystemUtil.java   
public static Struct getMemoryUsageAsStruct(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();

    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    long used=0,max=0,init=0;
    while(it.hasNext()){
        bean = it.next();
        usage = bean.getUsage();
        _type = bean.getType();
        if((type==MEMORY_TYPE_HEAP && _type==MemoryType.HEAP) || (type==MEMORY_TYPE_NON_HEAP && _type==MemoryType.NON_HEAP)){
            used+=usage.getUsed();
            max+=usage.getMax();
            init+=usage.getInit();
        }
    }
    Struct sct=new StructImpl();
    sct.setEL(KeyConstants._used, Caster.toDouble(used));
    sct.setEL(KeyConstants._max, Caster.toDouble(max));
    sct.setEL(KeyConstants._init, Caster.toDouble(init));
    sct.setEL(KeyImpl.init("available"), Caster.toDouble(max-used));
    return sct;
}
项目:Lucee4    文件:SystemUtil.java   
public static Struct getMemoryUsageCompact(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();

    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    Struct sct=new StructImpl();
    while(it.hasNext()){
        bean = it.next();
        usage = bean.getUsage();
        _type = bean.getType();
        if(type==MEMORY_TYPE_HEAP && _type!=MemoryType.HEAP)continue;
        if(type==MEMORY_TYPE_NON_HEAP && _type!=MemoryType.NON_HEAP)continue;

        double d=((int)(100D/usage.getMax()*usage.getUsed()))/100D;
        sct.setEL(KeyImpl.init(bean.getName()), Caster.toDouble(d));
    }
    return sct;
}
项目:Lucee    文件:MemoryControler.java   
public synchronized static void init(ConfigServer cs){
      if(init) return;
        // set level
      for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
          types.put(pool.getName(), pool.getType());
        // 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()) {
              long maxMemory = pool.getUsage().getMax();
              long warningThreshold = (long) (maxMemory * 0.9);
              //long warningThreshold = maxMemory -(10*1024*1024);
              pool.setUsageThreshold(warningThreshold);
          }
      }

      MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
      NotificationEmitter emitter = (NotificationEmitter) mbean;
      MemoryNotificationListener listener = new MemoryNotificationListener(types);
      emitter.addNotificationListener(listener, null, cs);
      init=true;
}
项目:Lucee    文件:SystemUtil.java   
public static Struct getMemoryUsageAsStruct(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();

    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    long used = 0, max = 0, init = 0;
    while(it.hasNext()) {
        bean = it.next();
        usage = bean.getUsage();
        _type = bean.getType();
        if((type == MEMORY_TYPE_HEAP && _type == MemoryType.HEAP) || (type == MEMORY_TYPE_NON_HEAP && _type == MemoryType.NON_HEAP)) {
            used += usage.getUsed();
            max += usage.getMax();
            init += usage.getInit();
        }
    }
    Struct sct = new StructImpl();
    sct.setEL(KeyConstants._used, Caster.toDouble(used));
    sct.setEL(KeyConstants._max, Caster.toDouble(max));
    sct.setEL(KeyConstants._init, Caster.toDouble(init));
    sct.setEL(KeyImpl.init("available"), Caster.toDouble(max - used));
    return sct;
}
项目:Lucee    文件:SystemUtil.java   
public static Struct getMemoryUsageCompact(int type) {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();

    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    Struct sct = new StructImpl();
    while(it.hasNext()) {
        bean = it.next();
        usage = bean.getUsage();
        _type = bean.getType();
        if(type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP)
            continue;
        if(type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP)
            continue;

        double d = ((int)(100D / usage.getMax() * usage.getUsed())) / 100D;
        sct.setEL(KeyImpl.init(bean.getName()), Caster.toDouble(d));
    }
    return sct;
}
项目:elpi    文件:UtilIOTests.java   
public void testReadWriteObject() throws Exception {
    checkBasicReadWriteObject(Boolean.TRUE, "java.lang.Boolean:true\n");
    checkBasicReadWriteObject(Byte.valueOf("1"), "java.lang.Byte:1\n");
    checkBasicReadWriteObject(Double.valueOf("1.0"), "java.lang.Double:1.0\n");
    checkBasicReadWriteObject(Float.valueOf("1.0"), "java.lang.Float:1.0\n");
    checkBasicReadWriteObject(Integer.valueOf("1"), "java.lang.Integer:1\n");
    checkBasicReadWriteObject(Long.valueOf("1"), "java.lang.Long:1\n");
    checkBasicReadWriteObject(Short.valueOf("1"), "java.lang.Short:1\n");
    checkBasicReadWriteObject(BigDecimal.valueOf(500.5), "java.math.BigDecimal:500.5\n");
    checkBasicReadWriteObject(BigInteger.valueOf(500), "java.math.BigInteger:500\n");
    checkBasicReadWriteObject("1", "java.lang.String:1\n");
    checkBasicReadObject(Arrays.asList(new Object[] {"a", UtilMisc.toMap("b", Long.valueOf(1))}), "[\n \"a\",\n {\n  \"b\": 1\n }\n]\n");
    checkBasicReadWriteObject(MemoryType.HEAP, "java.lang.management.MemoryType:HEAP\n");
    checkBasicReadWriteObject(MemoryType.NON_HEAP, "java.lang.management.MemoryType:NON_HEAP\n");
    checkBasicReadWriteObject(UtilIO.UTF8, "java.nio.charset.Charset:UTF-8\n");
    checkBasicReadWriteObject(InetAddress.getByAddress("localhost", new byte[] {127, 0, 0, 1}), "java.net.InetAddress:localhost\n");
    //checkBasicReadWriteObject(Pattern.compile("^([a-z]{3}.*?):$"), "java.util.regex.Pattern:^([a-z]{3}.*?):$\n");
    checkBasicReadWriteObject(Time.valueOf("12:34:56"), "java.sql.Time:12:34:56\n");
    //checkBasicReadWriteObject(new Timestamp(1234567890), "java.sql.Timestamp:1234567890 00:00:00\n");
    //checkBasicReadWriteObject(new java.util.Date(1234567890), "java.util.Date:1234567890\n");
    checkBasicReadWriteObject(UUID.fromString("c3241927-9f77-43e1-be16-bd71d245ef64"), "java.util.UUID:c3241927-9f77-43e1-be16-bd71d245ef64\n");
    checkBasicReadWriteObject(TimeZone.getTimeZone("America/Chicago"), "java.util.TimeZone:America/Chicago\n");
    checkBasicReadWriteObject(new SimpleDateFormat("MM/dd/yyyy hh:mm a"), "java.text.SimpleDateFormat:MM/dd/yyyy hh:mm a\n");
    checkBasicReadWriteObject(new Locale("en", "us"), "java.util.Locale:en_US\n");
}
项目:o3erp    文件:UtilIOTests.java   
public void testReadWriteObject() throws Exception {
    checkBasicReadWriteObject(Boolean.TRUE, "java.lang.Boolean:true\n");
    checkBasicReadWriteObject(Byte.valueOf("1"), "java.lang.Byte:1\n");
    checkBasicReadWriteObject(Double.valueOf("1.0"), "java.lang.Double:1.0\n");
    checkBasicReadWriteObject(Float.valueOf("1.0"), "java.lang.Float:1.0\n");
    checkBasicReadWriteObject(Integer.valueOf("1"), "java.lang.Integer:1\n");
    checkBasicReadWriteObject(Long.valueOf("1"), "java.lang.Long:1\n");
    checkBasicReadWriteObject(Short.valueOf("1"), "java.lang.Short:1\n");
    checkBasicReadWriteObject(BigDecimal.valueOf(500.5), "java.math.BigDecimal:500.5\n");
    checkBasicReadWriteObject(BigInteger.valueOf(500), "java.math.BigInteger:500\n");
    checkBasicReadWriteObject("1", "java.lang.String:1\n");
    checkBasicReadObject(Arrays.asList(new Object[] {"a", UtilMisc.toMap("b", Long.valueOf(1))}), "[\n \"a\",\n {\n  \"b\": 1\n }\n]\n");
    checkBasicReadWriteObject(MemoryType.HEAP, "java.lang.management.MemoryType:HEAP\n");
    checkBasicReadWriteObject(MemoryType.NON_HEAP, "java.lang.management.MemoryType:NON_HEAP\n");
    checkBasicReadWriteObject(UtilIO.UTF8, "java.nio.charset.Charset:UTF-8\n");
    checkBasicReadWriteObject(InetAddress.getByAddress("localhost", new byte[] {127, 0, 0, 1}), "java.net.InetAddress:localhost\n");
    //checkBasicReadWriteObject(Pattern.compile("^([a-z]{3}.*?):$"), "java.util.regex.Pattern:^([a-z]{3}.*?):$\n");
    checkBasicReadWriteObject(Time.valueOf("12:34:56"), "java.sql.Time:12:34:56\n");
    //checkBasicReadWriteObject(new Timestamp(1234567890), "java.sql.Timestamp:1234567890 00:00:00\n");
    //checkBasicReadWriteObject(new java.util.Date(1234567890), "java.util.Date:1234567890\n");
    checkBasicReadWriteObject(UUID.fromString("c3241927-9f77-43e1-be16-bd71d245ef64"), "java.util.UUID:c3241927-9f77-43e1-be16-bd71d245ef64\n");
    checkBasicReadWriteObject(TimeZone.getTimeZone("America/Chicago"), "java.util.TimeZone:America/Chicago\n");
    checkBasicReadWriteObject(new SimpleDateFormat("MM/dd/yyyy hh:mm a"), "java.text.SimpleDateFormat:MM/dd/yyyy hh:mm a\n");
    checkBasicReadWriteObject(new Locale("en", "us"), "java.util.Locale:en_US\n");
}
项目:hbase    文件:HRegionServer.java   
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 chunkCreator =
        ChunkCreator.initialize(chunkSize, offheap, globalMemStoreSize, poolSizePercentage,
    initialCountPercentage, this.hMemManager);
  }
}
项目:hbase    文件:RegionServerAccounting.java   
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);
}
项目:hbase    文件:RegionServerAccounting.java   
/**
 * 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 (getGlobalMemStoreDataSize() >= globalMemStoreLimitLowMark) {
      // Indicates that the offheap memstore's data 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;
}
项目:hbase    文件:MemorySizeUtil.java   
/**
 * @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);
}
项目:OLE-INST    文件:MemoryMonitor.java   
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);
}
项目:cn1    文件:MemoryPoolMXBeanImpl.java   
/**
 * Sets the metadata for this bean.
 * 
 * @param name
 * @param type
 * @param id
 * @param memBean
 */
MemoryPoolMXBeanImpl(String name, MemoryType type, int id,
        MemoryMXBeanImpl memBean) {
    this.name = name;
    this.type = type;
    this.id = id;
    this.memBean = memBean;
    setMBeanInfo(ManagementUtils
            .getMBeanInfo(java.lang.management.MemoryPoolMXBean.class
                    .getName()));
    if (isUsageThresholdSupported()
            || isCollectionUsageThresholdSupported()) {
        MemoryNotificationThread t = new MemoryNotificationThread(memBean,
                this, id);
        t.setDaemon(true);
        t.setName("MemoryPoolMXBean notification dispatcher");
        t.setPriority(Thread.NORM_PRIORITY + 1);
        t.start();
    }
}
项目:kfs    文件:MemoryMonitor.java   
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);
}
项目:calcite    文件:UtilTest.java   
/**
 * 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"));
}
项目:BfROpenLab    文件:WorkflowTest.java   
protected static MemoryUsage getHeapUsage() {
    System.gc();

    long initMem = 0;
    long maxMem = 0;
    long committedMem = 0;
    long usedMem = 0;
    for (MemoryPoolMXBean memoryPool : ManagementFactory.getMemoryPoolMXBeans()) {
        if (memoryPool.getType().equals(MemoryType.HEAP) && (memoryPool.getCollectionUsage() != null)) {
            MemoryUsage usage = memoryPool.getUsage();

            initMem += usage.getInit();
            maxMem += usage.getMax();
            committedMem += usage.getCommitted();
            usedMem += usage.getUsed();
        }
    }
    return new MemoryUsage(initMem, usedMem, committedMem, maxMem);
}
项目:freeVM    文件:MemoryPoolMXBeanImpl.java   
/**
 * Sets the metadata for this bean.
 * 
 * @param name
 * @param type
 * @param id
 * @param memBean
 */
MemoryPoolMXBeanImpl(String name, MemoryType type, int id,
        MemoryMXBeanImpl memBean) {
    this.name = name;
    this.type = type;
    this.id = id;
    this.memBean = memBean;
    setMBeanInfo(ManagementUtils
            .getMBeanInfo(java.lang.management.MemoryPoolMXBean.class
                    .getName()));
    if (isUsageThresholdSupported()
            || isCollectionUsageThresholdSupported()) {
        MemoryNotificationThread t = new MemoryNotificationThread(memBean,
                this, id);
        t.setDaemon(true);
        t.setName("MemoryPoolMXBean notification dispatcher");
        t.setPriority(Thread.NORM_PRIORITY + 1);
        t.start();
    }
}
项目:freeVM    文件:MemoryPoolMXBeanImpl.java   
/**
 * Sets the metadata for this bean.
 * 
 * @param name
 * @param type
 * @param id
 * @param memBean
 */
MemoryPoolMXBeanImpl(String name, MemoryType type, int id,
        MemoryMXBeanImpl memBean) {
    this.name = name;
    this.type = type;
    this.id = id;
    this.memBean = memBean;
    setMBeanInfo(ManagementUtils
            .getMBeanInfo(java.lang.management.MemoryPoolMXBean.class
                    .getName()));
    if (isUsageThresholdSupported()
            || isCollectionUsageThresholdSupported()) {
        MemoryNotificationThread t = new MemoryNotificationThread(memBean,
                this, id);
        t.setDaemon(true);
        t.setName("MemoryPoolMXBean notification dispatcher");
        t.setPriority(Thread.NORM_PRIORITY + 1);
        t.start();
    }
}
项目:javametrics    文件:MemoryPoolDataProvider.java   
private static long getMemory(MemoryType type, MemoryValue memval) {
    long total = 0;
    List<MemoryPoolMXBean> memoryPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
    if (memoryPoolBeans.isEmpty()) {
        return -1;
    }
    for (Iterator<MemoryPoolMXBean> iterator = memoryPoolBeans.iterator(); iterator.hasNext();) {
        MemoryPoolMXBean memoryPoolMXBean = iterator.next();
        if (memoryPoolMXBean.getType().equals(type)) {
            total += memval.getValue(memoryPoolMXBean);
        }
    }
    return total;
}
项目:OpenJSharp    文件:JvmMemoryImpl.java   
private MemoryUsage getMemoryUsage(MemoryType type) {
    if (type == MemoryType.HEAP) {
        return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    } else {
        return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    }
}
项目:OpenJSharp    文件:JvmMemoryImpl.java   
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;
    }

}
项目:OpenJSharp    文件:JvmMemoryImpl.java   
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;
    }
}
项目:OpenJSharp    文件:JvmMemPoolEntryImpl.java   
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);
}
项目:OpenJSharp    文件:MemoryPoolImpl.java   
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
项目:jdk8u-jdk    文件:JvmMemoryImpl.java   
private MemoryUsage getMemoryUsage(MemoryType type) {
    if (type == MemoryType.HEAP) {
        return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    } else {
        return ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    }
}
项目:jdk8u-jdk    文件:JvmMemoryImpl.java   
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;
    }

}
项目:jdk8u-jdk    文件:JvmMemoryImpl.java   
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;
    }
}