Search in sources :

Example 1 with JNIMethodScope

use of org.graalvm.jniutils.JNIMethodScope 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 JNIMethodScope

use of org.graalvm.jniutils.JNIMethodScope 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 JNIMethodScope

use of org.graalvm.jniutils.JNIMethodScope 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 JNIMethodScope

use of org.graalvm.jniutils.JNIMethodScope 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 JNIMethodScope

use of org.graalvm.jniutils.JNIMethodScope 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

JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)36 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)32 TruffleToLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)25 GetSuppliedString (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString)12 JString (org.graalvm.jniutils.JNI.JString)12 JNIUtil.createHSString (org.graalvm.jniutils.JNIUtil.createHSString)12 JNIUtil.createString (org.graalvm.jniutils.JNIUtil.createString)12 HotSpotTruffleCompilerImpl (org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl)9 JMXToLibGraal (org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal)7 JObject (org.graalvm.jniutils.JNI.JObject)7 TruffleDebugContext (org.graalvm.compiler.truffle.common.TruffleDebugContext)5 TruffleCompilationIdentifier (org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier)4 HSObject (org.graalvm.jniutils.HSObject)4 ObjectHandles (org.graalvm.nativeimage.ObjectHandles)4 AttributeList (javax.management.AttributeList)3 CompilableTruffleAST (org.graalvm.compiler.truffle.common.CompilableTruffleAST)3 TruffleCompilation (org.graalvm.compiler.truffle.common.TruffleCompilation)3 TruffleFromLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal)3 JNI (org.graalvm.jniutils.JNI)3 JObjectArray (org.graalvm.jniutils.JNI.JObjectArray)3