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