/*
* 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.
*/
/*
* @bug 5086470 6358247
* @summary LockingThread is used by LockedMonitors test.
* It will create threads that have:
* - a stack frame acquires no monitor
* - a stack frame acquires one or more monitors
* - a stack frame blocks on Object.wait
* and the monitor waiting is not locked.
* @author Mandy Chung
*
* @build Barrier
* @build ThreadDump
*/
static void startLockingThreads() {
// wait until t1 waits
while (count != 0) {
try {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
static long[] getThreadIds() {
}
throws Exception {
int matches = 0;
matches++;
}
matches++;
}
}
if (matches != 2) {
throw new RuntimeException("MonitorInfo missing");
}
}
static class Lock {
}
return name;
}
}
int numOwnedMonitors;
this.threadName = name;
}
int numOwnedMonitors,
this.waitingLock = waitingLock;
this.numOwnedMonitors = numOwnedMonitors;
this.ownedMonitors = ownedMonitors;
}
throws Exception {
throw new RuntimeException("Number of locked monitors = " +
" not matched. Expected: " + numOwnedMonitors);
}
// check if each monitor returned in the list is the expected
// one
for (MonitorInfo m : monitors) {
int depth = m.getLockedStackDepth();
}
// check if each expected monitor is included in the returned
// list
}
}
throw new RuntimeException("Number of locked synchronizers = " +
" not matched. Expected: 0.");
}
}
" not matched. Expected: " + getName());
}
throw new RuntimeException("LockInfo: " + l +
" not matched. Expected: " + waitingLock);
}
throw new RuntimeException("LockInfo : " + l +
" class name not matched. Expected: " + waitingLockName);
}
if (hcode != l.getIdentityHashCode()) {
throw new RuntimeException("LockInfo: " + l +
" IdentityHashCode not matched. Expected: " + hcode);
}
" class name not matched. Expected: " + waitingLockName);
}
if (hcode != i) {
" IdentityHashCode not matched. Expected: " + hcode);
}
}
stacktrace[depth]);
throw new RuntimeException("LockedStackFrame does not match " +
"stack frame in ThreadInfo.getStackTrace");
}
}
hcode == m.getIdentityHashCode()) {
// monitor matched the expected
return;
}
}
}
}
throw new RuntimeException("Monitor not expected" + m);
}
for (MonitorInfo m : monitors) {
hcode == m.getIdentityHashCode() &&
return;
}
}
throw new RuntimeException("Monitor not found in the returned list" +
}
public Thread1() {
super("t1");
}
public void run() {
A();
}
void A() {
synchronized(lock1) {
synchronized(lock2) {
synchronized(lock3) {
B();
}
}
}
}
void B() {
synchronized(lock4) {
synchronized(lock5) {
C();
}
}
}
void C() {
synchronized(lock6) {
D();
}
}
void D() {
synchronized(lock7) {
try {
// signal to about to wait
count--;
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
void initExpectedResult() {
}
}
public Thread2() {
super("t2");
}
public void run() {
synchronized(lock8) {
try {
synchronized(lock7) {
count--;
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
}