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