# HG changeset patch # User jbachorik # Date 1383152088 -3600 # Node ID 2a714dabb62402c56b8d1d150dcb7b6e071fc655 # Parent e45b48874ba96e05583a8b1d25fa5a03537ae7f8 8020467: Inconsistency between usage.getUsed() and isUsageThresholdExceeded() with CMS Old Gen pool Reviewed-by: mchung, brutisso diff -r e45b48874ba9 -r 2a714dabb624 test/java/lang/management/MemoryPoolMXBean/ThresholdTest.java --- a/test/java/lang/management/MemoryPoolMXBean/ThresholdTest.java Wed Oct 30 09:37:12 2013 -0700 +++ b/test/java/lang/management/MemoryPoolMXBean/ThresholdTest.java Wed Oct 30 17:54:48 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2013, 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 @@ -28,7 +28,7 @@ * MemoryPoolMXBean.isCollectionThresholdExceeded(). * @author Mandy Chung * - * @run main ThresholdTest + * @run main/othervm ThresholdTest */ import java.lang.management.*; @@ -36,6 +36,9 @@ public class ThresholdTest { public static void main(String args[]) throws Exception { + long[] bigObject = new long[1000000]; + + System.gc(); // force an initial full-gc List pools = ManagementFactory.getMemoryPoolMXBeans(); try { for (MemoryPoolMXBean p : pools) { @@ -82,6 +85,10 @@ } p.setUsageThreshold(1); + // force a full gc to minimize the likelihood of running GC + // between getting the usage and checking the threshold + System.gc(); + MemoryUsage u = p.getUsage(); if (u.getUsed() >= 1) { if (!p.isUsageThresholdExceeded()) {