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.PopFrame; 25 26 import nsk.share.Wicket; 27 import java.io.PrintStream; 28 29 /** 30 * This is auxiliary tested class 31 */ 32 public class popframe003p extends Thread { 33 static final int PASSED = 0; 34 static final int FAILED = 2; 35 36 private PrintStream out; 37 38 public static volatile int totRes = PASSED; 39 public static Object barrier = new Object(); 40 public Wicket startingBarrier; 41 42 // dummy global static fields 43 static public byte bytePubStatGlFld = 1; 44 static public short shortPubStatGlFld = 2; 45 static public int intPubStatGlFld = 3; 46 static public long longPubStatGlFld = 4L; 47 static public float floatPubStatGlFld = 5.1F; 48 static public double doublePubStatGlFld = 6.2D; 49 static public char charPubStatGlFld = 'a'; 50 static public boolean booleanPubStatGlFld = false; 51 static public String strPubStatGlFld = "static global field"; 52 53 // dummy instance fields 54 byte byteGlFld = 11; 55 short shortGlFld = 22; 56 int intGlFld = 33; 57 long longGlFld = 44L; 58 private float floatGlFld = 55F; 59 double doubleGlFld = 66D; 60 char charGlFld = 'c'; 61 boolean booleanGlFld = true; 62 String strGlFld = "instance field"; 63 Object objGl = this; 64 65 // dummy public instance fields 66 public byte bytePubGlFld = 0; 67 public short shortPubGlFld = -2; 68 public int intPubGlFld = -3; 69 public long longPubGlFld = -4L; 70 public float floatPubGlFld = -5.1F; 71 public double doublePubGlFld = -6.2D; 72 public char charPubGlFld = 'e'; 73 public boolean booleanPubGlFld = false; 74 public String strPubGlFld = "public instance field"; 75 76 private popFrameCls popframeCls; 77 78 popframe003p(String name, PrintStream out) { 79 super(name); 80 this.out = out; 81 startingBarrier = new Wicket(); 82 popframeCls = new popFrameCls(); 83 } 84 85 public void run() { 86 popframeCls.activeMeth(1, Long.MAX_VALUE, 87 Double.MIN_VALUE, 'c', false); 88 /* check that any changes for the global instance fields, 89 * which occurred in the called method, remain 90 */ 91 if (byteGlFld != 1 || shortGlFld != 2 || 92 intGlFld != 3 || longGlFld != 4L || 93 floatGlFld != 5.1F || doubleGlFld != 6.2D || 94 charGlFld != 'd' || booleanGlFld != false || 95 !strGlFld.equals("nstnc fld") || !objGl.equals(Integer.valueOf("1973")) || 96 bytePubGlFld != 7 || shortPubGlFld != 8 || 97 intPubGlFld != 9 || longPubGlFld != -10L || 98 floatPubGlFld != -11F || doublePubGlFld != -12D || 99 charPubGlFld != 'z' || booleanPubGlFld != false || 100 strPubGlFld != null) { 101 out.println("TEST FAILED: changes for the instance fields of a class,\n" + 102 "\twhich have been made in the popped frame's method, did not remain:\n" + 103 "\tinstance fields values:\n\t\tbyteGlFld=" + 104 byteGlFld + "\texpected: 1\n" + 105 "\t\tshortGlFld=" + shortGlFld + "\texpected: 2\n" + 106 "\t\tintGlFld=" + intGlFld + "\texpected: 3\n" + 107 "\t\tlongGlFld=" + longGlFld + "\texpected: 4\n" + 108 "\t\tfloatGlFld=" + floatGlFld + "\texpected: 5.1\n" + 109 "\t\tdoubleGlFld=" + doubleGlFld + "\texpected: 6.2\n" + 110 "\t\tcharGlFld='" + charGlFld + "'\texpected: 'd'\n" + 111 "\t\tbooleanGlFld=" + booleanGlFld + "\texpected: false\n" + 112 "\t\tstrGlFld=\"" + strGlFld + "\"\texpected: \"nstnc fld\"\n" + 113 "\t\tobjGl=\"" + objGl.toString() + "\"\texpected: \"123\"\n" + 114 "\tpublic instance fields values:\n\t\tbytePubGlFld=" + 115 bytePubGlFld + "\texpected: 2\n" + 116 "\t\tshortPubGlFld=" + shortPubGlFld + "\texpected: 3\n" + 117 "\t\tintPubGlFld=" + intPubGlFld + "\texpected: 4\n" + 118 "\t\tlongPubGlFld=" + longPubGlFld + "\texpected: 5\n" + 119 "\t\tfloatPubGlFld=" + floatPubGlFld + "\texpected: 6.2\n" + 120 "\t\tdoublePubGlFld=" + doublePubGlFld + "\texpected: 7.35\n" + 121 "\t\tcharPubGlFld='" + charPubGlFld + "'\texpected: 'b'\n" + 122 "\t\tbooleanPubGlFld=" + booleanPubGlFld + "\texpected: true\n" + 123 "\t\tstrPubGlFld=\"" + strPubGlFld + "\"\texpected: null\n"); 124 totRes = FAILED; 125 } else { 126 out.println("Check #5 PASSED: changes for the instance fields of a class,\n" + 127 "\twhich have been made in the popped frame's method, remained\n" + 128 "popframe003p (" + this + "): exiting..."); 129 } 130 } 131 132 class popFrameCls { 133 // dummy popFrameCls fields 134 protected byte bytePubFld = 10; 135 public short shortPubFld = 20; 136 public int intPubFld = 30; 137 public long longPubFld = 40L; 138 public float floatPubFld = 50.1F; 139 public double doublePubFld = 60.2D; 140 public char charPubFld = 'b'; 141 public boolean booleanPubFld = true; 142 protected String strPubFld = "static field"; 143 144 // flag to notify when exit from 'while' loop in activeMeth method 145 public volatile boolean popFrameHasBeenDone = false; 146 147 void activeMeth(int i, long l, double d, char c, boolean b) { 148 boolean compl = true; 149 150 if (popFrameHasBeenDone) { // popping has been done 151 out.println("popframe003p (" + this + "): enter activeMeth() after popping"); 152 /* check that any changes for the arguments, 153 * which occurred in the called method, remain 154 */ 155 if (i != 2 || l != Long.MIN_VALUE || 156 d != Double.MAX_VALUE || c != 'c' || b != true) { 157 out.println("TEST FAILED: changes for the arguments of " + 158 "the popped frame's method, did not remain\n" + 159 "\tcurrent argument values: i=" + i + " l=" + l + 160 " d=" + d + " c='" + c + "'\n"); 161 totRes = FAILED; 162 } else { 163 out.println("Check #3 PASSED: changes for the arguments of " + 164 "the popped frame's method, remained\n"); 165 } 166 /* check that any changes for the class fields, 167 * which occurred in the called method, remain 168 */ 169 if (bytePubFld != 0 || shortPubFld != 0 || 170 intPubFld != 0 || longPubFld != 0L || 171 floatPubFld != 0F || doublePubFld != 0D || 172 charPubFld != ' ' || booleanPubFld != false || 173 !strPubFld.equals("static fld")) { 174 out.println("TEST FAILED: changes for the fields of an inner class,\n" + 175 "\twhich have been made in the popped frame's method, did not remain:\n" + 176 "\tstatic fields values:\n\t\tbytePubFld=" + bytePubFld + "\texpected: 0\n" + 177 "\t\tshortPubFld=" + shortPubFld + "\texpected: 0\n" + 178 "\t\tintPubFld=" + intPubFld + "\texpected: 0\n" + 179 "\t\tlongPubFld=" + longPubFld + "\texpected: 0\n" + 180 "\t\tfloatPubFld=" + floatPubFld + "\texpected: 0\n" + 181 "\t\tdoublePubFld=" + doublePubFld + "\texpected: 0\n" + 182 "\t\tcharPubFld='" + charPubFld + "'\texpected: ' '\n" + 183 "\t\tbooleanPubFld=" + booleanPubFld + "\texpected: false\n" + 184 "\t\tstrPubFld=\"" + strPubFld + "\"\texpected: \"static fld\"\n"); 185 totRes = FAILED; 186 } else { 187 out.println("Check #4 PASSED: changes for the fields of an inner class,\n" + 188 "\twhich have been made in the popped frame's method, remained\n" + 189 "popframe003p (" + this + "): exiting...\n"); 190 } 191 192 return; 193 } 194 195 // make some variable changes: 196 // for the arguments 197 i = 2; 198 l = Long.MIN_VALUE; 199 d = Double.MAX_VALUE; 200 b = true; 201 202 // for the global static fields 203 bytePubStatGlFld = 2; 204 shortPubStatGlFld = 3; 205 intPubStatGlFld = 4; 206 longPubStatGlFld = 5L; 207 floatPubStatGlFld = 6.2F; 208 doublePubStatGlFld = 7.35D; 209 charPubStatGlFld = 'b'; 210 booleanPubStatGlFld = true; 211 strPubStatGlFld = "sttc glbl fld"; 212 213 // for the global instance fields 214 byteGlFld = 1; 215 shortGlFld = 2; 216 intGlFld = 3; 217 longGlFld = 4L; 218 floatGlFld = 5.1F; 219 doubleGlFld = 6.2D; 220 charGlFld = 'd'; 221 booleanGlFld = false; 222 strGlFld = "nstnc fld"; 223 objGl = new Integer(1973); 224 225 // for the global public instance fields 226 bytePubGlFld = 7; 227 shortPubGlFld = 8; 228 intPubGlFld = 9; 229 longPubGlFld = -10L; 230 floatPubGlFld = -11F; 231 doublePubGlFld = -12D; 232 charPubGlFld = 'z'; 233 booleanPubGlFld = false; 234 strPubGlFld = null; 235 236 // for the popFrameCls public fields 237 bytePubFld = 0; 238 shortPubFld = 0; 239 intPubFld = 0; 240 longPubFld = 0L; 241 floatPubFld = 0F; 242 doublePubFld = 0D; 243 charPubFld = ' '; 244 booleanPubFld = false; 245 strPubFld = "static fld"; 246 247 try { 248 // notify the main thread about readiness 249 synchronized (barrier) { 250 out.println("popFrameCls (" + this + "): notifying main thread"); 251 startingBarrier.unlock(); 252 out.println("popFrameCls (" + this + "): inside activeMethod()"); 253 } 254 // loop until the main thread pops us 255 int ii = 0; 256 int n = 1000; 257 while (!popFrameHasBeenDone) { 258 if (n <= 0) { 259 n = 1000; 260 } 261 if (ii > n) { 262 ii = 0; 263 n--; 264 } 265 ii++; 266 } 267 268 // popping has been done 269 out.println("TEST FAILED: a tested frame has not been really popped"); 270 totRes = FAILED; 271 compl = false; 272 273 } catch (Exception e) { 274 out.println("FAILURE: popframe003p (" + this + "): caught " + e); 275 totRes = FAILED; 276 compl = false; 277 } finally { 278 if (compl) { 279 out.println("TEST FAILED: finally block was executed after PopFrame()"); 280 totRes = FAILED; 281 } 282 } 283 } 284 } 285 286 public void popFrameHasBeenDone() { 287 popframeCls.popFrameHasBeenDone = true; 288 } 289 }