jdk/test/com/sun/jdi/MethodEntryExitEvents.java
author rbackman
Wed, 14 Mar 2012 08:43:28 +0100
changeset 12196 78184ec38cbe
parent 5506 202f599c92aa
child 14342 8435a30053c1
permissions -rw-r--r--
7145419: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events. Summary: Add more packages to filter avoids failing on events from background thread. Reviewed-by: acorn, sspitsyn, sla
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, 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 4409241 4432820
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary Test the bug fix for: MethodExitEvents disappear when Object-Methods are called from main
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  @author Tim Bell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @run compile -g MethodEntryExitEvents.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run main MethodEntryExitEvents SUSPEND_EVENT_THREAD MethodEntryExitEventsDebugee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run main MethodEntryExitEvents SUSPEND_NONE MethodEntryExitEventsDebugee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  @run main MethodEntryExitEvents SUSPEND_ALL MethodEntryExitEventsDebugee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.jdi.request.*;
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
class t2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public static void sayHello1(int i, int j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        sayHello2(i, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static void sayHello2(int i, int j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        sayHello3(i, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static void sayHello3(int i, int j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        sayHello4(i, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static void sayHello4(int i, int j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        sayHello5(i, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static void sayHello5(int i, int j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (i < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            sayHello1(++i, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            System.out.print  ("MethodEntryExitEventsDebugee: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            System.out.print  ("    -->> Hello.  j is: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            System.out.print  (j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            System.out.println(" <<--");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
class MethodEntryExitEventsDebugee {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static void loopComplete () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
         * The implementation here is deliberately inefficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
         * because the debugger is still watching this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        sb.append ("MethodEntryExitEventsDebugee: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        sb.append ("Executing loopComplete method for a graceful shutdown...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        String s = sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        for (int i = 0; i < s.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            char c = s.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            System.out.print(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        t2 test = new t2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        for (int j = 0; j < 3; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            test.sayHello1(0, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        loopComplete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
public class MethodEntryExitEvents extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    StepRequest stepReq = null; //Only one step request allowed per thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    boolean finishedCounting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Enter main() , then t2.<init>, then sayHello[1,2,3,4,5] 15 times 3 loops,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * then loopComplete()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    final int expectedEntryCount = 1 + 1 + (15 * 3) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    int methodEntryCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Exit t2.<init>, then sayHello[1,2,3,4,5] 15 times 3 loopa
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * (event monitoring is cancelled before we exit loopComplete() or main())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    final int expectedExitCount = 1 + (15 * 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    int methodExitCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Class patterns for which we don't want events (copied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * from the "Trace.java" example):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *     http://java.sun.com/javase/technologies/core/toolsapis/jpda/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private String[] excludes = {"java.*", "javax.*", "sun.*",
12196
78184ec38cbe 7145419: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events.
rbackman
parents: 5506
diff changeset
   117
                                 "com.sun.*", "com.oracle.*",
78184ec38cbe 7145419: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events.
rbackman
parents: 5506
diff changeset
   118
                                 "oracle.*"};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    MethodEntryExitEvents (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private void usage(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        StringBuffer sb = new StringBuffer("Usage: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        sb.append(System.getProperty("line.separator"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        sb.append("  java ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        sb.append(getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        sb.append(" [SUSPEND_NONE | SUSPEND_EVENT_THREAD | SUSPEND_ALL]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        sb.append(" [MethodEntryExitEventsDebugee | -connect <connector options...>] ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        throw new Exception (sb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        MethodEntryExitEvents meee = new MethodEntryExitEvents (args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        meee.startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public void exceptionThrown(ExceptionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        System.out.println("Exception: " + event.exception());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        System.out.println(" at catch location: " + event.catchLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        // Step to the catch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (stepReq == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            stepReq =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                eventRequestManager().createStepRequest(event.thread(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                                        StepRequest.STEP_MIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                                        StepRequest.STEP_INTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            stepReq.addCountFilter(1);  // next step only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            stepReq.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        stepReq.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public void stepCompleted(StepEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        System.out.println("stepCompleted: line#=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                           event.location().lineNumber() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                           " event=" + event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        // disable the step and then run to completion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        //eventRequestManager().deleteEventRequest(event.request());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        StepRequest str= (StepRequest)event.request();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        str.disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public void methodEntered(MethodEntryEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (! finishedCounting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            // We have to count the entry to loopComplete, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            // not the exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            methodEntryCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            System.out.print  (" Method entry number: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            System.out.print  (methodEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            System.out.print  ("  :  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            System.out.println(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if ("loopComplete".equals(event.method().name())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                finishedCounting = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
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
    public void methodExited(MethodExitEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (! finishedCounting){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            methodExitCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            System.out.print  (" Method exit  number: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            System.out.print  (methodExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            System.out.print  ("  :  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            System.out.println(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (args.length < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            usage(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        //Pick up the SUSPEND_xxx in first argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if ("SUSPEND_NONE".equals(args[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            sessionSuspendPolicy = EventRequest.SUSPEND_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } else if ("SUSPEND_EVENT_THREAD".equals(args[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        } else if ("SUSPEND_ALL".equals(args[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            usage(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        System.out.print("Suspend policy is: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        System.out.println(args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        // Skip the test arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        String[] args2 = new String[args.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        System.arraycopy(args, 1, args2, 0, args.length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (args2.length < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            usage(args2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        List argList = new ArrayList(Arrays.asList(args2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        System.out.println("run args: " + argList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        connect((String[]) argList.toArray(args2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        waitForVMStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
             * Ask for Exception events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            ExceptionRequest exceptionRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                eventRequestManager().createExceptionRequest(null, // refType (null == all instances)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                                             true, // notifyCaught
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                                             true);// notifyUncaught
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            exceptionRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            exceptionRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
             * Ask for method entry events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            MethodEntryRequest entryRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
               eventRequestManager().createMethodEntryRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            for (int i=0; i<excludes.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                entryRequest.addClassExclusionFilter(excludes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            entryRequest.setSuspendPolicy(sessionSuspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            entryRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
             * Ask for method exit events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            MethodExitRequest exitRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                eventRequestManager().createMethodExitRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            for (int i=0; i<excludes.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                exitRequest.addClassExclusionFilter(excludes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            exitRequest.setSuspendPolicy(sessionSuspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            exitRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
             * We are now set up to receive the notifications we want.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
             * Here we go.  This adds 'this' as a listener so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
             * that our handlers above will be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            System.out.println("All done...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        } catch (Exception ex){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            testFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if ((methodEntryCount != expectedEntryCount) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            (methodExitCount != expectedExitCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            testFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            System.out.println("MethodEntryExitEvents: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            System.out.print  ("    Method entry count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            System.out.println(methodEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            System.out.print  ("    Method exit  count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            System.out.println(methodExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            System.out.println("MethodEntryExitEvents: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            System.out.print  ("    expected method entry count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            System.out.println(expectedEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            System.out.print  ("    observed method entry count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            System.out.println(methodEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            System.out.print  ("    expected method exit  count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            System.out.println(expectedExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            System.out.print  ("    observed method exit  count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            System.out.println(methodExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            throw new Exception("MethodEntryExitEvents: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}