blob: 68ca92235f3b8cec88e219c385f2cb270bb08c21 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of Sun Microsystems nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32package com.sun.demo.jvmti.hprof;
33
34/* This class and it's methods are used by hprof when injecting bytecodes
35 * into class file images.
36 * See the directory src/share/demo/jvmti/hprof and the file README.txt
37 * for more details.
38 */
39
40public class Tracker {
41
42 /* Master switch that activates calls to native functions. */
43
44 private static int engaged = 0;
45
46 /* To track memory allocated, we need to catch object init's and arrays. */
47
48 /* At the beginning of java.jang.Object.<init>(), a call to
49 * Tracker.ObjectInit() is injected.
50 */
51
52 private static native void nativeObjectInit(Object thr, Object obj);
53
54 public static void ObjectInit(Object obj)
55 {
56 if ( engaged != 0 ) {
57 nativeObjectInit(Thread.currentThread(), obj);
58 }
59 }
60
61 /* Immediately following any of the newarray bytecodes, a call to
62 * Tracker.NewArray() is injected.
63 */
64
65 private static native void nativeNewArray(Object thr, Object obj);
66
67 public static void NewArray(Object obj)
68 {
69 if ( engaged != 0 ) {
70 nativeNewArray(Thread.currentThread(), obj);
71 }
72 }
73
74 /* For cpu time spent in methods, we need to inject for every method. */
75
76 /* At the very beginning of every method, a call to
77 * Tracker.CallSite() is injected.
78 */
79
80 private static native void nativeCallSite(Object thr, int cnum, int mnum);
81
82 public static void CallSite(int cnum, int mnum)
83 {
84 if ( engaged != 0 ) {
85 nativeCallSite(Thread.currentThread(), cnum, mnum);
86 }
87 }
88
89 /* Before any of the return bytecodes, a call to
90 * Tracker.ReturnSite() is injected.
91 */
92
93 private static native void nativeReturnSite(Object thr, int cnum, int mnum);
94
95 public static void ReturnSite(int cnum, int mnum)
96 {
97 if ( engaged != 0 ) {
98 nativeReturnSite(Thread.currentThread(), cnum, mnum);
99 }
100 }
101
102}