/*
* 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 4959889 6992968
* @summary Basic unit test of memory management testing:
* 1) setCollectionUsageThreshold() and getCollectionUsageThreshold()
* 2) test notification emitted for two different memory pools.
*
* @author Mandy Chung
*
* @build CollectionUsageThreshold MemoryUtil
*/
import javax.management.*;
public class CollectionUsageThreshold {
private static boolean trace = false;
private static boolean testFailed = false;
// semaphore to signal the arrival of a low memory notification
// barrier for the main thread to wait until the checker thread
// finishes checking the low memory notification result
static class PoolRecord {
this.pool = p;
}
int getListenerInvokedCount() {
return listenerInvoked;
}
long getNotifCount() {
return notifCount;
}
return pool;
}
}
}
" is not selected");
}
if (type != MemoryNotificationInfo.
" got unexpected notification type: " +
type);
}
synchronized (this) {
numNotifs++;
}
}
}
}
private static long newThreshold;
trace = true;
}
if (trace) {
}
// Find the Old generation which supports low memory detection
for (MemoryPoolMXBean p : pools) {
MemoryUsage u = p.getUsage();
if (p.isUsageThresholdSupported() && p.isCollectionUsageThresholdSupported()) {
break;
}
}
}
throw new RuntimeException("Unexpected number of selected pools");
}
try {
// This test creates a checker thread responsible for checking
// the low memory notifications. It blocks until a permit
// from the signals semaphore is available.
}
// The main thread invokes GC to trigger the VM to perform
// low memory detection and then waits until the checker thread
// finishes its work to check for a low-memory notification.
//
// At GC time, VM will issue low-memory notification and invoke
// the listener which will release a permit to the signals semaphore.
// When the checker thread acquires the permit and finishes
// checking the low-memory notification, it will also call
// barrier.await() to signal the main thread to resume its work.
for (int i = 0; i < NUM_GCS; i++) {
invokeGC();
}
} finally {
// restore the default
}
}
if (testFailed)
throw new RuntimeException("TEST FAILED.");
}
private static void invokeGC() {
numGCs++;
if (trace) {
}
}
}
private boolean checkerReady = false;
private boolean readyToCheck = false;
super(name);
};
public void run() {
while (true) {
try {
checkResult();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (BrokenBarrierException e) {
throw new RuntimeException(e);
}
}
}
fail("Listeners invoked count = " +
numGCs);
}
fail("Notif Count = " +
numGCs);
}
fail("CollectionUsageThresholdCount = " +
}
fail("isCollectionUsageThresholdExceeded" +
" expected to be true");
}
}
// wait until the main thread is waiting for notification
}
// reset the barrier to cause BrokenBarrierException to avoid hanging
throw new RuntimeException(msg);
}
}
}