JDK-8370964 : C2: Investigate effects of ClearArrayNode on allocation elimination
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 26
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • Submitted: 2025-10-30
  • Updated: 2025-11-03
  • Resolved: 2025-11-03
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.
Other
tbdResolved
Related Reports
Relates :  
Description
ClearArrayNode is used to initialize new allocation by widening stores to reduce number of instructions for small objects/arrays.
JDK-8370405 shows that mismatch between new array element type and stores may prevent EA elimination of array allocation.

ClearArrayNode could be created before EA. Idealizing it could also happened before. May be we should delay it until after last macro nodes elimination.
Comments
[~rcastanedalo] could be interested in this EA case.
03-11-2025

Allocation was eliminated after replacing loop with set of stores. Looks like max unroll loop optimization happens after EA. And presence of ClearArray did not affect elimination. I am closing this issue then.
03-11-2025

It could be a different reason for NSR but I see ClearArray node in OptoAssembly output. JavaObject(4) NoEscape(NoEscape) NSR [ 257F 255F 99F 81F 213F 92F 110F [ 54 59 ]] 42 AllocateArray === 5 6 7 8 1 (31 23 28 22 38 10 1 1 1 ) [[ 43 44 45 52 53 54 ]] rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, int, bool ) allocationKlass:[B TestClearArray::test @ bci:2 (line 3) !jvms: TestClearArray::test @ bci:2 (line 3)
03-11-2025

public class TestClearArray { public static int test(int c) { byte ar[] = new byte[16]; if ((c & 1) == 0) { ar[4] = (byte)(c * 2); ar[12] = (byte)(c * 4); } else { ar[0] = (byte)(c * 1); ar[8] = (byte)(c * 3); } int sum = 0; for (int i = 0; i < 16; i += 4) { sum += ar[i]; } return sum; } public static void main(String[] strArr) { for (int i = 0; i < 11000; i++) { test(i); } } }
03-11-2025

[~kvn] Do you have an example where this happens? Otherwise this task is a bit had to pick up for someone.
03-11-2025