jdk/test/java/util/logging/TestLoggerWeakRefLeak.java
author mchung
Thu, 28 May 2015 10:54:48 -0700
changeset 30820 0d4717a011d3
parent 28406 da2cb30a2df0
child 34327 50693d25f4a7
permissions -rw-r--r--
8081347: Add @modules to jdk_core tests Reviewed-by: alanb, joehw, lancea Contributed-by: alexander.kulyakhtin@oracle.com, alan.bateman@oracle.com, mandy.chung@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
/*
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
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
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 28406
diff changeset
    42
 * @build jdk.testlibrary.ProcessTools
28406
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    43
 * @run main/othervm TestLoggerWeakRefLeak Logger
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    44
 * @run main/othervm TestLoggerWeakRefLeak AnonymousLogger
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    45
 */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    46
public class TestLoggerWeakRefLeak {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    47
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    48
    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
    49
    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
    50
    private static int loggerCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    51
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    52
    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
    53
        if (args[0].equals("AnonymousLogger")) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    54
            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
    55
            testIfLeaking(TestLoggerWeakRefLeak::callAnonymousLogger);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    56
        } else {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    57
            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
    58
            testIfLeaking(TestLoggerWeakRefLeak::callLogger);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    59
        }
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
     * 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
    64
     * 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
    65
     * then there is no leak.
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    66
     */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    67
    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
    68
        long count = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    69
        int instanceCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    70
        int previousInstanceCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    71
        int increasingCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    72
        int decreasingCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    73
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    74
        while (true) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    75
            callLogger.run();
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    76
            count += INSTANCE_COUNT;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    77
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    78
            if ((count % 1000) == 0) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    79
                System.out.println("call count = " + count);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    80
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    81
                instanceCount = getInstanceCountFromHeapHisto();
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    82
                if (instanceCount > previousInstanceCount) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    83
                    increasingCount++;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    84
                } else {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    85
                    decreasingCount++;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    86
                    System.out.println("increasing count: " + increasingCount);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    87
                    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
    88
                    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
    89
                    break;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    90
                }
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    91
                previousInstanceCount = instanceCount;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    92
            }
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
            delayExecution();
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
    95
        }
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
     * 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
   100
     * - one in LogManager.LogNode
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   101
     * - one in Logger.kids
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   102
     */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   103
    private static void callLogger() {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   104
        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
   105
            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
   106
            if (++loggerCount >= 25000) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   107
                // 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
   108
                // 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
   109
                // 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
   110
                loggerCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   111
            }
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
     * 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
   117
     */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   118
    private static void callAnonymousLogger() {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   119
        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
   120
            java.util.logging.Logger.getAnonymousLogger();
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   121
        }
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
     * '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
   126
     */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   127
    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
   128
        int instanceCount = 0;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   129
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   130
        HotSpotVirtualMachine vm = (HotSpotVirtualMachine) VirtualMachine
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   131
                .attach(Integer.toString(ProcessTools.getProcessId()));
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   132
        try {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   133
            try (InputStream heapHistoStream = vm.heapHisto("-live");
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   134
                    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
   135
                String inputLine;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   136
                while ((inputLine = in.readLine()) != null) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   137
                    if (inputLine.contains(TARGET_CLASS)) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   138
                        instanceCount = Integer.parseInt(inputLine
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   139
                                .split("[ ]+")[2]);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   140
                        System.out.println("instance count: " + instanceCount);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   141
                        break;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   142
                    }
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
        } finally {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   146
            vm.detach();
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   147
        }
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
        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
   150
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   151
        return instanceCount;
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   152
    }
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
     * 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
   156
     */
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   157
    private static void delayExecution() {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   158
        try {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   159
            Thread.sleep(100);
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   160
        } catch (InterruptedException ie) {
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   161
            // Ignore any exceptions
da2cb30a2df0 6977426: sun/tools tests can intermittently fail to find app's Java pid
ykantser
parents:
diff changeset
   162
        }
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
}