Class CallUtil


  • public class CallUtil
    extends java.lang.Object
    Utility methods for call resolution.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void getSuperinterfaces​(Clazz start, java.util.Set<Clazz> accumulator)
      Get the transitive superinterfaces of a class/interface recursively.
      static java.util.Optional<java.lang.String> resolveFromSuperclasses​(Clazz start, java.lang.String name, java.lang.String descriptor)
      Search for the invocation target in a specific class and recursively in all superclasses.
      static java.util.Set<java.lang.String> resolveFromSuperinterfaces​(Clazz start, java.lang.String name, java.lang.String descriptor)
      Search for a maximally specific default implementation in all superinterfaces of a class.
      static java.util.Set<java.lang.String> resolveVirtual​(Clazz thisPointerType, java.lang.String methodName, java.lang.String descriptor)
      The invokevirtual and invokeinterface resolution algorithm, annotated with JVM spec §6.5.invokevirtual citations where appropriate, so that the specified lookup process can easily be compared to this implementation.
      static java.util.Set<java.lang.String> resolveVirtual​(Clazz callingClass, Clazz thisPointerType, AnyMethodrefConstant ref)
      The invokevirtual and invokeinterface resolution algorithm, annotated with JVM spec §6.5.invokevirtual citations where appropriate, so that the specified lookup process can easily be compared to this implementation.
      static java.util.Set<MethodSignature> resolveVirtualSignatures​(Clazz thisPointerType, java.lang.String methodName, java.lang.String descriptor)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • resolveVirtual

        public static java.util.Set<java.lang.String> resolveVirtual​(Clazz callingClass,
                                                                     Clazz thisPointerType,
                                                                     AnyMethodrefConstant ref)
        The invokevirtual and invokeinterface resolution algorithm, annotated with JVM spec §6.5.invokevirtual citations where appropriate, so that the specified lookup process can easily be compared to this implementation.
        Parameters:
        callingClass - JVM spec: "current class".
        thisPointerType - The type of the this pointer of the call (JVM spec: "objectref").
        ref - The AnyMethodrefConstant specifying name and descriptor of the method to be invoked.
        Returns:
        The fully qualified names of potential call target clases (usually just one, but see resolveFromSuperinterfaces(Clazz, String, String) for details on when there might be multiple).
      • resolveVirtual

        public static java.util.Set<java.lang.String> resolveVirtual​(Clazz thisPointerType,
                                                                     java.lang.String methodName,
                                                                     java.lang.String descriptor)
        The invokevirtual and invokeinterface resolution algorithm, annotated with JVM spec §6.5.invokevirtual citations where appropriate, so that the specified lookup process can easily be compared to this implementation.
        Parameters:
        thisPointerType - The type of the this pointer of the call (JVM spec: "objectref").
        methodName - The name of the invoked method.
        descriptor - The descriptor of the invoked method.
        Returns:
        The fully qualified names of potential call target clases (usually just one, but see resolveFromSuperinterfaces(Clazz, String, String) for details on when there might be multiple).
      • resolveFromSuperclasses

        public static java.util.Optional<java.lang.String> resolveFromSuperclasses​(Clazz start,
                                                                                   java.lang.String name,
                                                                                   java.lang.String descriptor)
        Search for the invocation target in a specific class and recursively in all superclasses.
        Parameters:
        start - The Clazz where the lookup is to be started.
        name - The name of the method.
        descriptor - The method descriptor.
        Returns:
        An Optional with the fully qualified name of the class containing the target method, empty if it couldn't be found.
      • resolveFromSuperinterfaces

        public static java.util.Set<java.lang.String> resolveFromSuperinterfaces​(Clazz start,
                                                                                 java.lang.String name,
                                                                                 java.lang.String descriptor)
        Search for a maximally specific default implementation in all superinterfaces of a class. This step is potentially unintuitive and difficult to grasp, see JVM spec §5.4.3.3 for more information, as well as this great blog post concerning the resolution pitfalls. The following is based on the information on those websites.
        Parameters:
        start - The Clazz whose superinterfaces are to be searched.
        name - The target method name.
        descriptor - The target method descriptor.
        Returns:
        The fully qualified name of the class(es) that contain the method to be invoked. Be aware that purely from a JVM point of view, this choice can be ambiguous, in which case it just chooses the candidate randomly. Here, we don't want to gamble, but rather want to add call graph edges for every possibility, if this ever happens. Javac ensures that such a case never occurs, but who knows how the bytecode has been generated, so this possibility is implemented just in case.
      • getSuperinterfaces

        public static void getSuperinterfaces​(Clazz start,
                                              java.util.Set<Clazz> accumulator)
        Get the transitive superinterfaces of a class/interface recursively.
        Parameters:
        start - The Clazz where the collection process is to be started.
        accumulator - The current set of superinterfaces, so that only one set is constructed at runtime.