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/dead15.
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.dead15.dead15
34  */
35 
36 package vm.compiler.jbe.dead.dead15;
37 
38 // dead15.java
39 
40 /* -- Test the elimination of a global variable assignment to itself.
41       Example:
42 
43       int bar;
44       void foo()
45       {
46          bar = bar;
47       }
48 
49       The assignment to bar can be eliminated. Though assignments of this
50       nature are unlikley to occur in an original code, it can actually
51       happen as a result of other optimizations. For example, consider the
52       following assignments after constant propagation.
53 
54       bat = 0;
55       bar = bar + bat;
56 
57       After constant propagation, the second statement becomes bar = bar + 0,
58       or bar = bar.  This test ensures that the final transformation, (i.e.
59       the elimination of this assignment) will occur.
60  */
61 
62 
63 public class dead15 {
64   int i00=0, i01=1, i02=2, i03=3, i04=4;
65   int i05=5, i06=6, i07=7, i08=8, i09=9;
66   int i10=10, i11=11, i12=12, i13=13, i14=14;
67   int i15=15, i16=16, i17=17, i18=18, i19=19;
68 
main(String args[])69   public static void main(String args[]) {
70     dead15 dce = new dead15();
71 
72     System.out.println("f()="+dce.f()+"; fopt()="+dce.fopt());
73     if (dce.f() == dce.fopt()) {
74       System.out.println("Test dead15 Passed.");
75     } else {
76       throw new Error("Test dead15 Failed: f()=" + dce.f() + " != fopt()=" + dce.fopt());
77     }
78   }
79 
80 
f()81   int f() {
82     i00 = i00;
83     i01 = i01;
84     i02 = i02;
85     i03 = i03;
86     i04 = i04;
87     i05 = i05;
88     i06 = i06;
89     i07 = i07;
90     i08 = i08;
91     i09 = i09;
92     i10 = i10;
93     i11 = i11;
94     i12 = i12;
95     i13 = i13;
96     i14 = i14;
97     i15 = i15;
98     i16 = i16;
99     i17 = i17;
100     i18 = i18;
101     i19 = i19;
102 
103     return i19;
104   }
105 
106   // Code fragment after dead code elimination
fopt()107   int fopt() {
108     return i19;
109   }
110 }
111