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 setfldw004 { 29 30 final static int JCK_STATUS_BASE = 95; 31 32 static { 33 try { 34 System.loadLibrary("setfldw004"); 35 } catch (UnsatisfiedLinkError ule) { 36 System.err.println("Could not load setfldw004 library"); 37 System.err.println("java.library.path:" 38 + System.getProperty("java.library.path")); 39 throw ule; 40 } 41 } 42 43 native static void getReady(); 44 native static void check(int ind); 45 native static int getRes(); 46 47 static PrintStream out; 48 static int result = 0; 49 static boolean flag = false; 50 51 static int fld0 = 17; 52 static int fld1; 53 int fld2 = 18; 54 int fld3; 55 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 63 public static int run(String argv[], PrintStream ref) { 64 out = ref; 65 setfldw004 t = new setfldw004(); 66 67 // access fields first to force cache load 68 t.meth(); 69 70 getReady(); 71 flag = true; 72 73 t.meth(); 74 75 return (getRes() | result); 76 } 77 78 public void meth() { 79 int loc; 80 81 // test getstatic bytecode for initialized field 82 loc = fld0; 83 checkEvent(0); 84 if (loc != 17) { 85 out.println("fld0 value is corrupted: expected=17, actual=" + loc); 86 result = 2; 87 } 88 89 // test getstatic bytecode for uninitialized field 90 loc = fld1; 91 checkEvent(1); 92 if (loc != 0) { 93 out.println("fld1 value is corrupted: expected=0, actual=" + loc); 94 result = 2; 95 } 96 97 // test getfield bytecode for initialized field 98 loc = fld2; 99 checkEvent(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 checkEvent(3); 108 if (loc != 0) { 109 out.println("fld3 value is corrupted: expected=0, actual=" + loc); 110 result = 2; 111 } 112 } 113 114 static void checkEvent(int ind) { 115 if (flag) { 116 check(ind); 117 } 118 } 119 } 120