diff --git a/jcl/src/java.base/share/classes/com/ibm/tools/attach/target/Attachment.java b/jcl/src/java.base/share/classes/com/ibm/tools/attach/target/Attachment.java index 8dd32c37b33..55000b40419 100644 --- a/jcl/src/java.base/share/classes/com/ibm/tools/attach/target/Attachment.java +++ b/jcl/src/java.base/share/classes/com/ibm/tools/attach/target/Attachment.java @@ -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 @@ -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 { @@ -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; } } diff --git a/test/TestConfig/resources/excludes/openj9_exclude.txt b/test/TestConfig/resources/excludes/openj9_exclude.txt index 12d4817849a..19bf88c65a9 100644 --- a/test/TestConfig/resources/excludes/openj9_exclude.txt +++ b/test/TestConfig/resources/excludes/openj9_exclude.txt @@ -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 \ No newline at end of file