Search in sources :

Example 1 with HotSpotGraalMBean

use of org.graalvm.compiler.hotspot.HotSpotGraalMBean in project graal by oracle.

the class HotSpotGraalMBeanTest method dumpOperation.

@Test
public void dumpOperation() throws Exception {
    Field field = null;
    try {
        field = stopMBeanServer();
    } catch (Exception ex) {
        if (ex.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
            // skip on JDK9
            return;
        }
    }
    assertNull("The platformMBeanServer isn't initialized now", field.get(null));
    ObjectName name;
    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());
    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);
    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);
    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);
    final MBeanOperationInfo[] arr = info.getOperations();
    assertEquals("Currently three overloads", 3, arr.length);
    MBeanOperationInfo dumpOp = null;
    for (int i = 0; i < arr.length; i++) {
        assertEquals("dumpMethod", arr[i].getName());
        if (arr[i].getSignature().length == 3) {
            dumpOp = arr[i];
        }
    }
    assertNotNull("three args variant found", dumpOp);
    server.invoke(name, "dumpMethod", new Object[] { "java.util.Arrays", "asList", ":3" }, null);
    MBeanAttributeInfo dump = (MBeanAttributeInfo) findAttributeInfo("Dump", info);
    Attribute dumpTo1 = new Attribute(dump.getName(), "");
    server.setAttribute(name, dumpTo1);
    Object after = server.getAttribute(name, dump.getName());
    assertEquals("", after);
    OptionValues empty = new OptionValues(EconomicMap.create());
    OptionValues unsetDump = realBean.optionsFor(empty, null);
    final MetaAccessProvider metaAccess = jdk.vm.ci.runtime.JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
    ResolvedJavaMethod method = metaAccess.lookupJavaMethod(Arrays.class.getMethod("asList", Object[].class));
    final OptionValues forMethod = realBean.optionsFor(unsetDump, method);
    assertNotSame(unsetDump, forMethod);
    Object nothing = unsetDump.getMap().get(DebugOptions.Dump);
    assertEquals("Empty string", "", nothing);
    Object specialValue = forMethod.getMap().get(DebugOptions.Dump);
    assertEquals(":3", specialValue);
    OptionValues normalMethod = realBean.optionsFor(unsetDump, null);
    Object noSpecialValue = normalMethod.getMap().get(DebugOptions.Dump);
    assertEquals("Empty string", "", noSpecialValue);
}
Also used : MBeanInfo(javax.management.MBeanInfo) OptionValues(org.graalvm.compiler.options.OptionValues) Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) ObjectInstance(javax.management.ObjectInstance) HotSpotGraalMBean(org.graalvm.compiler.hotspot.HotSpotGraalMBean) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Field(java.lang.reflect.Field) Arrays(java.util.Arrays) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) MBeanServer(javax.management.MBeanServer) GraalTest(org.graalvm.compiler.test.GraalTest) Test(org.junit.Test)

Example 2 with HotSpotGraalMBean

use of org.graalvm.compiler.hotspot.HotSpotGraalMBean in project graal by oracle.

the class HotSpotGraalMBeanTest method registration.

@Test
public void registration() throws Exception {
    ObjectName name;
    Field field = null;
    try {
        field = stopMBeanServer();
    } catch (Exception ex) {
        if (ex.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
            // skip on JDK9
            return;
        }
    }
    assertNull("The platformMBeanServer isn't initialized now", field.get(null));
    HotSpotGraalMBean bean = HotSpotGraalMBean.create(null);
    assertNotNull("Bean created", bean);
    assertNull("It is not registered yet", bean.ensureRegistered(true));
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    assertNotNull("Now the bean thinks it is registered", name = bean.ensureRegistered(true));
    assertNotNull("And the bean is found", server.getObjectInstance(name));
}
Also used : Field(java.lang.reflect.Field) HotSpotGraalMBean(org.graalvm.compiler.hotspot.HotSpotGraalMBean) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) GraalTest(org.graalvm.compiler.test.GraalTest) Test(org.junit.Test)

Example 3 with HotSpotGraalMBean

use of org.graalvm.compiler.hotspot.HotSpotGraalMBean in project graal by oracle.

the class HotSpotGraalMBeanTest method optionsAreCached.

@Test
public void optionsAreCached() throws Exception {
    ObjectName name;
    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());
    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);
    OptionValues original = new OptionValues(EconomicMap.create());
    assertSame(original, realBean.optionsFor(original, null));
    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);
    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);
    MBeanAttributeInfo dump = (MBeanAttributeInfo) findAttributeInfo("Dump", info);
    Attribute dumpTo1 = new Attribute(dump.getName(), 1);
    server.setAttribute(name, dumpTo1);
    Object after = server.getAttribute(name, dump.getName());
    assertEquals(1, after);
    final OptionValues modified1 = realBean.optionsFor(original, null);
    assertNotSame(original, modified1);
    final OptionValues modified2 = realBean.optionsFor(original, null);
    assertSame("Options are cached", modified1, modified2);
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) ObjectInstance(javax.management.ObjectInstance) HotSpotGraalMBean(org.graalvm.compiler.hotspot.HotSpotGraalMBean) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) GraalTest(org.graalvm.compiler.test.GraalTest) Test(org.junit.Test)

Example 4 with HotSpotGraalMBean

use of org.graalvm.compiler.hotspot.HotSpotGraalMBean in project graal by oracle.

the class HotSpotGraalMBeanTest method readBeanInfo.

@Test
public void readBeanInfo() throws Exception {
    ObjectName name;
    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());
    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);
    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);
    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);
    MBeanAttributeInfo printCompilation = (MBeanAttributeInfo) findAttributeInfo("PrintCompilation", info);
    assertNotNull("PrintCompilation found", printCompilation);
    assertEquals("true/false", Boolean.class.getName(), printCompilation.getType());
    Attribute printOn = new Attribute(printCompilation.getName(), Boolean.TRUE);
    Object before = server.getAttribute(name, printCompilation.getName());
    server.setAttribute(name, printOn);
    Object after = server.getAttribute(name, printCompilation.getName());
    assertNull("Default value was not set", before);
    assertEquals("Changed to on", Boolean.TRUE, after);
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) ObjectInstance(javax.management.ObjectInstance) HotSpotGraalMBean(org.graalvm.compiler.hotspot.HotSpotGraalMBean) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) GraalTest(org.graalvm.compiler.test.GraalTest) Test(org.junit.Test)

Aggregations

MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 HotSpotGraalMBean (org.graalvm.compiler.hotspot.HotSpotGraalMBean)4 GraalTest (org.graalvm.compiler.test.GraalTest)4 Test (org.junit.Test)4 Attribute (javax.management.Attribute)3 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)3 MBeanInfo (javax.management.MBeanInfo)3 ObjectInstance (javax.management.ObjectInstance)3 Field (java.lang.reflect.Field)2 OptionValues (org.graalvm.compiler.options.OptionValues)2 Arrays (java.util.Arrays)1 MBeanOperationInfo (javax.management.MBeanOperationInfo)1 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1