调用图生成的核心问题
对于 OOP 语言来说,搭建调用图的核心问题是有多态的场景下如何确定到底是哪一个方法被调用了,下面是 Java 的一些可能的函数调用 1
Static Call | Special Call | Virtual Call | |
---|---|---|---|
Instruction | invokestatic |
invokespecial |
invokeinterface, invokevirtual |
Receiver Objects | ❌ | ✅ | ✅ |
Target Methods | Static Method | Constructor, Private Instance Method, Superclass Instance Method | Other Instance Method |
Count of Possible Target Methods | 1 | 1 | $\ge 1$ (polymorphism) |
Determinancy | Compile-time | Compile-time | Run-time |
其中 Virtual Call 因为包含了多态,方法调用存在多个可能的目标方法