1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /**
  26  * @test
  27  * @bug 8149797
  28  * @summary node replaced by dominating dead cast during parsing
  29  * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:TypeProfileLevel=200 -XX:CompileCommand=dontinline,TestDominatingDeadCheckCast::not_inlined TestDominatingDeadCheckCast
  30  *
  31  */
  32 
  33 public class TestDominatingDeadCheckCast {
  34 
  35     static class A {
  36         int f;
  37     }
  38 
  39     static class B extends A {
  40     }
  41 
  42     static A not_inlined() {
  43         return new A();
  44     }
  45 
  46     static void inlined(A param) {
  47         param.f = 42;
  48     }
  49 
  50     static A field;
  51 
  52     static void test(boolean flag1, boolean flag2, boolean flag3, boolean flag4, boolean flag5) {
  53         // Go through memory rather than through a local to defeat C2's replace_in_map
  54         field = not_inlined();
  55         // Speculation adds a CheckCast on entry of this inlined
  56         // method for the parameter
  57         inlined(field);
  58         // Walk up the dominators is depth limited, make the CheckCast
  59         // above unreachable from the last inlined call
  60         if (flag1) {
  61             if (flag2) {
  62                 if (flag3) {
  63                     // Speculation adds a CheckCast on entry of this
  64                     // inlined method for the parameter. This
  65                     // CheckCast is replaced by the CheckCast of the
  66                     // first inlined method call but the replaced
  67                     // CheckCast is still around during parsing.
  68                     inlined(field);
  69                     // Same as above, some useless control
  70                     if (flag4) {
  71                         if (flag5) {
  72                             // Speculation adds a CheckCast on entry
  73                             // of this inlined method for the
  74                             // parameter. This CheckCast is replaced
  75                             // by the dead CheckCast of the previous
  76                             // inlined() call.
  77                             inlined(field);
  78                         }
  79                     }
  80                 }
  81             }
  82         }
  83     }
  84 
  85     static public void main(String[] args) {
  86         field = new A();
  87         for (int i = 0; i < 20000; i++) {
  88             test(true, true, true, true, true);
  89         }
  90     }
  91 }