首页 > 代码库 > J2SE 1.6 特性:java.lang.instrument
J2SE 1.6 特性:java.lang.instrument
1.
import java.lang.instrument.Instrumentation;public class ObjectSizeFetcher { private static Instrumentation instrumentation; public static void premain(String args, Instrumentation inst) { instrumentation = inst; } public static long getObjectSize(Object o) { return instrumentation.getObjectSize(o); }}
2.
jar cvf ObjectSizeFetcher.jar ObjectSizeFetcher.class
3.
Add the following to your MANIFEST.MF
:
Premain-Class: ObjectSizeFetcher
4.
public class C { private int x; private int y; public static void main(String [] args) { System.out.println(ObjectSizeFetcher.getObjectSize(new C())); }}
5.调用
java -javaagent:ObjectSizeFetcherAgent.jar C
J2SE 1.6 特性:java.lang.instrument
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。