Java Code Examples for java.lang.management.MemoryType.NON_HEAP

The following are Jave code examples for showing how to use NON_HEAP of the java.lang.management.MemoryType class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: flink   File: MemoryLogger.java   Source Code and License Vote up 6 votes
/**
 * 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
Project: SOMns   File: ActorExecutionTrace.java   Source Code and License Vote up 6 votes
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");
}
 
Example 3
Project: Lucee4   File: SystemUtil.java   Source Code and License Vote up 6 votes
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;
}
 
Example 4
Project: Lucee4   File: SystemUtil.java   Source Code and License Vote up 6 votes
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;
}
 
Example 5
Project: Lucee   File: SystemUtil.java   Source Code and License Vote up 6 votes
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;
}
 
Example 6
Project: Lucee   File: SystemUtil.java   Source Code and License Vote up 6 votes
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;
}
 
Example 7
Project: hbase   File: MemorySizeUtil.java   Source Code and License Vote up 6 votes
/**
 * @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 8
Project: OpenJSharp   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 9
Project: jdk8u-jdk   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 10
Project: openjdk-jdk10   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 11
Project: openjdk9   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 12
Project: jdk8u_jdk   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 13
Project: lookaside_java-1.8.0-openjdk   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 14
Project: infobip-open-jdk-8   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 15
Project: jdk8u-dev-jdk   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 16
Project: jdk7-jdk   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 17
Project: openjdk-source-code-learn   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 18
Project: OLD-OpenJDK8   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 19
Project: openjdk-jdk7u-jdk   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 20
Project: openjdk-icedtea7   File: MemoryPoolImpl.java   Source Code and License Vote up 5 votes
public MemoryType getType() {
    if (isHeap) {
        return MemoryType.HEAP;
    } else {
        return MemoryType.NON_HEAP;
    }
}
 
Example 21
Project: Lucee4   File: MemoryNotificationListener.java   Source Code and License Vote up 4 votes
@Override
public void handleNotification(Notification not, Object handback) {
	
	if (not.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
		CompositeDataSupport data=(CompositeDataSupport) not.getUserData();
		
		
		String poolName = (String) data.get("poolName");
		MemoryType type = types.get(poolName);
		if(type==MemoryType.HEAP){
			// clear heap
			aprint.e("Clear heap!");
		}
		else if(type==MemoryType.NON_HEAP) {
			// clear none-heap
			((Config) handback).checkPermGenSpace(false);
		}
		
		/*CompositeDataSupport usage=(CompositeDataSupport) data.get("usage");
		print.e(poolName);
		print.e(types.get(poolName));
		print.e(data.get("count"));
		
		print.e(usage.get("committed"));
		print.e(usage.get("init"));
		print.e(usage.get("max"));
		print.e(usage.get("used"));

		long max=Caster.toLongValue(usage.get("max"),0);
		long used=Caster.toLongValue(usage.get("used"),0);
		long free=max-used;
		print.o("m:"+max);
		print.o("f:"+free);
		print.o("%:"+(100L*used/max));
		//not.*/
	}
	/*
	javax.management.openmbean.CompositeDataSupport(
		compositeType=javax.management.openmbean.CompositeType(
			name=java.lang.management.MemoryUsage,
			items=(
				(itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
				(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
				(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
				(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),contents={committed=101580800, init=65404928, max=110362624, used=101085960})

	
	
	javax.management.openmbean.CompositeDataSupport(
			compositeType=javax.management.openmbean.CompositeType(
				name=java.lang.management.MemoryNotificationInfo,
				items=(
						(itemName=count,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
						(itemName=poolName,itemType=javax.management.openmbean.SimpleType(name=java.lang.String)),
						(itemName=usage,itemType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long))))))),contents={count=1, poolName=CMS Old Gen, usage=javax.management.openmbean.CompositeDataSupport(compositeType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),contents={committed=101580800, init=65404928, max=110362624, used=101085944})})

	*/
	/*
	print.e(data.getCompositeType());
	print.e(not.getSource().getClass().getName());
	print.e(not.getSource());
	ObjectName on=(ObjectName) not.getSource();
	print.e(on.getKeyPropertyList());
	*/
	
	
	
	/*
	print.e(not.getUserData().getClass().getName());
	print.e(not.getUserData());
	
	print.e(not.getMessage());
	print.e(not.getSequenceNumber());
	print.e(not.getTimeStamp());
	print.e(not.getType());*/
}
 
Example 22
Project: Lucee   File: MemoryNotificationListener.java   Source Code and License Vote up 4 votes
@Override
public void handleNotification(Notification not, Object handback) {
	
	if (not.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
		CompositeDataSupport data=(CompositeDataSupport) not.getUserData();
		
		
		String poolName = (String) data.get("poolName");
		MemoryType type = types.get(poolName);
		if(type==MemoryType.HEAP){
			// clear heap
			aprint.e("Clear heap!");
		}
		else if(type==MemoryType.NON_HEAP) {
			// clear none-heap
			((Config) handback).checkPermGenSpace(false);
		}
		
		/*CompositeDataSupport usage=(CompositeDataSupport) data.get("usage");
		print.e(poolName);
		print.e(types.get(poolName));
		print.e(data.get("count"));
		
		print.e(usage.get("committed"));
		print.e(usage.get("init"));
		print.e(usage.get("max"));
		print.e(usage.get("used"));

		long max=Caster.toLongValue(usage.get("max"),0);
		long used=Caster.toLongValue(usage.get("used"),0);
		long free=max-used;
		print.o("m:"+max);
		print.o("f:"+free);
		print.o("%:"+(100L*used/max));
		//not.*/
	}
	/*
	javax.management.openmbean.CompositeDataSupport(
		compositeType=javax.management.openmbean.CompositeType(
			name=java.lang.management.MemoryUsage,
			items=(
				(itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
				(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
				(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
				(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),contents={committed=101580800, init=65404928, max=110362624, used=101085960})

	
	
	javax.management.openmbean.CompositeDataSupport(
			compositeType=javax.management.openmbean.CompositeType(
				name=java.lang.management.MemoryNotificationInfo,
				items=(
						(itemName=count,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),
						(itemName=poolName,itemType=javax.management.openmbean.SimpleType(name=java.lang.String)),
						(itemName=usage,itemType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long))))))),contents={count=1, poolName=CMS Old Gen, usage=javax.management.openmbean.CompositeDataSupport(compositeType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),contents={committed=101580800, init=65404928, max=110362624, used=101085944})})

	*/
	/*
	print.e(data.getCompositeType());
	print.e(not.getSource().getClass().getName());
	print.e(not.getSource());
	ObjectName on=(ObjectName) not.getSource();
	print.e(on.getKeyPropertyList());
	*/
	
	
	
	/*
	print.e(not.getUserData().getClass().getName());
	print.e(not.getUserData());
	
	print.e(not.getMessage());
	print.e(not.getSequenceNumber());
	print.e(not.getTimeStamp());
	print.e(not.getType());*/
}
 
Example 23
Project: hbase   File: RegionServerAccounting.java   Source Code and License Vote up 4 votes
boolean isOffheap() {
  return this.memType == MemoryType.NON_HEAP;
}