Skip to content
Permalink
Browse files
6660: Make JMX API not return classes
Reviewed-by: hirt
  • Loading branch information
Jessye Coleman-Shapiro authored and thegreystone committed Jan 17, 2020
1 parent ea933fa commit afcf74db92fd10cc7a58261713e2f24a505f3e1e
@@ -26,7 +26,7 @@ java --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -XX:+FlightRecorder -ja
```

## Interacting with the agent
At runtime the agent can be used to modify the transformed state of a class. To specify a desired state, supply the setTransforms function with a XML description of transformations to keep or modify, and leave out all those that should be reverted to their preinstrumentation versions.
At runtime the agent can be used to modify the transformed state of a class. To specify a desired state, supply the defineEventProbes function with a XML description of event probes to add, keep or modify, and leave out all those that should be reverted to their preinstrumentation versions.

## Known Issues
* The full converter support is still to be merged into the open source repo
@@ -99,7 +99,7 @@
<configuration>
<argLine> --add-opens java.base/jdk.internal.misc=ALL-UNNAMED
-XX:+FlightRecorder</argLine>
<excludes>TestSetTransforms.java</excludes>
<excludes>TestDefineEventProbes.java</excludes>
</configuration>
</plugin>
<plugin>
@@ -118,7 +118,7 @@
<argLine> --add-opens java.base/jdk.internal.misc=ALL-UNNAMED
-XX:+FlightRecorder -javaagent:target/org.openjdk.jmc.agent-1.0.0-SNAPSHOT.jar=target/test-classes/org/openjdk/jmc/agent/test/jfrprobes_template.xml
-cp target/org.openjdk.jmc.agent-1.0.0-SNAPSHOT.jar:target/test-classes/ </argLine>
<includes>TestSetTransforms.java</includes>
<includes>TestDefineEventProbes.java</includes>
</configuration>
</plugin>
<plugin>
@@ -53,7 +53,7 @@ public AgentController(Instrumentation instrumentation, TransformRegistry regist
this.registry = registry;
}

public Class<?>[] setTransforms(String xmlDescription) throws Exception{
public void defineEventProbes(String xmlDescription) throws Exception{
HashSet<Class<?>> classesToRetransform = new HashSet<Class<?>>();
boolean revertAll = xmlDescription == null ? true : xmlDescription.isEmpty();
if (revertAll) {
@@ -71,7 +71,7 @@ public Class<?>[] setTransforms(String xmlDescription) throws Exception{
boolean noDescriptors = descriptors == null ? true : descriptors.isEmpty();
if (noDescriptors) {
logger.log(Level.SEVERE, "Failed to identify transformations: " + xmlDescription);
return null;
return;
}
for (TransformDescriptor descriptor : descriptors) {
try {
@@ -88,7 +88,5 @@ public Class<?>[] setTransforms(String xmlDescription) throws Exception{
registry.setRevertInstrumentation(true);
instrumentation.retransformClasses(classesToRetransformArray);
registry.setRevertInstrumentation(false);

return classesToRetransformArray;
}
}
@@ -33,5 +33,5 @@
package org.openjdk.jmc.agent.jmx;

public interface AgentControllerMBean {
public Class<?>[] setTransforms(String xmlDescription) throws Exception;
public void defineEventProbes(String xmlDescription) throws Exception;
}
@@ -58,7 +58,7 @@
import org.openjdk.jmc.agent.jfrnext.impl.JFRNextEventClassGenerator;
import org.openjdk.jmc.agent.util.TypeUtils;

public class TestSetTransforms {
public class TestDefineEventProbes {

private static final String AGENT_OBJECT_NAME = "org.openjdk.jmc.jfr.agent:type=AgentController"; //$NON-NLS-1$
private static final String EVENT_ID = "demo.jfr.test6";
@@ -87,7 +87,7 @@ public class TestSetTransforms {
+ "</jfragent>";

@Test
public void testSetTransforms() throws Exception {
public void testDefineEventProbes() throws Exception {
boolean exceptionThrown = false;
try {
InstrumentMe.printHelloWorldJFR6();
@@ -98,15 +98,15 @@ public void testSetTransforms() throws Exception {
assertFalse(exceptionThrown);

injectFailingEvent();
doSetTransforms(XML_DESCRIPTION);
doDefineEventProbes(XML_DESCRIPTION);
try {
InstrumentMe.printHelloWorldJFR6();
} catch (RuntimeException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);

doSetTransforms("");
doDefineEventProbes("");
try {
InstrumentMe.printHelloWorldJFR6();
exceptionThrown = false;
@@ -159,13 +159,13 @@ protected void onMethodExit(int opcode) {
ClassLoader.getSystemClassLoader(), null);
}

private void doSetTransforms(String xmlDescription) throws Exception {
private void doDefineEventProbes(String xmlDescription) throws Exception {
ObjectName name = new ObjectName(AGENT_OBJECT_NAME);
Object[] parameters = {xmlDescription};
String[] signature = {String.class.getName()};

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.invoke(name, "setTransforms", parameters, signature);
mbs.invoke(name, "defineEventProbes", parameters, signature);
}

public void test() {

0 comments on commit afcf74d

Please sign in to comment.