| /* |
| * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. |
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| * |
| * This code is free software; you can redistribute it and/or modify it |
| * under the terms of the GNU General Public License version 2 only, as |
| * published by the Free Software Foundation. |
| * |
| * This code is distributed in the hope that it will be useful, but WITHOUT |
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| * version 2 for more details (a copy is included in the LICENSE file that |
| * accompanied this code). |
| * |
| * You should have received a copy of the GNU General Public License version |
| * 2 along with this work; if not, write to the Free Software Foundation, |
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| * |
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| * or visit www.oracle.com if you need additional information or have any |
| * questions. |
| */ |
| |
| |
| super public class TestOnlyInfiniteLoops |
| { |
| public Method "<init>":"()V" |
| stack 2 locals 1 |
| { |
| aload_0; |
| invokespecial Method java/lang/Object."<init>":"()V"; |
| return; |
| } |
| |
| static Method test_simple:"(III)I" |
| stack 200 locals 10 |
| { |
| // Nested infinite loop, where inner loop eventually |
| // looses exit to outer loop. Then, the inner loop |
| // floats outside the inner loop. The entry from |
| // outer to inner loop now becomes an exit for the |
| // outer loop, where it now enters the next loop, that |
| // used to be the inner loop. |
| iconst_0; |
| istore 9; |
| |
| iload 0; |
| ifeq LEND; // skip |
| |
| LOOP1: |
| iload 1; |
| ifeq LOOP1; // dominates |
| LOOP2: |
| // SKIP: prevent loop-exit from becoming zero-trip guard |
| iload 2; |
| ifeq SKIP; |
| iinc 9, 1; |
| SKIP: |
| iload 1; |
| ifeq LOOP1; // is dominated |
| goto LOOP2; |
| |
| LEND: |
| iload 9; |
| ireturn; |
| } |
| static Method test_irreducible:"(IIII)V" |
| stack 200 locals 200 |
| { |
| iload_0; |
| ifeq LEND; // skip |
| |
| L1: |
| iload 1; |
| ifgt MERGE; |
| L2: |
| iload 2; |
| ifge MERGE; |
| goto L1; |
| |
| MERGE: |
| nop; |
| LOOP: |
| iload 3; |
| ifle L2; |
| iconst_0; // always true |
| ifeq LOOP; |
| iconst_0; // always true |
| ifeq LOOP; |
| INFTY: |
| goto INFTY; // infinite loop |
| |
| LEND: |
| return; |
| } |
| } |