JDK-8180290 : Allocation elimination fails on arrays of non-constant lengths
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9,10
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2017-05-12
  • Updated: 2025-05-27
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
tbdUnresolved
Related Reports
Relates :  
Description
This gets redundant allocations eliminated fine:

    @Benchmark
    public Object arr_const_2() {
        Object o;
        o = new int[10];
        o = new int[10];
        return o;
    }

...and here they are not:

    @Benchmark
    public Object arr_var_2() {
        Object o;
        o = new int[size];
        o = new int[size];
        return o;
    }

This seems to affect e.g. JavaGrande. 

Benchmarks:
 http://cr.openjdk.java.net/~shade/8180290/MultiAlloc.java
 http://cr.openjdk.java.net/~shade/8180290/benchmarks.jar

Perf data:
 http://cr.openjdk.java.net/~shade/8180290/perf.txt

Comments
This could perhaps be solved by extending PhaseMacroExpand::eliminate_allocate_node to handle the special case of dead AllocateArray nodes, similarly to https://github.com/openjdk/jdk/commit/c28f81a7ef2a4f3d3cb761ea23a80c09276e7e58. One difficulty not addressed in the patch is that early array elimination should still generate the nonnegative array size check code. See some background discussion here: https://github.com/openjdk/jdk/pull/24570#issuecomment-2891102076.
21-05-2025

Even arrays of constant lengths are not always eliminated (see -XX:EliminateAllocationArraySizeLimit which is 64 by default).
15-05-2017