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();
}
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();
}
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();
}
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);
}
}
}
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();
}
Aggregations