1 /*
   2  * Copyright (c) 2017, Red Hat, Inc. 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  * @test
  26  * @bug 8191153
  27  * @summary too strong assert from 8186125
  28  *
  29  * @run main/othervm -XX:-BackgroundCompilation -XX:CompileCommand=dontinline,TestSplitIfPinnedCMove::not_inlined -XX:CompileOnly=TestSplitIfPinnedCMove::test TestSplitIfPinnedCMove
  30  *
  31  */
  32 
  33 public class TestSplitIfPinnedCMove {
  34     static void not_inlined() {}
  35 
  36     static class A {
  37         A(int f) {
  38             this.f = f;
  39         }
  40         int f;
  41     }
  42 
  43     static int test(int i1, int i3, A a1, A a2) {
  44         // loops to trigger more loop optimization passes
  45         int res = 0;
  46         for (int i = 0; i < 2; i++) {
  47             for (int j = 0; j < 2; j++) {
  48                 for (int k = 0; k < 2; k++) {
  49                     res++;
  50                 }
  51             }
  52         }
  53         // null check a1 and a2
  54         res += a1.f + a2.f;
  55 
  56         boolean f2 = false;
  57         if (i1 > 0) {
  58             not_inlined();
  59             f2 = true;
  60         }
  61 
  62         // Should become CMoveP and be pinned here
  63         res += (i3 > 0 ? a1 : a2).f;
  64 
  65         // f2 should be split through phi with above if
  66         if (f2) {
  67             not_inlined();
  68             res += 42;
  69         }
  70 
  71         // Another use for i3 > 0
  72         if (i3 > 0) {
  73             res++;
  74         }
  75         return res;
  76     }
  77 
  78     public static void main(String[] args) {
  79         A a = new A(42);
  80         for (int i = 0; i < 20_000; i++) {
  81                 test((i % 2) == 0 ? 0 : 1, (i % 2) == 0 ? 0 : 1, a, a);
  82         }
  83     }
  84 }