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

StackMapDecoder::writeFrames makes lots of allocations

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 24
    • 24
    • core-libs

    Description

      The `writeFrames` method in StackMapDecoder makes lots of allocations. For N stack map entries, it can make up to a maximum of approximately 1 + N + N log2(N) allocations due to its use of TreeMap, along with Integer boxing. This is more than needed.

      If an array is used instead, then we need one allocation for the array, the toArray overhead, and one allocation for a comparator to sort with. Then we loop over the resultant array to write the entries themselves. Overall complexity is not significantly greater than the existing code.

      Additionally, validation was missing for the case where multiple stack map entries were existent for a given bytecode index. We can fix that easily as a side effect of this improvement.

      Care would be taken to avoid using method handles which would make this all even simpler (using streams etc.).

      Attachments

        Issue Links

          Activity

            People

              dmlloyd David Lloyd
              dmlloyd David Lloyd
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: