"findMethods" 没有 return 预期的结果

"findMethods" doesn't return expected results

我正在尝试实施分析(扩展 DefaultOneStepAnalysis)以构建 CHA 算法中的调用图。我的代码分为三部分:

1) method "doAnalyze" to return the "BasicReport"
2) method "analyze" to find call edges for each method in the given project
3) class "AnalysisContext" to store the context and methods using in the analysis.

在 3) 中,我使用方法 "callBySignature" 找出与 "CHACallGraphExtractor" 中相同的方法的 cbsMethods,但它没有 return 预期结果。 而我用原来OPAL的方式在Extractor中获取cbsMethods,得到的是一组方法

能否请您帮我确认一下问题出在哪里以及如何解决? 非常感谢。

此致, 蒋

----我代码的主要部分------------------------------------ --------------

object CHACGAnalysis extends DefaultOneStepAnalysis { 
    ... ...
    override def doAnalyze(
                                  project: Project[URL],
                                  parameters: Seq[String] = List.empty,
                                  isInterrupted: () ⇒ Boolean
                                  ): BasicReport = {
    ... ...
      for {
          classFile <- project.allProjectClassFiles
          method <- classFile.methods
        } {
        analyze(project, methodToCellCompleter, classFile, method))
        }
    ... ...
   }

  def analyze(
               project: Project[URL],
               methodToCellCompleter: Map[(String,Method), CellCompleter[K, Set[Method]]],
               classFile: ClassFile,
               method: Method
               ): Unit = {
   … …
       val context = new AnalysisContext(project, classFile, method) 
       method.body.get.foreach((pc, instruction) ⇒
       instruction.opcode match {
       ... ...
           case INVOKEINTERFACE.opcode ⇒
                val INVOKEINTERFACE(declaringClass, name, descriptor) = instruction
                context.addCallEdge_VirtualCall(pc, declaringClass, name, descriptor, true,cell1)
           ... ...
         } 
… …
}

protected[this] class AnalysisContext(
                                         val project:   SomeProject,
                                         val classFile: ClassFile,
                                         val method:    Method
                                         ) {
    val classHierarchy = project.classHierarchy
    val cbsIndex = project.get(CallBySignatureResolutionKey)
    val statistics = project.get(IntStatisticsKey)
    val instantiableClasses = project.get(InstantiableClassesKey)
    val cache = new CallGraphCache[MethodSignature, scala.collection.Set[Method]](project)
private[AnalysisContext] def callBySignature(
                                                  declaringClassType: ObjectType,
                                                  name:               String,
                                                  descriptor:         MethodDescriptor
                                                  ): Set[Method] = {
      val cbsMethods = cbsIndex.findMethods(
        name,
        descriptor,
        declaringClassType
      )
      cbsMethods
   }
def addCallEdge_VirtualCall(
                                 pc: PC,
                                 declaringClassType: ObjectType,
                                 name: String,
                                 descriptor: MethodDescriptor,
                                 isInterfaceInvocation: Boolean          = false,
                                 cell1: CellCompleter[K, Set[Method]]
                                 ): Unit = {

      val cbsCalls =
        if (isInterfaceInvocation) {
          callBySignature(declaringClassType, name, descriptor)
        }
        else
          Set.empty[Method]

 … …
}
… …
}

最后,我发现问题是由于"AnalysisMode" 将AnalysisMode重置为“CPA”后,问题就解决了。

我认为在设计算法之前我应该​​始终牢记 "AnalysisMode" 应该使用什么。

感谢您的关心 蒋