All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.holmos.cache.size.layout.ClassSizeInfoParser Maven / Gradle / Ivy

There is a newer version: 1.0.2u10
Show newest version
package com.holmos.cache.size.layout;

import com.holmos.cache.size.layout.impl.Hotspot32MemoryLayoutSpecification;
import com.holmos.cache.size.layout.impl.Hotspot64MemoryLayoutSpecification;

/**
 * 类的占用内存信息的获取器
 * 
 * @author 吴银龙([email protected])
 * */
public class ClassSizeInfoParser {
	
	private static MemoryLayoutSpecification memoryLayoutSpecification;
	public static MemoryLayoutSpecification getLayoutSpecification(){
		return memoryLayoutSpecification;
	}
	static{
		final String vmName = System.getProperty("java.vm.name");
	    if (vmName == null || !vmName.startsWith("Java HotSpot(TM) ")) {
	      throw new UnsupportedOperationException(
	          "ObjectSizeCalculator only supported on HotSpot VM");
	    }

	    final String dataModel = System.getProperty("sun.arch.data.model");
	    if ("32".equals(dataModel)) {
	    	memoryLayoutSpecification= new Hotspot32MemoryLayoutSpecification();
	    }else if("64".equals(dataModel)){
	    	memoryLayoutSpecification=new Hotspot64MemoryLayoutSpecification();
	    }
	}
	
	public static int getPrimitiveType(Class type){
		if(long.class == type || double.class == type)
			return 3;
		else if(int.class == type || float.class == type)
			return 2;
		else if(char.class == type || short.class == type)
			return 1;
		else if(boolean.class == type || byte.class == type)
			return 0;
		else
			return 4;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy