RFR: 8370519: C2: Hit MemLimit when running with +VerifyLoopOptimizations [v6]

Benoît Maillard bmaillard at openjdk.org
Wed Jan 28 10:25:25 UTC 2026


On Thu, 11 Dec 2025 15:42:42 GMT, Roland Westrelin <roland at openjdk.org> wrote:

>> For this failure memory stats are:
>> 
>> 
>> Total Usage: 1095525816 
>>     --- Arena Usage by Arena Type and compilation phase, at arena usage peak of 1095525816 ---
>>         Phase                         Total        ra      node      comp      type    states   reglive  regsplit   regmask superword     cienv        ha     other
>>         none                        5976032    331560   5402064    197512     33712     10200         0         0       984         0         0         0         0
>>         parse                       2716464     65456   1145480    196408   1112752         0         0         0         0         0    196368         0         0
>>         optimizer                     98184         0     32728         0     65456         0         0         0         0         0         0         0         0
>>         connectionGraph               32728         0         0     32728         0         0         0         0         0         0         0         0         0
>>         iterGVN                       32728         0     32728         0         0         0         0         0         0         0         0         0         0
>>         idealLoop                 918189632         0  38687056 872824784    392776         0         0         0         0         0   6285016         0         0
>>         idealLoopVerify             2228144         0         0   2228144         0         0         0         0         0         0         0         0         0
>>         macroExpand                   32728         0     32728         0         0         0         0         0         0         0         0         0         0
>>         graphReshape                  32728         0     32728         0         0         0         0         0         0         0         0         0         0
>>         matcher                    20135944   3369848   9033208   7536400     65456    131032         0         0         0         0         0         0         0
>>         postselect_cleanup           294872    294872         0         0         0         0         0         0         0         0         0         0         0
>>         scheduler                    752944    196488    556456         0         0         0         0         0         0         0         0         0         0
>>         regalloc                     388736    388736         0         0         0         0         0         0         0         0         0         0         0
>>        ...
>
> Roland Westrelin has updated the pull request incrementally with one additional commit since the last revision:
> 
>   package declaration

I was able to come up with this test, which is a bit more that 2 times faster than the original one on my machine. Its `memlimit` is set to `600M`, which is enough to make the old version fail. With the new one, the test passes even with a `memlimit` of `200M`, so this should be a good enough margin.

While looking into this I have also found out that some programs have an unexpectedly high usage of `output` (as was the case in the test case that I initially suggested). I am trying to get a good reproducer and will most likely file a follow-up. 


/**
 * @test
 * @key stress randomness
 * @bug 8370519
 * @summary C2: Hit MemLimit when running with +VerifyLoopOptimizations
 * @run main/othervm -XX:CompileCommand=compileonly,${test.main.class}::* -XX:-TieredCompilation -Xbatch
 *                   -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions
 *                   -XX:+StressLoopPeeling -XX:+VerifyLoopOptimizations
 *                   -XX:CompileCommand=memlimit,${test.main.class}::*,600M~crash
 *                   -XX:StressSeed=3106998670 ${test.main.class}
 * @run main ${test.main.class}
 */

package compiler.c2;

public class TestVerifyLoopOptimizationsHighMemUsage {
    public static final int N = 400;
    public static long instanceCount = -13L;
    public static volatile short sFld = -16143;
    public static int iFld = -159;
    public static float fArrFld[] = new float[N];

    public static long lMeth(int i1) {
        int i2 = 11, i3 = 37085, i4 = 177, i5 = 190, i6 = -234, i7 = 13060,
                iArr[] = new int[N];
        float f = 1.179F;
        double d = 2.9685;
        long lArr[] = new long[N];
        for (i2 = 15; i2 < 330; ++i2)
            for (i4 = 1; i4 < 5; ++i4) {
                fArrFld[i4 + 1] = (++i1);
                for (i6 = 2; i6 > 1; i6 -= 3)
                    switch ((i2 * 5) + 54) {
                        case 156:
                            if (i4 != 0)
                                ;
                        case 168:
                        case 342:
                        case 283:
                        case 281:
                        case 328:
                        case 322:
                        case 228:
                        case 114:
                        case 207:
                        case 209:
                        case 354:
                        case 108:
                            i1 <<= i1;
                        case 398:
                        case 144:
                        case 218:
                        case 116:
                        case 296:
                        case 198:
                        case 173:
                        case 105:
                        case 120:
                        case 248:
                        case 140:
                        case 352:
                            try {
                            } catch (ArithmeticException a_e) {
                            }
                        case 404:
                            i5 += (i6 ^ instanceCount);
                        case 370:
                        case 211:
                        case 231:
                            try {
                            } catch (ArithmeticException a_e) {
                            }
                        case 251:
                        case 179:
                            f += (((i6 * sFld) + i4) -
                                    iFld);
                    }
            }
        long meth_res = i1 + i2 + i3 + i4 + i5 + i6 + i7 + Float.floatToIntBits(f) +
                Double.doubleToLongBits(d) + +checkSum(iArr) +
                checkSum(lArr);
        return meth_res;
    }

    public static long checkSum(int[] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++)
            sum += (a[j] / (j + 1) + a[j] % (j + 1));
        return sum;
    }

    public static long checkSum(long[] a) {
        long sum = 0;
        for (int j = 0; j < a.length; j++)
            sum += (a[j] / (j + 1) + a[j] % (j + 1));
        return sum;
    }

  public static void main(String[] strArr) {
    for (int i = 0; i < 10; i++)
      lMeth(-159);
  }
}

-------------

PR Comment: https://git.openjdk.org/jdk/pull/28581#issuecomment-3810407567


More information about the hotspot-dev mailing list