/** * Attempts to load the agent through the Attach API * @return true if agent was loaded (which could have happened thought the -javaagent switch) */ static boolean loadAgent() { synchronized (AgentLoader.class.getName().intern()) { if (!agentIsAvailable() && VIRTUAL_MACHINE_LOAD_AGENT != null) { try { warnIfOSX(); String name = ManagementFactory.getRuntimeMXBean().getName(); Object vm = VIRTUAL_MACHINE_ATTACH.invoke(null, name.substring(0, name.indexOf('@'))); try { File agent = getAgentFile(); LOGGER.info("Trying to load agent @ {}", agent); if (agent != null) { VIRTUAL_MACHINE_LOAD_AGENT.invoke(vm, agent.getAbsolutePath()); } } finally { VIRTUAL_MACHINE_DETACH.invoke(vm); } } catch (InvocationTargetException ite) { Throwable cause = ite.getCause(); LOGGER.info("Failed to attach to VM and load the agent: {}: {}", cause.getClass(), cause.getMessage()); } catch (Throwable t) { LOGGER.info("Failed to attach to VM and load the agent: {}: {}", t.getClass(), t.getMessage()); } } return agentIsAvailable(); } }
@Override public long sizeOf(Object obj) { return Math.max(CURRENT_JVM_INFORMATION.getMinimumObjectSize(), AgentLoader.agentSizeOf(obj) + CURRENT_JVM_INFORMATION.getAgentSizeOfAdjustment()); } }
/** * Attempts to load the agent through the Attach API * @return true if agent was loaded (which could have happened thought the -javaagent switch) */ static boolean loadAgent() { synchronized (AgentLoader.class.getName().intern()) { if (!agentIsAvailable() && VIRTUAL_MACHINE_LOAD_AGENT != null) { try { warnIfOSX(); String name = ManagementFactory.getRuntimeMXBean().getName(); Object vm = VIRTUAL_MACHINE_ATTACH.invoke(null, name.substring(0, name.indexOf('@'))); try { File agent = getAgentFile(); LOGGER.info("Trying to load agent @ {}", agent); if (agent != null) { VIRTUAL_MACHINE_LOAD_AGENT.invoke(vm, agent.getAbsolutePath()); } } finally { VIRTUAL_MACHINE_DETACH.invoke(vm); } } catch (InvocationTargetException ite) { Throwable cause = ite.getCause(); LOGGER.info("Failed to attach to VM and load the agent: {}: {}", cause.getClass(), cause.getMessage()); } catch (Throwable t) { LOGGER.info("Failed to attach to VM and load the agent: {}: {}", t.getClass(), t.getMessage()); } } return agentIsAvailable(); } }
@Override public long sizeOf(Object obj) { return Math.max(CURRENT_JVM_INFORMATION.getMinimumObjectSize(), AgentLoader.agentSizeOf(obj) + CURRENT_JVM_INFORMATION.getAgentSizeOfAdjustment()); } }
/** * Attempts to load the agent through the Attach API * @return true if agent was loaded (which could have happened thought the -javaagent switch) */ static boolean loadAgent() { synchronized (AgentLoader.class.getName().intern()) { if (!agentIsAvailable() && VIRTUAL_MACHINE_LOAD_AGENT != null) { try { warnIfOSX(); String name = ManagementFactory.getRuntimeMXBean().getName(); Object vm = VIRTUAL_MACHINE_ATTACH.invoke(null, name.substring(0, name.indexOf('@'))); try { File agent = getAgentFile(); LOGGER.info("Trying to load agent @ {}", agent); if (agent != null) { VIRTUAL_MACHINE_LOAD_AGENT.invoke(vm, agent.getAbsolutePath()); } } finally { VIRTUAL_MACHINE_DETACH.invoke(vm); } } catch (InvocationTargetException ite) { Throwable cause = ite.getCause(); LOGGER.info("Failed to attach to VM and load the agent: {}: {}", cause.getClass(), cause.getMessage()); } catch (Throwable t) { LOGGER.info("Failed to attach to VM and load the agent: {}: {}", t.getClass(), t.getMessage()); } } return agentIsAvailable(); } }
@Override public long sizeOf(Object obj) { return Math.max(CURRENT_JVM_INFORMATION.getMinimumObjectSize(), AgentLoader.agentSizeOf(obj) + CURRENT_JVM_INFORMATION.getAgentSizeOfAdjustment()); } }
/** * Attempts to load the agent through the Attach API * @return true if agent was loaded (which could have happened thought the -javaagent switch) */ static boolean loadAgent() { synchronized (AgentLoader.class.getName().intern()) { if (!agentIsAvailable() && VIRTUAL_MACHINE_LOAD_AGENT != null) { try { warnIfOSX(); String name = ManagementFactory.getRuntimeMXBean().getName(); Object vm = VIRTUAL_MACHINE_ATTACH.invoke(null, name.substring(0, name.indexOf('@'))); try { File agent = getAgentFile(); LOGGER.info("Trying to load agent @ {}", agent); if (agent != null) { VIRTUAL_MACHINE_LOAD_AGENT.invoke(vm, agent.getAbsolutePath()); } } finally { VIRTUAL_MACHINE_DETACH.invoke(vm); } } catch (InvocationTargetException ite) { Throwable cause = ite.getCause(); LOGGER.info("Failed to attach to VM and load the agent: {}: {}", cause.getClass(), cause.getMessage()); } catch (Throwable t) { LOGGER.info("Failed to attach to VM and load the agent: {}: {}", t.getClass(), t.getMessage()); } } return agentIsAvailable(); } }
@Override public long sizeOf(Object obj) { return Math.max(CURRENT_JVM_INFORMATION.getMinimumObjectSize(), AgentLoader.agentSizeOf(obj) + CURRENT_JVM_INFORMATION.getAgentSizeOfAdjustment()); } }