我尝试使用BTrace来找出某个类型在我的程序中第一次被实例化的时间(Eclipse调试器找不到它),因为我看到了一些奇怪的行为( Javolution XMLStreamWriterImpl在我的XML中添加了元素,甚至在它应该被创建之前就添加了元素)。
无论如何,我通过JVisualVM使用了以下方法,但在运行时什么也没有显示出来。
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
import java.lang.String;
@BTrace
public class ClassLoad {
@OnMethod(clazz = "javolution.xml.stream.XMLStreamWriterImpl", method = "<init>", location = @Location(value=Kind.NEW))
public static void site(@ProbeMethodName(fqn=true) String caller) {
println(strcat("Called from @", caller));
}
}发布于 2013-02-13 21:59:48
您需要一个不同的@OnMethod定义。
@OnMethod(clazz="/.*/", method="/.*/", location=@Location(value=Kind.NEW, clazz="javolution.xml.stream.XMLStreamWriterImpl"))基本上,您指定要检查所有类的所有方法是否出现新的javolution.xml.stream.XMLStreamWriterImpl指令。
其余的代码可以保持不变。
https://stackoverflow.com/questions/14520344
复制相似问题