use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin in project graal by oracle.
the class StandardGraphBuilderPlugins method registerStringPlugins.
private static void registerStringPlugins(InvocationPlugins plugins, Replacements replacements, SnippetReflectionProvider snippetReflection, boolean arrayEqualsSubstitution) {
final Registration r = new Registration(plugins, String.class, replacements);
r.register(new InvocationPlugin("hashCode", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (receiver.isConstant()) {
String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
if (s != null) {
b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
return true;
}
}
return false;
}
});
r.register(new InvocationPlugin("intern", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (receiver.isConstant()) {
String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
if (s != null) {
JavaConstant interned = snippetReflection.forObject(s.intern());
b.addPush(JavaKind.Object, b.add(ConstantNode.forConstant(interned, b.getMetaAccess(), b.getGraph())));
return true;
}
}
return false;
}
});
if (arrayEqualsSubstitution) {
r.register(new StringEqualsInvocationPlugin());
}
final Registration utf16r = new Registration(plugins, "java.lang.StringUTF16", replacements);
utf16r.setAllowOverwrite(true);
utf16r.register(new InvocationPlugin("getChar", byte[].class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
b.addPush(JavaKind.Char, new JavaReadNode(JavaKind.Char, new IndexAddressNode(arg1, new LeftShiftNode(arg2, ConstantNode.forInt(1)), JavaKind.Byte), NamedLocationIdentity.getArrayLocation(JavaKind.Byte), BarrierType.NONE, false));
return true;
}
});
utf16r.register(new InvocationPlugin("putChar", byte[].class, int.class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3) {
b.add(new JavaWriteNode(JavaKind.Char, new IndexAddressNode(arg1, new LeftShiftNode(arg2, ConstantNode.forInt(1)), JavaKind.Byte), NamedLocationIdentity.getArrayLocation(JavaKind.Byte), arg3, BarrierType.NONE, false));
return true;
}
});
Registration sr = new Registration(plugins, StringHelperIntrinsics.class);
sr.register(new InlineOnlyInvocationPlugin("getByte", byte[].class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
b.addPush(JavaKind.Byte, new JavaReadNode(JavaKind.Byte, new IndexAddressNode(arg1, arg2, JavaKind.Byte), NamedLocationIdentity.getArrayLocation(JavaKind.Byte), BarrierType.NONE, false));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin in project graal by oracle.
the class StandardGraphBuilderPlugins method registerJFRThrowablePlugins.
private static void registerJFRThrowablePlugins(InvocationPlugins plugins, Replacements replacements) {
Registration r = new Registration(plugins, "oracle.jrockit.jfr.jdkevents.ThrowableTracer", replacements);
r.register(new InlineOnlyInvocationPlugin("traceThrowable", Throwable.class, String.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode throwable, ValueNode message) {
b.add(new VirtualizableInvokeMacroNode(MacroParams.of(b, targetMethod, throwable, message)));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin in project graal by oracle.
the class StandardGraphBuilderPlugins method registerPreconditionsPlugins.
private static void registerPreconditionsPlugins(InvocationPlugins plugins, Replacements replacements) {
final Registration preconditions = new Registration(plugins, "jdk.internal.util.Preconditions", replacements);
preconditions.register(new InlineOnlyInvocationPlugin("checkIndex", int.class, int.class, BiFunction.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode index, ValueNode length, ValueNode oobef) {
if (b.needsExplicitException()) {
return false;
} else {
ValueNode checkedIndex = index;
ValueNode checkedLength = length;
LogicNode lengthNegative = IntegerLessThanNode.create(length, ConstantNode.forInt(0), NodeView.DEFAULT);
if (!lengthNegative.isContradiction()) {
FixedGuardNode guard = b.append(new FixedGuardNode(lengthNegative, DeoptimizationReason.BoundsCheckException, DeoptimizationAction.InvalidateRecompile, true));
checkedLength = PiNode.create(length, length.stamp(NodeView.DEFAULT).improveWith(StampFactory.positiveInt()), guard);
}
LogicNode rangeCheck = IntegerBelowNode.create(index, checkedLength, NodeView.DEFAULT);
if (!rangeCheck.isTautology()) {
FixedGuardNode guard = b.append(new FixedGuardNode(rangeCheck, DeoptimizationReason.BoundsCheckException, DeoptimizationAction.InvalidateRecompile));
long upperBound = Math.max(0, ((IntegerStamp) checkedLength.stamp(NodeView.DEFAULT)).upperBound() - 1);
checkedIndex = PiNode.create(index, index.stamp(NodeView.DEFAULT).improveWith(StampFactory.forInteger(JavaKind.Int, 0, upperBound)), guard);
}
b.addPush(JavaKind.Int, checkedIndex);
return true;
}
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin in project graal by oracle.
the class StandardGraphBuilderPlugins method registerClassPlugins.
private static void registerClassPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Class.class);
r.register(new InvocationPlugin("isInstance", Receiver.class, Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode object) {
LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), type.get(), object, false));
b.push(JavaKind.Boolean, b.append(new ConditionalNode(condition).canonical(null)));
return true;
}
});
r.register(new InvocationPlugin("isAssignableFrom", Receiver.class, Class.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode otherType) {
ClassIsAssignableFromNode condition = b.append(new ClassIsAssignableFromNode(type.get(), b.nullCheckedValue(otherType)));
b.push(JavaKind.Boolean, b.append(new ConditionalNode(condition).canonical(null)));
return true;
}
});
r.register(new InvocationPlugin("isArray", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
LogicNode isArray = b.add(ClassIsArrayNode.create(b.getConstantReflection(), receiver.get()));
b.addPush(JavaKind.Boolean, ConditionalNode.create(isArray, NodeView.DEFAULT));
return true;
}
});
r.register(new InlineOnlyInvocationPlugin("cast", Receiver.class, Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
b.genCheckcastDynamic(object, receiver.get());
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin in project graal by oracle.
the class HotSpotGraphBuilderPlugins method registerReferencePlugins.
private static void registerReferencePlugins(InvocationPlugins plugins, Replacements replacements) {
Registration r = new Registration(plugins, Reference.class, replacements);
r.register(new InlineOnlyInvocationPlugin("refersTo0", Receiver.class, Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode o) {
ValueNode offset = b.add(ConstantNode.forLong(HotSpotReplacementsUtil.referentOffset(b.getMetaAccess())));
AddressNode address = b.add(new OffsetAddressNode(receiver.get(), offset));
FieldLocationIdentity locationIdentity = new FieldLocationIdentity(HotSpotReplacementsUtil.referentField(b.getMetaAccess()));
JavaReadNode read = b.add(new JavaReadNode(StampFactory.object(), JavaKind.Object, address, locationIdentity, BarrierType.WEAK_FIELD, true));
LogicNode objectEquals = b.add(ObjectEqualsNode.create(b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), read, o, NodeView.DEFAULT));
b.addPush(JavaKind.Boolean, ConditionalNode.create(objectEquals, b.add(forBoolean(true)), b.add(forBoolean(false)), NodeView.DEFAULT));
return true;
}
@Override
public boolean isOptional() {
return JavaVersionUtil.JAVA_SPEC < 16;
}
});
r = new Registration(plugins, PhantomReference.class, replacements);
r.register(new InlineOnlyInvocationPlugin("refersTo0", Receiver.class, Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode o) {
ValueNode offset = b.add(ConstantNode.forLong(HotSpotReplacementsUtil.referentOffset(b.getMetaAccess())));
AddressNode address = b.add(new OffsetAddressNode(receiver.get(), offset));
FieldLocationIdentity locationIdentity = new FieldLocationIdentity(HotSpotReplacementsUtil.referentField(b.getMetaAccess()));
JavaReadNode read = b.add(new JavaReadNode(StampFactory.object(), JavaKind.Object, address, locationIdentity, BarrierType.PHANTOM_FIELD, true));
LogicNode objectEquals = b.add(ObjectEqualsNode.create(b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), read, o, NodeView.DEFAULT));
b.addPush(JavaKind.Boolean, ConditionalNode.create(objectEquals, b.add(forBoolean(true)), b.add(forBoolean(false)), NodeView.DEFAULT));
return true;
}
@Override
public boolean isOptional() {
return JavaVersionUtil.JAVA_SPEC < 16;
}
});
}
Aggregations