Search in sources :

Example 1 with JMXToLibGraal

use of org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal in project graal by oracle.

the class JMXToLibGraalEntryPoints method getObjectName.

/**
 * Returns the name to use to register the MBean.
 */
@JMXToLibGraal(GetObjectName)
@CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_management_JMXToLibGraalCalls_getObjectName")
@SuppressWarnings({ "try", "unused" })
static JNI.JString getObjectName(JNI.JNIEnv env, JNI.JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) {
    JNIMethodScope scope = LibGraalUtil.openScope(JMXToLibGraalEntryPoints.class, GetObjectName, env);
    try (JNIMethodScope s = scope) {
        ObjectHandles globalHandles = ObjectHandles.getGlobal();
        MBeanProxy<?> registration = globalHandles.get(WordFactory.pointer(handle));
        String name = registration.getName();
        scope.setObjectResult(JNIUtil.createHSString(env, name));
    }
    return scope.getObjectResult();
}
Also used : ObjectHandles(org.graalvm.nativeimage.ObjectHandles) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) JMXToLibGraal(org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal)

Example 2 with JMXToLibGraal

use of org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal in project graal by oracle.

the class JMXToLibGraalEntryPoints method getAttributes.

/**
 * Returns the required {@link DynamicMBean}'s attribute values encoded as a byte array using
 * {@link OptionsEncoder}.
 */
@JMXToLibGraal(GetAttributes)
@CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_management_JMXToLibGraalCalls_getAttributes")
@SuppressWarnings({ "try", "unused" })
static JNI.JByteArray getAttributes(JNI.JNIEnv env, JNI.JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle, JNI.JObjectArray requiredAttributes) {
    JNIMethodScope scope = LibGraalUtil.openScope(JMXToLibGraalEntryPoints.class, GetAttributes, env);
    try (JNIMethodScope s = scope) {
        int len = JNIUtil.GetArrayLength(env, requiredAttributes);
        String[] attrNames = new String[len];
        for (int i = 0; i < len; i++) {
            JNI.JString el = (JNI.JString) JNIUtil.GetObjectArrayElement(env, requiredAttributes, i);
            attrNames[i] = JNIUtil.createString(env, el);
        }
        MBeanProxy<?> registration = ObjectHandles.getGlobal().get(WordFactory.pointer(handle));
        AttributeList attributesList = registration.getBean().getAttributes(attrNames);
        scope.setObjectResult(attributeListToRaw(env, attributesList));
    }
    return scope.getObjectResult();
}
Also used : JNI(org.graalvm.jniutils.JNI) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) AttributeList(javax.management.AttributeList) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) JMXToLibGraal(org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal)

Example 3 with JMXToLibGraal

use of org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal in project graal by oracle.

the class JMXToLibGraalEntryPoints method invoke.

/**
 * Invokes an action on {@link DynamicMBean}.
 */
@JMXToLibGraal(Invoke)
@CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_management_JMXToLibGraalCalls_invoke")
@SuppressWarnings({ "try", "unused" })
static JNI.JByteArray invoke(JNI.JNIEnv env, JNI.JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle, JNI.JString hsActionName, JNI.JByteArray hsParams, JNI.JObjectArray hsSignature) {
    JNIMethodScope scope = LibGraalUtil.openScope(JMXToLibGraalEntryPoints.class, Invoke, env);
    try (JNIMethodScope s = scope) {
        String actionName = JNIUtil.createString(env, hsActionName);
        int len = hsSignature.isNull() ? 0 : JNIUtil.GetArrayLength(env, hsSignature);
        String[] signature = new String[len];
        for (int i = 0; i < len; i++) {
            signature[i] = JNIUtil.createString(env, (JNI.JString) JNIUtil.GetObjectArrayElement(env, hsSignature, i));
        }
        Map<String, Object> map = rawToMap(env, hsParams);
        Object[] params = map.values().toArray(new Object[map.size()]);
        MBeanProxy<?> registration = ObjectHandles.getGlobal().get(WordFactory.pointer(handle));
        try {
            Object result = registration.getBean().invoke(actionName, params, signature);
            AttributeList attributesList = new AttributeList();
            if (result != null) {
                attributesList.add(new Attribute("result", result));
            }
            scope.setObjectResult(attributeListToRaw(env, attributesList));
        } catch (MBeanException | ReflectionException e) {
            scope.setObjectResult(WordFactory.nullPointer());
        }
    }
    return scope.getObjectResult();
}
Also used : ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) AttributeList(javax.management.AttributeList) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) MBeanException(javax.management.MBeanException) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) JMXToLibGraal(org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal)

Example 4 with JMXToLibGraal

use of org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal in project graal by oracle.

the class JMXToLibGraalEntryPoints method finishRegistration.

/**
 * Notifies the {@link MBeanProxy} about finished registration.
 */
@JMXToLibGraal(FinishRegistration)
@CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_management_JMXToLibGraalCalls_finishRegistration")
@SuppressWarnings({ "try", "unused" })
static void finishRegistration(JNI.JNIEnv env, JNI.JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, JNI.JLongArray handles) {
    try (JNIMethodScope s = LibGraalUtil.openScope(JMXToLibGraalEntryPoints.class, FinishRegistration, env)) {
        long len = JNIUtil.GetArrayLength(env, handles);
        CLongPointer elems = JNIUtil.GetLongArrayElements(env, handles, WordFactory.nullPointer());
        try {
            ObjectHandles globalHandles = ObjectHandles.getGlobal();
            for (int i = 0; i < len; i++) {
                MBeanProxy<?> registration = globalHandles.get(WordFactory.pointer(elems.read(i)));
                registration.finishRegistration();
            }
        } finally {
            JNIUtil.ReleaseLongArrayElements(env, handles, elems, JNI.JArray.MODE_RELEASE);
        }
    }
}
Also used : ObjectHandles(org.graalvm.nativeimage.ObjectHandles) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) CLongPointer(org.graalvm.nativeimage.c.type.CLongPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) JMXToLibGraal(org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal)

Example 5 with JMXToLibGraal

use of org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal in project graal by oracle.

the class JMXToLibGraalEntryPoints method setAttributes.

/**
 * Sets the given {@link DynamicMBean}'s attribute values.
 */
@JMXToLibGraal(SetAttributes)
@CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_management_JMXToLibGraalCalls_setAttributes")
@SuppressWarnings({ "try", "unused" })
static JNI.JByteArray setAttributes(JNI.JNIEnv env, JNI.JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle, JNI.JByteArray attributes) {
    JNIMethodScope scope = LibGraalUtil.openScope(JMXToLibGraalEntryPoints.class, SetAttributes, env);
    try (JNIMethodScope s = scope) {
        Map<String, Object> map = rawToMap(env, attributes);
        AttributeList attributesList = new AttributeList();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            attributesList.add(new Attribute(entry.getKey(), entry.getValue()));
        }
        MBeanProxy<?> registration = ObjectHandles.getGlobal().get(WordFactory.pointer(handle));
        attributesList = registration.getBean().setAttributes(attributesList);
        scope.setObjectResult(attributeListToRaw(env, attributesList));
    }
    return scope.getObjectResult();
}
Also used : Attribute(javax.management.Attribute) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) AttributeList(javax.management.AttributeList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) JMXToLibGraal(org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal)

Aggregations

JMXToLibGraal (org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal)7 JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)7 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)7 ObjectHandles (org.graalvm.nativeimage.ObjectHandles)4 AttributeList (javax.management.AttributeList)3 LinkedHashMap (java.util.LinkedHashMap)2 Attribute (javax.management.Attribute)2 JNI (org.graalvm.jniutils.JNI)2 CLongPointer (org.graalvm.nativeimage.c.type.CLongPointer)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 MBeanException (javax.management.MBeanException)1 MBeanInfo (javax.management.MBeanInfo)1 MBeanOperationInfo (javax.management.MBeanOperationInfo)1 ReflectionException (javax.management.ReflectionException)1 GetMBeanInfo (org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal.Id.GetMBeanInfo)1