KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sun > tools > hprof > Tracker


1 /*
2  * @(#)Tracker.java 1.7 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package sun.tools.hprof;
9
10 /* This class and it's methods are used by 5.0 hprof when injecting bytecodes
11  * into class file images.
12  * WARNING: This class may not be used by newer versions of hprof.
13  * See the directory src/share/demo/jvmti/hprof and the file README.txt
14  * for more details.
15  */

16
17 public class Tracker {
18  
19     /* Master switch that activates calls to native functions. */
20     
21     private static int engaged = 0;
22   
23     /* To track memory allocated, we need to catch object init's and arrays. */
24     
25     /* At the beginning of java.jang.Object.<init>(), a call to
26      * sun.tools.hprof.Tracker.ObjectInit() is injected.
27      */

28
29     private static native void nativeObjectInit(Object JavaDoc thr, Object JavaDoc obj);
30     
31     public static void ObjectInit(Object JavaDoc obj)
32     {
33     if ( engaged != 0 ) {
34         nativeObjectInit(Thread.currentThread(), obj);
35     }
36     }
37     
38     /* Immediately following any of the newarray bytecodes, a call to
39      * sun.tools.hprof.Tracker.NewArray() is injected.
40      */

41
42     private static native void nativeNewArray(Object JavaDoc thr, Object JavaDoc obj);
43    
44     public static void NewArray(Object JavaDoc obj)
45     {
46     if ( engaged != 0 ) {
47         nativeNewArray(Thread.currentThread(), obj);
48     }
49     }
50    
51     /* For cpu time spent in methods, we need to inject for every method. */
52
53     /* At the very beginning of every method, a call to
54      * sun.tools.hprof.Tracker.CallSite() is injected.
55      */

56
57     private static native void nativeCallSite(Object JavaDoc thr, int cnum, int mnum);
58     
59     public static void CallSite(int cnum, int mnum)
60     {
61     if ( engaged != 0 ) {
62         nativeCallSite(Thread.currentThread(), cnum, mnum);
63     }
64     }
65     
66     /* Before any of the return bytecodes, a call to
67      * sun.tools.hprof.Tracker.ReturnSite() is injected.
68      */

69
70     private static native void nativeReturnSite(Object JavaDoc thr, int cnum, int mnum);
71     
72     public static void ReturnSite(int cnum, int mnum)
73     {
74     if ( engaged != 0 ) {
75         nativeReturnSite(Thread.currentThread(), cnum, mnum);
76     }
77     }
78     
79 }
80
81
Popular Tags