1 /*
   2  * Copyright (c) 2020, 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 8244663
  27  * @summary Shenandoah: C2 assertion fails in Matcher::collect_null_checks
  28  * @key gc
  29  * @requires vm.flavor == "server"
  30  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  31  *
  32  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
  33  *                   -XX:CompileCommand=dontinline,TestShenandoahCmpPAfterCall::not_inlined TestShenandoahCmpPAfterCall
  34  *
  35  */
  36 
  37 public class TestShenandoahCmpPAfterCall {
  38     private static Object field1 = new Object();
  39     private static Object field2 = new Object();
  40     private static Object o3;
  41     private static volatile int barrier;
  42 
  43     public static void main(String[] args) {
  44         for (int i = 0; i < 20_000; i++) {
  45             test();
  46         }
  47     }
  48 
  49     private static void test() {
  50         Object o1 = null;
  51         Object o2 = field2;
  52         try {
  53             not_inlined();
  54             o1 = field1;
  55             if (o1 == o2) {
  56 
  57             }
  58         } catch (Exception1 ex1) {
  59             o1 = field1;
  60             if (o1 == o2) {
  61 
  62             }
  63         }
  64         barrier = 42;
  65         if (o1 == o2) {
  66 
  67         }
  68     }
  69 
  70     static int count = 0;
  71     private static void not_inlined() throws Exception1 {
  72         count++;
  73         if ((count % 100) == 0) {
  74             throw new Exception1();
  75         }
  76     }
  77 
  78     private static class Exception1 extends Exception {
  79     }
  80 }