agent/test/jdi/sagclient.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

duke@435 1 /*
trims@1907 2 * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 import com.sun.jdi.*;
duke@435 26 import com.sun.jdi.connect.*;
duke@435 27
duke@435 28 import java.util.Map;
duke@435 29 import java.util.List;
duke@435 30 import java.util.Iterator;
duke@435 31 import java.io.IOException;
duke@435 32
duke@435 33 public class sagclient {
duke@435 34 static AttachingConnector myCoreConn;
duke@435 35 static AttachingConnector myPIDConn;
duke@435 36 static AttachingConnector myDbgSvrConn;
duke@435 37 static VirtualMachine vm;
duke@435 38 static VirtualMachineManager vmmgr;
duke@435 39
duke@435 40 public static void println(String msg) {
duke@435 41 System.out.println("jj: " + msg);
duke@435 42 }
duke@435 43
duke@435 44
duke@435 45 public static void main(String args[]) {
duke@435 46 vmmgr = Bootstrap.virtualMachineManager();
duke@435 47 List attachingConnectors = vmmgr.attachingConnectors();
duke@435 48 if (attachingConnectors.isEmpty()) {
duke@435 49 System.err.println( "ERROR: No attaching connectors");
duke@435 50 return;
duke@435 51 }
duke@435 52 Iterator myIt = attachingConnectors.iterator();
duke@435 53 while (myIt.hasNext()) {
duke@435 54 AttachingConnector tmpCon = (AttachingConnector)myIt.next();
duke@435 55 if (tmpCon.name().equals(
duke@435 56 "sun.jvm.hotspot.jdi.SACoreAttachingConnector")) {
duke@435 57 myCoreConn = tmpCon;
duke@435 58 } else if (tmpCon.name().equals(
duke@435 59 "sun.jvm.hotspot.jdi.SAPIDAttachingConnector")) {
duke@435 60 myPIDConn = tmpCon;
duke@435 61 } else if (tmpCon.name().equals(
duke@435 62 "sun.jvm.hotspot.jdi.SADebugServerAttachingConnector")) {
duke@435 63 myDbgSvrConn = tmpCon;
duke@435 64 }
duke@435 65 }
duke@435 66 String execPath = null;
duke@435 67 String pidText = null;
duke@435 68 String coreFilename = null;
duke@435 69 String debugServer = null;
duke@435 70 int pid = 0;
duke@435 71 switch (args.length) {
duke@435 72 case (0):
duke@435 73 break;
duke@435 74 case (1):
duke@435 75 // If all numbers, it is a PID to attach to
duke@435 76 // Else, it is a pathname to a .../bin/java for a core file.
duke@435 77 try {
duke@435 78 pidText = args[0];
duke@435 79 pid = Integer.parseInt(pidText);
duke@435 80 System.out.println( "pid: " + pid);
duke@435 81 vm = attachPID(pid);
duke@435 82 } catch (NumberFormatException e) {
duke@435 83 System.out.println("trying remote server ..");
duke@435 84 debugServer = args[0];
duke@435 85 System.out.println( "remote server: " + debugServer);
duke@435 86 vm = attachDebugServer(debugServer);
duke@435 87 }
duke@435 88 break;
duke@435 89
duke@435 90 case (2):
duke@435 91 execPath = args[0];
duke@435 92 coreFilename = args[1];
duke@435 93 System.out.println( "jdk: " + execPath);
duke@435 94 System.out.println( "core: " + coreFilename);
duke@435 95 vm = attachCore(coreFilename, execPath);
duke@435 96 break;
duke@435 97 }
duke@435 98
duke@435 99
duke@435 100 if (vm != null) {
duke@435 101 System.out.println("sagclient: attached ok!");
duke@435 102 sagdoit mine = new sagdoit(vm);
duke@435 103 mine.doAll();
duke@435 104 vm.dispose();
duke@435 105 }
duke@435 106 }
duke@435 107
duke@435 108 private static VirtualMachine attachCore(String coreFilename, String execPath) {
duke@435 109 Map connArgs = myCoreConn.defaultArguments();
duke@435 110 System.out.println("connArgs = " + connArgs);
duke@435 111 VirtualMachine vm;
duke@435 112 Connector.StringArgument connArg = (Connector.StringArgument)connArgs.get("core");
duke@435 113 connArg.setValue(coreFilename);
duke@435 114
duke@435 115 connArg = (Connector.StringArgument)connArgs.get("javaExecutable");
duke@435 116 connArg.setValue(execPath);
duke@435 117 try {
duke@435 118 vm = myCoreConn.attach(connArgs);
duke@435 119 } catch (IOException ee) {
duke@435 120 System.err.println("ERROR: myCoreConn.attach got IO Exception:" + ee);
duke@435 121 vm = null;
duke@435 122 } catch (IllegalConnectorArgumentsException ee) {
duke@435 123 System.err.println("ERROR: myCoreConn.attach got illegal args exception:" + ee);
duke@435 124 vm = null;
duke@435 125 }
duke@435 126 return vm;
duke@435 127 }
duke@435 128
duke@435 129 private static VirtualMachine attachPID(int pid) {
duke@435 130 Map connArgs = myPIDConn.defaultArguments();
duke@435 131 System.out.println("connArgs = " + connArgs);
duke@435 132 VirtualMachine vm;
duke@435 133 Connector.StringArgument connArg = (Connector.StringArgument)connArgs.get("pid");
duke@435 134 connArg.setValue(Integer.toString(pid));
duke@435 135
duke@435 136 try {
duke@435 137 vm = myPIDConn.attach(connArgs);
duke@435 138 } catch (IOException ee) {
duke@435 139 System.err.println("ERROR: myPIDConn.attach got IO Exception:" + ee);
duke@435 140 vm = null;
duke@435 141 } catch (IllegalConnectorArgumentsException ee) {
duke@435 142 System.err.println("ERROR: myPIDConn.attach got illegal args exception:" + ee);
duke@435 143 vm = null;
duke@435 144 }
duke@435 145 return vm;
duke@435 146 }
duke@435 147
duke@435 148
duke@435 149 private static VirtualMachine attachDebugServer(String debugServer) {
duke@435 150 Map connArgs = myDbgSvrConn.defaultArguments();
duke@435 151 System.out.println("connArgs = " + connArgs);
duke@435 152 VirtualMachine vm;
duke@435 153 Connector.StringArgument connArg = (Connector.StringArgument)connArgs.get("debugServerName");
duke@435 154 connArg.setValue(debugServer);
duke@435 155
duke@435 156 try {
duke@435 157 vm = myDbgSvrConn.attach(connArgs);
duke@435 158 } catch (IOException ee) {
duke@435 159 System.err.println("ERROR: myDbgSvrConn.attach got IO Exception:" + ee);
duke@435 160 vm = null;
duke@435 161 } catch (IllegalConnectorArgumentsException ee) {
duke@435 162 System.err.println("ERROR: myDbgSvrConn.attach got illegal args exception:" + ee);
duke@435 163 vm = null;
duke@435 164 }
duke@435 165 return vm;
duke@435 166 }
duke@435 167 }

mercurial