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