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

@OnMethod with @Location(RETURN) and @Level causes NoSuchFieldError: $btrace$$level #419

Closed
m4tiz5zktonj opened this issue May 21, 2020 · 0 comments
Assignees
Milestone

Comments

@m4tiz5zktonj
Copy link

Hello.

I have an issue with BTrace v2.0.1 running on Windows 10 1909 and Oracle JDK.

Example class:

public class TestClass {
    public static void main(String[] args) {
        for (int i = 1; i <= 10; i++) {
            testMethod(i);
        }
    }
    private static void testMethod(int i) {
        System.out.println(i);
    }
}

BTrace class:

import org.openjdk.btrace.core.annotations.*;

import static org.openjdk.btrace.core.BTraceUtils.println;
import static org.openjdk.btrace.core.annotations.Kind.*;

@BTrace
public class BTraceLogger {
    @OnMethod(clazz = "TestClass", method = "testMethod", location = @Location(ENTRY), enableAt = @Level("100"))
    public static void logEntry(@ProbeMethodName String method) {
        println("enter " + method);
    }
    @OnMethod(clazz = "TestClass", method = "testMethod", location = @Location(RETURN), enableAt = @Level("100"))
    public static void logReturn(@ProbeMethodName String method, @Duration long duration) {
        println("exit " + method + ", took " + duration);
    }
}

Run btrace:

D:\Test>java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

D:\Test>javac -version
javac 1.8.0_202

D:\Test>javac TestClass.java

D:\Test>D:\Test\btrace\bin\btracec.bat BTraceLogger.java
btrace INFO: "org.openjdk.btrace.core.cmdQueueLimit" not provided. Using the default cmd queue limit of 100
btrace INFO: Can not load runtime factory: org.openjdk.btrace.runtime.BTraceRuntimeImpl_9$Factory
btrace INFO: Can not load runtime factory: org.openjdk.btrace.runtime.BTraceRuntimeImpl_11$Factory

D:\Test>mkdir scripts && move BTraceLogger.class scripts
1 file(s) moved.

D:\Test>java -javaagent:D:/Test/btrace/libs/btrace-agent.jar=level=100,debug=true,stdout=true,scriptdir=D:/Test/scripts TestClass
btrace DEBUG: parsed command line arguments
btrace DEBUG: Bootstrap ClassPath: /D:/Test/btrace/libs/btrace-boot.jar
btrace DEBUG: debugMode is true
btrace DEBUG: scriptdir is D:/Test/scripts
btrace DEBUG: Adding class transformer
btrace DEBUG: stdout is true
btrace DEBUG: found scriptdir: D:\Test\scripts
btrace DEBUG: loading BTrace class
### BTrace Log: 21.05.20 11:42

btrace DEBUG: verifying BTrace class ...
btrace INFO: "org.openjdk.btrace.core.cmdQueueLimit" not provided. Using the default cmd queue limit of 100
btrace INFO: Can not load runtime factory: org.openjdk.btrace.runtime.BTraceRuntimeImpl_9$Factory
btrace INFO: Can not load runtime factory: org.openjdk.btrace.runtime.BTraceRuntimeImpl_11$Factory
btrace DEBUG: BTrace class org.openjdk.btrace.runtime.aux.BTraceLogger verified
btrace DEBUG: preprocessing BTrace class org.openjdk.btrace.runtime.aux.BTraceLogger ...
btrace DEBUG: ... preprocessed
btrace DEBUG: loaded 'org.openjdk.btrace.runtime.aux.BTraceLogger' successfully
btrace DEBUG: class renamed to org.openjdk.btrace.runtime.aux.BTraceLogger
btrace DEBUG: client org.openjdk.btrace.runtime.aux.BTraceLogger: got org.openjdk.btrace.core.comm.RenameCommand@78308db1
btrace DEBUG: creating BTraceRuntime instance for org.openjdk.btrace.runtime.aux.BTraceLogger
btrace DEBUG: created BTraceRuntime instance for org.openjdk.btrace.runtime.aux.BTraceLogger
btrace DEBUG: sending Okay command
btrace DEBUG: client org.openjdk.btrace.runtime.aux.BTraceLogger: got org.openjdk.btrace.core.comm.OkayCommand@3fee733d
btrace DEBUG: about to defineClass org/openjdk/btrace/runtime/aux/BTraceLogger
btrace DEBUG: init: clazz = null, cl = class org.openjdk.btrace.runtime.aux.BTraceLogger
btrace DEBUG: init: timerHandlers = null
btrace DEBUG: defineClass succeeded for org.openjdk.btrace.runtime.aux.BTraceLogger
btrace DEBUG: skipping transform for BTrace class org/openjdk/btrace/agent/Main$5
btrace DEBUG: skipping transform for BTrace class java/lang/instrument/UnmodifiableClassException
btrace DEBUG: new Client created org.openjdk.btrace.agent.FileClient@4d0b6d80
btrace DEBUG: retransforming loaded classes
btrace DEBUG: filtering loaded classes
btrace DEBUG: skipping transform for BTrace class org/openjdk/btrace/instr/ClassCache$Singleton
btrace DEBUG: noServer is true, server not started
btrace DEBUG: Agent init took: 190581400ns
btrace DEBUG: client org.openjdk.btrace.runtime.aux.BTraceLogger: got org.openjdk.btrace.core.comm.OkayCommand@5ff8ad2a
btrace DEBUG: skipping transform for BTrace class java/lang/invoke/MethodHandleImpl
btrace DEBUG: skipping transform for BTrace class java/lang/invoke/MethodHandleImpl$1
btrace DEBUG: skipping transform for BTrace class java/lang/invoke/MethodHandleImpl$2
btrace DEBUG: skipping transform for BTrace class java/lang/invoke/MethodHandleImpl$3
btrace DEBUG: skipping transform for BTrace class java/lang/invoke/MethodHandleImpl$4
btrace DEBUG: skipping transform for BTrace class java/lang/invoke/MemberName$Factory
btrace DEBUG: skipping transform for BTrace class java/lang/invoke/MethodHandleStatics
btrace DEBUG: skipping transform for BTrace class java/lang/invoke/MethodHandleStatics$1
btrace DEBUG: transformed class TestClass
Exception in thread "main" java.lang.NoSuchFieldError: $btrace$$level
        at TestClass.testMethod(TestClass.java)
        at TestClass.main(TestClass.java:4)
btrace DEBUG: client org.openjdk.btrace.runtime.aux.BTraceLogger: got org.openjdk.btrace.core.comm.ExitCommand@513f58a5
btrace DEBUG: onExit:
btrace DEBUG: cleaning up transformers
btrace DEBUG: onExit: removing transformer for org.openjdk.btrace.runtime.aux.BTraceLogger
btrace DEBUG: removing instrumentation
btrace DEBUG: retransforming loaded classes
btrace DEBUG: filtering loaded classes
btrace DEBUG: candidate class TestClass added
btrace DEBUG: client org.openjdk.btrace.runtime.aux.BTraceLogger: got org.openjdk.btrace.core.comm.RetransformationStartNotification@a092c49
btrace DEBUG: calling retransformClasses (1 classes to be retransformed)
btrace DEBUG: Attempting to retransform class: TestClass
btrace DEBUG: closing all I/O

With @OnMethod(clazz = "TestClass", method = "testMethod", location = @Location(RETURN)) on logReturn method everything works as expected.

Could you, please, fix this?

Thanks!

@jbachorik jbachorik self-assigned this May 24, 2020
@jbachorik jbachorik added this to the 2.0.2 milestone May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants