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 setfmodw006 { 29 30 final static int JCK_STATUS_BASE = 95; 31 final static int NUM_TRIES = 1000; 32 33 static { 34 try { 35 System.loadLibrary("setfmodw006"); 36 } catch (UnsatisfiedLinkError ule) { 37 System.err.println("Could not load setfmodw006 library"); 38 System.err.println("java.library.path:" 39 + System.getProperty("java.library.path")); 40 throw ule; 41 } 42 } 43 getReady(int n)44 native static void getReady(int n); check(boolean flag)45 native static int check(boolean flag); 46 47 static boolean staticBoolean; 48 static byte staticByte; 49 static short staticShort; 50 static int staticInt; 51 static long staticLong; 52 static float staticFloat; 53 static double staticDouble; 54 static char staticChar; 55 static Object staticObject; 56 static int staticArrInt[]; 57 58 boolean instanceBoolean; 59 byte instanceByte; 60 short instanceShort; 61 int instanceInt; 62 long instanceLong; 63 float instanceFloat; 64 double instanceDouble; 65 char instanceChar; 66 Object instanceObject; 67 int instanceArrInt[]; 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 args[], PrintStream out)76 public static int run(String args[], PrintStream out) { 77 setfmodw006 t = new setfmodw006(); 78 getReady(NUM_TRIES); 79 t.tryModification(); 80 check(true); 81 t.tryAccess(); 82 return check(false); 83 } 84 tryModification()85 public void tryModification() { 86 for (int i = 0; i < NUM_TRIES; i++) { 87 staticBoolean = true; 88 staticByte = 1; 89 staticShort = 2; 90 staticInt = 3; 91 staticLong = 4L; 92 staticFloat = 0.5F; 93 staticDouble = 0.6; 94 staticChar = '\u0007'; 95 staticObject = null; 96 staticArrInt = null; 97 this.instanceBoolean = false; 98 this.instanceByte = 10; 99 this.instanceShort = 20; 100 this.instanceInt = 30; 101 this.instanceLong = 40L; 102 this.instanceFloat = 0.05F; 103 this.instanceDouble = 0.06; 104 this.instanceChar = '\u0070'; 105 this.instanceObject = null; 106 this.instanceArrInt = null; 107 } 108 } 109 tryAccess()110 public void tryAccess() { 111 int count = 0; 112 for (int i = 0; i < NUM_TRIES; i++) { 113 if (staticBoolean == true) count++; 114 if (staticByte == 1) count++; 115 if (staticShort == 2) count++; 116 if (staticInt == 3) count++; 117 if (staticLong == 4L) count++; 118 if (staticFloat == 0.5F) count++; 119 if (staticDouble == 0.6) count++; 120 if (staticChar == '\u0007') count++; 121 if (staticObject == null) count++; 122 if (staticArrInt == null) count++; 123 if (this.instanceBoolean == false) count++; 124 if (this.instanceByte == 10) count++; 125 if (this.instanceShort == 20) count++; 126 if (this.instanceInt == 30) count++; 127 if (this.instanceLong == 40L) count++; 128 if (this.instanceFloat == 0.05F) count++; 129 if (this.instanceDouble == 0.06) count++; 130 if (this.instanceChar == '\u0070') count++; 131 if (this.instanceObject == null) count++; 132 if (this.instanceArrInt == null) count++; 133 } 134 } 135 } 136