2015-10-05 205 views
3

我刚开始使用Wala Java切片器来做一些源代码分析任务。我对图书馆的正确使用有一个疑问。假设我有以下示例代码:Wala Java切片器 - 从切片丢失的语句

public void main(String[] args) { 
    ... 
    UserType ut = userType; 
    int i = ut.getInt(); 
    ... 
    System.out.println(i); 
} 

计算为println语句瓦剌片提供了以下声明:

NORMAL_RET_CALLER:Node: < Application, LRTExecutionClass, main([Ljava/lang/String;)V > Context: Everywhere[15]13 = invokevirtual < Application, LUserType, getInt()I > 11 @27 exception:12 
NORMAL main:23 = getstatic < Application, Ljava/lang/System, out, <Application,Ljava/io/PrintStream> > Node: < Application, LRTExecutionClass, main([Ljava/lang/String;)V > Context: Everywhere 
NORMAL main:invokevirtual < Application, Ljava/io/PrintStream, println(I)V > 23,13 @63 exception:24 Node: < Application, LRTExecutionClass, main([Ljava/lang/String;)V > Context: Everywhere 

的代码我使用的创建与瓦剌切片如下图所示:

AnalysisScope scope = AnalysisScopeReader.readJavaScope("...", 
          null, WalaJavaSlicer.class.getClassLoader()); 
ClassHierarchy cha = ClassHierarchy.make(scope); 

Iterable<Entrypoint> entrypoints = Util.makeMainEntrypoints(scope, cha); 
AnalysisOptions options = new AnalysisOptions(scope, entrypoints); 

// Build the call graph 
CallGraphBuilder cgb = Util.makeZeroCFABuilder(options, new AnalysisCache(),cha, scope, null, null); 
CallGraph cg = cgb.makeCallGraph(options, null); 
PointerAnalysis pa = cgb.getPointerAnalysis(); 

// Find seed statement 
Statement statement = findCallTo(findMainMethod(cg), "println"); 

// Context-sensitive thin slice 
Collection<Statement> slice = Slicer.computeBackwardSlice(statement, cg, pa, DataDependenceOptions.NO_BASE_NO_HEAP, ControlDependenceOptions.NONE); 
dumpSlice(slice); 

有一些说法,我期望在片找到,但不存在:

  • 的赋值语句不包含即使相关的方法调用ut.getInt()ut = userType,包括在片
  • getInt()实施的任何声明都包括在内。是否有激活“程序间”切片的选项?我在这里应该提到.class文件包含在用于创建AnalysisScope的路径中。

正如你所看到的,我使用的依赖选项DataDependenceOptions.NO_BASE_NO_HEAPControlDependenceOptions.NONE。但即使当我使用FULL时,问题仍然存在。

我在做什么错?

回答

1

的赋值语句UT =即使 相关的方法调用ut.getInt(),包括在片

我怀疑是分配从来没有做它成字节码不包括USERTYPE因为它是一个未要求的局部变量,因此是不可见的,以WALA:

由于SSA IR已经有所优化,一些 语句,例如简单的分配(X = Y,Y = Z)做不出现在 IR,由于复制传播优化在SSBuilder类的 SSA构建期间自动完成。实际上,没有SSA 分配指令;另外,javac编译器可以自由地执行这些优化,因此这些语句甚至不会出现在 字节码中。因此,这些Java语句将永远不会出现在切片中。

http://wala.sourceforge.net/wiki/index.php/UserGuide:Slicer#Warning:_exclusion_of_copy_statements_from_slice

+0

谢谢!我完全错过了Wala页面上的警告。这是否意味着如果我需要这些语句,那么我必须分析源代码而不是字节码? – Rizkallah

+0

我想这取决于你想要达到的目标;在大多数情况下,分析这种分配并不重要,因为它是调用对象的方法,而不是参考的存储位置。跟踪引用可能会成为你和编译器之间的战斗,这是一场艰苦的战斗。祝你好运! – StuPointerException

+0

我想跟踪哪个引用被用来执行方法调用,而不仅仅是方法调用自己。这就是为什么分配对我很重要。我想我需要对这个话题做更多的研究。再次感谢你! – Rizkallah