use of org.graalvm.compiler.replacements.arraycopy.ArrayCopyCallNode in project graal by oracle.
the class HotSpotGraphBuilderPlugins method registerStringPlugins.
private static void registerStringPlugins(InvocationPlugins plugins, Replacements replacements, WordTypes wordTypes, ArrayCopyForeignCalls foreignCalls, GraalHotSpotVMConfig vmConfig) {
final Registration utf16r = new Registration(plugins, "java.lang.StringUTF16", replacements);
utf16r.register(new InvocationPlugin("toBytes", char[].class, int.class, int.class) {
private static final int MAX_LENGTH = Integer.MAX_VALUE >> 1;
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value, ValueNode srcBegin, ValueNode length) {
try (HotSpotInvocationPluginHelper helper = new HotSpotInvocationPluginHelper(b, targetMethod, vmConfig)) {
helper.intrinsicRangeCheck(srcBegin, Condition.LT, ConstantNode.forInt(0));
helper.intrinsicRangeCheck(length, Condition.LT, ConstantNode.forInt(0));
helper.intrinsicRangeCheck(length, Condition.GT, ConstantNode.forInt(MAX_LENGTH));
ValueNode valueLength = b.add(new ArrayLengthNode(value));
ValueNode limit = b.add(new SubNode(valueLength, length));
helper.intrinsicRangeCheck(srcBegin, Condition.GT, limit);
ValueNode newArray = b.add(new NewArrayNode(b.getMetaAccess().lookupJavaType(Byte.TYPE), b.add(new LeftShiftNode(length, ConstantNode.forInt(1))), false));
b.addPush(JavaKind.Object, newArray);
// The stateAfter should include the value pushed, so push it first and then
// perform the call that fills in the array.
b.add(new ArrayCopyCallNode(foreignCalls, wordTypes, value, srcBegin, newArray, ConstantNode.forInt(0), length, JavaKind.Char, LocationIdentity.init(), false, true, true, vmConfig.heapWordSize));
}
return true;
}
});
utf16r.register(new InvocationPlugin("getChars", byte[].class, int.class, int.class, char[].class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value, ValueNode srcBegin, ValueNode srcEnd, ValueNode dst, ValueNode dstBegin) {
try (HotSpotInvocationPluginHelper helper = new HotSpotInvocationPluginHelper(b, targetMethod, vmConfig)) {
ValueNode length = helper.sub(srcEnd, srcBegin);
helper.intrinsicRangeCheck(srcBegin, Condition.LT, ConstantNode.forInt(0));
helper.intrinsicRangeCheck(length, Condition.LT, ConstantNode.forInt(0));
ValueNode srcLimit = helper.sub(helper.shr(helper.length(value), 1), length);
helper.intrinsicRangeCheck(srcBegin, Condition.GT, srcLimit);
ValueNode limit = helper.sub(helper.length(dst), length);
helper.intrinsicRangeCheck(dstBegin, Condition.GT, limit);
b.add(new ArrayCopyCallNode(foreignCalls, wordTypes, value, srcBegin, dst, dstBegin, length, JavaKind.Char, JavaKind.Byte, JavaKind.Char, false, true, true, vmConfig.heapWordSize));
}
return true;
}
});
}
Aggregations