Search in sources :

Example 1 with ObjectHandles

use of org.graalvm.nativeimage.ObjectHandles 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 ObjectHandles

use of org.graalvm.nativeimage.ObjectHandles 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 3 with ObjectHandles

use of org.graalvm.nativeimage.ObjectHandles in project graal by oracle.

the class JMXToLibGraalEntryPoints method pollRegistrations.

/**
 * Returns the pending {@link DynamicMBean} registrations.
 */
@JMXToLibGraal(PollRegistrations)
@CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_management_JMXToLibGraalCalls_pollRegistrations")
@SuppressWarnings({ "try", "unused" })
static JNI.JLongArray pollRegistrations(JNI.JNIEnv env, JNI.JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId) {
    JNIMethodScope scope = LibGraalUtil.openScope(JMXToLibGraalEntryPoints.class, PollRegistrations, env);
    try (JNIMethodScope s = scope) {
        List<MBeanProxy<?>> registrations = MBeanProxy.drainRegistrations();
        JNI.JLongArray res = JNIUtil.NewLongArray(env, registrations.size());
        CLongPointer elems = JNIUtil.GetLongArrayElements(env, res, WordFactory.nullPointer());
        try {
            ObjectHandles globalHandles = ObjectHandles.getGlobal();
            for (int i = 0; i < registrations.size(); i++) {
                long handle = globalHandles.create(registrations.get(i)).rawValue();
                elems.write(i, handle);
            }
        } finally {
            JNIUtil.ReleaseLongArrayElements(env, res, elems, JNI.JArray.MODE_WRITE_RELEASE);
        }
        scope.setObjectResult(res);
    }
    return scope.getObjectResult();
}
Also used : ObjectHandles(org.graalvm.nativeimage.ObjectHandles) JNI(org.graalvm.jniutils.JNI) 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 4 with ObjectHandles

use of org.graalvm.nativeimage.ObjectHandles in project graal by oracle.

the class JMXToLibGraalEntryPoints method getMBeanInfo.

/**
 * Returns the {@link MBeanInfo} encoded as a byte array using {@link OptionsEncoder}.
 */
@JMXToLibGraal(GetMBeanInfo)
@CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_management_JMXToLibGraalCalls_getMBeanInfo")
@SuppressWarnings({ "try", "unused" })
static JNI.JByteArray getMBeanInfo(JNI.JNIEnv env, JNI.JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) {
    JNIMethodScope scope = LibGraalUtil.openScope(JMXToLibGraalEntryPoints.class, GetMBeanInfo, env);
    try (JNIMethodScope s = scope) {
        ObjectHandles globalHandles = ObjectHandles.getGlobal();
        MBeanProxy<?> registration = globalHandles.get(WordFactory.pointer(handle));
        MBeanInfo info = registration.getBean().getMBeanInfo();
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("bean.class", info.getClassName());
        map.put("bean.description", info.getDescription());
        for (MBeanAttributeInfo attr : info.getAttributes()) {
            putAttributeInfo(map, attr);
        }
        int opCounter = 0;
        for (MBeanOperationInfo op : info.getOperations()) {
            putOperationInfo(map, op, ++opCounter);
        }
        scope.setObjectResult(mapToRaw(env, map));
    }
    return scope.getObjectResult();
}
Also used : ObjectHandles(org.graalvm.nativeimage.ObjectHandles) GetMBeanInfo(org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal.Id.GetMBeanInfo) MBeanInfo(javax.management.MBeanInfo) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) LinkedHashMap(java.util.LinkedHashMap) 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)4 JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)4 ObjectHandles (org.graalvm.nativeimage.ObjectHandles)4 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)4 CLongPointer (org.graalvm.nativeimage.c.type.CLongPointer)2 LinkedHashMap (java.util.LinkedHashMap)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 MBeanInfo (javax.management.MBeanInfo)1 MBeanOperationInfo (javax.management.MBeanOperationInfo)1 GetMBeanInfo (org.graalvm.compiler.hotspot.management.libgraal.annotation.JMXToLibGraal.Id.GetMBeanInfo)1 JNI (org.graalvm.jniutils.JNI)1