jdk/test/com/sun/jdi/MultiBreakpointsTest.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 24973 8c4bc3fa4c4e
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
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) 2001, 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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @bug 4359247
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  @summary Breakpoints on multiple threads have problems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  @author tbell, jjh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run compile -g MultiBreakpointsTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  @run main MultiBreakpointsTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This test runs a debuggee with n threads each of which just loops
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * doing some printlns and calling a method.  The debugger sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * bkpts on these methods and verifies that they are all hit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The default number of threads is 4.  To change it to say 10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * pass this to the testcase on the cmd line:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      -Dnthreads=10
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The current max allowed value of nthreads is 30.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * You can also do this, for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *     -Dnhits=30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * to change the number of times the bkpts are to be hit from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * the default of 100 to 30.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
class MultiBreakpointsTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    MultiBreakpointsTarg(int numThreads, int numHits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        for (int ii = 0; ii < numThreads; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            console(ii, numHits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        int nthreads;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        int nhits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        String nStr = System.getProperty("nthreads");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (nStr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            throw new RuntimeException("nthreads = null in debuggee");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        nthreads = Integer.parseInt(nStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        nStr = System.getProperty("nhits");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (nStr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            throw new RuntimeException("nhits = null in debuggee");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        nhits = Integer.parseInt(nStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        System.out.println("Debuggee: nthreads = " + nthreads + ", nhits = " + nhits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        MultiBreakpointsTarg ptr = new MultiBreakpointsTarg(nthreads, nhits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
//         for (int i = 0; i < nthreads; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
//             ptr.console(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
//         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // The brute force approach for simplicity - don't use reflection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // nor set thread specific bkpts.  Use of those features would
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // make for interesting tests too, and maybe would prove that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // we don't really have to bother doing it this dumb way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    void bkpt0() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    void bkpt1() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    void bkpt2() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    void bkpt3() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    void bkpt4() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    void bkpt5() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    void bkpt6() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    void bkpt7() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    void bkpt8() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    void bkpt9() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    void bkpt10() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    void bkpt11() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    void bkpt12() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    void bkpt13() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    void bkpt14() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    void bkpt15() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    void bkpt16() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    void bkpt17() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    void bkpt18() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    void bkpt19() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    void bkpt20() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    void bkpt21() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    void bkpt22() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    void bkpt23() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    void bkpt24() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    void bkpt25() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    void bkpt26() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    void bkpt27() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    void bkpt28() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    void bkpt29() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    void console(final int num, final int nhits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        final InputStreamReader isr = new InputStreamReader(System.in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        final BufferedReader    br  = new BufferedReader(isr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // Create the threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        //final String threadName = "DebuggeeThread: " + num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        final String threadName = "" + num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        Thread thrd = new Thread( threadName ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    synchronized( isr ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        boolean done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                            // For each thread, run until numHits bkpts have been hit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                            for( int i = 0; i < nhits; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                // This is a tendril from the original jdb test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                // It could probably be deleted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                System.out.println("Thread " + threadName + " Enter a string: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                String s = "test" + num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                switch (num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                case 0: bkpt0(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                case 1: bkpt1(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                case 2: bkpt2(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                case 3: bkpt3(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                case 4: bkpt4(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                case 5: bkpt5(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                case 6: bkpt6(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                case 7: bkpt7(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                case 8: bkpt8(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                case 9: bkpt9(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                case 10: bkpt10(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                case 11: bkpt11(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                case 12: bkpt12(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                case 13: bkpt13(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                case 14: bkpt14(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                case 15: bkpt15(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                case 16: bkpt16(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                case 17: bkpt17(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                case 18: bkpt18(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                case 19: bkpt19(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                case 20: bkpt20(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                case 21: bkpt21(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                case 22: bkpt22(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                case 23: bkpt23(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                case 24: bkpt24(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                case 25: bkpt25(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                case 26: bkpt26(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                case 27: bkpt27(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                case 28: bkpt28(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                case 29: bkpt29(); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                System.out.println("Thread " + threadName + " You entered : " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                if( s.compareTo( "quit" ) == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                    done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                            System.out.println("WOOPS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        thrd.setPriority(Thread.MAX_PRIORITY-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        thrd.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
/********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
public class MultiBreakpointsTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    EventRequestManager erm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    static int nthreads;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    static int nhits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    BreakpointRequest bkpts[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    int hits[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    MultiBreakpointsTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        bkpts = new BreakpointRequest[nthreads];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        hits = new int[nthreads];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        String countStr = System.getProperty("nthreads");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (countStr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            nthreads = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            nthreads = Integer.parseInt(countStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if ( nthreads > 30) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            throw new RuntimeException("nthreads is greater than 30: " + nthreads);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        countStr = System.getProperty("nhits");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (countStr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            nhits = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            nhits = Integer.parseInt(countStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        args = new String[] { "-J-Dnthreads=" + nthreads, "-J-Dnhits=" + nhits} ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        new MultiBreakpointsTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /********** event handlers **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public void breakpointReached(BreakpointEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        BreakpointRequest req = (BreakpointRequest)event.request();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        for ( int ii = 0; ii < nthreads; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (req == bkpts[ii]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                println("Hit bkpt on thread: " +ii+ ": " +  ++hits[ii]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public BreakpointRequest setBreakpoint(String clsName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                           String methodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                           String methodSignature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        ReferenceType rt = findReferenceType(clsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            rt = resumeToPrepareOf(clsName).referenceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        Method method = findMethod(rt, methodName, methodSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            throw new IllegalArgumentException("Bad method name/signature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        BreakpointRequest bpr = erm.createBreakpointRequest(method.location());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        bpr.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        //bpr.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        bpr.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return bpr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        BreakpointEvent bpe = startToMain("MultiBreakpointsTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        erm = vm().eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        for (int ii = 0 ; ii < nthreads; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            bkpts[ii] = setBreakpoint("MultiBreakpointsTarg",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                              "bkpt" + ii,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                              "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         * resume the target listening for events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        for ( int ii = 0; ii < nthreads; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (hits[ii] != nhits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                failure("FAILED: Expected " + nhits + " breakpoints for thread " + ii + " but only got " + hits[ii]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            println("MultiBreakpointsTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            throw new Exception("MultiBreakpointsTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}