use of com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerArraysPlugins.
private static void registerArraysPlugins(InvocationPlugins plugins, boolean analysis) {
Registration r = new Registration(plugins, Arrays.class).setAllowOverwrite(true);
r.register2("copyOf", Object[].class, int.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode original, ValueNode newLength) {
if (analysis) {
b.addPush(JavaKind.Object, new AnalysisArraysCopyOfNode(b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp(), original, newLength));
} else {
/* Get the class from the original node. */
GetClassNode originalArrayType = b.add(new GetClassNode(original.stamp(NodeView.DEFAULT), b.nullCheckedValue(original)));
ValueNode originalLength = b.add(ArrayLengthNode.create(original, b.getConstantReflection()));
Stamp stamp = b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp().join(original.stamp(NodeView.DEFAULT));
b.addPush(JavaKind.Object, new SubstrateArraysCopyOfNode(stamp, original, originalLength, newLength, originalArrayType));
}
return true;
}
});
r.register3("copyOf", Object[].class, int.class, Class.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode original, ValueNode newLength, ValueNode newArrayType) {
if (analysis) {
/*
* If the new array type comes from a GetClassNode or is a constant we can infer
* the concrete type of the new array, otherwise we conservatively assume that
* the new array can have any of the instantiated array types.
*/
b.addPush(JavaKind.Object, new AnalysisArraysCopyOfNode(b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp(), original, newLength, newArrayType));
} else {
Stamp stamp;
if (newArrayType.isConstant()) {
ResolvedJavaType newType = b.getConstantReflection().asJavaType(newArrayType.asConstant());
stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(newType));
} else {
stamp = b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp();
}
ValueNode originalLength = b.add(ArrayLengthNode.create(original, b.getConstantReflection()));
b.addPush(JavaKind.Object, new SubstrateArraysCopyOfNode(stamp, original, originalLength, newLength, newArrayType));
}
return true;
}
});
}
use of com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode in project graal by oracle.
the class PointstoGraphBuilderPlugins method registerArraysPlugins.
public static void registerArraysPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Arrays.class).setAllowOverwrite(true);
r.register2("copyOf", Object[].class, int.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode original, ValueNode newLength) {
b.addPush(JavaKind.Object, new AnalysisArraysCopyOfNode(b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp(), original, newLength));
return true;
}
});
r.register3("copyOf", Object[].class, int.class, Class.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode original, ValueNode newLength, ValueNode newObjectElementType) {
if (newObjectElementType instanceof GetClassNode || newObjectElementType.isConstant()) {
// We can infer the concrete type of the new array
b.addPush(JavaKind.Object, new AnalysisArraysCopyOfNode(b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp(), original, newLength, newObjectElementType));
return true;
}
return false;
}
});
}
Aggregations