首页 > 编程语言 > 详细

J2SE 1.6 特性:java.lang.instrument

时间:2014-11-10 19:35:11      阅读:295      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/yuyutianxia/p/4087699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!