hotspot/test/compiler/macronodes/TestEliminateAllocationPhi.java
author roland
Sat, 02 Aug 2014 07:06:08 +0200
changeset 25935 59b08808cb9c
child 40059 c2304140ed64
permissions -rw-r--r--
8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943 Summary: PhiNode inserted between AllocateNode and Initialization node confuses allocation elimination Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25935
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
     1
/*
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
     4
 *
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
     8
 *
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    13
 * accompanied this code).
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    14
 *
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    18
 *
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    21
 * questions.
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    22
 */
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    23
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    24
/*
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    25
 * @test
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    26
 * @bug 8046698
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    27
 * @summary PhiNode inserted between AllocateNode and Initialization node confuses allocation elimination
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    28
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestEliminateAllocationPhi
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    29
 *
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    30
 */
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    31
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    32
public class TestEliminateAllocationPhi {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    33
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    34
    // This will return I when called from m(0 and once optimized will
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    35
    // go away but this will confuse escape analysis in m(): it will
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    36
    // find I as non escaping but non scalar replaceable. In its own
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    37
    // method so that we can make the profile of the if() branch look
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    38
    // like it's taken sometimes.
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    39
    static Integer m2(Integer I, int i) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    40
        for (; i < 10; i=(i+2)*(i+2)) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    41
        }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    42
        if (i == 121) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    43
            return II;
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    44
        }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    45
        return I;
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    46
    }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    47
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    48
    static Integer II = new Integer(42);
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    49
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    50
    static int m(int[] integers, boolean flag) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    51
        int j = 0;
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    52
        while(true) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    53
            try {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    54
                int k = integers[j++];
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    55
                // A branch that will cause loop unswitching
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    56
                if (flag) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    57
                    k += 42;
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    58
                }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    59
                if (k < 1000) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    60
                    throw new Exception();
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    61
                }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    62
                // Because of the try/catch the Allocate node for this
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    63
                // new will be in the loop while the Initialization
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    64
                // node will be outside the loop. When loop
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    65
                // unswitching happens, the Allocate node will be
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    66
                // cloned and the results of both will be inputs to a
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    67
                // Phi that will be between the Allocate nodes and the
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    68
                // Initialization nodes.
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    69
                Integer I = new Integer(k);
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    70
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    71
                I = m2(I, 0);
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    72
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    73
                int i = I.intValue();
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    74
                return i;
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    75
            } catch(Exception e) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    76
            }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    77
        }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    78
    }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    79
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    80
    static public void main(String[] args) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    81
        for (int i = 0; i < 5000; i++) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    82
            m2(null, 1);
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    83
        }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    84
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    85
        int[] integers = { 2000 };
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    86
        for (int i = 0; i < 6000; i++) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    87
            m(integers, (i%2) == 0);
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    88
        }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    89
        int[] integers2 = { 1, 2, 3, 4, 5, 2000 };
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    90
        for (int i = 0; i < 10000; i++) {
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    91
            m(integers2, (i%2) == 0);
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    92
        }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    93
    }
59b08808cb9c 8046698: assert(false) failed: only Initialize or AddP expected macro.cpp:943
roland
parents:
diff changeset
    94
}