Class AbstractAnnotationLiteral


  • public abstract class AbstractAnnotationLiteral
    extends Object
    Superclass of all annotation literals generated by ArC. Redeclares some Annotation methods to be able to replace interface type checks with class type checks. There are two typical use cases:
    1. checking against Annotation can be replaced with checking against AbstractAnnotationLiteral, when the caller knows that the annotation instance is likely to come from ArC;
    2. checking against some concrete annotation type can be replaced with checking equality to annotationType().

    Replacing interface type checks with class type checks is useful on the HotSpot JVM. Its type check algorithm has a fast path for classes and a slow path for interfaces [1]. That slow path is fronted with a single-element cache, containing the last successfully tested type. This often improves the slow path performance, but in presence of repeated successful type checks against different interfaces, the cache never hits and keeps changing all the time.

    Moreover, if such pathologic type checks happen concurrently on multiple CPU cores, those CPU cores will compete for the ability to write to the CPU cache line containing the single-element type cache. This leads to significant increase in CPU cache coherence traffic and worse performance.

    [1] This is a simplification. Fast path is only possible for classes that don't have too many superclasses, which is fortunately the common case. Type checks against classes that are deep in an inheritance hierarchy have to go through the slow path too.

    References:

    Note: replacing interface type checks with class type checks as described above may easily lead to non-idiomatic, harder to understand code. Demonstrating measurable performance improvements should be a necessary prerequisite for using this technique.

    • Constructor Detail

      • AbstractAnnotationLiteral

        public AbstractAnnotationLiteral()