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

[lworld] Substitutability test may perform heap allocations

      The substitutability test used to compare to instances of a value class is implemented with MethodHandles. When the values being compared include a flat field, the current implementation uses Unsafe.getValue() on it. This method returns a heap buffered copy of the flat field, meaning that it allocates memory in the Java heap and copies the content of the field to the new instance. From a performance point of view, this is less than ideal to have heap allocations when executing an acmp bytecode.

      One solution to avoid those allocation could be to re-implement the substitutability test to perform a recursive discovery of the fields in the nested value and compute their exact location through offset arithmetic to end up having only primitive or reference comparisons and no more call to getValue().

            liach Chen Liang
            fparain Frederic Parain
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: