1 /*
   2  * Copyright (c) 2018, 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 8212673
  27  * @summary Node::eqv_uncast() shouldn't step over load barriers unconditionally
  28  * @library /test/lib /
  29  * @modules java.base/jdk.internal.misc
  30  *
  31  * @build sun.hotspot.WhiteBox
  32  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  33  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
  34  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-UseOnStackReplacement -XX:-TieredCompilation EqvUncastStepOverBarrier
  35  */
  36 
  37 import sun.hotspot.WhiteBox;
  38 import java.lang.reflect.Method;
  39 
  40 public class EqvUncastStepOverBarrier {
  41     static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
  42 
  43     private static Object field = new A();
  44 
  45     public static void main(String[] args) throws Exception {
  46         for (int i = 0; i < 20_000; i++) {
  47             test();
  48             test();
  49             test_helper(null, 0);
  50         }
  51         Method m = EqvUncastStepOverBarrier.class.getDeclaredMethod("test");
  52         WHITE_BOX.enqueueMethodForCompilation(m, 4);
  53         if (!WHITE_BOX.isMethodCompiled(m, false)) {
  54             throw new RuntimeException("Method compilation failed");
  55         }
  56     }
  57 
  58     private static Object test() {
  59         Object o = field;
  60         if (o == null) {}
  61         for (int i = 1; i < 100; i *= 2) {
  62             int j = 0;
  63             for (; j < 4; j++) ;
  64             o = test_helper(o, j);
  65         }
  66         return o;
  67     }
  68 
  69     private static Object test_helper(Object o, int j) {
  70         if (j == 4) {
  71             A a = (A) o;
  72             o = a;
  73         } else {
  74             o = new Object();
  75         }
  76         return o;
  77     }
  78 
  79     private static class A {
  80     }
  81 }