WALA
WALA copied to clipboard
com.ibm.wala.ipa.cha.ClassHierarchyException: failed to load root <Primordial,Ljava/lang/Object> of class hierarchy
I am trying to perform slicing of a java source code but i am getting this error:
com.ibm.wala.ipa.cha.ClassHierarchyException: failed to load root <Primordial,Ljava/lang/Object> of class hierarchy at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:261) at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:176) at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:54) at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:34)
According to the Troubleshooting the java_runtime_dir property in your wala.properties file is incorrect. I have set this to the following value:
java_runtime_dir = /usr/lib/jvm/java-8-oracle/jre/lib
I built the code using maven with java8 and i am running the program under Debian Jessie. Here is there source code i used:
public static void main(String args[]) throws IllegalArgumentException, CancelException,
IOException {
try {
// create an analysis scope representing the appJar as a J2SE application
AnalysisScope scope = AnalysisScopeReader.readJavaScope("...",
null, Main.class.getClassLoader());
// build a class hierarchy, call graph, and system dependence graph
ClassHierarchy cha = ClassHierarchyFactory.make(scope);
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha);
AnalysisOptions options = new AnalysisOptions(scope, entrypoints);
CallGraphBuilder<InstanceKey> builder = Util.makeZeroOneCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(), cha, scope);
CallGraph cg = builder.makeCallGraph(options, null);
Statement statement = findCallTo(findMainMethod(cg), "println");
System.err.println("Statement: " + statement);
// compute the slice as a collection of statements
Collection<Statement> slice = null;
// if (true) {
final PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
slice = Slicer.computeBackwardSlice(statement, cg, pointerAnalysis, Slicer.DataDependenceOptions.NO_BASE_PTRS,
Slicer.ControlDependenceOptions.NONE);
dumpSlice(slice);
} catch (WalaException e) {
// something bad happened.
e.printStackTrace();
}
}
public static CGNode findMainMethod(CallGraph cg) {
Descriptor d = Descriptor.findOrCreateUTF8("([Ljava/lang/String;)V");
Atom name = Atom.findOrCreateUnicodeAtom("main");
for (Iterator<? extends CGNode> it = cg.getSuccNodes(cg.getFakeRootNode()); it.hasNext(); ) {
CGNode n = it.next();
if (n.getMethod().getName().equals(name) && n.getMethod().getDescriptor().equals(d)) {
return n;
}
}
Assertions.UNREACHABLE("failed to find main() method");
return null;
}
public static Statement findCallTo(CGNode n, String methodName) {
IR ir = n.getIR();
for (Iterator<SSAInstruction> it = ir.iterateAllInstructions(); it.hasNext(); ) {
SSAInstruction s = it.next();
if (s instanceof com.ibm.wala.ssa.SSAAbstractInvokeInstruction) {
com.ibm.wala.ssa.SSAAbstractInvokeInstruction call = (com.ibm.wala.ssa.SSAAbstractInvokeInstruction) s;
if (call.getCallSite().getDeclaredTarget().getName().toString().equals(methodName)) {
com.ibm.wala.util.intset.IntSet indices = ir.getCallInstructionIndices(call.getCallSite());
com.ibm.wala.util.debug.Assertions.productionAssertion(indices.size() == 1, "expected 1 but got " + indices.size());
return new com.ibm.wala.ipa.slicer.NormalStatement(n, indices.intIterator().next());
}
}
}
Assertions.UNREACHABLE("failed to find call to " + methodName + " in " + n);
return null;
}
public static void dumpSlice(Collection<Statement> slice) {
for (Statement s : slice) {
System.err.println(s);
}
}
The primodial.txt file used:
Primordial,Java,sourceFile,{Path to java source file}
I am new to the subject. The code i used is more or less what is used in the PDFSlice example. Any idea what i am doing wrong
i occurred the same wrong