jdk/test/com/sun/jdi/MethodEntryExitEvents.java
author jjg
Thu, 22 May 2008 15:51:41 -0700
changeset 655 1ebc7ce89018
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6705945: com.sun.tools.javac.zip files do not have valid copyright Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2001-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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.*",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                 "com.sun.*"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    MethodEntryExitEvents (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private void usage(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        StringBuffer sb = new StringBuffer("Usage: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        sb.append(System.getProperty("line.separator"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        sb.append("  java ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        sb.append(getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        sb.append(" [SUSPEND_NONE | SUSPEND_EVENT_THREAD | SUSPEND_ALL]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        sb.append(" [MethodEntryExitEventsDebugee | -connect <connector options...>] ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        throw new Exception (sb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        MethodEntryExitEvents meee = new MethodEntryExitEvents (args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        meee.startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void exceptionThrown(ExceptionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        System.out.println("Exception: " + event.exception());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        System.out.println(" at catch location: " + event.catchLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // Step to the catch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (stepReq == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            stepReq =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                eventRequestManager().createStepRequest(event.thread(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                                        StepRequest.STEP_MIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                                        StepRequest.STEP_INTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            stepReq.addCountFilter(1);  // next step only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            stepReq.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        stepReq.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void stepCompleted(StepEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        System.out.println("stepCompleted: line#=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                           event.location().lineNumber() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                           " event=" + event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        // disable the step and then run to completion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        //eventRequestManager().deleteEventRequest(event.request());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        StepRequest str= (StepRequest)event.request();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        str.disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public void methodEntered(MethodEntryEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (! finishedCounting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            // We have to count the entry to loopComplete, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            // not the exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            methodEntryCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            System.out.print  (" Method entry number: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            System.out.print  (methodEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            System.out.print  ("  :  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            System.out.println(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if ("loopComplete".equals(event.method().name())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                finishedCounting = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
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
    public void methodExited(MethodExitEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (! finishedCounting){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            methodExitCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            System.out.print  (" Method exit  number: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            System.out.print  (methodExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            System.out.print  ("  :  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            System.out.println(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (args.length < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            usage(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        //Pick up the SUSPEND_xxx in first argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if ("SUSPEND_NONE".equals(args[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            sessionSuspendPolicy = EventRequest.SUSPEND_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        } else if ("SUSPEND_EVENT_THREAD".equals(args[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } else if ("SUSPEND_ALL".equals(args[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            usage(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        System.out.print("Suspend policy is: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        System.out.println(args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // Skip the test arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        String[] args2 = new String[args.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        System.arraycopy(args, 1, args2, 0, args.length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (args2.length < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            usage(args2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        List argList = new ArrayList(Arrays.asList(args2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        System.out.println("run args: " + argList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        connect((String[]) argList.toArray(args2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        waitForVMStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
             * Ask for Exception events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            ExceptionRequest exceptionRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                eventRequestManager().createExceptionRequest(null, // refType (null == all instances)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                                             true, // notifyCaught
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                                             true);// notifyUncaught
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            exceptionRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            exceptionRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
             * Ask for method entry events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            MethodEntryRequest entryRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
               eventRequestManager().createMethodEntryRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            for (int i=0; i<excludes.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                entryRequest.addClassExclusionFilter(excludes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            entryRequest.setSuspendPolicy(sessionSuspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            entryRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
             * Ask for method exit events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            MethodExitRequest exitRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                eventRequestManager().createMethodExitRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            for (int i=0; i<excludes.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                exitRequest.addClassExclusionFilter(excludes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            exitRequest.setSuspendPolicy(sessionSuspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            exitRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
             * We are now set up to receive the notifications we want.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
             * Here we go.  This adds 'this' as a listener so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
             * that our handlers above will be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            System.out.println("All done...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        } catch (Exception ex){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            testFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if ((methodEntryCount != expectedEntryCount) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            (methodExitCount != expectedExitCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            testFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            System.out.println("MethodEntryExitEvents: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            System.out.print  ("    Method entry count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            System.out.println(methodEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            System.out.print  ("    Method exit  count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            System.out.println(methodExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            System.out.println("MethodEntryExitEvents: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            System.out.print  ("    expected method entry count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            System.out.println(expectedEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            System.out.print  ("    observed method entry count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            System.out.println(methodEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            System.out.print  ("    expected method exit  count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            System.out.println(expectedExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            System.out.print  ("    observed method exit  count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            System.out.println(methodExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            throw new Exception("MethodEntryExitEvents: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
}