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/dead08. 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.dead08.dead08 34 */ 35 36 package vm.compiler.jbe.dead.dead08; 37 38 /* -- Test the elimination of dead assignment to class fields within an IF statement 39 40 In the example below, the values assigned to i1-i7 in struct within th IF statement are never used,thus can be eliminated. 41 42 */ 43 44 class struct { 45 int i1 = 2; 46 int i2 = 3; 47 int i3 = 4; 48 int i4 = 5; 49 int i5 = 6; 50 int i6 = 7; 51 int i7 = 8; 52 int i8 = 9; 53 } 54 55 public class dead08 { 56 boolean bol = true; 57 58 public static void main(String args[]) { 59 dead08 dce = new dead08(); 60 61 System.out.println("f()="+dce.f()+"; fopt()="+dce.fopt()); 62 if (dce.f() == dce.fopt()) { 63 System.out.println("Test dead08 Passed."); 64 } else { 65 throw new Error("Test dead08 Failed: f()=" + dce.f() + " != fopt()=" + dce.fopt()); 66 } 67 } 68 69 int f() { 70 struct s = new struct(); 71 72 if (bol) 73 s.i1 = 1; 74 if (bol) 75 s.i2 = 2; 76 if (bol) 77 s.i3 = 3; 78 if (bol) 79 s.i4 = 4; 80 if (bol) 81 s.i5 = 5; 82 if (bol) 83 s.i6 = 6; 84 if (bol) 85 s.i7 = 7; 86 if (bol) 87 s.i8 = 8; 88 89 if (bol) 90 s.i1 = 1; 91 if (bol) 92 s.i2 = 2; 93 if (bol) 94 s.i3 = 3; 95 if (bol) 96 s.i4 = 4; 97 if (bol) 98 s.i5 = 5; 99 if (bol) 100 s.i6 = 6; 101 if (bol) 102 s.i7 = 7; 103 if (bol) 104 s.i8 = 8; 105 106 if (bol) 107 s.i1 = 1; 108 if (bol) 109 s.i2 = 2; 110 if (bol) 111 s.i3 = 3; 112 if (bol) 113 s.i4 = 4; 114 if (bol) 115 s.i5 = 5; 116 if (bol) 117 s.i6 = 6; 118 if (bol) 119 s.i7 = 7; 120 if (bol) 121 s.i8 = 8; 122 123 return s.i8; 124 } 125 126 // Code fragment after dead code elimination 127 int fopt() { 128 struct s = new struct(); 129 130 s.i8 = 8; 131 return s.i8; 132 } 133 }