jdk/test/com/sun/jdi/RepStep.java
author iignatyev
Wed, 15 Mar 2017 22:48:59 -0700
changeset 44423 306c020eb154
parent 30376 2ccf2cf7ea48
permissions -rw-r--r--
8176176: fix @modules in jdk_svc tests Reviewed-by: shurailine, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 24973
diff changeset
     2
 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4335
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4335
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4335
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
/**
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    25
 * @test
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    26
 * @bug 4334008
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary RepStep detects missed step events due to lack of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * frame pop events (in back-end).
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    29
 * @author Robert Field
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    30
 *
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    31
 * @run compile -g RepStepTarg.java
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    32
 * @run build VMConnection RepStep
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    33
 *
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    34
 * @run driver RepStep
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 com.sun.jdi.connect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class RepStep {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static final String TARGET = "RepStepTarg";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static final int GRANULARITY = StepRequest.STEP_LINE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final int DEPTH = StepRequest.STEP_INTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static final int SUCCESS_COUNT = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    VirtualMachine vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    final EventRequestManager requestManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    int stepNum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    boolean passed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        new RepStep(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    RepStep(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        if (args.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            attachTarget(args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            launchTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        //        vm.setDebugTraceMode(VirtualMachine.TRACE_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        requestManager = vm.eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        runTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        dieNice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private void createStep(ThreadReference thread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        final StepRequest sr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                  requestManager.createStepRequest(thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                                   GRANULARITY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                                   DEPTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        sr.addClassExclusionFilter("java.*");
20184
a2c4b7079eb6 8024985: com/sun/jdi/StepTest.java failed since jdk8b107
sla
parents: 5506
diff changeset
    77
        sr.addClassExclusionFilter("javax.*");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        sr.addClassExclusionFilter("sun.*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        sr.addClassExclusionFilter("com.sun.*");
20184
a2c4b7079eb6 8024985: com/sun/jdi/StepTest.java failed since jdk8b107
sla
parents: 5506
diff changeset
    80
        sr.addClassExclusionFilter("com.oracle.*");
a2c4b7079eb6 8024985: com/sun/jdi/StepTest.java failed since jdk8b107
sla
parents: 5506
diff changeset
    81
        sr.addClassExclusionFilter("oracle.*");
a2c4b7079eb6 8024985: com/sun/jdi/StepTest.java failed since jdk8b107
sla
parents: 5506
diff changeset
    82
        sr.addClassExclusionFilter("jdk.internal.*");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        sr.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        ThreadReference thread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        EventQueue queue = vm.eventQueue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            EventSet set = queue.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            for (EventIterator it = set.eventIterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                Event event = it.nextEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                if (event instanceof VMStartEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    // get thread for setting step later
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    thread = ((VMStartEvent)event).thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    ClassPrepareRequest cpReq
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        = requestManager.createClassPrepareRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    cpReq.addClassFilter(TARGET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    cpReq.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                } else if (event instanceof ClassPrepareEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    createStep(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    event.request().disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                } else if (event instanceof StepEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    // StepEvent stepEvent = (StepEvent)event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    // System.out.println(stepEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    System.out.println(++stepNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    if (stepNum >= SUCCESS_COUNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                        // would have failed by now (> 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                        System.out.println("RepStep passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                        event.request().disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                        set.resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                        return; // Success exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                } else if (event instanceof VMDeathEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    throw new Exception("RepStep failed: steps missed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    throw new Exception("Unexpected event: " + event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            set.resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
       }
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 dieNice() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        EventQueue queue = vm.eventQueue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            EventSet set = queue.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            for (EventIterator it = set.eventIterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                Event event = it.nextEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                if (event instanceof VMDeathEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                } else if (event instanceof VMDisconnectEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    set.resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    return; // Success exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    throw new Exception("Unexpected event: " + event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            set.resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private Connector findConnector(String name) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        List connectors = Bootstrap.virtualMachineManager().allConnectors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        Iterator iter = connectors.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            Connector connector = (Connector)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (connector.name().equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                return connector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        throw new Exception("No connector: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /* launch child target vm */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private void launchTarget() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        LaunchingConnector launcher =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
          (LaunchingConnector)findConnector("com.sun.jdi.CommandLineLaunch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        Map connectorArgs = launcher.defaultArguments();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        Connector.Argument mainArg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            (Connector.Argument)connectorArgs.get("main");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        mainArg.setValue(TARGET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        Connector.Argument optionsArg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            (Connector.Argument)connectorArgs.get("options");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        optionsArg.setValue(VMConnection.getDebuggeeVMOptions());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        vm = launcher.launch(connectorArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        System.out.println("launched: " + TARGET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private void attachTarget(String portNum) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        AttachingConnector conn =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            (AttachingConnector)findConnector("com.sun.jdi.SocketAttach");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        Map connectorArgs = conn.defaultArguments();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        Connector.Argument portArg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            (Connector.Argument)connectorArgs.get("port");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        portArg.setValue(portNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        vm = conn.attach(connectorArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        System.out.println("attached to: " + portNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
}