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.SetFieldModificationWatch; 25 26 import java.io.PrintStream; 27 28 public class setfmodw003 { 29 30 final static int JCK_STATUS_BASE = 95; 31 32 static { 33 try { 34 System.loadLibrary("setfmodw003"); 35 } catch (UnsatisfiedLinkError ule) { 36 System.err.println("Could not load setfmodw003 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 setfmodw003 t = new setfmodw003(); 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 76 // test putstatic bytecode for initialized field 77 fld0 = 42; 78 check(0); 79 if (fld0 != 42) { 80 out.println("fld0 value is corrupted: expected=42, actual=" + fld0); 81 result = 2; 82 } 83 84 // test putstatic bytecode for uninitialized field 85 fld1 = 43; 86 check(1); 87 if (fld1 != 43) { 88 out.println("fld1 value is corrupted: expected=43, actual=" + fld1); 89 result = 2; 90 } 91 } 92 meth()93 public void meth() { 94 int loc; 95 96 // test putfield bytecode for initialized field 97 fld2 = 44; 98 check(2); 99 if (fld2 != 44) { 100 out.println("fld2 value is corrupted: expected=44, actual=" + fld2); 101 result = 2; 102 } 103 104 // test putfield bytecode for uninitialized field 105 fld3 = 45; 106 check(3); 107 if (fld3 != 45) { 108 out.println("fld3 value is corrupted: expected=45, actual=" + fld3); 109 result = 2; 110 } 111 } 112 } 113