jdk/test/com/sun/jdi/PopAndInvokeTest.java
author sla
Tue, 17 Jun 2014 10:01:16 +0200
changeset 24973 8c4bc3fa4c4e
parent 7668 d4a77089c587
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
6622468: TEST_BUG: Time to retire the @debuggeeVMOptions mechanism used in the com.sun.jdi infrastructure Summary: Use jtreg "@run driver" for the JDI tests Reviewed-by: sspitsyn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5813
diff changeset
     2
 * Copyright (c) 2007, 2010, 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 6517249
5813
8e455cd3e807 6962617: Testcase changes, cleanup of problem list for jdk_tools targets
ohair
parents: 5506
diff changeset
    27
 *  @ignore 6951287
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  @summary JDWP: Cannot do an invokeMethod after a popFrames operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  @author jjh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run compile -g PopAndInvokeTest.java
24973
8c4bc3fa4c4e 6622468: TEST_BUG: Time to retire the @debuggeeVMOptions mechanism used in the com.sun.jdi infrastructure
sla
parents: 7668
diff changeset
    34
 *  @run driver PopAndInvokeTest
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 java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
class PopAndInvokeTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    static boolean waiting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public static void A() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        System.out.println("    debuggee: in A");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static void invokeee() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        System.out.println("    debuggee: invokee");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static void waiter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        if (waiting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        waiting = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        System.out.println("    debuggee: in waiter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        System.out.println("    debuggee: Howdy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
         * Debugger will bkpt in A, popFrames back to here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
         * and then do an invokeMethod on invokeee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
         * This should work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        A();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
         * Debugger will resume and we will enter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
         * waiter().  Debugger will then do a suspend,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
         * a popFrames back to here, and an invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
         * which should fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        waiter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        System.out.println("    debuggee: Goodbye from PopAndInvokeTarg!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
public class PopAndInvokeTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    ClassType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    PopAndInvokeTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        super(args);
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 static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        new PopAndInvokeTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    StackFrame frameFor(String methodName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        Iterator it = mainThread.frames().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            StackFrame frame = (StackFrame)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (frame.location().method().name().equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                return frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        failure("FAIL: " + methodName + " not on stack");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        runOnce();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    void runOnce() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        BreakpointEvent bpe = startTo("PopAndInvokeTarg", "A", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        targetClass = (ClassType)bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         * Verify that an invokeMethod works ok after a popFrames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         * in a thread suspended by an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        mainThread.popFrames(frameFor("A"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        System.out.println("Debugger: Popped back to the call to A()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        System.out.println("Debugger: Doing invoke");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        Method invokeeeMethod = (Method)targetClass.methodsByName("invokeee").get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            targetClass.invokeMethod(mainThread, invokeeeMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                     new ArrayList(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            failure("failure: invoke got unexpected exception: " + ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        System.out.println("Debugger: invoke done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         * Verify that an invokeMethod gets an IncompatibleThreadStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * after a popFrames in a thread that is _not_ suspended by an event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        System.out.println("Debugger: Resuming debuggee");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        vm().resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        Field waiting = targetClass.fieldByName("waiting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            // Wait until debuggee enters the 'waiting' method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            BooleanValue bv= (BooleanValue)targetClass.getValue(waiting);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (!bv.value()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    Thread.sleep(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                } catch (InterruptedException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            // debuggee has entered the waiting method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            System.out.println("Debugger: Suspending debuggee");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            vm().suspend();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            System.out.println("Debugger: Popping frame for waiter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            mainThread.popFrames(frameFor("waiter"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            System.out.println("Debugger: Invoking method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                targetClass.invokeMethod(mainThread, invokeeeMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                         new ArrayList(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            } catch (IncompatibleThreadStateException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                System.out.println("Debugger: Success: Got expected IncompatibleThreadStateException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            } catch (Exception ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                failure("FAIL: Got unexpected exception: " + ee);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            failure("FAIL: Did not get IncompatibleThreadStateException " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    "when debuggee is not suspended by an event");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            throw new Exception("PopAndInvokeTest failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        System.out.println("Passed:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
}