KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > container > monitor > jvm > v15 > ExoInstrument


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.container.monitor.jvm.v15;
6
7 import java.lang.instrument.ClassFileTransformer JavaDoc;
8 import java.lang.instrument.IllegalClassFormatException JavaDoc;
9 import java.lang.instrument.Instrumentation JavaDoc;
10 /**
11  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
12  * @since Feb 8, 2005
13  * @version $Id$
14  * You should pass -javaagent:org.exoplatform.container.monitor.jvm.v15.ExoInstrument
15  * to JAVA_OPTS
16  */

17 public class ExoInstrument {
18   static private Instrumentation JavaDoc ins_ ;
19   
20   public static void main(String JavaDoc args[] ) {
21     System.out.println("Hello World" );
22   }
23   
24   public static void premain(String JavaDoc options, Instrumentation JavaDoc ins) {
25     //ins.addTransformer(new Logger() );
26
ins_ = ins ;
27     System.out.println("==========================> call premain") ;
28   }
29   
30   public static Instrumentation JavaDoc getInstrumentation() { return ins_ ; }
31   
32   public void printObjectSize(Object JavaDoc object) {
33     System.out.println("size of " + object.getClass().getName() + " = "+ ins_.getObjectSize(object)) ;
34   }
35   
36   /*Sample transformer , this class just print the loaded classes*/
37   public static class Logger implements ClassFileTransformer JavaDoc {
38     public byte[] transform(java.lang.ClassLoader JavaDoc loader,
39                             java.lang.String JavaDoc className,
40                             java.lang.Class JavaDoc classBeingRedefined,
41                             java.security.ProtectionDomain JavaDoc protectionDomain,
42                             byte[] classfileBuffer) throws IllegalClassFormatException JavaDoc {
43       System.out.println(className );
44       return null;
45     }
46   }
47 }
Popular Tags