How to migrate from Soot

    Terminology

    TermSootJacoDB
    bytecode storage-JacoDB
    scope of visible classesSceneJcClasspath
    classSootClassJcClassOrInterface
    class methodSootMethodJcMethod
    class fieldSootFieldJcField
    type (with generic substitution)-JcJvmType
    3-address bytecode representationJimpleBodyJcRawInstList
    control flow graphClassicCompleteUnitGraphJcGraph
    class hierarchyHierarchyHierarchyExt
    call graphCallGraphUsagesExt

    Recommendations

    1. Remember to close the resource: JcClasspath, JacoDB.
    2. Creating classpath is a heavy operation involving I/O. All the JAR files or folders passed to a classpath are checked. We check:
    • whether they have been processed already,
    • whether they have been changed since having been processed before,
    • whether they are being processed right now as they have not been processed already. As a result, the code should try to reuse a classpath instance. After that, we recommend to call the close method as JacoDB is able to delete the processed resources, which seem to be out of date with regard to the file system.
    1. If there is a chance that the code calls for class hierarchies, then it is better to install the InMemoryHierarchy feature.
    2. Use persisted data in the file system if your code base is huge enough or if living upon the process restart is possible.
    3. Install only those features that are required for this database.

    Operations

    Create storage

    // points to specific runtime version
    G.v().initJdk(new G.JreInfo(location, version));
    Options options = Options.v();
    options.set_soot_classpath(files);
    Scene.v().loadNecessaryClasses();
    PackManager.v().runPacks();

    Find class

    SootClass clazz = Scene.v().getSootClass("java.lang.String");

    Get 3-address bytecode representation

    SootClass clazz = Scene.v().getSootClass("java.lang.String");
    clazz.getMethod("length", Lists.emptyList()).retrieveActiveBody()

    Get control flow graph

    new ClassicCompleteUnitGraph(sootMethod.getActiveBody());

    Get hierarchy

    Hierarchy h = new Hierarchy();
    h.getDirectSubclassesOf(clazz);
    h.getDirectSubinterfacesOf(clazz);

    Get CallGraph/Usages

    CallGraph cg = new CallGraph();
    cg.edgesInto(edge);
    cg.edgesOutOf(edge);