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 test checks that after popping a method's frame by the JVMTI 31 * function <code>PopFrame()</code>: 32 * <li>the method arguments will be added back and any changes to 33 * the arguments, which occurred in the called method, will remain 34 * <li>changes to global state, which occurred in the called method, 35 * will remain 36 * <li>no JVMTI events are generated by the function <code>PopFrame()</code> 37 * <br><br>The test was changed due to the bug 4448675. 38 */ 39 public class popframe003 { 40 public static final int PASSED = 0; 41 public static final int FAILED = 2; 42 static final int JCK_STATUS_BASE = 95; 43 44 private popframe003p popFrameClsThr; 45 46 static { 47 try { 48 System.loadLibrary("popframe003"); 49 } catch (UnsatisfiedLinkError e) { 50 System.err.println("Could not load popframe003 library"); 51 System.err.println("java.library.path:" + 52 System.getProperty("java.library.path")); 53 throw e; 54 } 55 } 56 57 native static int doPopFrame(popframe003p popFrameClsThr); 58 native static int suspThread(popframe003p popFrameClsThr); 59 native static int resThread(popframe003p popFrameClsThr); 60 61 public static void main(String[] argv) { 62 argv = nsk.share.jvmti.JVMTITest.commonInit(argv); 63 64 System.exit(run(argv, System.out) + JCK_STATUS_BASE); 65 } 66 67 public static int run(String argv[], PrintStream out) { 68 return new popframe003().runIt(argv, out); 69 } 70 71 private int runIt(String argv[], PrintStream out) { 72 int retValue = 0; 73 74 popFrameClsThr = new popframe003p("Tested Thread", out); 75 // start the child thread 76 popFrameClsThr.start(); 77 popFrameClsThr.startingBarrier.waitFor(); 78 // pause until the child thread exits notification-block 79 synchronized (popFrameClsThr.barrier) { 80 } 81 82 out.println("Going to suspend the thread..."); 83 retValue = suspThread(popFrameClsThr); 84 if (retValue != PASSED) { 85 out.println("TEST: failed to suspend thread"); 86 return FAILED; 87 } 88 89 // pop the frame 90 out.println("Going to pop a frame..."); 91 retValue = doPopFrame(popFrameClsThr); 92 93 popFrameClsThr.popFrameHasBeenDone(); 94 95 if (retValue != PASSED) { 96 out.println("TEST: failed to pop frame"); 97 resThread(popFrameClsThr); 98 return FAILED; 99 } 100 101 out.println("Going to resume the thread..."); 102 retValue = resThread(popFrameClsThr); 103 if (retValue != PASSED) { 104 out.println("TEST: failed to resume thread"); 105 return FAILED; 106 } 107 108 try { 109 popFrameClsThr.join(); 110 } catch (InterruptedException e) { 111 out.println("TEST INCOMPLETE: caught " + e); 112 return FAILED; 113 } 114 115 /* check that any changes for the static global fields, 116 * which occurred in the called method, remain 117 */ 118 if (popframe003p.bytePubStatGlFld != 2 || popframe003p.shortPubStatGlFld != 3 || 119 popframe003p.intPubStatGlFld != 4 || popframe003p.longPubStatGlFld != 5L || 120 popframe003p.floatPubStatGlFld != 6.2F || popframe003p.doublePubStatGlFld != 7.35D || 121 popframe003p.charPubStatGlFld != 'b' || popframe003p.booleanPubStatGlFld != true || 122 !popframe003p.strPubStatGlFld.equals("sttc glbl fld")) { 123 out.println("TEST FAILED: changes for the static fields of a class,\n" + 124 "\twhich have been made in the popped frame's method, did not remain:\n" + 125 "\tstatic fields values:\n\t\tbytePubStatGlFld=" + popframe003p.bytePubStatGlFld + "\texpected: 2\n" + 126 "\t\tshortPubStatGlFld=" + popframe003p.shortPubStatGlFld + "\texpected: 3\n" + 127 "\t\tintPubStatGlFld=" + popframe003p.intPubStatGlFld + "\texpected: 4\n" + 128 "\t\tlongPubStatGlFld=" + popframe003p.longPubStatGlFld + "\texpected: 5\n" + 129 "\t\tfloatPubStatGlFld=" + popframe003p.floatPubStatGlFld + "\texpected: 6.2\n" + 130 "\t\tdoublePubStatGlFld=" + popframe003p.doublePubStatGlFld + "\texpected: 7.35\n" + 131 "\t\tcharPubStatGlFld='" + popframe003p.charPubStatGlFld + "'\texpected: 'b'\n" + 132 "\t\tbooleanPubStatGlFld=" + popframe003p.booleanPubStatGlFld + "\texpected: true\n" + 133 "\t\tstrPubStatGlFld=\"" + popframe003p.strPubStatGlFld + "\"\texpected: \"sttc glbl fld\""); 134 return FAILED; 135 } else { 136 out.println("Check #6 PASSED: changes for the static fields of a class,\n" + 137 "\twhich have been made in the popped frame's method, remained\n"); 138 } 139 140 return popframe003p.totRes; 141 } 142 }