test/jdk/com/sun/jdi/InvokeHangTest.java
author jlahoda
Tue, 12 Nov 2019 06:32:13 +0000
changeset 59021 cfc7bb9a5a92
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232684: Make switch expressions final Reviewed-by: alanb, mcimadamore, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
41199
cca6aec2bd7b 6648858: InvokeHangTest.java fails due to "failure: Debuggee appears to be hung" when running with -Xcomp
ctornqvi
parents: 30376
diff changeset
     2
 * Copyright (c) 2006, 2016, 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
/**
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    25
 * @test
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    26
 * @bug 6293795
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    27
 * @summary  Backend hangs when invokeMethod is called from a JDI eventHandler
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    28
 * @author jjh
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    30
 * @library /test/lib
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    31
 * @modules java.management
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    32
 *          jdk.jdi
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    33
 *
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    34
 * @run build TestScaffold VMConnection TargetListener TargetAdapter
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    35
 * @run compile -g InvokeHangTest.java
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 41199
diff changeset
    36
 * @run driver InvokeHangTest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * This debuggee basically runs two threads each of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * which loop, hitting a bkpt in each iteration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
class InvokeHangTarg extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static boolean one = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static String name1 = "Thread 1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static String name2 = "Thread 2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static int count = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        System.out.println("Howdy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        InvokeHangTarg t1 = new InvokeHangTarg(name1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        InvokeHangTarg t2 = new InvokeHangTarg(name2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        t1.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        t2.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // This is called from the debugger via invokeMethod
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public double invokeee() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        System.out.println("Debuggee: invokeee in thread "+Thread.currentThread().toString());
59021
cfc7bb9a5a92 8232684: Make switch expressions final
jlahoda
parents: 47216
diff changeset
    67
        Thread.yield();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return longMethod(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public double longMethod(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        double a = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        double s = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            a += i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            for (int j = -1000*i; j < 1000*i; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                a = a*(1 + i/(j + 0.5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                s += Math.sin(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        System.out.println("Debuggee: invokeee finished");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public InvokeHangTarg(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (getName().equals(name1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            run1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            run2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public void bkpt1(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        System.out.println("Debuggee: " + Thread.currentThread() +" is running:" + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            Thread.currentThread().sleep(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } catch (InterruptedException iex) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        //yield();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public void run1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        while (i < count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            bkpt1(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public void bkpt2(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        System.out.println("Debuggee: " + Thread.currentThread() +" is running:" + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            Thread.currentThread().sleep(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        } catch (InterruptedException iex) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            //yield();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public void run2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        while (i < count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            bkpt2(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
/********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
public class InvokeHangTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    BreakpointRequest request1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    BreakpointRequest request2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    static volatile int bkpts = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    Thread timerThread;
41199
cca6aec2bd7b 6648858: InvokeHangTest.java fails due to "failure: Debuggee appears to be hung" when running with -Xcomp
ctornqvi
parents: 30376
diff changeset
   138
    static long waitTime = jdk.test.lib.Utils.adjustTimeout(20000);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    InvokeHangTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        new InvokeHangTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    void doInvoke(ThreadReference thread, ObjectReference ref, String methodName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        List methods = ref.referenceType().methodsByName(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        Method method = (Method) methods.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            System.err.println("  Debugger: Invoking in thread" + thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            ref.invokeMethod(thread, method, new ArrayList(), ref.INVOKE_NONVIRTUAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            System.err.println("  Debugger: Invoke done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            failure("failure: Exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    // BreakpointEvent handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public void breakpointReached(BreakpointEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (bkpts == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
             * This thread will watch for n secs to go by with no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
             * calls to this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            timerThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        synchronized("abc") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
             * Note that this will most likely never get to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
             * the number of times the two bkpt lines in the debuggee
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
             * are hit because bkpts are lost while they are disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            bkpts++;
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
         * The bug occurs when the requests are disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         * and then an invoke is done in the event handler.  In some cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * the other thread has hit a bkpt and the back-end is waiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         * to send it.  When the back-end resumes the debuggee to do the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         * invokeMethod, this 2nd bkpt is released, the debuggee is suspended, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         * the thread on which the invoke was done (because it is a SUSPEND_ALL bkpt),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         * the bkpt is sent to the front-end, but the client event handler is sitting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * here waiting for the invoke to finish, so it doesn't get the 2nd bkpt and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         * do the resume for it.  Thus, the debuggee is suspended waiting for a resume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * that never comes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        request1.disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        request2.disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        ThreadReference thread = event.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            StackFrame sf = thread.frame(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            System.err.println("  Debugger: Breakpoint hit at "+sf.location());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            doInvoke(thread, sf.thisObject(), "invokeee");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        } catch (IncompatibleThreadStateException itsex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            itsex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            failure("failure: Exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        request1.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        request2.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        BreakpointEvent bpe = startToMain("InvokeHangTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        EventRequestManager erm = vm().eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        final Thread mainThread = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
         * Set event requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        Location loc1 = findMethod(targetClass, "bkpt1", "(I)V").location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        Location loc2 = findMethod(targetClass, "bkpt2", "(I)V").location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        request1 = erm.createBreakpointRequest(loc1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        request2 = erm.createBreakpointRequest(loc2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        request1.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        request2.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         * This thread will be started when we get the first bkpt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         * (Which we always expect to get).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         * It awakens every n seconds and checks to see if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         * got any breakpoint events while it was asleep.  If not, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         * we assume the debuggee is hung and fail the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        timerThread = new Thread("test timer") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    int myBkpts = bkpts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            Thread.sleep(waitTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            System.out.println("bkpts = " + bkpts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                            if (myBkpts == bkpts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                // no bkpt for 'waitTime' msecs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                                failure("failure: Debuggee appears to be hung");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                vmDisconnected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                // This awakens the main thread which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                // waiting for a VMDisconnect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                mainThread.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                            myBkpts = bkpts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                        } catch (InterruptedException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                            // If the test completes, this occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                            println("timer Interrupted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
         * resume the target, listening for events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        timerThread.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            println("InvokeHangTest: passed; bkpts = " + bkpts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            throw new Exception("InvokeHangTest: failed; bkpts = " + bkpts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
}