You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Andreas Beeker <ki...@apache.org> on 2020/05/16 13:49:37 UTC

Use btrace for comparing call chains

Hi,

I'm currently trying to upgrade the Saxon dependency in XmlBeans and found a few bugs in the XmlBeans-Dom implementation.
To find out where the error was/is, I'm comparing the calls with the Xerces Dom.
As I was struggling solely with the debugger, I've looked for a method on tracing the calls and I'm using btrace [1] now.

So in my IntelliJ config, I'm simply adding the VM paramters [2] and before running you need to compile the btrace script [3] with btracec.
There are some limitations with btrace and not all methods can be instrumented, e.g. methods with synchronizations, but overall I get a good idea, when the call chain differs when comparing the btrace output with Xerces/Jaxp.

That's all for now.

Andi


[1] https://github.com/btraceio/btrace/blob/master/docs/BTraceTutorial.md

[2]
-ea
-Xmx256m
-Djava.io.tmpdir=<project>/xmlbeans/build/tmp
-Dxbean.rootdir=<project>/xmlbeans/
-Dcases.location=test/cases
-javaagent:<project>/xmlbeans/btrace/libs/btrace-agent.jar=script=<project>/xmlbeans/btrace/xmlbeans/Saxon.class,bootClassPath=<project>/xmlbeans/btrace/libs/btrace-boot.jar,scriptOutputFile=<outputfile>

[3]

package xmlbeans; import org.openjdk.btrace.core.annotations.*; import static org.openjdk.btrace.core.BTraceUtils.*; @BTrace public class Saxon {

    @OnMethod(
        clazz="/net\\.sf\\.saxon\\.dom\\..*/", method="/.*/" )
    public static void m(@ProbeClassName String probeClass, @ProbeMethodName String probeMethod) {
        print(Strings.strcat("entered ", probeClass)); println(Strings.strcat(".", probeMethod)); }

// @OnMethod( // clazz="/org\\.apache\\.xmlbeans\\.impl\\.store\\..*|com\\.sun\\.org\\.apache\\.xerces\\.internal\\.dom\\..*/", // method="/node_getNextSibling|node_getLastChild|_node_isSameNode|_node_getNodeType|appendChild|cloneNode|getAttributes|getChildNodes|getParentNode|removeChild|getFirstChild|getLastChild|getLocalName|getNamespaceURI|getNextSibling|getNodeName|getNodeType|getNodeValue|getOwnerDocument|getPrefix|getPreviousSibling|hasAttributes|hasChildNodes|insertBefore|isSupported|normalize|replaceChild|setNodeValue|setPrefix|getUserData|setUserData|getFeature|isEqualNode|isSameNode|lookupNamespaceURI|lookupPrefix|isDefaultNamespace|setTextContent|getTextContent|compareDocumentPosition|getBaseURI/" //
) // public static void m2(@ProbeClassName String probeClass, @ProbeMethodName String probeMethod) { // print(Strings.strcat("entered ", probeClass)); // println(Strings.strcat(".", probeMethod)); // } @OnMethod(
        clazz="/org\\.apache\\.xmlbeans\\.impl\\.store\\..*|com\\.sun\\.org\\.apache\\.xerces\\.internal\\.dom\\..*/", method="/getNodeType|compareDocumentPosition/", location=@Location(Kind.RETURN)
    )
    public static void retShort(@ProbeMethodName String probeMethod, @Return short result) {
        print(Strings.strcat(probeMethod, ": ")); println(result); }

    @OnMethod(
        clazz="/org\\.apache\\.xmlbeans\\.impl\\.store\\..*|com\\.sun\\.org\\.apache\\.xerces\\.internal\\.dom\\..*/", method="/hasChildNodes|isSameNode/", location=@Location(Kind.RETURN)
    )
    public static void retBoolean(@ProbeMethodName String probeMethod, @Return boolean result) {
        print(Strings.strcat(probeMethod, ": ")); println(result); }

    @OnMethod(
        clazz="/net\\.sf\\.saxon\\.dom\\.DOMNodeWrapper/", method="/getNodeKind|getSiblingPosition/", location=@Location(Kind.RETURN)
    )
    public static void retInt(@ProbeMethodName String probeMethod, @Return int result) {
        print(Strings.strcat(probeMethod, ": ")); println(result); }
}