jdk/test/com/sun/jdi/MethodEntryExitEvents.java
author alexsch
Thu, 31 Jul 2014 14:28:10 +0400
changeset 26019 10a56d28f48d
parent 24973 8c4bc3fa4c4e
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
8051838: [Findbugs]sun.awt.image.MultiResolutionCachedImage expose internal representation Reviewed-by: serb, pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21355
diff changeset
     2
 * Copyright (c) 2001, 2013, 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
24973
8c4bc3fa4c4e 6622468: TEST_BUG: Time to retire the @debuggeeVMOptions mechanism used in the com.sun.jdi infrastructure
sla
parents: 23010
diff changeset
    32
 *  @run driver MethodEntryExitEvents SUSPEND_EVENT_THREAD MethodEntryExitEventsDebugee
8c4bc3fa4c4e 6622468: TEST_BUG: Time to retire the @debuggeeVMOptions mechanism used in the com.sun.jdi infrastructure
sla
parents: 23010
diff changeset
    33
 *  @run driver MethodEntryExitEvents SUSPEND_NONE MethodEntryExitEventsDebugee
8c4bc3fa4c4e 6622468: TEST_BUG: Time to retire the @debuggeeVMOptions mechanism used in the com.sun.jdi infrastructure
sla
parents: 23010
diff changeset
    34
 *  @run driver MethodEntryExitEvents SUSPEND_ALL MethodEntryExitEventsDebugee
2
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
21355
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   111
    // Classes which we are interested in
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   112
    private List includes = Arrays.asList(new String[] {
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   113
        "MethodEntryExitEventsDebugee",
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   114
        "t2"
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   115
    });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    MethodEntryExitEvents (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private void usage(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        StringBuffer sb = new StringBuffer("Usage: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        sb.append(System.getProperty("line.separator"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        sb.append("  java ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        sb.append(getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        sb.append(" [SUSPEND_NONE | SUSPEND_EVENT_THREAD | SUSPEND_ALL]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        sb.append(" [MethodEntryExitEventsDebugee | -connect <connector options...>] ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        throw new Exception (sb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        MethodEntryExitEvents meee = new MethodEntryExitEvents (args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        meee.startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public void exceptionThrown(ExceptionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        System.out.println("Exception: " + event.exception());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        System.out.println(" at catch location: " + event.catchLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // Step to the catch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (stepReq == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            stepReq =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                eventRequestManager().createStepRequest(event.thread(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                                        StepRequest.STEP_MIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                                        StepRequest.STEP_INTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            stepReq.addCountFilter(1);  // next step only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            stepReq.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        stepReq.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public void stepCompleted(StepEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        System.out.println("stepCompleted: line#=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                           event.location().lineNumber() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                           " event=" + event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        // disable the step and then run to completion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        //eventRequestManager().deleteEventRequest(event.request());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        StepRequest str= (StepRequest)event.request();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        str.disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public void methodEntered(MethodEntryEvent event) {
21355
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   161
        if (!includes.contains(event.method().declaringType().name())) {
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   162
            return;
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   163
        }
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   164
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (! finishedCounting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            // We have to count the entry to loopComplete, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            // not the exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            methodEntryCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            System.out.print  (" Method entry number: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            System.out.print  (methodEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            System.out.print  ("  :  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            System.out.println(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if ("loopComplete".equals(event.method().name())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                finishedCounting = true;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public void methodExited(MethodExitEvent event) {
21355
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   180
        if (!includes.contains(event.method().declaringType().name())) {
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   181
            return;
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   182
        }
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   183
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (! finishedCounting){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            methodExitCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            System.out.print  (" Method exit  number: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            System.out.print  (methodExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            System.out.print  ("  :  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            System.out.println(event);
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
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (args.length < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            usage(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        //Pick up the SUSPEND_xxx in first argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if ("SUSPEND_NONE".equals(args[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            sessionSuspendPolicy = EventRequest.SUSPEND_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        } else if ("SUSPEND_EVENT_THREAD".equals(args[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        } else if ("SUSPEND_ALL".equals(args[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            usage(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        System.out.print("Suspend policy is: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        System.out.println(args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // Skip the test arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        String[] args2 = new String[args.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        System.arraycopy(args, 1, args2, 0, args.length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (args2.length < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            usage(args2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        List argList = new ArrayList(Arrays.asList(args2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        System.out.println("run args: " + argList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        connect((String[]) argList.toArray(args2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        waitForVMStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
21355
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   222
        // Determine main thread
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   223
        ClassPrepareEvent e = resumeToPrepareOf("MethodEntryExitEventsDebugee");
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   224
        mainThread = e.thread();
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   225
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        try {
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 Exception events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            ExceptionRequest exceptionRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                eventRequestManager().createExceptionRequest(null, // refType (null == all instances)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                                             true, // notifyCaught
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                                             true);// notifyUncaught
21355
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   235
            exceptionRequest.addThreadFilter(mainThread);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            exceptionRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            exceptionRequest.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 entry events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            MethodEntryRequest entryRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
               eventRequestManager().createMethodEntryRequest();
21355
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   244
            entryRequest.addThreadFilter(mainThread);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            entryRequest.setSuspendPolicy(sessionSuspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            entryRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
             * Ask for method exit events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            MethodExitRequest exitRequest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                eventRequestManager().createMethodExitRequest();
21355
c53a16ac1969 8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
sla
parents: 20185
diff changeset
   253
            exitRequest.addThreadFilter(mainThread);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            exitRequest.setSuspendPolicy(sessionSuspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            exitRequest.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
             * We are now set up to receive the notifications we want.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
             * Here we go.  This adds 'this' as a listener so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
             * that our handlers above will be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            System.out.println("All done...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        } catch (Exception ex){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            ex.printStackTrace();
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if ((methodEntryCount != expectedEntryCount) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            (methodExitCount != expectedExitCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            testFailed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            System.out.println("MethodEntryExitEvents: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            System.out.print  ("    Method entry count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            System.out.println(methodEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            System.out.print  ("    Method exit  count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            System.out.println(methodExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            System.out.println("MethodEntryExitEvents: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            System.out.print  ("    expected method entry count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            System.out.println(expectedEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            System.out.print  ("    observed method entry count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            System.out.println(methodEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            System.out.print  ("    expected method exit  count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            System.out.println(expectedExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            System.out.print  ("    observed method exit  count: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            System.out.println(methodExitCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            throw new Exception("MethodEntryExitEvents: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
}