当我尝试生成火花调用图时,出现以下错误:
java.lang.OutOfMemoryError: GC overhead limit exceeded.
这是堆栈跟踪:
at java.util.concurrent.ConcurrentHashMap$KeySetView.iterator(ConcurrentHashMap.java:4578)
at java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1039)
at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1038)
at soot.FastHierarchy.canStoreClass(FastHierarchy.java:324)
at soot.FastHierarchy.canStoreType(FastHierarchy.java:233)
at soot.jimple.toolkits.callgraph.VirtualCalls.resolve(VirtualCalls.java:147)
at soot.jimple.toolkits.callgraph.VirtualCalls.resolveAnySubType(VirtualCalls.java:196)
at soot.jimple.toolkits.callgraph.VirtualCalls.resolve(VirtualCalls.java:180)
at soot.jimple.toolkits.callgraph.VirtualCalls.resolve(VirtualCalls.java:130)
at soot.jimple.toolkits.callgraph.OnFlyCallGraphBuilder.addType(OnFlyCallGraphBuilder.java:549)
at soot.jimple.toolkits.callgraph.CallGraphBuilder.build(CallGraphBuilder.java:118)
at soot.jimple.spark.SparkTransformer.internalTransform(SparkTransformer.java:154)
at soot.SceneTransformer.transform(SceneTransformer.java:39)
at com.company.Project.runPacks(Project.java:130)
at com.company.Project.<init>(Project.java:60)
at com.test.TestTemporary.loadP1(TestTemporary.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
我的代码是这样的:
我这样设置烟尘选项:
private void setSootOptions() {
List<String> argsList = new ArrayList<>();
argsList.add("-verbose");
argsList.add("-w"); // whole program mode
argsList.add("-cp"); // Soot class-path
argsList.add(path + ";C:\\soot\\soot-3.1.0-jar-with-
dependencies.jar;C:\\Program
Files\\Java\\jdk1.8.0_112\\jre\\lib\\rt.jar;C:\\Program
Files\\Java\\jdk1.8.0_112\\jre\\lib\\jce.jar;C:\\Program
Files\\JetBrains\\IntelliJ IDEA Community Edition
2018.1.5\\lib\\junit-4.12.jar;C:\\Program
Files\\JetBrains\\IntelliJ IDEA Community Edition
2018.1.5\\lib\\hamcrest-core-1.3.jar;");
Options.v().parse(argsList.toArray(new String[0]));
}
给一个目录,我将目录中的所有.class文件添加为烟尘中的应用程序类(用Scene.v()。loadClassAndSupport()加载后)
我找到了给定项目中的所有junit测试方法,并将所有方法都设置为入口点
我生成一个火花调用图:
private void runPacks() {
Transform sparkTranform = new Transform("cg.spark", null);
PhaseOptions.v().setPhaseOption(sparkTranform, "enabled:true");
PhaseOptions.v().setPhaseOption(sparkTranform, "rta:true");
PhaseOptions.v().setPhaseOption(sparkTranform, "verbose:true");
PhaseOptions.v().setPhaseOption(sparkTranform, "propagator:worklist");
PhaseOptions.v().setPhaseOption(sparkTranform, "simple-edges-bidirectional:false");
PhaseOptions.v().setPhaseOption(sparkTranform, "on-fly-cg:false");
PhaseOptions.v().setPhaseOption(sparkTranform, "set-impl:double");
PhaseOptions.v().setPhaseOption(sparkTranform, "double-set-old:hybrid");
PhaseOptions.v().setPhaseOption(sparkTranform, "double-set-new:hybrid");
PhaseOptions.v().setPhaseOption(sparkTranform, "force-cg:true");
Map opt = PhaseOptions.v().getPhaseOptions(sparkTranform);
System.out.println("rta call graph building...");
SparkTransformer.v().transform(sparkTranform.getPhaseName(), opt);
System.out.println("...rta call graph builded");
CallGraph c = Scene.v().getCallGraph();
setCallGraph(c);
System.out.println("Serialize call graph start...");
serializeCallGraph(callGraph, path + "//" + "-call-grsph" + DotGraph.DOT_EXTENSION);
System.out.println("...Serialize call graph completed");
}
我已经在2个项目上测试了我的代码,其中一个项目我没有问题,而第二个项目我之前报告了错误(超出了GC开销限制)。我了解问题在于烟灰,在调用图生成时,尝试分析这两种方法:
@Test
public void realPassTest(){
ArrayList<String> a = st.realMethodToTest();
Assert.assertTrue(a.contains("real"));
}
@Test
public void realFailureTest(){
ArrayList<String> a = st.realMethodToTest();
Assert.assertTrue(a.contains("fail"));
}
[...]
public ArrayList<String> realMethodToTest() {
ArrayList a = new ArrayList<>();
a.add("real");
a.add("method");
a.add("toTest");
return a;
}
使用调试器,我看到生成调用图的煤烟加载了ArrayList
的所有java方法。我该如何解决?
我试图用“ rta:false”“ on-fly-cg:true”生成一个火花调用图,但我遇到了另一个问题:另一个项目(p1)调用图缺少一些边缘,因为我不能使用静态方法作为入口点,使用rta(p1)的调用图已完成,但是在该projet中,我只有原始类型和一些带有空主体的方法,如果我尝试在(p)之前显示的项目上使用rta,则存在该问题
我尝试过也使用“ -app”烟尘选项,但是给我有关加载类的问题。