Examples of MemoryPoolMXBean


Examples of java.lang.management.MemoryPoolMXBean

    private static SpillableMemoryManager manager;

    private SpillableMemoryManager() {
        ((NotificationEmitter)ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
        List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans();
        MemoryPoolMXBean biggestHeap = null;
        long biggestSize = 0;
        for (MemoryPoolMXBean b: mpbeans) {
            log.debug("Found heap (" + b.getName() +
                ") of type " + b.getType());
            if (b.getType() == MemoryType.HEAP) {
                /* Here we are making the leap of faith that the biggest
                 * heap is the tenured heap
                 */
                long size = b.getUsage().getMax();
                if (size > biggestSize) {
                    biggestSize = size;
                    biggestHeap = b;
                }
            }
        }
        if (biggestHeap == null) {
            throw new RuntimeException("Couldn't find heap");
        }
        log.debug("Selected heap to monitor (" +
            biggestHeap.getName() + ")");
       
        // we want to set both collection and usage threshold alerts to be
        // safe. In some local tests after a point only collection threshold
        // notifications were being sent though usage threshold notifications
        // were sent early on. So using both would ensure that
        // 1) we get notified early (though usage threshold exceeded notifications)
        // 2) we get notified always when threshold is exceeded (either usage or
        //    collection)
       
        /* We set the threshold to be 50% of tenured since that is where
         * the GC starts to dominate CPU time according to Sun doc */
        biggestHeap.setCollectionUsageThreshold((long)(biggestSize * collectionMemoryThresholdFraction));
        // we set a higher threshold for usage threshold exceeded notification
        // since this is more likely to be effective sooner and we do not
        // want to be spilling too soon
        biggestHeap.setUsageThreshold((long)(biggestSize * memoryThresholdFraction));
    }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

            .append("\nRuntime max:").append(kbString(run.maxMemory()))
            .append("\nRuntime total:").append(kbString(run.totalMemory()));
      Iterator<MemoryPoolMXBean> iter = ManagementFactory.getMemoryPoolMXBeans().iterator();
      while (iter.hasNext())
      {
         MemoryPoolMXBean item = iter.next();
         MemoryUsage usage = item.getUsage();
         memoryInfo.append("\nMX ").append(item.getName()).append("(").append(item.getType()).append("): ")
               .append("used: ").append(kbString(usage.getUsed()))
               .append(", init: ").append(kbString(usage.getInit()))
               .append(", committed: ").append(kbString(usage.getCommitted()))
               .append(", max: ").append(kbString(usage.getMax()));
      }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

            poolNames = new String[pools.size()];
            int i = 0;
            for (ListIterator iter = pools.listIterator();
                 iter.hasNext();
                 i++) {
                MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
                poolNames[i] = p.getName();
            }
        }
        return poolNames;
    }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

    private static volatile SpillableMemoryManager manager;

    private SpillableMemoryManager() {
        ((NotificationEmitter)ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
        List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans();
        MemoryPoolMXBean tenuredHeap = null;
        long tenuredHeapSize = 0;
        long totalSize = 0;
        for (MemoryPoolMXBean pool : mpbeans) {
            log.debug("Found heap (" + pool.getName() + ") of type " + pool.getType());
            if (pool.getType() == MemoryType.HEAP) {
                long size = pool.getUsage().getMax();
                totalSize += size;
                // CMS Old Gen or "tenured" is the only heap that supports
                // setting usage threshold.
                if (pool.isUsageThresholdSupported()) {
                    tenuredHeapSize = size;
                    tenuredHeap = pool;
                }
            }
        }
        extraGCSpillSizeThreshold  = (long) (totalSize * extraGCThresholdFraction);
        if (tenuredHeap == null) {
            throw new RuntimeException("Couldn't find heap");
        }
        log.debug("Selected heap to monitor (" +
            tenuredHeap.getName() + ")");

        // we want to set both collection and usage threshold alerts to be
        // safe. In some local tests after a point only collection threshold
        // notifications were being sent though usage threshold notifications
        // were sent early on. So using both would ensure that
        // 1) we get notified early (though usage threshold exceeded notifications)
        // 2) we get notified always when threshold is exceeded (either usage or
        //    collection)

        /* We set the threshold to be 50% of tenured since that is where
         * the GC starts to dominate CPU time according to Sun doc */
        tenuredHeap.setCollectionUsageThreshold((long)(tenuredHeapSize * collectionMemoryThresholdFraction));
        // we set a higher threshold for usage threshold exceeded notification
        // since this is more likely to be effective sooner and we do not
        // want to be spilling too soon
        tenuredHeap.setUsageThreshold((long)(tenuredHeapSize * memoryThresholdFraction));
    }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

 
 
 
  public static MemoryPoolMXBean getPermGenSpaceBean() {
    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    MemoryPoolMXBean bean;
    // PERM GEN
    Iterator<MemoryPoolMXBean> it = manager.iterator();
    while(it.hasNext()){
      bean = it.next();
      if("Perm Gen".equalsIgnoreCase(bean.getName()) || "CMS Perm Gen".equalsIgnoreCase(bean.getName())) {
        return bean;
      }
    }
    it = manager.iterator();
    while(it.hasNext()){
      bean = it.next();
      if(StringUtil.indexOfIgnoreCase(bean.getName(),"Perm Gen")!=-1 || StringUtil.indexOfIgnoreCase(bean.getName(),"PermGen")!=-1) {
        return bean;
      }
    }
    // take none-heap when only one
    it = manager.iterator();
    LinkedList<MemoryPoolMXBean> beans=new LinkedList<MemoryPoolMXBean>();
    while(it.hasNext()){
      bean = it.next();
      if(bean.getType().equals(MemoryType.NON_HEAP)) {
        beans.add(bean);
        return bean;
      }
    }
    if(beans.size()==1) return beans.getFirst();
   
    // Class Memory/ClassBlock Memory?
    it = manager.iterator();
    while(it.hasNext()){
      bean = it.next();
      if(StringUtil.indexOfIgnoreCase(bean.getName(),"Class Memory")!=-1) {
        return bean;
      }
    }
   
   
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

  }*/
 
  private static MemoryUsage getPermGenSpaceSize(MemoryUsage defaultValue) {
    if(permGenSpaceBean!=null) return permGenSpaceBean.getUsage();
    // create on the fly when the bean is not permanent
    MemoryPoolMXBean tmp = getPermGenSpaceBean();
    if(tmp!=null) return tmp.getUsage();
   
    return defaultValue;
  }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

        KeyConstants._max,
        KeyConstants._init
    },0,"memory");
   
    int row=0;
    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    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;
       
      row++;
      qry.addRow();
      qry.setAtEL(KeyConstants._name, row, bean.getName());
      qry.setAtEL(KeyConstants._type, row, _type.name());
      qry.setAtEL(KeyConstants._max, row, Caster.toDouble(usage.getMax()));
      qry.setAtEL(KeyConstants._used, row, Caster.toDouble(usage.getUsed()));
      qry.setAtEL(KeyConstants._init, row, Caster.toDouble(usage.getInit()));
     
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

 
  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();
      }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

  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;
  }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

    }
  };

  @Test
  public void explodePermGen() throws Exception {
    MemoryPoolMXBean permGenPool = null;
    for (MemoryPoolMXBean mp : ManagementFactory.getMemoryPoolMXBeans()) {
      if (mp.getName().contains("Perm Gen")) {
        permGenPool = mp;
        break;
      }
    }

    if (permGenPool == null) {
      // No permgen pool?
      Assume.assumeTrue(false);
    }

    // Just keep on loading classes until we explode.
    Random rnd = new Random(0xdeadbeef);
    int classes = 0;
    List<Class<?>> keep = new ArrayList<Class<?>>();
    while (true) {
      if ((classes++ % 1000) == 0) {
        System.out.println(permGenPool.getName() + " => " + permGenPool.getUsage());
      }

      // Prepare a new unique exception class with asm. Throw it.
      Class<?> clz = generateExceptionClass(rnd.nextLong());
      clz.newInstance();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.