JAVA

[java] Java sizeof 구현해보기 jdk5 이상가능

AlrepondTech 2011. 3. 23. 17:54
반응형

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 

 

참고: 

http://ko.w3support.net/index.php?db=so&id=52353

출처: 

http://www.javaworld.com/javaforums/showflat.php?Cat=2&Board=javabeginner&Number=42012&Searchpage=1&Main=42007&Words=+Yaogao&topic=&Search=true

import java.lang.instrument.Instrumentation;
import java.util.Calendar;

public class Test {

private static Instrumentation inst;

public static void premain(String options, Instrumentation inst) {
Test.inst = inst;
System.out.println("options= " + options);

Class[] loaded = inst.getAllLoadedClasses();

for (Class clazz : loaded) {
System.out.println(clazz);
}
}

public static long sizeOf(Object o) {
assert inst != null;
return inst.getObjectSize(o);
}

public static void main(String[] args) {
System.out.println("Size of Object: " + sizeOf(new Object()));
System.out.println("Size of direct subclass: " + sizeOf(new Test()));
System.out.println("Size of Calendar: "
+ sizeOf(Calendar.getInstance()));
}
}


// 매니페스트 설정
First, create a MANIFEST.MF file, and add the following content in it.
Manifest-Version: 1.0
Premain-Class: Test
Second, package the class and MANIFEST.MF into a jar file test.jar
Third, run the program by command:java -ea -javaagent:est.jar 
 

 

 

=================================

=================================

=================================

 

 

반응형