1 /*
2  * Copyright (c) 2003, 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 package nsk.jvmti.SetFieldAccessWatch;
25 
26 import java.io.PrintStream;
27 
28 public class setfldw003 {
29 
30     final static int JCK_STATUS_BASE = 95;
31 
32     static {
33         try {
34             System.loadLibrary("setfldw003");
35         } catch (UnsatisfiedLinkError ule) {
36             System.err.println("Could not load setfldw003 library");
37             System.err.println("java.library.path:"
38                 + System.getProperty("java.library.path"));
39             throw ule;
40         }
41     }
42 
getReady()43     native static void getReady();
check(int ind)44     native static void check(int ind);
getRes()45     native static int getRes();
46 
47     static PrintStream out;
48     static int result = 0;
49 
50     static int fld0 = 17;
51     static int fld1;
52 
53     int fld2 = 18;
54     int fld3;
55 
main(String[] args)56     public static void main(String[] args) {
57         args = nsk.share.jvmti.JVMTITest.commonInit(args);
58 
59         // produce JCK-like exit status.
60         System.exit(run(args, System.out) + JCK_STATUS_BASE);
61     }
62 
run(String argv[], PrintStream ref)63     public static int run(String argv[], PrintStream ref) {
64         out = ref;
65         setfldw003 t = new setfldw003();
66         getReady();
67 
68         stat_meth();
69         t.meth();
70 
71         return (getRes() | result);
72     }
73 
stat_meth()74     public static void stat_meth() {
75         int loc;
76 
77         // test getstatic bytecode for initialized field
78         loc = fld0;
79         check(0);
80         if (loc != 17) {
81             out.println("fld0 value is corrupted: expected=17, actual=" + loc);
82             result = 2;
83         }
84 
85         // test getstatic bytecode for uninitialized field
86         loc = fld1;
87         check(1);
88         if (loc != 0) {
89             out.println("fld1 value is corrupted: expected=0, actual=" + loc);
90             result = 2;
91         }
92     }
93 
meth()94     public void meth() {
95         int loc;
96 
97         // test getfield bytecode for initialized field
98         loc = fld2;
99         check(2);
100         if (loc != 18) {
101             out.println("fld2 value is corrupted: expected=18, actual=" + loc);
102             result = 2;
103         }
104 
105         // test getfield bytecode for uninitialized field
106         loc = fld3;
107         check(3);
108         if (loc != 0) {
109             out.println("fld3 value is corrupted: expected=0, actual=" + loc);
110             result = 2;
111         }
112     }
113 }
114