test/jdk/com/sun/jdi/connect/spi/SimpleLaunchingConnector.java
author cjplummer
Sat, 19 May 2018 13:13:09 -0700
changeset 50189 b8ed2c98202a
parent 47216 71c04702a3d5
permissions -rw-r--r--
8203391: Update com/sun/jdi/JdbMethodExitTest.sh to pass valid URL[] Summary: use a valid URL[] Reviewed-by: sspitsyn, amenkov, dtitov
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: 20201
diff changeset
     2
 * Copyright (c) 2003, 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: 4342
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4342
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4342
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
 * A Simple LaunchingConnector used by unit test :-
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * test/com/sun/jdi/connect/spi/DebugUsingCustomConnector.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jdi.VirtualMachine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jdi.Bootstrap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jdi.connect.Connector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.jdi.connect.LaunchingConnector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.jdi.connect.Transport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jdi.connect.VMStartException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.connect.spi.TransportService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.connect.spi.Connection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class SimpleLaunchingConnector implements LaunchingConnector {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    TransportService ts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    String ARG_NAME = "class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Simple implementation of Connector.StringArgument
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static class StringArgumentImpl implements Connector.StringArgument {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        String label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        String description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        String value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        StringArgumentImpl(String name, String label, String description, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            this.label = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        public String name() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        public String label() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            return label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        public String description() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        public String value() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        public void setValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        public boolean isValid(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            if (value.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        public boolean mustSpecify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public SimpleLaunchingConnector() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        try {
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 20201
diff changeset
    96
            Class<?> c = Class.forName("com.sun.tools.jdi.SocketTransportService");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            ts = (TransportService)c.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            throw new Error(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public String name() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return "SimpleLaunchingConnector";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public String description() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return "SimpleLaunchingConnector";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public Transport transport() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return new Transport() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            public String name() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                return ts.name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public Map defaultArguments() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        HashMap map = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        map.put(ARG_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                new StringArgumentImpl(ARG_NAME, "class name", "class name", ""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public VirtualMachine launch(Map<String, ? extends Connector.Argument> arguments) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                              IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                              IllegalConnectorArgumentsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                              VMStartException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         * Get the class name that we are to execute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        String className = ((StringArgumentImpl)arguments.get(ARG_NAME)).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (className.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            throw new IllegalConnectorArgumentsException("class name missing", ARG_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         * Listen on an emperical port; launch the debuggee; wait for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         * for the debuggee to connect; stop listening;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        TransportService.ListenKey key = ts.startListening();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        String exe = System.getProperty("java.home") + File.separator + "bin" +
20201
50cc2d25a60b 8020552: [launcher] changes to support removal of Solaris 32-bit distribution
ksrini
parents: 5506
diff changeset
   146
            File.separator + "java";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        String cmd = exe + " -Xdebug -Xrunjdwp:transport=dt_socket,timeout=15000,address=" +
4335
365eb4449319 6904183: Fix jdk/test/com/sun/jdi tests to run with -samevm
ohair
parents: 2
diff changeset
   148
            key.address() +
365eb4449319 6904183: Fix jdk/test/com/sun/jdi tests to run with -samevm
ohair
parents: 2
diff changeset
   149
            " -classpath " + System.getProperty("test.classes") +
365eb4449319 6904183: Fix jdk/test/com/sun/jdi tests to run with -samevm
ohair
parents: 2
diff changeset
   150
            " " + className;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        Process process = Runtime.getRuntime().exec(cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        Connection conn = ts.accept(key, 30*1000, 9*1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        ts.stopListening(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         * Debugee is connected - return the virtual machine mirror
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return Bootstrap.virtualMachineManager().createVirtualMachine(conn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}