jdk/test/java/util/logging/TestLoggerWeakRefLeak.java
author alanb
Thu, 04 May 2017 07:26:55 +0000
changeset 45004 ea3137042a61
parent 35768 7066da300a08
permissions -rw-r--r--
8178380: Module system implementation refresh (5/2017) Reviewed-by: mchung, alanb, sspitsyn Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, chris.hegarty@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28406
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
     1
/*
35768
7066da300a08 8149391: Fix module dependences in java/util tests
shurailine
parents: 34327
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
28406
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
     4
 *
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
     7
 * published by the Free Software Foundation.
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
     8
 *
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    13
 * accompanied this code).
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    14
 *
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    18
 *
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    21
 * questions.
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    22
 */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    23
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    24
import java.io.BufferedReader;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    25
import java.io.InputStream;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    26
import java.io.InputStreamReader;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    27
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    28
import static jdk.testlibrary.Asserts.assertGreaterThan;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    29
import jdk.testlibrary.ProcessTools;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    30
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    31
import com.sun.tools.attach.AttachNotSupportedException;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    32
import com.sun.tools.attach.VirtualMachine;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    33
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    34
import sun.tools.attach.HotSpotVirtualMachine;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    35
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    36
/*
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    37
 * @test
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    38
 * @bug 6942989
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    39
 * @summary Check for WeakReference leak in Logger and anonymous Logger objects
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    40
 * @library /lib/testlibrary
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 28406
diff changeset
    41
 * @modules jdk.attach/sun.tools.attach
35768
7066da300a08 8149391: Fix module dependences in java/util tests
shurailine
parents: 34327
diff changeset
    42
 *          java.logging
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 28406
diff changeset
    43
 * @build jdk.testlibrary.ProcessTools
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 35768
diff changeset
    44
 * @run main/othervm -Djdk.attach.allowAttachSelf TestLoggerWeakRefLeak Logger
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 35768
diff changeset
    45
 * @run main/othervm -Djdk.attach.allowAttachSelf TestLoggerWeakRefLeak AnonymousLogger
28406
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    46
 */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    47
public class TestLoggerWeakRefLeak {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    48
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    49
    private static final String TARGET_CLASS = "java.lang.ref.WeakReference";
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    50
    private static final int INSTANCE_COUNT = 100;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    51
    private static int loggerCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    52
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    53
    public static void main(String[] args) throws Exception {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    54
        if (args[0].equals("AnonymousLogger")) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    55
            System.out.println("Test for WeakReference leak in AnonymousLogger object");
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    56
            testIfLeaking(TestLoggerWeakRefLeak::callAnonymousLogger);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    57
        } else {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    58
            System.out.println("Test for WeakReference leak in Logger object");
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    59
            testIfLeaking(TestLoggerWeakRefLeak::callLogger);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    60
        }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    61
    }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    62
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    63
    /**
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    64
     * For these particular WeakReference leaks, the count was always observed
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    65
     * to be increasing so if decreasing or the same count is observed,
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    66
     * then there is no leak.
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    67
     */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    68
    private static void testIfLeaking(Runnable callLogger) throws Exception {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    69
        long count = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    70
        int instanceCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    71
        int previousInstanceCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    72
        int increasingCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    73
        int decreasingCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    74
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    75
        while (true) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    76
            callLogger.run();
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    77
            count += INSTANCE_COUNT;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    78
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    79
            if ((count % 1000) == 0) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    80
                System.out.println("call count = " + count);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    81
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    82
                instanceCount = getInstanceCountFromHeapHisto();
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    83
                if (instanceCount > previousInstanceCount) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    84
                    increasingCount++;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    85
                } else {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    86
                    decreasingCount++;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    87
                    System.out.println("increasing count: " + increasingCount);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    88
                    System.out.println("decreasing or the same count: " + decreasingCount);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    89
                    System.out.println("Test passed: decreasing or the same instance count is observed");
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    90
                    break;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    91
                }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    92
                previousInstanceCount = instanceCount;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    93
            }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    94
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    95
            delayExecution();
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    96
        }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    97
    }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    98
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    99
    /**
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   100
     * This Logger call is leaking two different WeakReferences:
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   101
     * - one in LogManager.LogNode
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   102
     * - one in Logger.kids
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   103
     */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   104
    private static void callLogger() {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   105
        for (int i = 0; i < INSTANCE_COUNT; i++) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   106
            java.util.logging.Logger.getLogger("logger-" + loggerCount);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   107
            if (++loggerCount >= 25000) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   108
                // Limit the Logger namespace used by the test so the weak refs
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   109
                // in LogManager.loggers that are being properly managed
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   110
                // don't skew the counts by too much.
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   111
                loggerCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   112
            }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   113
        }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   114
    }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   115
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   116
    /**
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   117
     * This Logger call is leaking a WeakReference in Logger.kids
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   118
     */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   119
    private static void callAnonymousLogger() {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   120
        for (int i = 0; i < INSTANCE_COUNT; i++) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   121
            java.util.logging.Logger.getAnonymousLogger();
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   122
        }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   123
    }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   124
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   125
    /**
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   126
     * 'vm.heapHisto("-live")' will request a full GC
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   127
     */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   128
    private static int getInstanceCountFromHeapHisto() throws AttachNotSupportedException, Exception {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   129
        int instanceCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   130
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   131
        HotSpotVirtualMachine vm = (HotSpotVirtualMachine) VirtualMachine
34327
50693d25f4a7 8139430: Refactor test library to decrease module dependencies of tests
shurailine
parents: 30820
diff changeset
   132
                .attach(Long.toString(ProcessTools.getProcessId()));
28406
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   133
        try {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   134
            try (InputStream heapHistoStream = vm.heapHisto("-live");
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   135
                    BufferedReader in = new BufferedReader(new InputStreamReader(heapHistoStream))) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   136
                String inputLine;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   137
                while ((inputLine = in.readLine()) != null) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   138
                    if (inputLine.contains(TARGET_CLASS)) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   139
                        instanceCount = Integer.parseInt(inputLine
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   140
                                .split("[ ]+")[2]);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   141
                        System.out.println("instance count: " + instanceCount);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   142
                        break;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   143
                    }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   144
                }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   145
            }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   146
        } finally {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   147
            vm.detach();
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   148
        }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   149
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   150
        assertGreaterThan(instanceCount, 0, "No instances of " + TARGET_CLASS + " are found");
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   151
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   152
        return instanceCount;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   153
    }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   154
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   155
    /**
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   156
     * Delay for 1/10 of a second to avoid CPU saturation
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   157
     */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   158
    private static void delayExecution() {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   159
        try {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   160
            Thread.sleep(100);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   161
        } catch (InterruptedException ie) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   162
            // Ignore any exceptions
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   163
        }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   164
    }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   165
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   166
}