1 /* 2 * Copyright (c) 2002, 2020, 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/dead11. 28 * VM Testbase keywords: [quick, runtime] 29 * 30 * @library /vmTestbase 31 * /test/lib 32 * @run main/othervm vm.compiler.jbe.dead.dead11.dead11 33 */ 34 35 package vm.compiler.jbe.dead.dead11; 36 37 // dead11.java 38 39 /* -- Test the elimination of dead assignments to a local array 40 Example: 41 42 void foo() 43 { 44 int arr[] = new int[SIZE]; 45 arr[1] = 3; 46 } 47 48 In the example below, most of the assignments to the local array a[] are dead and can be eliminated. 49 */ 50 51 public class dead11 { 52 int SIZE = 30; 53 main(String args[])54 public static void main(String args[]) { 55 dead11 dce = new dead11(); 56 57 System.out.println("f()="+dce.f()+"; fopt()="+dce.fopt()); 58 if (dce.f() == dce.fopt()) { 59 System.out.println("Test dead11 Passed."); 60 } else { 61 throw new Error("Test dead11 Failed: f()=" + dce.f() + " != fopt()=" + dce.fopt()); 62 } 63 } 64 f()65 int f() { 66 int a[] = new int[SIZE]; 67 68 a[0] = 0; 69 a[1] = 1; 70 a[2] = 2; 71 a[3] = 3; 72 a[4] = 4; 73 a[5] = 5; 74 a[6] = 6; 75 a[7] = 7; 76 a[8] = 8; 77 a[9] = 9; 78 a[10] = 10; 79 a[11] = 11; 80 a[12] = 12; 81 a[13] = 13; 82 a[14] = 14; 83 a[15] = 15; 84 a[16] = 16; 85 a[17] = 17; 86 a[18] = 18; 87 a[19] = 19; 88 a[20] = 20; 89 a[21] = 21; 90 a[22] = 22; 91 a[23] = 23; 92 a[24] = 24; 93 a[25] = 25; 94 a[26] = 26; 95 a[27] = 27; 96 a[28] = 28; 97 a[29] = 29; 98 99 return a[12]; 100 } 101 102 // Code fragment after dead code elimination fopt()103 int fopt() { 104 int a[] = new int[SIZE]; 105 106 a[12] = 12; 107 return a[12] = 12; 108 } 109 } 110