0

当我运行这个简单的 Java8 程序时

package test;

public class TraceInt {
public static void main(String args[]) throws InterruptedException{
    TraceInt ti = new TraceInt();
    while(true){
        Integer.valueOf((int)System.currentTimeMillis());
        ti.sleep(1000);
        //System.getProperty("user.dir");
    }
}

public void sleep(int millis){
    try {
        Thread.sleep(millis);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}

并针对它运行这个 btrace 脚本

@OnMethod(
    clazz = "/.*/",
    method = "/java.lang.*/",
    location = @Location(value = Kind.ENTRY, where = Where.BEFORE)
)
public static void onEntry(Object obj) {
    println(Strings.strcat("on entry: ", identityStr(obj)));
}

我在程序中收到此错误

java.lang.IllegalArgumentException: INVOKESPECIAL/STATIC on interfaces require ASM 5
at com.sun.btrace.org.objectweb.asm.MethodVisitor.visitMethodInsn(Unknown Source)
at com.sun.btrace.util.templates.TemplateExpanderVisitor.visitMethodInsn(TemplateExpanderVisitor.java:85)
at com.sun.btrace.org.objectweb.asm.MethodVisitor.visitMethodInsn(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.a(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.b(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.accept(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.accept(Unknown Source)
at com.sun.btrace.runtime.InstrumentUtils.accept(InstrumentUtils.java:66)
at com.sun.btrace.runtime.InstrumentUtils.accept(InstrumentUtils.java:62)
at com.sun.btrace.agent.Client.instrument(Client.java:392)
at com.sun.btrace.agent.Client.doTransform(Client.java:213)
at com.sun.btrace.agent.Client.transform(Client.java:165)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
at com.sun.btrace.agent.Main$4.run(Main.java:464)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

任何帮助表示赞赏

4

1 回答 1

1

过了一会儿,我意识到我正在使用旧版本的 btrace 来对抗 Java8。一旦我转移到最新版本,一切都很好。

于 2016-09-27T14:46:25.943 回答