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 setfldw005 { 29 30 final static int JCK_STATUS_BASE = 95; 31 32 static { 33 try { 34 System.loadLibrary("setfldw005"); 35 } catch (UnsatisfiedLinkError ule) { 36 System.err.println("Could not load setfldw005 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 long fld0 = 12345678901L; 51 long fld1 = 22345678901L; 52 static float fld2 = 123.456F; 53 float fld3 = 223.456F; 54 static double fld4 = 123456.654321; 55 double fld5 = 223456.654321; 56 static Object fld6 = new Object(); 57 Object fld7 = new Object(); 58 static Object copy6; 59 static Object copy7; 60 static boolean fld8 = true; 61 boolean fld9 = false; 62 static byte fld10 = 123; 63 byte fld11 = -123; 64 static short fld12 = 12345; 65 short fld13 = -12345; 66 static char fld14 = '\uabcd'; 67 char fld15 = '\udcba'; 68 main(String[] args)69 public static void main(String[] args) { 70 args = nsk.share.jvmti.JVMTITest.commonInit(args); 71 72 // produce JCK-like exit status. 73 System.exit(run(args, System.out) + JCK_STATUS_BASE); 74 } 75 run(String argv[], PrintStream ref)76 public static int run(String argv[], PrintStream ref) { 77 out = ref; 78 setfldw005 t = new setfldw005(); 79 copy6 = fld6; 80 copy7 = t.fld7; 81 82 getReady(); 83 84 t.meth(); 85 86 return (getRes() | result); 87 } 88 meth()89 public void meth() { 90 long loc_l; 91 float loc_f; 92 double loc_d; 93 Object loc_o; 94 boolean loc_z; 95 byte loc_b; 96 short loc_s; 97 char loc_c; 98 99 loc_l = fld0; 100 check(0); 101 if (loc_l != 12345678901L) { 102 out.print("fld0 value is corrupted: "); 103 out.println("expected=12345678901L, actual=" + loc_l); 104 result = 2; 105 } 106 107 loc_l = fld1; 108 check(1); 109 if (loc_l != 22345678901L) { 110 out.print("fld1 value is corrupted: "); 111 out.println("expected=22345678901L, actual=" + loc_l); 112 result = 2; 113 } 114 115 loc_f = fld2; 116 check(2); 117 if (loc_f != 123.456F) { 118 out.print("fld2 value is corrupted: "); 119 out.println("expected=123.456F, actual=" + loc_f); 120 result = 2; 121 } 122 123 loc_f = fld3; 124 check(3); 125 if (loc_f != 223.456F) { 126 out.print("fld3 value is corrupted: "); 127 out.println("expected=223.456F, actual=" + loc_f); 128 result = 2; 129 } 130 131 loc_d = fld4; 132 check(4); 133 if (loc_d != 123456.654321) { 134 out.print("fld4 value is corrupted: "); 135 out.println("expected=123456.654321, actual=" + loc_d); 136 result = 2; 137 } 138 139 loc_d = fld5; 140 check(5); 141 if (loc_d != 223456.654321) { 142 out.print("fld5 value is corrupted: "); 143 out.println("expected=223456.654321, actual=" + loc_d); 144 result = 2; 145 } 146 147 loc_o = fld6; 148 check(6); 149 if (loc_o != copy6) { 150 out.print("fld6 value is corrupted: "); 151 out.println("Object does not match saved copy"); 152 result = 2; 153 } 154 155 loc_o = fld7; 156 check(7); 157 if (loc_o != copy7) { 158 out.print("fld7 value is corrupted: "); 159 out.println("Object does not match saved copy"); 160 result = 2; 161 } 162 163 loc_z = fld8; 164 check(8); 165 if (loc_z != true) { 166 out.print("fld8 value is corrupted: "); 167 out.println("expected=true, actual=" + loc_z); 168 result = 2; 169 } 170 171 loc_z = fld9; 172 check(9); 173 if (loc_z != false) { 174 out.print("fld9 value is corrupted: "); 175 out.println("expected=false, actual=" + loc_z); 176 result = 2; 177 } 178 179 loc_b = fld10; 180 check(10); 181 if (loc_b != 123) { 182 out.print("fld10 value is corrupted: "); 183 out.println("expected=123, actual=" + loc_b); 184 result = 2; 185 } 186 187 loc_b = fld11; 188 check(11); 189 if (loc_b != -123) { 190 out.print("fld11 value is corrupted: "); 191 out.println("expected=-123, actual=" + loc_b); 192 result = 2; 193 } 194 195 loc_s = fld12; 196 check(12); 197 if (loc_s != 12345) { 198 out.print("fld12 value is corrupted: "); 199 out.println("expected=12345, actual=" + loc_s); 200 result = 2; 201 } 202 203 loc_s = fld13; 204 check(13); 205 if (loc_s != -12345) { 206 out.print("fld13 value is corrupted: "); 207 out.println("expected=-12345, actual=" + loc_s); 208 result = 2; 209 } 210 211 loc_c = fld14; 212 check(14); 213 if (loc_c != '\uabcd') { 214 out.print("fld14 value is corrupted: "); 215 out.println("expected=\\uabcd, actual=\\u" 216 + Integer.toHexString((int)loc_c)); 217 result = 2; 218 } 219 220 loc_c = fld15; 221 check(15); 222 if (loc_c != '\udcba') { 223 out.print("fld15 value is corrupted: "); 224 out.println("expected=\\udcba, actual=\\u" 225 + Integer.toHexString((int)loc_c)); 226 result = 2; 227 } 228 } 229 } 230