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