Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6660: Make JMX API not return classes #32

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/org.openjdk.jmc.agent/README.md
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/org.openjdk.jmc.agent/pom.xml
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -88,7 +88,5 @@ public Class<?>[] setTransforms(String xmlDescription) throws Exception{
registry.setRevertInstrumentation(true);
instrumentation.retransformClasses(classesToRetransformArray);
registry.setRevertInstrumentation(false);

return classesToRetransformArray;
}
}
Expand Up @@ -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;
}
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down