use of org.graalvm.compiler.nodes.FixedGuardNode in project graal by oracle.
the class HotSpotGraphBuilderPlugins method registerClassPlugins.
private static void registerClassPlugins(Plugins plugins, GraalHotSpotVMConfig config, BytecodeProvider bytecodeProvider) {
Registration r = new Registration(plugins.getInvocationPlugins(), Class.class, bytecodeProvider);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getModifiers", Receiver.class);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isInterface", Receiver.class);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isArray", Receiver.class);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isPrimitive", Receiver.class);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getSuperclass", Receiver.class);
if (config.getFieldOffset("ArrayKlass::_component_mirror", Integer.class, "oop", Integer.MAX_VALUE) != Integer.MAX_VALUE) {
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getComponentType", Receiver.class);
}
r.register2("cast", Receiver.class, Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
ValueNode javaClass = receiver.get();
LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), javaClass, object, true));
if (condition.isTautology()) {
b.addPush(JavaKind.Object, object);
} else {
FixedGuardNode fixedGuard = b.add(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
b.addPush(JavaKind.Object, DynamicPiNode.create(b.getAssumptions(), b.getConstantReflection(), object, fixedGuard, javaClass));
}
return true;
}
@Override
public boolean inlineOnly() {
return true;
}
});
}
use of org.graalvm.compiler.nodes.FixedGuardNode in project graal by oracle.
the class MethodHandleNode method maybeCastArgument.
/**
* Inserts a node to cast the argument at index to the given type if the given type is more
* concrete than the argument type.
*
* @param adder
* @param index of the argument to be cast
* @param type the type the argument should be cast to
*/
private static void maybeCastArgument(GraphAdder adder, ValueNode[] arguments, int index, JavaType type) {
ValueNode argument = arguments[index];
if (type instanceof ResolvedJavaType && !((ResolvedJavaType) type).isJavaLangObject()) {
Assumptions assumptions = adder.getAssumptions();
TypeReference targetType = TypeReference.create(assumptions, (ResolvedJavaType) type);
/*
* When an argument is a Word type, we can have a mismatch of primitive/object types
* here. Not inserting a PiNode is a safe fallback, and Word types need no additional
* type information anyway.
*/
if (targetType != null && !targetType.getType().isPrimitive() && !argument.getStackKind().isPrimitive()) {
ResolvedJavaType argumentType = StampTool.typeOrNull(argument.stamp(NodeView.DEFAULT));
if (argumentType == null || (argumentType.isAssignableFrom(targetType.getType()) && !argumentType.equals(targetType.getType()))) {
LogicNode inst = InstanceOfNode.createAllowNull(targetType, argument, null, null);
assert !inst.isAlive();
if (!inst.isTautology()) {
inst = adder.add(inst);
AnchoringNode guardAnchor = adder.getGuardAnchor();
DeoptimizationReason reason = DeoptimizationReason.ClassCastException;
DeoptimizationAction action = DeoptimizationAction.InvalidateRecompile;
JavaConstant speculation = JavaConstant.NULL_POINTER;
GuardingNode guard;
if (guardAnchor == null) {
FixedGuardNode fixedGuard = adder.add(new FixedGuardNode(inst, reason, action, speculation, false));
guard = fixedGuard;
} else {
GuardNode newGuard = adder.add(new GuardNode(inst, guardAnchor, reason, action, false, speculation));
adder.add(new ValueAnchorNode(newGuard));
guard = newGuard;
}
ValueNode valueNode = adder.add(PiNode.create(argument, StampFactory.object(targetType), guard.asNode()));
arguments[index] = valueNode;
}
}
}
}
}
use of org.graalvm.compiler.nodes.FixedGuardNode in project graal by oracle.
the class BytecodeParser method handleUnresolvedCheckCast.
/**
* @param type the unresolved type of the type check
* @param object the object value whose type is being checked against {@code type}
*/
protected void handleUnresolvedCheckCast(JavaType type, ValueNode object) {
assert !graphBuilderConfig.unresolvedIsError();
append(new FixedGuardNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), Unresolved, InvalidateRecompile));
frameState.push(JavaKind.Object, appendConstant(JavaConstant.NULL_POINTER));
}
use of org.graalvm.compiler.nodes.FixedGuardNode in project graal by oracle.
the class BytecodeParser method tryInvocationPlugin.
@SuppressWarnings("try")
protected boolean tryInvocationPlugin(InvokeKind invokeKind, ValueNode[] args, ResolvedJavaMethod targetMethod, JavaKind resultType, JavaType returnType) {
InvocationPlugin plugin = graphBuilderConfig.getPlugins().getInvocationPlugins().lookupInvocation(targetMethod);
if (plugin != null) {
if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) {
// method should be called.
assert !targetMethod.hasBytecodes() : "TODO: when does this happen?";
return false;
}
InvocationPluginReceiver pluginReceiver = invocationPluginReceiver.init(targetMethod, args);
IntrinsicGuard intrinsicGuard = null;
if (invokeKind.isIndirect()) {
intrinsicGuard = guardIntrinsic(args, targetMethod, pluginReceiver);
if (intrinsicGuard == null) {
return false;
} else if (intrinsicGuard.nonIntrinsicBranch == null) {
assert lastInstr instanceof FixedGuardNode;
}
}
InvocationPluginAssertions assertions = Assertions.assertionsEnabled() ? new InvocationPluginAssertions(plugin, args, targetMethod, resultType) : null;
try (DebugCloseable context = openNodeContext(targetMethod)) {
if (plugin.execute(this, targetMethod, pluginReceiver, args)) {
afterInvocationPluginExecution(true, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
return true;
} else {
afterInvocationPluginExecution(false, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
}
}
}
return false;
}
use of org.graalvm.compiler.nodes.FixedGuardNode in project graal by oracle.
the class BytecodeParser method emitCheckForInvokeSuperSpecial.
/**
* Checks that the class of the receiver of an {@link Bytecodes#INVOKESPECIAL} in a method
* declared in an interface (i.e., a default method) is assignable to the interface. If not,
* then deoptimize so that the interpreter can throw an {@link IllegalAccessError}.
*
* This is a check not performed by the verifier and so must be performed at runtime.
*
* @param args arguments to an {@link Bytecodes#INVOKESPECIAL} implementing a direct call to a
* method in a super class
*/
protected void emitCheckForInvokeSuperSpecial(ValueNode[] args) {
ResolvedJavaType callingClass = method.getDeclaringClass();
if (callingClass.getHostClass() != null) {
callingClass = callingClass.getHostClass();
}
if (callingClass.isInterface()) {
ValueNode receiver = args[0];
TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), callingClass);
LogicNode condition = genUnique(createInstanceOf(checkedType, receiver, null));
FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, ClassCastException, None, false));
args[0] = append(PiNode.create(receiver, StampFactory.object(checkedType, true), fixedGuard));
}
}
Aggregations