com.sun.tools.attach.AgentLoadException Java Examples
The following examples show how to use
com.sun.tools.attach.AgentLoadException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HotSpotVirtualMachine.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options) throws AgentLoadException, AgentInitializationException, IOException { InputStream in = execute("load", agentLibrary, isAbsolute ? "true" : "false", options); try { int result = readInt(in); if (result != 0) { throw new AgentInitializationException("Agent_OnAttach failed", result); } } finally { in.close(); } }
Example #2
Source File: HotSpotVirtualMachine.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options) throws AgentLoadException, AgentInitializationException, IOException { InputStream in = execute("load", agentLibrary, isAbsolute ? "true" : "false", options); try { int result = readInt(in); if (result != 0) { throw new AgentInitializationException("Agent_OnAttach failed", result); } } finally { in.close(); } }
Example #3
Source File: PromagentLoader.java From promagent with Apache License 2.0 | 6 votes |
private static String getMessage(AgentLoadException e) { switch (e.getMessage()) { case "-4": return "Insuffient memory"; case "100": return "Agent JAR not found or no Agent-Class attribute"; case "101": return "Unable to add JAR file to system class path"; case "102": return "Agent JAR loaded but agent failed to initialize"; default: return e.getMessage(); } }
Example #4
Source File: TestJVMAgent.java From tracing-framework with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testBadModification2() throws ClassNotFoundException, AgentLoadException, AgentInitializationException, IOException, AttachNotSupportedException, UnmodifiableClassException { // Rewrite method DynamicModification badModification = new DynamicModification() { public Collection<String> affects() { return Lists.newArrayList(TestJVMAgent.class.getName()); } public void apply(ClassPool arg0) throws NotFoundException, CannotCompileException { CtClass cls = arg0.getCtClass(TestJVMAgent.class.getName()); cls.getMethods()[0].insertBefore("definitely not code..."); } }; JVMAgent dynamic = JVMAgent.get(); // Modification should just be ignored since it throws a notfoundexception try { dynamic.install(badModification); fail(); } catch (CannotCompileException e) { } }
Example #5
Source File: HotSpotVirtualMachine.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options) throws AgentLoadException, AgentInitializationException, IOException { InputStream in = execute("load", agentLibrary, isAbsolute ? "true" : "false", options); try { int result = readInt(in); if (result != 0) { throw new AgentInitializationException("Agent_OnAttach failed", result); } } finally { in.close(); } }
Example #6
Source File: HotSpotVirtualMachine.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options) throws AgentLoadException, AgentInitializationException, IOException { InputStream in = execute("load", agentLibrary, isAbsolute ? "true" : "false", options); try { int result = readInt(in); if (result != 0) { throw new AgentInitializationException("Agent_OnAttach failed", result); } } finally { in.close(); } }
Example #7
Source File: HotSpotVirtualMachine.java From hottub with GNU General Public License v2.0 | 6 votes |
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options) throws AgentLoadException, AgentInitializationException, IOException { InputStream in = execute("load", agentLibrary, isAbsolute ? "true" : "false", options); try { int result = readInt(in); if (result != 0) { throw new AgentInitializationException("Agent_OnAttach failed", result); } } finally { in.close(); } }
Example #8
Source File: HotSpotVirtualMachine.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options) throws AgentLoadException, AgentInitializationException, IOException { InputStream in = execute("load", agentLibrary, isAbsolute ? "true" : "false", options); try { int result = readInt(in); if (result != 0) { throw new AgentInitializationException("Agent_OnAttach failed", result); } } finally { in.close(); } }
Example #9
Source File: TestJDWPAgentDebug.java From tracing-framework with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testBadModification2() throws ClassNotFoundException, AgentLoadException, AgentInitializationException, IOException, AttachNotSupportedException, UnmodifiableClassException, IllegalConnectorArgumentsException { // Rewrite method DynamicModification badModification = new DynamicModification() { public Collection<String> affects() { return Lists.newArrayList(TestJDWPAgentDebug.class.getName()); } public void apply(ClassPool arg0) throws NotFoundException, CannotCompileException { CtClass cls = arg0.getCtClass(TestJDWPAgentDebug.class.getName()); cls.getMethods()[0].insertBefore("definitely not code..."); } }; JDWPAgent dynamic = JDWPAgent.get(); // Modification should just be ignored since it throws a notfoundexception try { dynamic.install(badModification); fail(); } catch (CannotCompileException e) { } }
Example #10
Source File: AgentMainTest.java From fastjgame with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { String pid = getPid(); VirtualMachine vm = VirtualMachine.attach(pid); vm.loadAgent("game-classreloadagent-1.0.jar"); System.out.println(ClassReloadAgent.isRedefineClassesSupported()); System.out.println(ClassReloadAgent.isModifiableClass(AgentMainTest.class)); }
Example #11
Source File: HotSpotVirtualMachine.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private InputStream executeCommand(String cmd, Object ... args) throws IOException { try { return execute(cmd, args); } catch (AgentLoadException x) { throw new InternalError("Should not get here", x); } }
Example #12
Source File: HotSpotVirtualMachine.java From hottub with GNU General Public License v2.0 | 5 votes |
private InputStream executeCommand(String cmd, Object ... args) throws IOException { try { return execute(cmd, args); } catch (AgentLoadException x) { throw new InternalError("Should not get here", x); } }
Example #13
Source File: HotSpotVirtualMachine.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private InputStream executeCommand(String cmd, Object ... args) throws IOException { try { return execute(cmd, args); } catch (AgentLoadException x) { throw new InternalError("Should not get here", x); } }
Example #14
Source File: HotSpotVirtualMachine.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options) throws AgentLoadException, AgentInitializationException, IOException { InputStream in = execute("load", agentLibrary, isAbsolute ? "true" : "false", options); try { int result = readInt(in); if (result != 0) { throw new AgentInitializationException("Agent_OnAttach failed", result); } } finally { in.close(); } }
Example #15
Source File: CougarHelpers.java From cougar with Apache License 2.0 | 5 votes |
public JMXConnector createJMXConnector(String id) throws IOException,AgentLoadException, AgentInitializationException, AttachNotSupportedException { // attach to the target application VirtualMachine vm = VirtualMachine.attach(id); // get the connector address String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); // no connector address, so we start the JMX agent if (connectorAddress == null) { String agent = vm.getSystemProperties() .getProperty("java.home") + File.separator + "lib" + File.separator + "management-agent.jar"; vm.loadAgent(agent); // agent is started, get the connector address connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); } // establish connection to connector server JMXServiceURL url = new JMXServiceURL(connectorAddress); return JMXConnectorFactory.connect(url); }
Example #16
Source File: HotSpotVirtualMachine.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private InputStream executeCommand(String cmd, Object ... args) throws IOException { try { return execute(cmd, args); } catch (AgentLoadException x) { throw new InternalError("Should not get here", x); } }
Example #17
Source File: HotSpotVirtualMachine.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public InputStream executeCommand(String cmd, Object ... args) throws IOException { try { return execute(cmd, args); } catch (AgentLoadException x) { throw new InternalError("Should not get here", x); } }
Example #18
Source File: SimpleProvider.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void loadAgentLibrary(String agentLibrary, String options) throws IOException, AgentLoadException, AgentInitializationException { }
Example #19
Source File: HotSpotVirtualMachine.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public void loadAgentLibrary(String agentLibrary, String options) throws AgentLoadException, AgentInitializationException, IOException { loadAgentLibrary(agentLibrary, false, options); }
Example #20
Source File: HotSpotVirtualMachine.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void loadAgentLibrary(String agentLibrary, String options) throws AgentLoadException, AgentInitializationException, IOException { loadAgentLibrary(agentLibrary, false, options); }
Example #21
Source File: BsdVirtualMachine.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Execute the given command in the target VM. */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null // did we detach? String p; synchronized (this) { if (this.path == null) { throw new IOException("Detached from target VM"); } p = this.path; } // create UNIX socket int s = socket(); // connect to target VM try { connect(s, p); } catch (IOException x) { close(s); throw x; } IOException ioe = null; // connected - write request // <ver> <cmd> <args...> try { writeString(s, PROTOCOL_VERSION); writeString(s, cmd); for (int i=0; i<3; i++) { if (i < args.length && args[i] != null) { writeString(s, (String)args[i]); } else { writeString(s, ""); } } } catch (IOException x) { ioe = x; } // Create an input stream to read reply SocketInputStream sis = new SocketInputStream(s); // Read the command completion status int completionStatus; try { completionStatus = readInt(sis); } catch (IOException x) { sis.close(); if (ioe != null) { throw ioe; } else { throw x; } } if (completionStatus != 0) { // read from the stream and use that as the error message String message = readErrorMessage(sis); sis.close(); // In the event of a protocol mismatch then the target VM // returns a known error so that we can throw a reasonable // error. if (completionStatus == ATTACH_ERROR_BADVERSION) { throw new IOException("Protocol mismatch with target VM"); } // Special-case the "load" command so that the right exception is // thrown. if (cmd.equals("load")) { throw new AgentLoadException("Failed to load agent library"); } else { if (message == null) { throw new AttachOperationFailedException("Command failed in target VM"); } else { throw new AttachOperationFailedException(message); } } } // Return the input stream so that the command output can be read return sis; }
Example #22
Source File: AixVirtualMachine.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Execute the given command in the target VM. */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null // did we detach? String p; synchronized (this) { if (this.path == null) { throw new IOException("Detached from target VM"); } p = this.path; } // create UNIX socket int s = socket(); // connect to target VM try { connect(s, p); } catch (IOException x) { close(s); throw x; } IOException ioe = null; // connected - write request // <ver> <cmd> <args...> try { writeString(s, PROTOCOL_VERSION); writeString(s, cmd); for (int i=0; i<3; i++) { if (i < args.length && args[i] != null) { writeString(s, (String)args[i]); } else { writeString(s, ""); } } } catch (IOException x) { ioe = x; } // Create an input stream to read reply SocketInputStream sis = new SocketInputStream(s); // Read the command completion status int completionStatus; try { completionStatus = readInt(sis); } catch (IOException x) { sis.close(); if (ioe != null) { throw ioe; } else { throw x; } } if (completionStatus != 0) { // read from the stream and use that as the error message String message = readErrorMessage(sis); sis.close(); // In the event of a protocol mismatch then the target VM // returns a known error so that we can throw a reasonable // error. if (completionStatus == ATTACH_ERROR_BADVERSION) { throw new IOException("Protocol mismatch with target VM"); } // Special-case the "load" command so that the right exception is // thrown. if (cmd.equals("load")) { throw new AgentLoadException("Failed to load agent library"); } else { if (message == null) { throw new AttachOperationFailedException("Command failed in target VM"); } else { throw new AttachOperationFailedException(message); } } } // Return the input stream so that the command output can be read return sis; }
Example #23
Source File: HotSpotVirtualMachine.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
abstract InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException;
Example #24
Source File: VirtualMachineImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Execute the given command in the target VM. */ InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException { assert args.length <= 3; // includes null // first check that we are still attached int door; synchronized (this) { if (fd == -1) { throw new IOException("Detached from target VM"); } door = fd; } // enqueue the command via a door call int s = enqueue(door, cmd, args); assert s >= 0; // valid file descriptor // The door call returns a file descriptor (one end of a socket pair). // Create an input stream around it. SocketInputStream sis = new SocketInputStream(s); // Read the command completion status int completionStatus; try { completionStatus = readInt(sis); } catch (IOException ioe) { sis.close(); throw ioe; } // If non-0 it means an error but we need to special-case the // "load" command to ensure that the right exception is thrown. if (completionStatus != 0) { // read from the stream and use that as the error message String message = readErrorMessage(sis); sis.close(); if (cmd.equals("load")) { String msg = "Failed to load agent library"; if (!message.isEmpty()) msg += ": " + message; throw new AgentLoadException(msg); } else { if (message.isEmpty()) message = "Command failed in target VM"; throw new AttachOperationFailedException(message); } } // Return the input stream so that the command output can be read return sis; }
Example #25
Source File: AgentHookUtil.java From util4j with Apache License 2.0 | 4 votes |
public synchronized static AgentHook getAgentHook() throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { return getAgentHook(null,true); }
Example #26
Source File: AgentHookUtil.java From util4j with Apache License 2.0 | 4 votes |
public synchronized static AgentHook getAgentHook(boolean deleteOndetach) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { return getAgentHook(null,deleteOndetach); }
Example #27
Source File: AgentHookUtil.java From util4j with Apache License 2.0 | 4 votes |
/** * 指定一个../xx.jar的临时文件路径用于agent的加载 * @param agentTmpPath String path = File.createTempFile("agent_tmp", ".jar", new File("").getAbsoluteFile()).getPath(); * @param deleteOndetach * @return * @throws IOException * @throws AttachNotSupportedException * @throws AgentLoadException * @throws AgentInitializationException */ public synchronized static AgentHook getAgentHook(String agentTmpPath,boolean deleteOndetach) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { if(agentHook!=null){ return agentHook; } File tempFile=null; VirtualMachine virtualMachine=null; FileOutputStream fos; try { InputStream resourceAsStream = AgentHookUtil.class.getClassLoader().getResourceAsStream(agentName); byte[] agentData=InputStreamUtils.getBytes(resourceAsStream); if(agentTmpPath!=null){ try { tempFile=new File(agentTmpPath); tempFile.createNewFile(); }catch (Exception e){ log.error(e.getMessage(),e); } } if(tempFile==null){ tempFile = File.createTempFile("agent_tmp", ".jar"); } fos=new FileOutputStream(tempFile); fos.write(agentData); fos.close(); resourceAsStream.close(); String path=tempFile.toString(); System.out.println("loadAgentUsePath:"+path); log.info("loadAgentUsePath:"+path); virtualMachine = VmUtil.getVirtualMachine(); String arg=AgentHookImpl.class.getName(); virtualMachine.loadAgent(path,arg); agentHook=AgentHookImpl.getInstance(); return agentHook; }finally { if(virtualMachine!=null){ virtualMachine.detach(); log.info("detach agent"); } if(deleteOndetach){ if(tempFile!=null){ tempFile.delete(); if(tempFile.exists()){ tempFile.deleteOnExit(); } } } } }
Example #28
Source File: HotSpotVirtualMachine.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
abstract InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException;
Example #29
Source File: HotSpotVirtualMachine.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public void loadAgentLibrary(String agentLibrary, String options) throws AgentLoadException, AgentInitializationException, IOException { loadAgentLibrary(agentLibrary, false, options); }
Example #30
Source File: SimpleProvider.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void loadAgent(String agentLibrary, String options) throws IOException, AgentLoadException, AgentInitializationException { }