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/dead02. 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.dead02.dead02 34 */ 35 36 package vm.compiler.jbe.dead.dead02; 37 38 /* -- Test the elimination of dead assignment to static variables 39 In the example below, the value assigned to i is never used, all dead stores to static global can be eliminated, and the last return statement in f() is unreachable; Both dead/unused stores and unreachable statement can be eliminated. 40 41 */ 42 43 public class dead02 { 44 static int global; 45 static int i; 46 47 public static void main(String args[]) { 48 dead02 dce = new dead02(); 49 50 System.out.println("f()="+dce.f()+"; fopt()="+dce.fopt()); 51 if (dce.f() == dce.fopt()) { 52 System.out.println("Test dead02 Passed."); 53 } else { 54 throw new Error("Test dead02 Failed: f()=" + dce.f() + " != fopt()=" + dce.fopt()); 55 } 56 } 57 58 59 int f() { 60 61 i = 1; /* dead store */ 62 global = 8; /* dead store */ 63 global = 7; /* dead store */ 64 global = 6; /* dead store */ 65 global = 5; /* dead store */ 66 global = 4; /* dead store */ 67 global = 3; /* dead store */ 68 global = 2; /* dead store */ 69 global = 1; /* dead store */ 70 global = 0; /* dead store */ 71 global = -1; /* dead store */ 72 global = -2; /* dead store */ 73 74 i = 1; /* dead store */ 75 global = 8; /* dead store */ 76 global = 7; /* dead store */ 77 global = 6; /* dead store */ 78 global = 5; /* dead store */ 79 global = 4; /* dead store */ 80 global = 3; /* dead store */ 81 global = 2; /* dead store */ 82 global = 1; /* dead store */ 83 global = 0; /* dead store */ 84 global = -1; /* dead store */ 85 global = -2; /* dead store */ 86 87 i = 1; /* dead store */ 88 global = 8; /* dead store */ 89 global = 7; /* dead store */ 90 global = 6; /* dead store */ 91 global = 5; /* dead store */ 92 global = 4; /* dead store */ 93 global = 3; /* dead store */ 94 global = 2; /* dead store */ 95 global = 1; /* dead store */ 96 global = 0; /* dead store */ 97 global = -1; /* dead store */ 98 global = -2; 99 100 if (Math.abs(global) >= 0) /* always true */ 101 return global; 102 return global; /* unreachable */ 103 } 104 105 // Code fragment after dead code elimination 106 int fopt() { 107 108 global = -2; 109 return global; 110 } 111 }