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