jdk/test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java
author mchung
Fri, 18 Jun 2010 09:35:22 -0700
changeset 5808 3a1f603c5ca7
parent 5506 202f599c92aa
child 7019 f2f6b61d34ac
permissions -rw-r--r--
6961894: TEST_BUG: jdk_lang tests fail in samevm mode Summary: Fixed jdk_lang tests to run in samevm mode or mark to run in othervm Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug     4959889
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Basic unit test of memory management testing:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *          1) setCollectionUsageThreshold() and getCollectionUsageThreshold()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *          2) test notification emitted for two different memory pools.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @build CollectionUsageThreshold MemoryUtil
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @run main/timeout=300 CollectionUsageThreshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.lang.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class CollectionUsageThreshold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static MemoryMXBean mm = ManagementFactory.getMemoryMXBean();
5808
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
    44
    private static List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
    45
    private static List<MemoryManagerMXBean> managers = ManagementFactory.getMemoryManagerMXBeans();
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
    46
    private static Map<String, PoolRecord> result = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static boolean trace = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static boolean testFailed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final int EXPECTED_NUM_POOLS = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final int NUM_GCS = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final int THRESHOLD = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static Checker checker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static int numGCs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static class PoolRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        private MemoryPoolMXBean pool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        private int listenerInvoked = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        private long notifCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        PoolRecord(MemoryPoolMXBean p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            this.pool = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        int getListenerInvokedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            return listenerInvoked;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        long getNotifCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            return notifCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        MemoryPoolMXBean getPool() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            return pool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        void addNotification(MemoryNotificationInfo minfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            listenerInvoked++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            notifCount = minfo.getCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    static class SensorListener implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        private int numNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        public void handleNotification(Notification notif, Object handback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            String type = notif.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                type.equals(MemoryNotificationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                MemoryNotificationInfo minfo = MemoryNotificationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    from((CompositeData) notif.getUserData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                MemoryUtil.printMemoryNotificationInfo(minfo, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                PoolRecord pr = (PoolRecord) result.get(minfo.getPoolName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                if (pr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    throw new RuntimeException("Pool " + minfo.getPoolName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                        " is not selected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                if (type != MemoryNotificationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                        MEMORY_COLLECTION_THRESHOLD_EXCEEDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    throw new RuntimeException("Pool " + minfo.getPoolName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                        " got unexpected notification type: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                pr.addNotification(minfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    numNotifs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    if (numNotifs > 0 && (numNotifs % EXPECTED_NUM_POOLS) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        checker.goCheckResult();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static long newThreshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (args.length > 0 && args[0].equals("trace")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            trace = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (trace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            MemoryUtil.printMemoryPools(pools);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            MemoryUtil.printMemoryManagers(managers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        // Find the Old generation which supports low memory detection
5808
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   122
        for (MemoryPoolMXBean p : pools) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            MemoryUsage u = p.getUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (p.isUsageThresholdSupported() && p.isCollectionUsageThresholdSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                PoolRecord pr = new PoolRecord(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                result.put(p.getName(), pr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                if (result.size() == EXPECTED_NUM_POOLS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (result.size() != EXPECTED_NUM_POOLS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            throw new RuntimeException("Unexpected number of selected pools");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
5808
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   136
        try {
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   137
            checker = new Checker("Checker thread");
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   138
            checker.setDaemon(true);
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   139
            checker.start();
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   140
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   141
            for (PoolRecord pr : result.values()) {
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   142
                pr.getPool().setCollectionUsageThreshold(THRESHOLD);
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   143
                System.out.println("Collection usage threshold of " +
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   144
                    pr.getPool().getName() + " set to " + THRESHOLD);
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   145
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
5808
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   147
            SensorListener listener = new SensorListener();
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   148
            NotificationEmitter emitter = (NotificationEmitter) mm;
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   149
            emitter.addNotificationListener(listener, null, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
5808
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   151
            for (int i = 0; i < NUM_GCS; i++) {
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   152
                invokeGC();
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   153
                checker.waitForCheckResult();
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   154
            }
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   155
        } finally {
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   156
            // restore the default
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   157
            for (PoolRecord pr : result.values()) {
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   158
                pr.getPool().setCollectionUsageThreshold(0);
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   159
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (testFailed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            throw new RuntimeException("TEST FAILED.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        System.out.println("Test passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private static void invokeGC() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        System.out.println("Calling System.gc()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        numGCs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        mm.gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (trace) {
5808
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   175
            for (PoolRecord pr : result.values()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                System.out.println("Usage after GC for: " + pr.getPool().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                MemoryUtil.printMemoryUsage(pr.getPool().getUsage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    static class Checker extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        private Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        private Object go = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        private boolean checkerReady = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        private int waiters = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        private boolean readyToCheck = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        Checker(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    checkerReady = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                        lock.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                        // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    checkResult();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    checkerReady = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        private void checkResult() {
5808
3a1f603c5ca7 6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents: 5506
diff changeset
   206
            for (PoolRecord pr : result.values()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                if (pr.getListenerInvokedCount() != numGCs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    throw new RuntimeException("Listeners invoked count = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                         pr.getListenerInvokedCount() + " expected to be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                         numGCs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                if (pr.getNotifCount() != numGCs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    throw new RuntimeException("Notif Count = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                         pr.getNotifCount() + " expected to be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                         numGCs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                long count = pr.getPool().getCollectionUsageThresholdCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                if (count != numGCs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    throw new RuntimeException("CollectionUsageThresholdCount = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                         count + " expected to be " + numGCs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                if (!pr.getPool().isCollectionUsageThresholdExceeded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    throw new RuntimeException("isCollectionUsageThresholdExceeded" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                         " expected to be true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            synchronized (go) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                // wait until the main thread is waiting for notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                while (waiters == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        go.wait(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                        // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                System.out.println(Thread.currentThread().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    " notifying main thread to continue - result checking finished");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                go.notify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        public void goCheckResult() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            System.out.println(Thread.currentThread().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                " notifying to check result");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                while (!checkerReady) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        lock.wait(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                lock.notify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        public void waitForCheckResult() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            System.out.println(Thread.currentThread().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                " waiting for result checking finishes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            synchronized (go) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                waiters++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    go.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                waiters--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}