< prev index next >
test/vmTestbase/nsk/jvmti/PopFrame/popframe005.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2003, 2018, 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.
--- 1,7 ----
/*
! * Copyright (c) 2003, 2019, 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.
*** 21,45 ****
* questions.
*/
package nsk.jvmti.PopFrame;
import nsk.share.Consts;
-
import nsk.share.Wicket;
import java.io.PrintStream;
/**
* This test checks that after popping a method's frame by the JVMTI
* function <code>PopFrame()</code>:
* <li>lock acquired by the popped frame will be released
* <li>no JVMTI events will be generated by the function <code>PopFrame()</code>
*/
public class popframe005 {
! static final int WAIT_TIME = 2000;
- static boolean DEBUG_MODE = false;
static volatile int testedStep = 0; /* 0- action no yet started
1- a frame is to be popped
2- checking monitors state
3- finishing the test */
static volatile int result = Consts.TEST_PASSED;
--- 21,44 ----
* questions.
*/
package nsk.jvmti.PopFrame;
+ import jdk.test.lib.Utils;
import nsk.share.Consts;
import nsk.share.Wicket;
import java.io.PrintStream;
/**
* This test checks that after popping a method's frame by the JVMTI
* function <code>PopFrame()</code>:
* <li>lock acquired by the popped frame will be released
* <li>no JVMTI events will be generated by the function <code>PopFrame()</code>
*/
public class popframe005 {
! static final long WAIT_TIME = Utils.adjustTimeout(2000);
static volatile int testedStep = 0; /* 0- action no yet started
1- a frame is to be popped
2- checking monitors state
3- finishing the test */
static volatile int result = Consts.TEST_PASSED;
*** 76,98 ****
private int runIt(String argv[], PrintStream out) {
Object lockObj[] = new Object[2];
this.out = out;
- for (int i = 0; i < argv.length; i++) {
- if (argv[i].equals("-v")) // verbose mode
- DEBUG_MODE = true;
- }
lockObj[0] = new Object();
lockObj[1] = new Object();
! startGuarantee = new Wicket("startGuarantee", 1, (DEBUG_MODE ? System.out : null));
! finishGuarantee = new Wicket("finishGuarantee", 1, (DEBUG_MODE ? System.out : null));
allThreadsStoppedGuarantee =
! new Wicket("allThreadsStoppedGuarantee", 3, (DEBUG_MODE ? System.out : null));
// start a thread whose top frame is to be popped
popFrameClsThr = new popFrameCls("Tested Thread", lockObj);
popFrameClsThr.start();
--- 75,93 ----
private int runIt(String argv[], PrintStream out) {
Object lockObj[] = new Object[2];
this.out = out;
lockObj[0] = new Object();
lockObj[1] = new Object();
! startGuarantee = new Wicket("startGuarantee", 1, System.out);
! finishGuarantee = new Wicket("finishGuarantee", 1, System.out);
allThreadsStoppedGuarantee =
! new Wicket("allThreadsStoppedGuarantee", 3, System.out);
// start a thread whose top frame is to be popped
popFrameClsThr = new popFrameCls("Tested Thread", lockObj);
popFrameClsThr.start();
*** 107,183 ****
objWaiterThr2.start();
// pause until the first thread exit notification-block
allThreadsStoppedGuarantee.waitFor();
synchronized (allThreadsStoppedBarrier) {
- if (DEBUG_MODE) {
out.println("Passed barrier in main thread");
out.flush();
}
- }
/////////////////////// popping a frame ////////////////////////
testedStep = 1;
- if (DEBUG_MODE) {
out.println("State transition: testedStep: 0->1");
out.println("Going to pop the frame...");
out.flush();
- }
boolean retValue = doPopFrame(popFrameClsThr);
popFrameClsThr.letItGo();
if (!retValue)
return Consts.TEST_FAILED;
///////////////////// check monitors state /////////////////////
testedStep = 2;
- if (DEBUG_MODE) {
out.println("State transition: testedStep: 1->2");
out.flush();
- }
if (!popFrameClsThr.isAlive()) {
out.println("TEST FAILURE: thread with the method's popped frame is dead");
return Consts.TEST_FAILED;
}
try {
objWaiterThr2.join(WAIT_TIME);
} catch (InterruptedException e) {
- if (DEBUG_MODE)
out.println("Joining the objWaiterThr2's thread: caught " + e);
}
if (objWaiterThr2.isAlive()) { // objWaiterThr2 should be dead
out.println("TEST FAILED: Lock acquired by a popped frame wasn't released\n" + "\twhen the frame had been popped");
result = Consts.TEST_FAILED;
}
try {
! objWaiterThr1.join(WAIT_TIME);
} catch (InterruptedException e) {
- if (DEBUG_MODE) {
out.println("Joining the objWaiterThr1's thread: caught " + e);
out.flush();
}
- }
if (!objWaiterThr1.isAlive()) { // objWaiterThr2 should be alive
out.println("TEST FAILED: Lock acquired by a frame, different from the popped one,\n"
+ "\twas released when the popped frame had been popped");
result = Consts.TEST_FAILED;
}
/////////////////////// finish the test ///////////////////////
testedStep = 3;
- if (DEBUG_MODE) {
out.println("State transition: testedStep: 2->3");
out.flush();
- }
finishGuarantee.unlock();
try {
if (popFrameClsThr.isAlive())
--- 102,168 ----
objWaiterThr2.start();
// pause until the first thread exit notification-block
allThreadsStoppedGuarantee.waitFor();
synchronized (allThreadsStoppedBarrier) {
out.println("Passed barrier in main thread");
out.flush();
}
/////////////////////// popping a frame ////////////////////////
testedStep = 1;
out.println("State transition: testedStep: 0->1");
out.println("Going to pop the frame...");
out.flush();
boolean retValue = doPopFrame(popFrameClsThr);
popFrameClsThr.letItGo();
if (!retValue)
return Consts.TEST_FAILED;
///////////////////// check monitors state /////////////////////
testedStep = 2;
out.println("State transition: testedStep: 1->2");
out.flush();
if (!popFrameClsThr.isAlive()) {
out.println("TEST FAILURE: thread with the method's popped frame is dead");
return Consts.TEST_FAILED;
}
try {
objWaiterThr2.join(WAIT_TIME);
} catch (InterruptedException e) {
out.println("Joining the objWaiterThr2's thread: caught " + e);
}
if (objWaiterThr2.isAlive()) { // objWaiterThr2 should be dead
out.println("TEST FAILED: Lock acquired by a popped frame wasn't released\n" + "\twhen the frame had been popped");
result = Consts.TEST_FAILED;
}
try {
! // don't want to wait too much if timeout.factor is big
! objWaiterThr1.join(Math.min(WAIT_TIME, 5000));
} catch (InterruptedException e) {
out.println("Joining the objWaiterThr1's thread: caught " + e);
out.flush();
}
if (!objWaiterThr1.isAlive()) { // objWaiterThr2 should be alive
out.println("TEST FAILED: Lock acquired by a frame, different from the popped one,\n"
+ "\twas released when the popped frame had been popped");
result = Consts.TEST_FAILED;
}
/////////////////////// finish the test ///////////////////////
testedStep = 3;
out.println("State transition: testedStep: 2->3");
out.flush();
finishGuarantee.unlock();
try {
if (popFrameClsThr.isAlive())
*** 207,250 ****
public void run() {
synchronized(lockObj[0]) {
activeMethod();
}
! if (DEBUG_MODE)
! out.println("popFrameCls (" + this +
! "): exiting..."); out.flush();
}
public void activeMethod() {
boolean compl = true;
if (popframe005.testedStep != 0) { // popping has been done
! if (DEBUG_MODE) {
! out.println("popFrameCls (" + this +
! "): enter activeMethod() after popping");
out.flush();
- }
// wait for checking monitors state by the main thread
finishGuarantee.waitFor();
! if (DEBUG_MODE) {
! out.println("popFrameCls (" + this +
! "): leaving activeMethod()");
out.flush();
- }
return;
}
try {
synchronized(lockObj[1]) {
synchronized(allThreadsStoppedBarrier) {
- if (DEBUG_MODE) {
out.println("popFrameCls (" + this + "): inside activeMethod()");
out.flush();
- }
// notify the main thread
startGuarantee.unlock();
allThreadsStoppedGuarantee.unlock();
--- 192,226 ----
public void run() {
synchronized(lockObj[0]) {
activeMethod();
}
! out.println("popFrameCls (" + this + "): exiting...");
! out.flush();
}
public void activeMethod() {
boolean compl = true;
if (popframe005.testedStep != 0) { // popping has been done
! out.println("popFrameCls (" + this + "): enter activeMethod() after popping");
out.flush();
// wait for checking monitors state by the main thread
finishGuarantee.waitFor();
! out.println("popFrameCls (" + this + "): leaving activeMethod()");
out.flush();
return;
}
try {
synchronized(lockObj[1]) {
synchronized(allThreadsStoppedBarrier) {
out.println("popFrameCls (" + this + "): inside activeMethod()");
out.flush();
// notify the main thread
startGuarantee.unlock();
allThreadsStoppedGuarantee.unlock();
*** 299,335 ****
}
public void run() {
// notify the main thread
synchronized(allThreadsStoppedBarrier) {
- if (DEBUG_MODE) {
out.println("objWaiter(" + this +
"): waiting for a lockObj" + objIdent +
"'s monitor; testedStep=" + testedStep);
out.flush();
- }
allThreadsStoppedGuarantee.unlock();
}
try {
synchronized(lockObj) {
if (testedStep <= contrVal) {
out.println("TEST FAILED: the lockObj" + objIdent +
"'s monitor became free too early");
result = Consts.TEST_FAILED;
! } else if (DEBUG_MODE) {
out.println("Check PASSED: objWaiter(" + this +
"): enter the lockObj" + objIdent + "'s monitor");
out.flush();
}
}
- if (DEBUG_MODE) {
out.println("objWaiter (" + this + "): exiting...");
out.flush();
- }
} catch (Exception e) {
out.println("TEST FAILURE: objWaiter (" + this + "): caught " + e);
}
}
}
--- 275,307 ----
}
public void run() {
// notify the main thread
synchronized(allThreadsStoppedBarrier) {
out.println("objWaiter(" + this +
"): waiting for a lockObj" + objIdent +
"'s monitor; testedStep=" + testedStep);
out.flush();
allThreadsStoppedGuarantee.unlock();
}
try {
synchronized(lockObj) {
if (testedStep <= contrVal) {
out.println("TEST FAILED: the lockObj" + objIdent +
"'s monitor became free too early");
result = Consts.TEST_FAILED;
! } else {
out.println("Check PASSED: objWaiter(" + this +
"): enter the lockObj" + objIdent + "'s monitor");
out.flush();
}
}
out.println("objWaiter (" + this + "): exiting...");
out.flush();
} catch (Exception e) {
out.println("TEST FAILURE: objWaiter (" + this + "): caught " + e);
}
}
}
< prev index next >