use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext in project graal by oracle.
the class StandardGraphBuilderPlugins method registerJFRThrowablePlugins.
private static void registerJFRThrowablePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
Registration r = new Registration(plugins, "oracle.jrockit.jfr.jdkevents.ThrowableTracer", bytecodeProvider);
r.register2("traceThrowable", Throwable.class, String.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode throwable, ValueNode message) {
b.add(new VirtualizableInvokeMacroNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnStamp(b.getAssumptions()), throwable, message));
return true;
}
@Override
public boolean inlineOnly() {
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext in project graal by oracle.
the class StandardGraphBuilderPlugins method registerGraalDirectivesPlugins.
private static void registerGraalDirectivesPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, GraalDirectives.class);
r.register0("deoptimize", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter));
return true;
}
});
r.register0("deoptimizeAndInvalidate", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
return true;
}
});
r.register0("deoptimizeAndInvalidateWithSpeculation", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
GraalError.guarantee(b.getGraph().getSpeculationLog() != null, "A speculation log is need to use `deoptimizeAndInvalidateWithSpeculation`");
BytecodePosition pos = new BytecodePosition(null, b.getMethod(), b.bci());
DirectiveSpeculationReason reason = new DirectiveSpeculationReason(pos);
JavaConstant speculation;
if (b.getGraph().getSpeculationLog().maySpeculate(reason)) {
speculation = b.getGraph().getSpeculationLog().speculate(reason);
} else {
speculation = JavaConstant.defaultForKind(JavaKind.Object);
}
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter, speculation));
return true;
}
});
r.register0("inCompiledCode", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
return true;
}
});
r.register0("controlFlowAnchor", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new ControlFlowAnchorNode());
return true;
}
});
r.register2("injectBranchProbability", double.class, boolean.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode probability, ValueNode condition) {
b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probability, condition));
return true;
}
});
InvocationPlugin blackholePlugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.add(new BlackholeNode(value));
return true;
}
};
InvocationPlugin bindToRegisterPlugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.add(new BindToRegisterNode(value));
return true;
}
};
for (JavaKind kind : JavaKind.values()) {
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
r.register1("blackhole", javaClass, blackholePlugin);
r.register1("bindToRegister", javaClass, bindToRegisterPlugin);
r.register1("opaque", javaClass, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.addPush(kind, new OpaqueNode(value));
return true;
}
});
}
}
InvocationPlugin spillPlugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new SpillRegistersNode());
return true;
}
};
r.register0("spillRegisters", spillPlugin);
r.register1("guardingNonNull", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.addPush(value.getStackKind(), b.nullCheckedValue(value));
return true;
}
});
r.register1("ensureVirtualized", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
b.add(new EnsureVirtualizedNode(object, false));
return true;
}
});
r.register1("ensureVirtualizedHere", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
b.add(new EnsureVirtualizedNode(object, true));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext in project graal by oracle.
the class StandardGraphBuilderPlugins method registerEdgesPlugins.
/**
* Substitutions for improving the performance of some critical methods in {@link Edges}. These
* substitutions improve the performance by forcing the relevant methods to be inlined
* (intrinsification being a special form of inlining) and removing a checked cast.
*/
private static void registerEdgesPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
Registration r = new Registration(plugins, Edges.class);
for (Class<?> c : new Class<?>[] { Node.class, NodeList.class }) {
r.register2("get" + c.getSimpleName() + "Unsafe", Node.class, long.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode node, ValueNode offset) {
ObjectStamp stamp = StampFactory.object(TypeReference.createTrusted(b.getAssumptions(), metaAccess.lookupJavaType(c)));
RawLoadNode value = b.add(new RawLoadNode(stamp, node, offset, LocationIdentity.any(), JavaKind.Object));
b.addPush(JavaKind.Object, value);
return true;
}
});
r.register3("put" + c.getSimpleName() + "Unsafe", Node.class, long.class, c, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode node, ValueNode offset, ValueNode value) {
b.add(new RawStoreNode(node, offset, value, JavaKind.Object, LocationIdentity.any()));
return true;
}
});
}
}
use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext in project graal by oracle.
the class StandardGraphBuilderPlugins method registerObjectPlugins.
private static void registerObjectPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Object.class);
r.register1("<init>", Receiver.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
/*
* Object.<init> is a common instrumentation point so only perform this rewrite if
* the current definition is the normal empty method with a single return bytecode.
* The finalizer registration will instead be performed by the BytecodeParser.
*/
if (targetMethod.getCodeSize() == 1) {
ValueNode object = receiver.get();
if (RegisterFinalizerNode.mayHaveFinalizer(object, b.getAssumptions())) {
b.add(new RegisterFinalizerNode(object));
}
return true;
}
return false;
}
});
r.register1("getClass", Receiver.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
ValueNode object = receiver.get();
ValueNode folded = GetClassNode.tryFold(b.getMetaAccess(), b.getConstantReflection(), NodeView.DEFAULT, GraphUtil.originalValue(object));
if (folded != null) {
b.addPush(JavaKind.Object, folded);
} else {
Stamp stamp = StampFactory.objectNonNull(TypeReference.createTrusted(b.getAssumptions(), b.getMetaAccess().lookupJavaType(Class.class)));
b.addPush(JavaKind.Object, new GetClassNode(stamp, object));
}
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext in project graal by oracle.
the class StandardGraphBuilderPlugins method registerUnsafePlugins.
private static void registerUnsafePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
Registration r;
if (Java8OrEarlier) {
r = new Registration(plugins, Unsafe.class);
} else {
r = new Registration(plugins, "jdk.internal.misc.Unsafe", bytecodeProvider);
}
for (JavaKind kind : JavaKind.values()) {
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
String kindName = kind.name();
String getName = "get" + kindName;
String putName = "put" + kindName;
// Object-based accesses
r.register3(getName, Receiver.class, Object.class, long.class, new UnsafeGetPlugin(kind, false));
r.register4(putName, Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, false));
// Volatile object-based accesses
r.register3(getName + "Volatile", Receiver.class, Object.class, long.class, new UnsafeGetPlugin(kind, true));
r.register4(putName + "Volatile", Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, true));
// Ordered object-based accesses
if (Java8OrEarlier) {
if (kind == JavaKind.Int || kind == JavaKind.Long || kind == JavaKind.Object) {
r.register4("putOrdered" + kindName, Receiver.class, Object.class, long.class, javaClass, UnsafePutPlugin.putOrdered(kind));
}
} else {
r.register4("put" + kindName + "Release", Receiver.class, Object.class, long.class, javaClass, UnsafePutPlugin.putOrdered(kind));
}
if (kind != JavaKind.Boolean && kind != JavaKind.Object) {
// Raw accesses to memory addresses
r.register2(getName, Receiver.class, long.class, new UnsafeGetPlugin(kind, false));
r.register3(putName, Receiver.class, long.class, kind.toJavaClass(), new UnsafePutPlugin(kind, false));
}
}
}
// Accesses to native memory addresses.
r.register2("getAddress", Receiver.class, long.class, new UnsafeGetPlugin(JavaKind.Long, false));
r.register3("putAddress", Receiver.class, long.class, long.class, new UnsafePutPlugin(JavaKind.Long, false));
for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long, JavaKind.Object }) {
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
String casName;
if (Java8OrEarlier) {
casName = "compareAndSwap";
} else {
casName = "compareAndSet";
}
r.register5(casName + kind.name(), Receiver.class, Object.class, long.class, javaClass, javaClass, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode expected, ValueNode x) {
// Emits a null-check for the otherwise unused receiver
unsafe.get();
b.addPush(JavaKind.Int, new UnsafeCompareAndSwapNode(object, offset, expected, x, kind, LocationIdentity.any()));
b.getGraph().markUnsafeAccess();
return true;
}
});
}
r.register2("allocateInstance", Receiver.class, Class.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode clazz) {
// Emits a null-check for the otherwise unused receiver
unsafe.get();
b.addPush(JavaKind.Object, new DynamicNewInstanceNode(b.nullCheckedValue(clazz, DeoptimizationAction.None), true));
return true;
}
});
r.register1("loadFence", Receiver.class, new UnsafeFencePlugin(LOAD_LOAD | LOAD_STORE));
r.register1("storeFence", Receiver.class, new UnsafeFencePlugin(STORE_STORE | LOAD_STORE));
r.register1("fullFence", Receiver.class, new UnsafeFencePlugin(LOAD_LOAD | STORE_STORE | LOAD_STORE | STORE_LOAD));
}
Aggregations