Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly set field name for @TargetMethodOrField #700

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,8 @@ && matches(targetFieldName, name)) {
getMethodOrFieldName(
om.isTargetMethodOrFieldFqn(),
opcode,
targetClassName,
targetFieldName,
owner,
name,
desc)),
constArg(om.getClassNameParameter(), className.replace('/', '.')),
constArg(om.getMethodParameter(), getName(om.isMethodFqn())),
Expand Down Expand Up @@ -1015,8 +1015,8 @@ && matches(targetFieldName, name)) {
getMethodOrFieldName(
om.isTargetMethodOrFieldFqn(),
opcode,
targetClassName,
targetFieldName,
owner,
name,
desc)),
localVarArg(om.getReturnParameter(), fldType, returnValIndex),
constArg(om.getClassNameParameter(), className.replace('/', '.')),
Expand Down Expand Up @@ -1085,8 +1085,8 @@ && matches(targetFieldName, name)) {
getMethodOrFieldName(
om.isTargetMethodOrFieldFqn(),
opcode,
targetClassName,
targetFieldName,
owner,
name,
desc)),
constArg(om.getClassNameParameter(), className.replace('/', '.')),
constArg(om.getMethodParameter(), getName(om.isMethodFqn())),
Expand Down Expand Up @@ -1129,8 +1129,8 @@ && matches(targetFieldName, name)) {
getMethodOrFieldName(
om.isTargetMethodOrFieldFqn(),
opcode,
targetClassName,
targetFieldName,
owner,
name,
desc)),
constArg(om.getClassNameParameter(), className.replace('/', '.')),
constArg(om.getMethodParameter(), getName(om.isMethodFqn())),
Expand Down
4 changes: 2 additions & 2 deletions btrace-instr/src/test/btrace/onmethod/FieldGetAfter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class FieldGetAfter {
location =
@Location(
value = Kind.FIELD_GET,
clazz = "resources.OnMethodTest",
field = "field",
clazz = "/^resources.OnMethodTest$/",
field = "/^field$/",
where = Where.AFTER))
public static void args(
@Self Object self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class FieldGetAfterStatic {
location =
@Location(
value = Kind.FIELD_GET,
clazz = "resources.OnMethodTest",
field = "sField",
clazz = "/^resources.OnMethodTest$/",
field = "/^sField$/",
where = Where.AFTER))
public static void args(
@Self Object self,
Expand Down
2 changes: 1 addition & 1 deletion btrace-instr/src/test/btrace/onmethod/FieldGetBefore.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FieldGetBefore {
@OnMethod(
clazz = "/.*\\.OnMethodTest/",
method = "field",
location = @Location(value = Kind.FIELD_GET, clazz = "/.*\\.OnMethodTest/", field = "field"))
location = @Location(value = Kind.FIELD_GET, clazz = "/.*\\.OnMethodTest/", field = "/^field$/"))
public static void args(
@Self Object self, @TargetInstance Object inst, @TargetMethodOrField String fldName) {
println("args");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FieldGetBeforeStatic {
@OnMethod(
clazz = "/.*\\.OnMethodTest/",
method = "staticField",
location = @Location(value = Kind.FIELD_GET, clazz = "/.*\\.OnMethodTest/", field = "sField"))
location = @Location(value = Kind.FIELD_GET, clazz = "/.*\\.OnMethodTest/", field = "/^sField$/"))
public static void args(
@Self Object self, @TargetInstance Object inst, @TargetMethodOrField String fldName) {
println("args");
Expand Down
2 changes: 1 addition & 1 deletion btrace-instr/src/test/btrace/onmethod/FieldSetAfter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class FieldSetAfter {
@Location(
value = Kind.FIELD_SET,
clazz = "resources.OnMethodTest",
field = "field",
field = "/^field$/",
where = Where.AFTER))
public static void args(
@Self Object self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class FieldSetAfterStatic {
@Location(
value = Kind.FIELD_SET,
clazz = "resources.OnMethodTest",
field = "sField",
field = "/^sField$/",
where = Where.AFTER))
public static void args(
@Self Object self,
Expand Down
2 changes: 1 addition & 1 deletion btrace-instr/src/test/btrace/onmethod/FieldSetBefore.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FieldSetBefore {
@OnMethod(
clazz = "/.*\\.OnMethodTest/",
method = "field",
location = @Location(value = Kind.FIELD_SET, clazz = "/.*\\.OnMethodTest/", field = "field"))
location = @Location(value = Kind.FIELD_SET, clazz = "/.*\\.OnMethodTest/", field = "/^field$/"))
public static void args(
@Self Object self,
@TargetInstance Object inst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FieldSetBeforeStatic {
@OnMethod(
clazz = "/.*\\.OnMethodTest/",
method = "staticField",
location = @Location(value = Kind.FIELD_SET, clazz = "/.*\\.OnMethodTest/", field = "sField"))
location = @Location(value = Kind.FIELD_SET, clazz = "/.*\\.OnMethodTest/", field = "/^sField$/"))
public static void args(
@Self Object self,
@TargetInstance Object inst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class FieldGetAfter {
location =
@Location(
value = Kind.FIELD_GET,
clazz = "resources.OnMethodTest",
field = "field",
clazz = "/^resources.OnMethodTest$/",
field = "/^field$/",
where = Where.AFTER),
enableAt = @Level(">=1"))
public static void args(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class FieldGetAfterStatic {
location =
@Location(
value = Kind.FIELD_GET,
clazz = "resources.OnMethodTest",
field = "sField",
clazz = "/^resources.OnMethodTest$/",
field = "/^sField$/",
where = Where.AFTER),
enableAt = @Level(">=1"))
public static void args(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class FieldGetBefore {
@OnMethod(
clazz = "/.*\\.OnMethodTest/",
method = "field",
location = @Location(value = Kind.FIELD_GET, clazz = "/.*\\.OnMethodTest/", field = "field"),
location = @Location(value = Kind.FIELD_GET, clazz = "/.*\\.OnMethodTest/", field = "/^field$/"),
enableAt = @Level(">=1"))
public static void args(
@Self Object self, @TargetInstance Object inst, @TargetMethodOrField String fldName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class FieldGetBeforeStatic {
@OnMethod(
clazz = "/.*\\.OnMethodTest/",
method = "staticField",
location = @Location(value = Kind.FIELD_GET, clazz = "/.*\\.OnMethodTest/", field = "sField"),
location = @Location(value = Kind.FIELD_GET, clazz = "/.*\\.OnMethodTest/", field = "/^sField$/"),
enableAt = @Level(">=1"))
public static void args(
@Self Object self, @TargetInstance Object inst, @TargetMethodOrField String fldName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class FieldSetAfter {
@Location(
value = Kind.FIELD_SET,
clazz = "resources.OnMethodTest",
field = "field",
field = "/^field$/",
where = Where.AFTER),
enableAt = @Level(">=1"))
public static void args(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class FieldSetAfterStatic {
@Location(
value = Kind.FIELD_SET,
clazz = "resources.OnMethodTest",
field = "sField",
field = "/^sField$/",
where = Where.AFTER),
enableAt = @Level(">=1"))
public static void args(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class FieldSetBefore {
@OnMethod(
clazz = "/.*\\.OnMethodTest/",
method = "field",
location = @Location(value = Kind.FIELD_SET, clazz = "/.*\\.OnMethodTest/", field = "field"),
location = @Location(value = Kind.FIELD_SET, clazz = "/.*\\.OnMethodTest/", field = "/^field$/"),
enableAt = @Level(">=1"))
public static void args(
@Self Object self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class FieldSetBeforeStatic {
@OnMethod(
clazz = "/.*\\.OnMethodTest/",
method = "staticField",
location = @Location(value = Kind.FIELD_SET, clazz = "/.*\\.OnMethodTest/", field = "sField"),
location = @Location(value = Kind.FIELD_SET, clazz = "/.*\\.OnMethodTest/", field = "/^sField$/"),
enableAt = @Level(">=1"))
public static void args(
@Self Object self,
Expand Down
12 changes: 12 additions & 0 deletions integration-tests/src/test/btrace/OnMethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public static void args(@Self Object self, int i, String s) {
println("prop: " + property("btrace.test"));
}

@OnMethod(clazz = "resources.Main", method = "/^call.*/",
location = @Location(value = Kind.FIELD_GET, clazz = "resources.Main", field = "/^s?[fF]ield$/"))
public static void fieldGet(@TargetMethodOrField(fqn = true) String fldName) {
println("fieldGet: " + fldName);
}

@OnMethod(clazz = "resources.Main", method = "/^call.*/",
location = @Location(value = Kind.FIELD_SET, clazz = "resources.Main", field = "/^s?[fF]ield$/"))
public static void fieldSet(@TargetMethodOrField(fqn = true) String fldName) {
println("fieldSet: " + fldName);
}

@OnTimer(500)
public static void doRecurrent() {
long x = 10;
Expand Down
6 changes: 5 additions & 1 deletion integration-tests/src/test/java/resources/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
*/
public class Main extends TestApp {
private String id = "xxx";
private String field;
private static String sField;

public static void main(String[] args) throws Exception {
Main i = new Main();
Expand All @@ -49,11 +51,13 @@ protected void startWork() {
}

private void callA() {
field = "AAA";
sField = "BBB";
print("i=" + callB(1, "Hello World"));
}

private int callB(int i, String s) {
print("[" + i + "] = " + s);
print("[" + i + "] = " + s + ", field = " + field + ", sField = " + sField);
return i + 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void testOnMethod() throws Exception {
test(
"resources.Main",
"btrace/OnMethodTest.java",
10,
14,
new ResultValidator() {
@Override
public void validate(String stdout, String stderr, int retcode, String jfrFile) {
Expand All @@ -164,6 +164,10 @@ public void validate(String stdout, String stderr, int retcode, String jfrFile)
assertTrue(stdout.contains("{xxx}"));
assertTrue(stdout.contains("heap:init"));
assertTrue(stdout.contains("prop: test"));
assertTrue(stdout.contains("fieldSet: field java.lang.String resources.Main#field"));
assertTrue(stdout.contains("fieldSet: static field java.lang.String resources.Main#sField"));
assertTrue(stdout.contains("fieldGet: field java.lang.String resources.Main#field"));
assertTrue(stdout.contains("fieldGet: static field java.lang.String resources.Main#sField"));
}
});
}
Expand Down
Loading