btraceio / btrace

BTrace - a safe, dynamic tracing tool for the Java platform
5.82k stars 961 forks source link

help!! btrace issue #685

Open cf0415 opened 6 months ago

cf0415 commented 6 months ago

Hey, brother! When I use the BTrace tool to trace methods in java.lang, I don't see any log output. I have already tried to use jdk version 8 , 11 and 17,the btrace version is v2.3.0. Can you provide any insights or suggestions to help me troubleshoot this issue? ?

Here are the steps I followed:

import java.io.IOException; import java.util.Scanner; import java.lang.Thread;

public class Demo { public static void main(String[] args) throws InterruptedException {

     MyThread thread = new MyThread();
     thread.start();
     try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

    for (int i = 0; i < 100; i++) {
        System.out.println("Main thread executing");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

static class MyThread extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("Thread executing");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

}

And,I have used the trace script from the sample directory, as following:

import org.openjdk.btrace.core.annotations.BTrace; import org.openjdk.btrace.core.annotations.OnMethod; import org.openjdk.btrace.core.annotations.Self;

import static org.openjdk.btrace.core.BTraceUtils.*;

/*

jbachorik commented 6 months ago

Most probably the problem is trying to raise the D probe while not running on Solaris (I assume you are not running on Solaris). Please, try using https://github.com/btraceio/btrace/blob/develop/btrace-dist/src/main/resources/samples/AllMethods1.java as an example and see if that fixes your problem.

cf0415 commented 6 months ago

Most probably the problem is trying to raise the D probe while not running on Solaris (I assume you are not running on Solaris). Please, try using https://github.com/btraceio/btrace/blob/develop/btrace-dist/src/main/resources/samples/AllMethods1.java as an example and see if that fixes your problem.

The example provided in the URL, https://github.com/btraceio/btrace/blob/develop/btrace-dist/src/main/resources/samples/AllMethods1.java, works fine and can get trace logs. However, if you change clazz = "/javax.swing../" to clazz = "/java.lang../", there will be no any output. It seems that BTrace versions 2.1.0 and above do not support tracing java.lang, but BTrace versions below 2.0.2 can support it. My runtime environment is Ubuntu 20.04.

cf0415 commented 6 months ago

The example provided in the URL, https://github.com/btraceio/btrace/blob/develop/btrace-dist/src/main/resources/samples/AllMethods1.java, works fine and can get trace logs. However, if you change clazz = "/javax.swing../" to clazz = "/java.lang../", there will be no any output. It seems that BTrace versions 2.1.0 and above do not support tracing java.lang, but BTrace versions below 2.0.2 can support it. My runtime environment is Ubuntu 20.04.

jbachorik commented 6 months ago

Ah, I see. Currently, BTrace is not able to trace java.lang.* classes - due to the necessity to use invoke dynamic in anything newer than Java 8 there is a good chance of deadlocking the indy bootstrap if some of the lang classes used from that bootstrap internally get instrumented and the instrumentation needs to bootstrap the binding again :/

cf0415 commented 6 months ago

Ah, I see. Currently, BTrace is not able to trace java.lang.* classes - due to the necessity to use invoke dynamic in anything newer than Java 8 there is a good chance of deadlocking the indy bootstrap if some of the lang classes used from that bootstrap internally get instrumented and the instrumentation needs to bootstrap the binding again :/

Are there any good solutions or viable alternatives to address this issue currently?

jbachorik commented 6 months ago

No, not really. Except of patching and building BTrace yourself. I did several attempts to relax the filter but it would take tracing the bootstrap process in detail to see which classes are involved and even then it would be brittle as the bootstrap process is an internal detail of JVM and can change from version to version. An alternative would be to modify the BTrace instrumentation to add guard calls before calling invokedynamic (doing the checks in the generated probe code is too late) - that will increase the amount of disturbance to the instrumented method (adding more branches, potentially changing JIT decisions etc.) and as such I did not have enough motivation to proceed with that, just to allow tracing core Java classes ...

cf0415 commented 6 months ago

No, not really. Except of patching and building BTrace yourself. I did several attempts to relax the filter but it would take tracing the bootstrap process in detail to see which classes are involved and even then it would be brittle as the bootstrap process is an internal detail of JVM and can change from version to version. An alternative would be to modify the BTrace instrumentation to add guard calls before calling invokedynamic (doing the checks in the generated probe code is too late) - that will increase the amount of disturbance to the instrumented method (adding more branches, potentially changing JIT decisions etc.) and as such I did not have enough motivation to proceed with that, just to allow tracing core Java classes ...

Okay,Another question: why BTrace v2.0.2 is unable to enable the unsafe mode? btrace WARNING:Unable to load BTrace script...... And no any trace output.

cf0415 commented 6 months ago

Okay,Another question: why BTrace v2.0.2 is unable to enable the unsafe mode? btrace WARNING:Unable to load BTrace script...... And no any trace output.

github-actions[bot] commented 4 months ago

Stale issue message

jbachorik commented 2 weeks ago

TBH, I don't know why unsafe mode does not work with 2.0.2

Does it work with 2.2.6 (the most recent version)?