JDK-8339492 : StackMapDecoder::writeFrames makes lots of allocations
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.classfile
  • Affected Version: 24
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-09-03
  • Updated: 2024-09-05
  • Resolved: 2024-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 24
24 b14Fixed
Related Reports
Relates :  
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.).
Comments
Changeset: 433f6d8a Branch: master Author: David M. Lloyd <david.lloyd@redhat.com> Committer: Chen Liang <liach@openjdk.org> Date: 2024-09-04 16:46:44 +0000 URL: https://git.openjdk.org/jdk/commit/433f6d8a0643b59663bf76c0f3a2af27a6cc56b7
04-09-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/20841 Date: 2024-09-03 16:13:39 +0000
03-09-2024