Skip to content

8308105: Multi-array allocations are very slow#30550

Draft
bulasevich wants to merge 1 commit intoopenjdk:masterfrom
bulasevich:multiarray3
Draft

8308105: Multi-array allocations are very slow#30550
bulasevich wants to merge 1 commit intoopenjdk:masterfrom
bulasevich:multiarray3

Conversation

@bulasevich
Copy link
Copy Markdown
Contributor

@bulasevich bulasevich commented Apr 2, 2026

Multidimensional array allocations such as new int[n1][n2] are very slow because HotSpot routes them through a runtime call (multianewarray) that allocates the outer array and each subarray sequentially.

For constant-size cases like new int[2][2], C2 already optimizes during the parse phase by inlining a fixed number of AllocateArray nodes. This change extends that optimization to the variable-size 2D case. When ndimensions == 2, Parse::do_multianewarray now calls Parse::init_array2d, which builds a C2 IR graph equivalent to:

  T[] array = new T[size1];
  for (int i = 0; i < size1; i++) {
      array[i] = new T[size2];
  }

The performance result is like this:

  Benchmark                      (size)  (size2)  Mode  Cnt   Score    Error   Units
  ArrayAllocation.full (before)     128        2  avgt    4  540.707 ± 12.154  ns/op
  ArrayAllocation.full (after)      128        2  avgt    4   12.713 ±  0.435  ns/op
  ArrayAllocation.piecemeal         128        2  avgt    4   12.966 ±  0.297  ns/op

Status:

  • jtreg tier1-3 passed with -Xcomp -XX:-TieredCompilation options. Further testing is in progress

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8308105: Multi-array allocations are very slow (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30550/head:pull/30550
$ git checkout pull/30550

Update a local copy of the PR:
$ git checkout pull/30550
$ git pull https://git.openjdk.org/jdk.git pull/30550/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30550

View PR using the GUI difftool:
$ git pr show -t 30550

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30550.diff

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Apr 2, 2026

👋 Welcome back bulasevich! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 2, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Apr 2, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 2, 2026

@bulasevich The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

address fun = nullptr;
switch (ndimensions) {
case 1: ShouldNotReachHere(); break;
case 2: fun = OptoRuntime::multianewarray2_Java(); break;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead branch now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler hotspot-compiler-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

2 participants