Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8255030

[lworld] Vectorize equality comparison of some inline types

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • repo-valhalla
    • repo-valhalla
    • hotspot

    Description

      On some machines it may be possible and preferable to use SIMD instructions to perform sameness (acmp) and/or Object.equals tests, on both inline and identity objects, when the equality semantics is "component-wise". This is true of record types.

      The basic idea is to load all (or some) of an object's storage into a vector register, and mask off irrelevant bits (such as header or padding). This is done to both operands of the acmp, and if bitwise equality is detected, then no further testing is required to verify that the components are equal.

      The type of either or both operands should be speculated or determined, so that the size and masking of the vector images can be chosen by the JIT. This works even if the dynamic type of *one* of the operands is unknown, if the masking is selected so that the _klass field of both objects is treated as an additional component to be checked for equality. Clearly, if one of the objects is an unexpected type, then the masked comparison, being sensitive to the _klass, will fail.

      If the masked comparison fails, it may still be possible that the two objects are component-wise equal, if a recursive descent is required into separately buffered images of the same inline value, or if user logic uses something like Arrays.equals or recursive calls to Object.equals. Still, the vectorized check will correctly detect numerically identical pointers, allowing a short circuit.

      Even if some pointers are problematic, an object with a mix of primitive and reference components can still profitably be the subject of a masked SIMD comparison, if the reference components are suppressed by the mask, and only the primitive components are bitwise compared. The code in that case would quickly compare all components for which bitwise comparison is profitable, and then more carefully compare the reference components using scalar (not SIMD vector) operations.

      This idea is akin to the old optimization of pointer comparison (reference acmp) as an optimization of a full component-wise equality check. Indeed, in cases where a vectorized comparison of memory is possible, it may be useful to *also* compare the base pointers, and report equality if the base pointers are equal, before the component images are tested using a SIMD instruction.

      Since SIMD operations tend to have overheads beyond simple scalar operations, this optimization is probably useful only for inline objects which contain several fields, not those which contain only one or two fields.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jrose John Rose
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: