use of org.graalvm.libgraal.LibGraalScope in project graal by oracle.
the class LibGraalMBean method setAttributes.
/**
* Sets the values of several attributes of the Dynamic MBean by delegating to
* {@link DynamicMBean} instance in the libgraal heap.
*
* @param attributes a list of attributes: The identification of the attributes to be set and
* the values they are to be set to.
*/
@Override
public AttributeList setAttributes(AttributeList attributes) {
try (LibGraalScope scope = new LibGraalScope(isolate)) {
Map<String, Object> map = new LinkedHashMap<>();
for (Object item : attributes) {
Attribute attribute = (Attribute) item;
map.put(attribute.getName(), attribute.getValue());
}
byte[] rawData = OptionsEncoder.encode(map);
rawData = JMXToLibGraalCalls.setAttributes(scope.getIsolateThreadAddress(), handle, rawData);
return rawToAttributeList(rawData);
}
}
use of org.graalvm.libgraal.LibGraalScope in project graal by oracle.
the class LibGraalMBean method getMBeanInfo.
/**
* Provides the attributes and actions of the Dynamic MBean by delegating to
* {@link DynamicMBean} instance in the libgraal heap.
*/
@Override
public MBeanInfo getMBeanInfo() {
try (LibGraalScope scope = new LibGraalScope(isolate)) {
byte[] rawData = JMXToLibGraalCalls.getMBeanInfo(scope.getIsolateThreadAddress(), handle);
Map<String, Object> map = OptionsEncoder.decode(rawData);
String className = null;
String description = null;
List<MBeanAttributeInfo> attributes = new ArrayList<>();
List<MBeanOperationInfo> operations = new ArrayList<>();
for (PushBackIterator<Map.Entry<String, Object>> it = new PushBackIterator<>(map.entrySet().iterator()); it.hasNext(); ) {
Map.Entry<String, ?> entry = it.next();
String key = entry.getKey();
if (key.equals("bean.class")) {
className = (String) entry.getValue();
} else if (key.equals("bean.description")) {
description = (String) entry.getValue();
} else if (key.startsWith("attr.")) {
String attrName = (String) entry.getValue();
if (!key.equals("attr." + attrName + ".name")) {
throw new IllegalStateException("Invalid order of attribute properties");
}
MBeanAttributeInfo attr = createAttributeInfo(attrName, it);
attributes.add(attr);
} else if (key.startsWith("op.")) {
int opId = (Integer) entry.getValue();
if (!key.equals("op." + opId + ".id")) {
throw new IllegalStateException("Invalid order of operation properties");
}
MBeanOperationInfo op = createOperationInfo(opId, it);
operations.add(op);
}
}
Objects.requireNonNull(className, "ClassName must be non null.");
Objects.requireNonNull(description, "Description must be non null.");
return new MBeanInfo(className, description, attributes.toArray(new MBeanAttributeInfo[attributes.size()]), null, operations.toArray(new MBeanOperationInfo[operations.size()]), null);
}
}
use of org.graalvm.libgraal.LibGraalScope in project graal by oracle.
the class Factory method process.
/**
* Creates {@link LibGraalMBean}s for pending libgraal {@link DynamicMBean}s and registers them
* {@link MBeanServer}.
*
* @return {@code true}
* @throws SecurityException can be thrown by {@link MBeanServer}
* @throws UnsatisfiedLinkError can be thrown by {@link MBeanServer}
* @throws NoClassDefFoundError can be thrown by {@link MBeanServer}
* @throws UnsupportedOperationException can be thrown by {@link MBeanServer}
*/
private boolean process() {
for (Iterator<Long> iter = pendingIsolates.iterator(); iter.hasNext(); ) {
long isolate = iter.next();
iter.remove();
try (LibGraalScope scope = new LibGraalScope(isolate)) {
long isolateThread = scope.getIsolateThreadAddress();
long[] handles = JMXToLibGraalCalls.pollRegistrations(isolateThread);
if (handles.length > 0) {
List<ObjectName> objectNames = new ArrayList<>(handles.length);
try {
for (long handle : handles) {
LibGraalMBean bean = new LibGraalMBean(isolate, handle);
String name = JMXToLibGraalCalls.getObjectName(isolateThread, handle);
try {
ObjectName objectName = new ObjectName(name);
objectNames.add(objectName);
if (isLibGraalMBean(objectName)) {
if (aggregatedMemoryPoolBean == null) {
aggregatedMemoryPoolBean = new AggregatedMemoryPoolBean(bean, objectName);
platformMBeanServer.registerMBean(aggregatedMemoryPoolBean, aggregatedMemoryPoolBean.getObjectName());
} else {
aggregatedMemoryPoolBean.addDelegate(bean, objectName);
}
}
platformMBeanServer.registerMBean(bean, objectName);
} catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
e.printStackTrace(TTY.out);
}
}
} finally {
if (mbeansForActiveIsolate == null) {
mbeansForActiveIsolate = new HashMap<>();
}
mbeansForActiveIsolate.put(isolate, objectNames.toArray(new ObjectName[objectNames.size()]));
}
}
}
}
return true;
}
use of org.graalvm.libgraal.LibGraalScope in project graal by oracle.
the class LibGraalHotSpotTruffleCompiler method installTruffleReservedOopMethod.
@Override
@SuppressWarnings("try")
public void installTruffleReservedOopMethod(ResolvedJavaMethod method) {
try (LibGraalScope scope = new LibGraalScope(LibGraalScope.DetachAction.DETACH_RUNTIME_AND_RELEASE)) {
Map<String, Object> options = previousOptions;
assert options != null : "truffle compiler was never initialized";
TruffleToLibGraalCalls.installTruffleReservedOopMethod(getIsolateThread(), handle(options, null), LibGraal.translate(method));
}
}
use of org.graalvm.libgraal.LibGraalScope in project graal by oracle.
the class LibGraalMBean method invoke.
/**
* Invokes an action on the Dynamic MBean by delegating to {@link DynamicMBean} instance in the
* libgraal heap.
*
* @param actionName the name of the action to be invoked
* @param params an array containing the parameters to be set when the action is invoked
* @param signature an array containing the signature of the action. The class objects will be
* loaded through the same class loader as the one used for loading the MBean on
* which the action is invoked
*
* @return The object returned by the action, which represents the result of invoking the action
* on the MBean specified.
*/
@Override
public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException {
try (LibGraalScope scope = new LibGraalScope(isolate)) {
Map<String, Object> paramsMap = new LinkedHashMap<>();
if (params != null) {
for (int i = 0; i < params.length; i++) {
paramsMap.put(Integer.toString(i), params[i]);
}
}
byte[] rawData = OptionsEncoder.encode(paramsMap);
rawData = JMXToLibGraalCalls.invoke(scope.getIsolateThreadAddress(), handle, actionName, rawData, signature);
if (rawData == null) {
throw new MBeanException(null);
}
AttributeList attributesList = rawToAttributeList(rawData);
return attributesList.isEmpty() ? null : ((Attribute) attributesList.get(0)).getValue();
}
}
Aggregations