1 /*
   2  * Copyright (c) 2015, 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 8069191
  28  * @summary predicate moved out of loops and CastPP removal causes dependency to be lost
  29  * @run main/othervm -Xcomp -XX:CompileOnly=TestPredicateLostDependency.m1 -XX:+IgnoreUnrecognizedVMOptions -XX:+StressGCM TestPredicateLostDependency
  30  *
  31  */
  32 
  33 public class TestPredicateLostDependency {
  34     static class A {
  35         int i;
  36     }
  37 
  38     static class B extends A {
  39     }
  40 
  41     static boolean crash = false;
  42 
  43     static boolean m2() {
  44         return crash;
  45     }
  46 
  47     static int m3(float[] arr) {
  48         return 0;
  49     }
  50 
  51     static float m1(A aa) {
  52         float res = 0;
  53         float[] arr = new float[10];
  54         for (int i = 0; i < 10; i++) {
  55             if (m2()) {
  56                 arr = null;
  57             }
  58             m3(arr);
  59             int j = arr.length;
  60             int k = 0;
  61             for (k = 9; k < j; k++) {
  62             }
  63             if (k == 10) {
  64                 if (aa instanceof B) {
  65                 }
  66             }
  67             res += arr[0];
  68             res += arr[1];
  69         }
  70         return res;
  71     }
  72 
  73     static public void main(String args[]) {
  74         A a = new A();
  75         B b = new B();
  76         for (int i = 0; i < 20000; i++) {
  77             m1(a);
  78         }
  79         crash = true;
  80         try {
  81             m1(a);
  82         } catch (NullPointerException npe) {}
  83     }
  84 }