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