/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/*
* @test
* @bug 4530538
* @summary Basic unit test of ThreadInfo.getStackTrace() and
* ThreadInfo.getThreadState()
* @author Mandy Chung
*
* @run build Semaphore Utils
* @run main ThreadStackTrace
*/
public class ThreadStackTrace {
private static boolean notified = false;
private static volatile boolean testFailed = false;
}
throw new RuntimeException("TEST FAILED: " +
"getThreadInfo() is expected to return null for " + t);
}
}
private static boolean trace = false;
trace = true;
}
// Start the threads and check them in Blocked and Waiting states
// block until examiner begins doing its real work
"is waiting to begin.");
// The Examiner should be waiting to be notified by the BlockedThread
// Check that the stack is returned correctly for a new thread
try {
} catch (InterruptedException e) {
e.printStackTrace();
testFailed = true;
}
// Check that the stack is returned correctly for a terminated thread
if (testFailed)
throw new RuntimeException("TEST FAILED.");
}
if (t != null) {
}
}
}
if (trace) {
printStack(t, stack);
}
for (int i = 0; i < depth; i++) {
throw new RuntimeException("TEST FAILED: " +
}
frame--;
}
}
super(name);
}
boolean hasWaitersForBlocked() {
}
void waitUntilBlocked() {
// give a chance for the examiner thread to really wait
}
void waitUntilLockAReleased() {
// give a chance for the examiner thread to really wait
}
private void notifyWaiter() {
// wait until the examiner waits on the semaphore
}
}
private void test() {
A();
}
private void A() {
B();
}
private void B() {
C();
// notify the examiner about to block on lockB
notifyWaiter();
synchronized (lockB) {
};
}
private void C() {
D();
}
private void D() {
// Notify that examiner about to enter lockA
notifyWaiter();
synchronized (lockA) {
notified = false;
while (!notified) {
try {
// notify the examiner about to release lockA
notifyWaiter();
// Wait and let examiner thread check the mbean
} catch (InterruptedException e) {
e.printStackTrace();
testFailed = true;
}
}
}
}
public void run() {
test();
} // run()
} // BlockedThread
super(name);
}
}
public synchronized void waitForStarted() {
// wait until the examiner is about to block
// wait until the examiner is waiting for blockedThread's notification
while (!blockedThread.hasWaitersForBlocked()) {
}
// give a chance for the examiner thread to really wait
}
private void examine1() {
synchronized (lockB) {
examine2();
try {
// wait until blockedThread is blocked on lockB
"BlockedThread - should be blocked on lockB.");
} catch (Exception e) {
e.printStackTrace();
testFailed = true;
}
}
}
private void examine2() {
synchronized (lockA) {
// wait until main thread gets signalled of the semaphore
}
try {
// Wait until BlockedThread is about to block on lockA
"BlockedThread - should be blocked on lockA.");
} catch (Exception e) {
e.printStackTrace();
testFailed = true;
}
}
// release lockA and let BlockedThread to get the lock
// and wait on lockA
synchronized (lockA) {
try {
"BlockedThread - should be waiting on lockA.");
// Let the blocked thread go
notified = true;
} catch (Exception e) {
e.printStackTrace();
testFailed = true;
}
}
// give some time for BlockedThread to proceed
} // examine2()
public void run() {
examine1();
} // run()
} // Examiner
}