test/hotspot/jtreg/compiler/controldependency/TestEliminatedCastPPAtPhi.java
author iignatyev
Mon, 18 Feb 2019 09:31:07 -0800
changeset 53791 bec6c8739833
parent 47216 71c04702a3d5
permissions -rw-r--r--
8219157: vm/mlvm/mixed/stress/java/findDeadlock should be problem-listed only on mac Reviewed-by: thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35545
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
     1
/*
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
     4
 *
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
     8
 *
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    13
 * accompanied this code).
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    14
 *
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    18
 *
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    21
 * questions.
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    22
 */
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    23
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    24
/**
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    25
 * @test
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    26
 * @bug 8139771
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    27
 * @summary Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    28
 * @requires vm.gc=="Serial" | vm.gc=="Parallel"
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35545
diff changeset
    29
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35545
diff changeset
    30
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
40062
3b21b3295f19 8160761: [TESTBUG] Several compiler tests fail with product bits
ppunegov
parents: 40059
diff changeset
    31
 *      -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions -XX:+StressGCM
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35545
diff changeset
    32
 *      compiler.controldependency.TestEliminatedCastPPAtPhi
35545
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    33
 *
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    34
 */
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    35
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35545
diff changeset
    36
package compiler.controldependency;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35545
diff changeset
    37
35545
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    38
public class TestEliminatedCastPPAtPhi {
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    39
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    40
    static TestEliminatedCastPPAtPhi saved;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    41
    static TestEliminatedCastPPAtPhi saved_not_null;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    42
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    43
    int f;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    44
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    45
    static int test(TestEliminatedCastPPAtPhi obj, int[] array, boolean flag) {
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    46
        int ret = array[0] + array[20];
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    47
        saved = obj;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    48
        if (obj == null) {
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    49
            return ret;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    50
        }
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    51
        saved_not_null = obj;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    52
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    53
        // empty loop to be optimized out. Delays range check smearing
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    54
        // for the array access below until the if diamond is
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    55
        // optimized out
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    56
        int i = 0;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    57
        for (; i < 10; i++);
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    58
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    59
        ret += array[i];
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    60
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    61
        TestEliminatedCastPPAtPhi res;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    62
        if (flag) {
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    63
            // load is optimized out and res is obj here
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    64
            res = saved;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    65
        } else {
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    66
            // load is optimized out and res is non null CastPP of res here
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    67
            res = saved_not_null;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    68
        }
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    69
        // null check + CastPP here for res field load below
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    70
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    71
        // 1) null check is pushed in the branches of the if above by
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    72
        // split through phi because res is non null in the second
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    73
        // branch and the null check can be optimized out in that
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    74
        // branch. The Castpp stays here.
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    75
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    76
        // 2) null check in the first branch is also optimized out
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    77
        // because a dominating null check is found (the explicit null
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    78
        // check at the beggining of the test)
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    79
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    80
        // 3) the Phi for the if above merges a CastPP'ed value and
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    81
        // the same value so it's optimized out and replaced by the
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    82
        // uncasted value: obj
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    83
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    84
        // 4) the if above has 2 empty branches so it's optimized
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    85
        // out. The control of the CastPP that is still here is now
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    86
        // the success branch of the range check for the array access
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    87
        // above
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    88
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    89
        // 5) the loop above is optimized out, i = 10, the range check
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    90
        // for the array access above is optimized out and all its
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    91
        // uses are replaced by the range check for the array accesses
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    92
        // at the beginning of the method. The castPP here is one of
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    93
        // the uses and so its control is now the range check at the
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    94
        // beginning of the method: the control of the CastPP bypasses
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    95
        // the explicit null check
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    96
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    97
        return ret + res.f;
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    98
    }
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
    99
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
   100
    static public void main(String[] args) {
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
   101
        int[] array = new int[100];
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
   102
        TestEliminatedCastPPAtPhi obj = new TestEliminatedCastPPAtPhi();
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
   103
        for (int i = 0; i < 20000; i++) {
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
   104
            test(obj, array, (i%2) == 0);
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
   105
        }
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
   106
        test(null, array, true);
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
   107
    }
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
   108
a8f29dfd62b2 8139771: Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
roland
parents:
diff changeset
   109
}