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 8174164
  27  * @summary SafePointNode::_replaced_nodes breaks with irreducible loops
  28  * @run main/othervm -XX:-BackgroundCompilation TestReplacedNodesOSR
  29  *
  30  */
  31 
  32 public class TestReplacedNodesOSR {
  33 
  34     static Object dummy;
  35 
  36     static interface I {
  37     }
  38 
  39     static class A implements I {
  40     }
  41 
  42     static final class MyException extends Exception {
  43     }
  44 
  45     static final A obj = new A();
  46     static I static_field() { return obj; }
  47     
  48     // When OSR compiled, this method has an irreducible loop
  49     static void test(int v, MyException e) {
  50         int i = 0;
  51         for (;;) {
  52             if (i == 1000) {
  53                 break;
  54             }
  55             try {
  56                 if ((i%2) == 0) {
  57                     int j = 0;
  58                     for (;;) {
  59                         j++;
  60                         if (i+j != v) {
  61                             if (j == 1000) {
  62                                 break;
  63                             }
  64                         } else {
  65                             A a = (A)static_field();
  66                             // replaced node recorded here
  67                             throw e;
  68                         }
  69                     }
  70                 }
  71             } catch(MyException ex) {
  72             }
  73             i++;
  74             // replaced node applied on return of the method
  75             // replaced node used here
  76             dummy = static_field();
  77         }
  78     }
  79 
  80 
  81     static public void main(String[] args) {
  82         for (int i = 0; i < 1000; i++) {
  83             test(1100, new MyException());
  84         }
  85     }
  86 }