agent/test/jdi/multivm.java

Mon, 28 Jul 2014 15:06:38 -0700

author
fzhinkin
date
Mon, 28 Jul 2014 15:06:38 -0700
changeset 6997
dbb05f6d93c4
parent 1907
c18cbe5936b8
child 6876
710a3c8b516e
permissions
-rw-r--r--

8051344: JVM crashed in Compile::start() during method parsing w/ UseRTMDeopt turned on
Summary: call rtm_deopt() only if there were no compilation bailouts before.
Reviewed-by: kvn

     1 /*
     2  * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 import com.sun.jdi.*;
    26 import com.sun.jdi.connect.*;
    28 import java.util.Map;
    29 import java.util.List;
    30 import java.util.Iterator;
    31 import java.io.IOException;
    33 /* This class is used to test multi VM connectivity feature of
    34  * SA/JDI. Accepts two PIDs as arguments. Connects to first VM
    35  *, Connects to second VM and disposes them in that order.
    36  */
    38 public class multivm {
    39     static AttachingConnector myPIDConn;
    40     static VirtualMachine vm1;
    41     static VirtualMachine vm2;
    42     static VirtualMachineManager vmmgr;
    44     public static void println(String msg) {
    45         System.out.println(msg);
    46     }
    48     private static void usage() {
    49         System.err.println("Usage: java multivm <pid1> <pid2>");
    50         System.exit(1);
    51     }
    53     public static void main(String args[]) {
    54         vmmgr = Bootstrap.virtualMachineManager();
    55         List attachingConnectors = vmmgr.attachingConnectors();
    56         if (attachingConnectors.isEmpty()) {
    57             System.err.println( "ERROR: No attaching connectors");
    58             return;
    59         }
    60         Iterator myIt = attachingConnectors.iterator();
    61         while (myIt.hasNext()) {
    62             AttachingConnector tmpCon = (AttachingConnector)myIt.next();
    63             if (tmpCon.name().equals(
    64                 "sun.jvm.hotspot.jdi.SAPIDAttachingConnector")) {
    65                 myPIDConn = tmpCon;
    66                 break;
    67             }
    68         }
    70         int pid1 = 0, pid2 = 0;
    71         String pidText = null;
    72         switch (args.length) {
    73         case (2):
    74             try {
    75                 pidText = args[0];
    76                 pid1 = Integer.parseInt(pidText);
    77                 System.out.println( "pid1: " + pid1);
    78                 vm1 = attachPID(pid1);
    79                 pidText = args[1];
    80                 pid2 = Integer.parseInt(pidText);
    81                 System.out.println( "pid2: " + pid2);
    82                 vm2 = attachPID(pid2);
    83             } catch (NumberFormatException e) {
    84                 println(e.getMessage());
    85                 usage();
    86             }
    87             break;
    88         default:
    89             usage();
    90         }
    92         if (vm1 != null) {
    93             System.out.println("vm1: attached ok!");
    94             System.out.println(vm1.version());
    95             sagdoit mine = new sagdoit(vm1);
    96             mine.doAll();
    97         }
    99         if (vm2 != null) {
   100             System.out.println("vm2: attached ok!");
   101             System.out.println(vm2.version());
   102             sagdoit mine = new sagdoit(vm2);
   103             mine.doAll();
   104         }
   106         if (vm1 != null) {
   107             vm1.dispose();
   108         }
   110         if (vm2 != null) {
   111             vm2.dispose();
   112         }
   113     }
   115    private static VirtualMachine attachPID(int pid) {
   116         Map connArgs = myPIDConn.defaultArguments();
   117         System.out.println("connArgs = " + connArgs);
   118         VirtualMachine vm;
   119         Connector.StringArgument connArg = (Connector.StringArgument)connArgs.get("pid");
   120         connArg.setValue(Integer.toString(pid));
   122         try {
   123             vm = myPIDConn.attach(connArgs);
   124         } catch (IOException ee) {
   125             System.err.println("ERROR: myPIDConn.attach got IO Exception:" + ee);
   126             vm = null;
   127         } catch (IllegalConnectorArgumentsException ee) {
   128             System.err.println("ERROR: myPIDConn.attach got illegal args exception:" + ee);
   129             vm = null;
   130         }
   131         return vm;
   132    }
   133 }

mercurial