1 /* 2 * Copyright (c) 2001, 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 25 package nsk.jdi.ThreadReference.popFrames; 26 27 import nsk.share.*; 28 import nsk.share.jpda.*; 29 import nsk.share.jdi.*; 30 31 /** 32 * This class is used as debuggee application for the popframes004 JDI test. 33 */ 34 35 public class popframes004a { 36 37 //----------------------------------------------------- templete section 38 39 static final int PASSED = 0; 40 static final int FAILED = 2; 41 static final int PASS_BASE = 95; 42 43 static ArgumentHandler argHandler; 44 static Log log; 45 46 //-------------------------------------------------- log procedures 47 48 log1(String message)49 private static void log1(String message) { 50 log.display("**> debuggee: " + message); 51 } 52 logErr(String message)53 private static void logErr(String message) { 54 log.complain("**> debuggee: " + message); 55 } 56 57 //====================================================== test program 58 59 static Thread2popframes004a thread2 = null; 60 61 //------------------------------------------------------ common section 62 static int instruction = 1; 63 static int end = 0; 64 // static int quit = 0; 65 // static int continue = 2; 66 static int maxInstr = 1; // 2; 67 68 static int lineForComm = 2; methodForCommunication()69 private static void methodForCommunication() { 70 int i1 = instruction; 71 int i2 = i1; 72 int i3 = i2; 73 } 74 75 76 static class JDIDebuggeeException extends Exception { JDIDebuggeeException(String str)77 JDIDebuggeeException(String str) { 78 super("JDIDebuggeeException : " + str); 79 } 80 } 81 //---------------------------------------------------- main method 82 83 static int var1 = 0; 84 static volatile int testVar = 0; 85 main(String argv[])86 public static void main (String argv[]) { 87 88 argHandler = new ArgumentHandler(argv); 89 log = argHandler.createDebugeeLog(); 90 91 log1("debuggee started!"); 92 93 int exitCode = PASSED; 94 95 label0: 96 { 97 thread2 = new Thread2popframes004a("thread2"); 98 log1(" thread2 is created"); 99 100 synchronized (lockingObject2) { 101 log1(" thread2.start()"); 102 if ( threadStart(thread2) != PASSED ) 103 break label0; 104 105 log1(" methodForCommunication();"); 106 methodForCommunication(); 107 } 108 methodForCommunication(); 109 } 110 111 System.exit(exitCode + PASS_BASE); 112 } 113 114 static Object waitnotifyObj = new Object(); 115 static Object lockingObject = new Object(); 116 threadStart(Thread t)117 static int threadStart(Thread t) { 118 synchronized (waitnotifyObj) { 119 t.start(); 120 try { 121 log1(" before: waitnotifyObj.wait();"); 122 waitnotifyObj.wait(); 123 log1(" after: waitnotifyObj.wait();"); 124 } catch ( Exception e) { 125 logErr(" Exception : " + e ); 126 return FAILED; 127 } 128 } 129 return PASSED; 130 } 131 132 133 static int breakpointLine = 3; 134 breakpointMethod()135 static void breakpointMethod () { 136 log1("breakpointMethod entered by the thread : " + Thread.currentThread().getName() ); 137 var1 += 1; 138 var1 += 1; 139 var1 += 1; 140 log1("breakpointMethod: exit"); 141 } 142 poppedMethod(int arg)143 static void poppedMethod(int arg) { 144 log1("poppedMethod entered by the thread : " + Thread.currentThread().getName() ); 145 try { 146 if (arg == 0) { 147 log1("thread2: try clause: calling breakpointMethod();"); 148 breakpointMethod(); 149 } else { 150 log1("thread2: try clause: throwing JDIDebuggeeException"); 151 throw new JDIDebuggeeException("poppedMethod"); 152 } 153 } catch ( JDIDebuggeeException e ) { 154 log1("thread2: catch clause: caught JDIDebuggeeException"); 155 log1("thread2: catch clause: calling breakpointMethod();"); 156 breakpointMethod(); 157 } finally { 158 log1("thread2: finally clause"); 159 testVar = 1; 160 } 161 162 log1("poppedMethod: exit"); 163 return; 164 } 165 166 static Object lockingObject2 = new Object(); 167 168 static class Thread2popframes004a extends Thread { 169 Thread2popframes004a(String threadName)170 public Thread2popframes004a(String threadName) { 171 super(threadName); 172 } 173 run()174 public void run() { 175 log1("thread2: method 'run' enter"); 176 synchronized (waitnotifyObj) { 177 log1("thread2: entered into block: synchronized (waitnotifyObj)"); 178 waitnotifyObj.notify(); 179 } 180 log1("thread2: exited from block: synchronized (waitnotifyObj)"); 181 182 synchronized (lockingObject2) { 183 testVar = 0; 184 log1("thread2: before: 'poppedMethod(0)'"); 185 poppedMethod(0); 186 log1("thread2: after: 'poppedMethod(0)'"); 187 188 testVar = 0; 189 log1("thread2: before: 'poppedMethod(1)'"); 190 poppedMethod(1); 191 log1("thread2: after: 'poppedMethod(1)'"); 192 } 193 return; 194 } 195 } 196 197 } 198