Skip to content

Commit

Permalink
Merge pull request eclipse-openj9#236 from pdbain-ibm/start_local_agent
Browse files Browse the repository at this point in the history
Use VMSupport to get attach API localConnectorAddress
  • Loading branch information
pshipton authored Oct 20, 2017
2 parents e8fb2b9 + 00b82ea commit d6cd930
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
import java.net.Socket;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects;
import java.util.Properties;
/*[IF Sidecar19-SE-B165]*/
import jdk.internal.vm.VMSupport;
/*[ENDIF]*/
import static com.ibm.tools.attach.target.IPC.LOCAL_CONNECTOR_ADDRESS;

/**
* This class handles established connections initiated by another VM
Expand Down Expand Up @@ -218,7 +223,7 @@ boolean doCommand(InputStream cmdStream, OutputStream respStream) {
agentProperties = IPC.receiveProperties(cmdStream, true);
}
/*[PR 102391 properties may be appended to the command]*/
IPC.logMessage("startAgent:"+ cmd); //$NON-NLS-1$
IPC.logMessage("startAgent:" + cmd); //$NON-NLS-1$
if (startAgent(agentProperties)) {
AttachmentConnection.streamSend(respStream, Response.ACK);
} else {
Expand Down Expand Up @@ -390,16 +395,38 @@ private static String startLocalAgent() throws IbmAttachOperationFailedException
if (null != MethodRefsHolder.startLocalManagementAgentMethod) { /* forces initialization */
MethodRefsHolder.startLocalManagementAgentMethod.invoke(null);
} else {
throw new IbmAttachOperationFailedException("startLocalManagementAgent cannot access "+START_LOCAL_MANAGEMENT_AGENT); //$NON-NLS-1$
throw new IbmAttachOperationFailedException("startLocalManagementAgent cannot access " + START_LOCAL_MANAGEMENT_AGENT); //$NON-NLS-1$
}
} catch (Throwable e) {
throw new IbmAttachOperationFailedException("startLocalManagementAgent error starting agent:"+e.getClass()+" "+e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
throw new IbmAttachOperationFailedException("startLocalManagementAgent error starting agent:" + e.getClass() + " " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
}
String addr = com.ibm.oti.vm.VM.getVMLangAccess().internalGetProperties().getProperty(IPC.LOCAL_CONNECTOR_ADDRESS);
if (null == addr) {
throw new IbmAttachOperationFailedException("startLocalManagementAgent: "+IPC.LOCAL_CONNECTOR_ADDRESS+" not defined"); //$NON-NLS-1$ //$NON-NLS-2$
/*
* sun.management.Agent.startLocalManagementAgent() in Java 8 sets
* c.s.m.j.localConnectorAddress in System.properties.
* jdk.internal.agent.Agent.startLocalManagementAgent() in Java 9 sets
* c.s.m.j.localConnectorAddress in a different Properties object.
*/
Properties systemProperties = com.ibm.oti.vm.VM.getVMLangAccess().internalGetProperties();
String addr;
/*[IF Sidecar19-SE-B165]*/
synchronized (systemProperties) {
addr = systemProperties.getProperty(LOCAL_CONNECTOR_ADDRESS);
if (Objects.isNull(addr)) {
addr = VMSupport.getAgentProperties().getProperty(LOCAL_CONNECTOR_ADDRESS);
if (!Objects.isNull(addr)) {
systemProperties.setProperty(LOCAL_CONNECTOR_ADDRESS, addr);
}
}
}
/*[ELSE] Sidecar19-SE-B165 */
addr = systemProperties.getProperty(LOCAL_CONNECTOR_ADDRESS);
/*[ENDIF] Sidecar19-SE-B165*/
if (Objects.isNull(addr)) {
/* startLocalAgent() should have set the property. */
IPC.logMessage(LOCAL_CONNECTOR_ADDRESS + " not set"); //$NON-NLS-1$
throw new IbmAttachOperationFailedException("startLocalManagementAgent: " + LOCAL_CONNECTOR_ADDRESS + " not defined"); //$NON-NLS-1$ //$NON-NLS-2$
}
IPC.logMessage(IPC.LOCAL_CONNECTOR_ADDRESS+"=", addr); //$NON-NLS-1$
IPC.logMessage(LOCAL_CONNECTOR_ADDRESS + "=", addr); //$NON-NLS-1$
return addr;
}
}
1 change: 0 additions & 1 deletion test/TestConfig/resources/excludes/openj9_exclude.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ org.openj9.test.attachAPI.TestAttachAPI:test_agntld01 238 generi
org.openj9.test.attachAPI.TestAttachAPI:test_agntld02 238 generic-all
org.openj9.test.attachAPI.TestAttachAPI:test_agntld03 238 generic-all
org.openj9.test.attachAPI.TestSunAttachClasses:testAgentLoading 238 generic-all
org.openj9.test.attachAPI.TestManagementAgent:test_startLocalManagementAgent 241 generic-all
org.openj9.test.vmArguments.VmArgumentTests:testCrNocr 244 generic-all

0 comments on commit d6cd930

Please sign in to comment.