hotspot/test/compiler/types/TestPhiElimination.java
author stuefe
Thu, 28 Apr 2016 15:40:45 +0200
changeset 38215 fe1677e95252
parent 36611 eb4fe2f11579
child 40059 c2304140ed64
permissions -rw-r--r--
8155639: Remove STEP numbers from error reporting Reviewed-by: coleenp, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36611
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
     1
/*
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
     4
 *
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
     8
 *
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    13
 * accompanied this code).
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    14
 *
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    18
 *
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    21
 * questions.
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    22
 *
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    23
 */
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    24
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    25
/**
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    26
 * @test
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    27
 * @bug 8150804
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    28
 * @summary Tests elimination of Phi nodes without losing type information.
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    29
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestPhiElimination
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    30
 */
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    31
public class TestPhiElimination {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    32
    /*
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    33
       A::get() is inlined into test(obj) producing the following graph:
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    34
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    35
               Parm (obj)
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    36
            TestPhiElimination
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    37
                   |
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    38
                 CastPP
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    39
        TestPhiElimination:NotNull
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    40
                   |
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    41
              CheckCastPP
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    42
               A:NotNull
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    43
               /       \
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    44
       CheckCastPP     |
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    45
        A:NotNull      |
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    46
                \     /
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    47
                  Phi
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    48
                   A
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    49
                   |
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    50
               Safepoint
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    51
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    52
       PhiNode::ideal() then replaces the Phi by a CheckCastPP:
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    53
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    54
               Parm (obj)
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    55
            TestPhiElimination
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    56
                   |
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    57
              CheckCastPP
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    58
                   A
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    59
                   |
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    60
               Safepoint
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    61
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    62
       losing the :NotNull information. Therefore, we cannot prove that obj != null
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    63
       when accessing a field and add an uncommon trap. Since obj is used as monitor, we
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    64
       set it to TOP in the uncommon trap branch and later fail in Process_OopMap_Node
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    65
       because the monitor object is TOP.
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    66
    */
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    67
    public Object test(TestPhiElimination obj) {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    68
        if (obj instanceof A) {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    69
            return ((A) obj).get();
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    70
        }
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    71
        return null;
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    72
    }
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    73
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    74
    static public void main(String[] args) {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    75
        TestPhiElimination t = new TestPhiElimination();
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    76
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    77
        // Warmup
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    78
        B b = new B();
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    79
        for (int i = 0; i < 1_000; ++i) {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    80
            t.test(b);
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    81
        }
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    82
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    83
        // Compile
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    84
        A a = new A();
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    85
        for (int i = 0; i < 20_000; ++i) {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    86
            if (i % 2 == 0) {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    87
                a.f = null;
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    88
            }
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    89
            t.test(a);
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    90
        }
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    91
    }
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    92
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    93
}
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    94
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    95
class A extends TestPhiElimination {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    96
    public Object f;
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    97
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    98
    public A create() {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
    99
        return new A();
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   100
    }
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   101
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   102
    public synchronized Object get() {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   103
        if (f == null) {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   104
            f = create();
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   105
        }
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   106
        return f;
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   107
    }
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   108
}
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   109
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   110
class B extends A {
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   111
eb4fe2f11579 8150804: C2 Compilation fails with assert(_base >= OopPtr && _base <= AryPtr) failed: Not a Java pointer
thartmann
parents:
diff changeset
   112
}