1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/*
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package nsk.jdi.ObjectReference.invokeMethod;
import nsk.share.*;
import nsk.share.jpda.*;
import nsk.share.jdi.*;
// THIS TEST IS LINE NUMBER SENSITIVE
/**
* This is a main debuggee class.
*/
public class invokemethod013t {
static Log log;
private invokemethod013Thr thrs013[] = new invokemethod013Thr[invokemethod013.THRDS_NUM-1];
private Thread thrs[] = new Thread[invokemethod013.THRDS_NUM-1];
private IOPipe pipe;
public static void main(String args[]) {
System.exit(run(args) + Consts.JCK_STATUS_BASE);
}
public static int run(String args[]) {
return new invokemethod013t().runIt(args);
}
private int runIt(String args[]) {
ArgumentHandler argHandler = new ArgumentHandler(args);
invokemethod013tDummyClass invokemethod013tdummyCls =
new invokemethod013tDummyClass();
log = argHandler.createDebugeeLog();
pipe = argHandler.createDebugeeIOPipe();
Thread.currentThread().setName(invokemethod013.DEBUGGEE_THRDS[0][0]);
// Start several dummy threads with given names
startThreads();
// Now the debuggee is ready for testing
pipe.println(invokemethod013.COMMAND_READY);
String cmd = pipe.readln();
if (cmd.equals(invokemethod013.COMMAND_QUIT)) {
log.complain("Debuggee: exiting due to the command "
+ cmd);
killThreads(argHandler.getWaitTime()*60000);
return Consts.TEST_PASSED;
}
int stopMeHere = 0; // invokemethod013.DEBUGGEE_STOPATLINE
cmd = pipe.readln();
if (!cmd.equals(invokemethod013.COMMAND_QUIT)) {
killThreads(argHandler.getWaitTime()*60000);
log.complain("TEST BUG: unknown debugger command: "
+ cmd);
System.exit(Consts.JCK_STATUS_BASE +
Consts.TEST_FAILED);
}
killThreads(argHandler.getWaitTime()*60000);
return Consts.TEST_PASSED;
}
private void startThreads() {
Object readyObj = new Object();
for (int i=0; i < invokemethod013.THRDS_NUM-1; i++) {
thrs013[i] = new invokemethod013Thr(readyObj, invokemethod013.DEBUGGEE_THRDS[i+1][0]);
thrs[i] = JDIThreadFactory.newThread(thrs013[i]);
thrs[i].setDaemon(true);
log.display("Debuggee: starting thread #"
+ i + " \"" + thrs[i].getName() + "\" ...");
synchronized(readyObj) {
thrs[i].start();
try {
readyObj.wait(); // wait for the thread's readiness
} catch (InterruptedException e) {
log.complain("TEST FAILURE: Debuggee: waiting for the thread "
+ thrs[i].toString() + " start: caught " + e);
pipe.println("failed");
System.exit(Consts.JCK_STATUS_BASE +
Consts.TEST_FAILED);
}
}
log.display("Debuggee: the thread #"
+ i + " \"" + thrs[i].getName() + "\" started");
}
}
private void killThreads(int waitTime) {
for (int i=0; i < invokemethod013.THRDS_NUM-1 ; i++) {
thrs013[i].doExit = true;
try {
thrs[i].join(waitTime);
log.display("Debuggee: thread #"
+ i + " \"" + thrs[i].getName() + "\" done");
} catch (InterruptedException e) {
log.complain("TEST FAILURE: Debuggee: joining the thread #"
+ i + " \"" + thrs[i].getName() + "\": caught " + e);
}
}
}
/**
* This is an auxiliary thread class used to check method
* invocation in the debugger.
*/
class invokemethod013Thr extends NamedTask {
volatile boolean doExit = false;
private Object readyObj;
invokemethod013Thr(Object readyObj, String name) {
super(name);
this.readyObj = readyObj;
}
public void run() {
Thread thr = Thread.currentThread();
Object waitObj = new Object();
synchronized(readyObj) {
readyObj.notify(); // notify the main thread
}
log.display("Debuggee thread \""
+ thr.getName() + "\": going to loop");
while(!doExit) {
int i = 0;
i++; i--;
// reliable analogue of Thread.yield()
synchronized(waitObj) {
try {
waitObj.wait(30);
} catch (InterruptedException e) {
e.printStackTrace(log.getOutStream());
log.complain("TEST FAILURE: Debuggee thread \""
+ thr.getName()
+ "\" interrupted while sleeping:\n\t" + e);
break;
}
}
}
log.display("Debuggee thread \""
+ thr.getName() + "\" exiting ...");
}
}
/////////////////////////////////////////////////////////////////////////////
}
/**
* Dummy class used to check method invocation in the debugger.
*/
class invokemethod013tDummyClass {
// used by the debugger to let the invoked method return
volatile boolean doExit = false;
// indicator that the method has been really invoked
volatile boolean isInvoked = false;
long longMeth(long l) throws InterruptedException {
/*
* WARNING: Since this method is called using INVOKE_SINGLE_THREADED, we need to
* be careful not to do anything that might block on another thread. That includes
* calling Thread.sleep(), which can be a problem for virtual threads.
*/
invokemethod013t.log.display("invokemethod013tDummyClass: longMeth: going to loop");
isInvoked = true;
while(!doExit) {
l--; l++;
}
invokemethod013t.log.display("invokemethod013tDummyClass: longMeth: exiting");
isInvoked = false;
doExit = false;
return l;
}
}
|