Skip to content

Commit 8f2c76d

Browse files
author
Jaroslav Bachorik
committed
btraceio#37 - experimental support for additional annotations @self, @return, @CalledInstance, @CalledMethod
btraceio#37 - experimental support for additional annotations @self, @return, @CalledInstance, @CalledMethod
1 parent ff1402b commit 8f2c76d

33 files changed

Lines changed: 1796 additions & 1357 deletions

‎docs/usersguide.html‎

Lines changed: 503 additions & 478 deletions
Large diffs are not rendered by default.

‎samples/AWTEventTracer.java‎

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1-
/*
2-
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
3-
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4-
*
5-
* This code is free software; you can redistribute it and/or modify it
6-
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation. Sun designates this
8-
* particular file as subject to the "Classpath" exception as provided
9-
* by Sun in the LICENSE file that accompanied this code.
10-
*
11-
* This code is distributed in the hope that it will be useful, but WITHOUT
12-
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13-
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14-
* version 2 for more details (a copy is included in the LICENSE file that
15-
* accompanied this code).
16-
*
17-
* You should have received a copy of the GNU General Public License version
18-
* 2 along with this work; if not, write to the Free Software Foundation,
19-
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20-
*
21-
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22-
* CA 95054 USA or visit www.sun.com if you need additional information or
23-
* have any questions.
24-
*/
25-
26-
package com.sun.btrace.samples;
27-
28-
import com.sun.btrace.annotations.*;
29-
import static com.sun.btrace.BTraceUtils.*;
30-
import java.awt.EventQueue;
31-
import java.awt.AWTEvent;
32-
import java.awt.event.FocusEvent;
33-
34-
/**
35-
* This simple script traces every AWT focus event in
36-
* the target process.
37-
*/
38-
@BTrace
39-
public class AWTEventTracer {
40-
@OnMethod(
41-
clazz="java.awt.EventQueue",
42-
method="dispatchEvent"
43-
)
44-
public static void onevent(EventQueue queue, AWTEvent event) {
45-
if (event instanceof FocusEvent) {
46-
println(event);
47-
println();
48-
}
49-
}
50-
}
51-
1+
/*
2+
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Sun designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Sun in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22+
* CA 95054 USA or visit www.sun.com if you need additional information or
23+
* have any questions.
24+
*/
25+
26+
package com.sun.btrace.samples;
27+
28+
import com.sun.btrace.annotations.*;
29+
import static com.sun.btrace.BTraceUtils.*;
30+
import java.awt.EventQueue;
31+
import java.awt.AWTEvent;
32+
import java.awt.event.FocusEvent;
33+
34+
/**
35+
* This simple script traces every AWT focus event in
36+
* the target process.
37+
*/
38+
@BTrace
39+
public class AWTEventTracer {
40+
@OnMethod(
41+
clazz="java.awt.EventQueue",
42+
method="dispatchEvent"
43+
)
44+
public static void onevent(@Self EventQueue queue, AWTEvent event) {
45+
if (event instanceof FocusEvent) {
46+
println(event);
47+
println();
48+
}
49+
}
50+
}
51+

‎samples/AllCalls1.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
@BTrace public class AllCalls1 {
3838
@OnMethod(clazz="javax.swing.JTextField", method="/.*/",
3939
location=@Location(value=Kind.CALL, clazz="/.*/", method="/.*/"))
40-
public static void m(Object self, String method) { // all calls to the methods with signature "()"
40+
public static void m(@Self Object self, @CalledMethod String method) { // all calls to the methods with signature "()"
4141
println(method);
4242
}
4343
}

‎samples/AllCalls2.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
@BTrace public class AllCalls2 {
3939
@OnMethod(clazz="/javax\\.swing\\..*/", method="/.*/",
4040
location=@Location(value=Kind.CALL, clazz="/.*/", method="/.*/"))
41-
public static void n(Object self, String method, String text) { // all calls to the methods with signature "(String)"
41+
public static void n(@Self Object self, @CalledInstance Object instance, @CalledMethod String method, String text) { // all calls to the methods with signature "(String)"
4242
print(method);
4343
print(" ");
4444
println(text);

‎samples/Classload.java‎

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
/*
2-
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
3-
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4-
*
5-
* This code is free software; you can redistribute it and/or modify it
6-
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation. Sun designates this
8-
* particular file as subject to the "Classpath" exception as provided
9-
* by Sun in the LICENSE file that accompanied this code.
10-
*
11-
* This code is distributed in the hope that it will be useful, but WITHOUT
12-
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13-
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14-
* version 2 for more details (a copy is included in the LICENSE file that
15-
* accompanied this code).
16-
*
17-
* You should have received a copy of the GNU General Public License version
18-
* 2 along with this work; if not, write to the Free Software Foundation,
19-
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20-
*
21-
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22-
* CA 95054 USA or visit www.sun.com if you need additional information or
23-
* have any questions.
24-
*/
25-
26-
package com.sun.btrace.samples;
27-
28-
import static com.sun.btrace.BTraceUtils.*;
29-
import com.sun.btrace.annotations.*;
30-
31-
/**
32-
* A simple BTrace program that prints stack trace
33-
* whenever a class is loaded by a user-defined
34-
* class loader. We insert a return point probe in
35-
* ClassLoader.defineClass method to detect successful
36-
* class load.
37-
*/
38-
@BTrace public class Classload {
39-
@OnMethod(
40-
clazz="java.lang.ClassLoader",
41-
method="defineClass",
42-
location=@Location(Kind.RETURN)
43-
)
44-
public static void defineclass(Class cl) {
45-
println(strcat("loaded ", name(cl)));
46-
jstack();
47-
println("==========================");
48-
}
49-
}
1+
/*
2+
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Sun designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Sun in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22+
* CA 95054 USA or visit www.sun.com if you need additional information or
23+
* have any questions.
24+
*/
25+
26+
package com.sun.btrace.samples;
27+
28+
import static com.sun.btrace.BTraceUtils.*;
29+
import com.sun.btrace.annotations.*;
30+
31+
/**
32+
* A simple BTrace program that prints stack trace
33+
* whenever a class is loaded by a user-defined
34+
* class loader. We insert a return point probe in
35+
* ClassLoader.defineClass method to detect successful
36+
* class load.
37+
*/
38+
@BTrace public class Classload {
39+
@OnMethod(
40+
clazz="+java.lang.ClassLoader",
41+
method="defineClass",
42+
location=@Location(Kind.RETURN)
43+
)
44+
public static void defineclass(@Return Class cl) {
45+
println(strcat("loaded ", name(cl)));
46+
jstack();
47+
println("==========================");
48+
}
49+
}

‎samples/FileTracker.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
clazz="java.io.FileInputStream",
4545
method="<init>"
4646
)
47-
public static void onNewFileInputStream(FileInputStream self, File f) {
47+
public static void onNewFileInputStream(@Self FileInputStream self, File f) {
4848
name = str(f);
4949
}
5050

@@ -65,7 +65,7 @@ public static void onNewFileInputStreamReturn() {
6565
clazz="java.io.FileOutputStream",
6666
method="<init>"
6767
)
68-
public static void onNewFileOutputStream(FileOutputStream self, File f, boolean b) {
68+
public static void onNewFileOutputStream(@Self FileOutputStream self, File f, boolean b) {
6969
name = str(f);
7070
}
7171

‎samples/FinalizeTracker.java‎

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
1-
/*
2-
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
3-
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4-
*
5-
* This code is free software; you can redistribute it and/or modify it
6-
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation. Sun designates this
8-
* particular file as subject to the "Classpath" exception as provided
9-
* by Sun in the LICENSE file that accompanied this code.
10-
*
11-
* This code is distributed in the hope that it will be useful, but WITHOUT
12-
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13-
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14-
* version 2 for more details (a copy is included in the LICENSE file that
15-
* accompanied this code).
16-
*
17-
* You should have received a copy of the GNU General Public License version
18-
* 2 along with this work; if not, write to the Free Software Foundation,
19-
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20-
*
21-
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22-
* CA 95054 USA or visit www.sun.com if you need additional information or
23-
* have any questions.
24-
*/
25-
26-
package com.sun.btrace.samples;
27-
28-
import com.sun.btrace.annotations.*;
29-
import static com.sun.btrace.BTraceUtils.*;
30-
import java.lang.reflect.Field;
31-
32-
@BTrace public class FinalizeTracker {
33-
private static Field fdField =
34-
field("java.io.FileInputStream", "fd");
35-
36-
@OnTimer(4000)
37-
public static void ontimer() {
38-
runFinalization();
39-
}
40-
41-
@OnMethod(
42-
clazz="java.io.FileInputStream",
43-
method="finalize"
44-
)
45-
public static void onfinalize(Object me) {
46-
println(concat("finalizing ", str(me)));
47-
printFields(me);
48-
printFields(get(fdField, me));
49-
println("==========");
50-
}
51-
52-
@OnMethod(
53-
clazz="java.io.FileInputStream",
54-
method="close"
55-
)
56-
public static void onclose(Object me) {
57-
println(concat("closing ", str(me)));
58-
println(concat("thread: ", str(currentThread())));
59-
printFields(me);
60-
printFields(get(fdField, me));
61-
jstack();
62-
println("=============");
63-
}
64-
}
1+
/*
2+
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Sun designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Sun in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22+
* CA 95054 USA or visit www.sun.com if you need additional information or
23+
* have any questions.
24+
*/
25+
26+
package com.sun.btrace.samples;
27+
28+
import com.sun.btrace.annotations.*;
29+
import static com.sun.btrace.BTraceUtils.*;
30+
import java.lang.reflect.Field;
31+
32+
@BTrace public class FinalizeTracker {
33+
private static Field fdField =
34+
field("java.io.FileInputStream", "fd");
35+
36+
@OnTimer(4000)
37+
public static void ontimer() {
38+
runFinalization();
39+
}
40+
41+
@OnMethod(
42+
clazz="java.io.FileInputStream",
43+
method="finalize"
44+
)
45+
public static void onfinalize(@Self Object me) {
46+
println(concat("finalizing ", str(me)));
47+
printFields(me);
48+
printFields(get(fdField, me));
49+
println("==========");
50+
}
51+
52+
@OnMethod(
53+
clazz="java.io.FileInputStream",
54+
method="close"
55+
)
56+
public static void onclose(@Self Object me) {
57+
println(concat("closing ", str(me)));
58+
println(concat("thread: ", str(currentThread())));
59+
printFields(me);
60+
printFields(get(fdField, me));
61+
jstack();
62+
println("=============");
63+
}
64+
}

‎samples/HistoOnEvent.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
clazz="javax.swing.JComponent",
4343
method="<init>"
4444
)
45-
public static void onnewObject(Object obj) {
45+
public static void onnewObject(@Self Object obj) {
4646
String cn = name(classOf(obj));
4747
AtomicInteger ai = get(histo, cn);
4848
if (ai == null) {

0 commit comments

Comments
 (0)