test/hotspot/jtreg/vmTestbase/vm/compiler/jbe/dead/dead12/dead12.java
changeset 50366 4d85990f9c4a
equal deleted inserted replaced
50365:18e65332ac5c 50366:4d85990f9c4a
       
     1 /*
       
     2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. 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  *
       
    27  * @summary converted from VM Testbase runtime/jbe/dead/dead12.
       
    28  * VM Testbase keywords: [quick, runtime]
       
    29  *
       
    30  * @library /vmTestbase
       
    31  *          /test/lib
       
    32  * @run driver jdk.test.lib.FileInstaller . .
       
    33  * @run main/othervm vm.compiler.jbe.dead.dead12.dead12
       
    34  */
       
    35 
       
    36 package vm.compiler.jbe.dead.dead12;
       
    37 
       
    38 // dead12.java
       
    39 
       
    40 /* -- Test the elimination of dead assignments to a local array within IF statement
       
    41       Example:
       
    42 
       
    43       boolean bol = true;
       
    44       void foo()
       
    45       {
       
    46          int arr[] = new int[SIZE];
       
    47          if (bol) arr[1] = 3;
       
    48       }
       
    49 
       
    50 In the example below, most of the assignments to the local array a[] are dead and can be eliminated.
       
    51  */
       
    52 
       
    53 public class dead12 {
       
    54   int SIZE = 30;
       
    55   boolean bol = true;
       
    56 
       
    57   public static void main(String args[]) {
       
    58     dead12 dce = new dead12();
       
    59 
       
    60     System.out.println("f()="+dce.f()+"; fopt()="+dce.fopt());
       
    61     if (dce.f() == dce.fopt()) {
       
    62       System.out.println("Test dead12 Passed.");
       
    63     } else {
       
    64       throw new Error("Test dead12 Failed: f()=" + dce.f() + " != fopt()=" + dce.fopt());
       
    65     }
       
    66   }
       
    67 
       
    68   int f() {
       
    69 
       
    70     int a[] = new int[SIZE];
       
    71 
       
    72     if (bol)
       
    73       a[0] = 0;
       
    74     if (bol)
       
    75       a[1] = 1;
       
    76     if (bol)
       
    77       a[2] = 2;
       
    78     if (bol)
       
    79       a[3] = 3;
       
    80     if (bol)
       
    81       a[4] = 4;
       
    82     if (bol)
       
    83       a[5] = 5;
       
    84     if (bol)
       
    85       a[6] = 6;
       
    86     if (bol)
       
    87       a[7] = 7;
       
    88     if (bol)
       
    89       a[8] = 8;
       
    90     if (bol)
       
    91       a[9] = 9;
       
    92     if (bol)
       
    93       a[10] = 10;
       
    94     if (bol)
       
    95       a[11] = 11;
       
    96     if (bol)
       
    97       a[12] = 12;
       
    98     if (bol)
       
    99       a[13] = 13;
       
   100     if (bol)
       
   101       a[14] = 14;
       
   102     if (bol)
       
   103       a[15] = 15;
       
   104     if (bol)
       
   105       a[16] = 16;
       
   106     if (bol)
       
   107       a[17] = 17;
       
   108     if (bol)
       
   109       a[18] = 18;
       
   110     if (bol)
       
   111       a[19] = 19;
       
   112     if (bol)
       
   113       a[20] = 20;
       
   114     if (bol)
       
   115       a[21] = 21;
       
   116     if (bol)
       
   117       a[22] = 22;
       
   118     if (bol)
       
   119       a[23] = 23;
       
   120     if (bol)
       
   121       a[24] = 24;
       
   122     if (bol)
       
   123       a[25] = 25;
       
   124     if (bol)
       
   125       a[26] = 26;
       
   126     if (bol)
       
   127       a[27] = 27;
       
   128      if (bol)
       
   129        a[28] = 28;
       
   130     if (bol)
       
   131       a[29] = 29;
       
   132 
       
   133     return a[12];
       
   134   }
       
   135 
       
   136   // Code fragment after dead code elimination
       
   137   int fopt() {
       
   138     int a[] = new int[SIZE];
       
   139 
       
   140     a[12] = 12;
       
   141     return a[12] = 12;
       
   142   }
       
   143 }