soot-oss / soot

Soot - A Java optimization framework
GNU Lesser General Public License v2.1
2.89k stars 708 forks source link

Can Multi Thread to Resolve all Classes #1867

Closed davidfunn closed 2 years ago

davidfunn commented 2 years ago

When use soot to do static code analyze, a big project will coat a lot of time in loading necessary classes. And i found actually cost time is in method processResolveWorklist which in source code [SootResolver.java line 154]。But it use a worklist to iterate classes and resolve it one by one.If use multi thread, it will has exception.How to make it work in multi thread.

public void loadNecessaryClasses() {...}

public SootClass loadClassAndSupport(String className) {...}

public SootClass resolveClass(String className, int desiredLevel){...}

protected void processResolveWorklist() { for (int i = SootClass.BODIES; i >= SootClass.HIERARCHY; i--) { while (!worklist[i].isEmpty()) { SootClass sc = worklist[i].pop(); if (resolveEverything()) { // Whole program mode boolean onlySignatures = sc.isPhantom() || (Options.v().no_bodies_for_excluded() && Scene.v().isExcluded(sc) && !Scene.v().getBasicClasses().contains(sc.getName())); if (onlySignatures) { bringToSignatures(sc); sc.setPhantomClass(); for (SootMethod m : sc.getMethods()) { m.setPhantom(true); } for (SootField f : sc.getFields()) { f.setPhantom(true); } } else { bringToBodies(sc); } } else { // No transitive switch (i) { case SootClass.BODIES: bringToBodies(sc); break; case SootClass.SIGNATURES: bringToSignatures(sc); break; case SootClass.HIERARCHY: bringToHierarchy(sc); break; } } } } }

davidfunn commented 2 years ago

@StevenArzt

StevenArzt commented 2 years ago

That's non-trivial, because classes can depend on each other (hierarchy, references, etc.) I don't have enough time at the moment to look into this. You can try to propose a multi-threaded approach, but test it thoroughly not to break anything.