use of org.graalvm.compiler.hotspot.HotSpotGraalManagementRegistration in project graal by oracle.
the class HotSpotGraalManagementTest method publicJmxApiOfGraalDumpOperation.
/**
* Tests publicaly visible names and identifiers used by tools developed and distributed on an
* independent schedule (like VisualVM). Consider keeping the test passing without any semantic
* modifications. The cost of changes is higher than you estimate. Include all available
* stakeholders as reviewers to give them a chance to stop you before causing too much damage.
*/
@Test
public void publicJmxApiOfGraalDumpOperation() throws Exception {
assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());
HotSpotGraalRuntime runtime = (HotSpotGraalRuntime) Graal.getRuntime();
HotSpotGraalManagementRegistration management = runtime.getManagement();
if (management == null) {
return;
}
ObjectName mbeanName;
assertNotNull("Bean is registered", mbeanName = (ObjectName) management.poll(true));
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
assertEquals("Domain name is used to lookup the beans by VisualVM", "org.graalvm.compiler.hotspot", mbeanName.getDomain());
assertEquals("type can be used to identify the Graal bean", "HotSpotGraalRuntime_VM", mbeanName.getKeyProperty("type"));
ObjectInstance bean = server.getObjectInstance(mbeanName);
assertNotNull("Bean is registered", bean);
MBeanInfo info = server.getMBeanInfo(mbeanName);
assertNotNull("Info is found", info);
final MBeanOperationInfo[] arr = info.getOperations();
MBeanOperationInfo dumpOp = null;
int dumpMethodCount = 0;
for (int i = 0; i < arr.length; i++) {
if ("dumpMethod".equals(arr[i].getName())) {
if (arr[i].getSignature().length == 3) {
dumpOp = arr[i];
}
dumpMethodCount++;
}
}
assertEquals("Currently three overloads", 3, dumpMethodCount);
assertNotNull("three args variant (as used by VisualVM) found", dumpOp);
MBeanAttributeInfo dumpPath = findAttributeInfo("DumpPath", info);
MBeanAttributeInfo printGraphFile = findAttributeInfo("PrintGraphFile", info);
MBeanAttributeInfo showDumpFiles = findAttributeInfo("ShowDumpFiles", info);
MBeanAttributeInfo methodFilter = findAttributeInfo("MethodFilter", info);
Object originalDumpPath = server.getAttribute(mbeanName, dumpPath.getName());
Object originalPrintGraphFile = server.getAttribute(mbeanName, printGraphFile.getName());
Object originalShowDumpFiles = server.getAttribute(mbeanName, showDumpFiles.getName());
Object originalMethodFilter = server.getAttribute(mbeanName, methodFilter.getName());
final File tmpDir = new File(HotSpotGraalManagementTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
server.setAttribute(mbeanName, new Attribute(dumpPath.getName(), quoted(tmpDir)));
server.setAttribute(mbeanName, new Attribute(methodFilter.getName(), ""));
// Force output to a file even if there's a running IGV instance available.
server.setAttribute(mbeanName, new Attribute(printGraphFile.getName(), true));
server.setAttribute(mbeanName, new Attribute(showDumpFiles.getName(), false));
Object[] params = { "java.util.Arrays", "asList", ":3" };
try {
server.invoke(mbeanName, "dumpMethod", params, null);
boolean found = false;
String expectedIgvDumpSuffix = "[Arrays.asList(Object[])List].bgv";
Assert.assertTrue(tmpDir.toString() + " was not created or is not a directory", tmpDir.isDirectory());
List<String> dumpPathEntries = Arrays.asList(tmpDir.list());
for (String entry : dumpPathEntries) {
if (entry.endsWith(expectedIgvDumpSuffix)) {
found = true;
}
}
if (!found) {
Assert.fail(String.format("Expected file ending with \"%s\" in %s but only found:%n%s", expectedIgvDumpSuffix, tmpDir, dumpPathEntries.stream().collect(Collectors.joining(System.lineSeparator()))));
}
} finally {
if (tmpDir.isDirectory()) {
deleteDirectory(tmpDir.toPath());
}
server.setAttribute(mbeanName, new Attribute(dumpPath.getName(), originalDumpPath));
server.setAttribute(mbeanName, new Attribute(methodFilter.getName(), originalMethodFilter));
server.setAttribute(mbeanName, new Attribute(printGraphFile.getName(), originalPrintGraphFile));
server.setAttribute(mbeanName, new Attribute(showDumpFiles.getName(), originalShowDumpFiles));
}
}
use of org.graalvm.compiler.hotspot.HotSpotGraalManagementRegistration in project graal by oracle.
the class HotSpotGraalManagementTest method registration.
@Test
public void registration() throws Exception {
HotSpotGraalRuntime runtime = (HotSpotGraalRuntime) Graal.getRuntime();
HotSpotGraalManagementRegistration management = runtime.getManagement();
if (management == null) {
return;
}
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName name;
assertNotNull("Now the bean thinks it is registered", name = (ObjectName) management.poll(true));
assertNotNull("And the bean is found", server.getObjectInstance(name));
}
use of org.graalvm.compiler.hotspot.HotSpotGraalManagementRegistration in project graal by oracle.
the class HotSpotGraalManagementTest method readBeanInfo.
@Test
public void readBeanInfo() throws Exception {
assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());
HotSpotGraalRuntime runtime = (HotSpotGraalRuntime) Graal.getRuntime();
HotSpotGraalManagementRegistration management = runtime.getManagement();
if (management == null) {
return;
}
ObjectName mbeanName;
assertNotNull("Bean is registered", mbeanName = (ObjectName) management.poll(true));
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectInstance bean = server.getObjectInstance(mbeanName);
assertNotNull("Bean is registered", bean);
MBeanInfo info = server.getMBeanInfo(mbeanName);
assertNotNull("Info is found", info);
AttributeList originalValues = new AttributeList();
AttributeList newValues = new AttributeList();
for (OptionDescriptors set : OptionsParser.getOptionsLoader()) {
for (OptionDescriptor option : set) {
JunitShield.testOption(info, mbeanName, server, runtime, option, newValues, originalValues);
}
}
String[] attributeNames = new String[originalValues.size()];
for (int i = 0; i < attributeNames.length; i++) {
attributeNames[i] = ((Attribute) originalValues.get(i)).getName();
}
AttributeList actualValues = server.getAttributes(mbeanName, attributeNames);
assertEquals(originalValues.size(), actualValues.size());
for (int i = 0; i < attributeNames.length; i++) {
Object expect = String.valueOf(((Attribute) originalValues.get(i)).getValue());
Object actual = String.valueOf(((Attribute) actualValues.get(i)).getValue());
assertEquals(attributeNames[i], expect, actual);
}
try {
server.setAttributes(mbeanName, newValues);
} finally {
server.setAttributes(mbeanName, originalValues);
}
}
Aggregations