use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class MethodHandleNode method getTargetInvokeNode.
/**
* Helper function to get the {@link InvokeNode} for the targetMethod of a
* java.lang.invoke.MemberName.
*
* @param adder
* @param target the target, already loaded from the member name node
*
* @return invoke node for the member name target
*/
private static InvokeNode getTargetInvokeNode(GraphAdder adder, IntrinsicMethod intrinsicMethod, int bci, StampPair returnStamp, ValueNode[] originalArguments, ResolvedJavaMethod target, ResolvedJavaMethod original) {
if (target == null) {
return null;
}
// In lambda forms we erase signature types to avoid resolving issues
// involving class loaders. When we optimize a method handle invoke
// to a direct call we must cast the receiver and arguments to its
// actual types.
Signature signature = target.getSignature();
final boolean isStatic = target.isStatic();
final int receiverSkip = isStatic ? 0 : 1;
Assumptions assumptions = adder.getAssumptions();
ResolvedJavaMethod realTarget = null;
if (target.canBeStaticallyBound()) {
realTarget = target;
} else {
ResolvedJavaType targetType = target.getDeclaringClass();
// Try to bind based on the declaredType
AssumptionResult<ResolvedJavaMethod> concreteMethod = targetType.findUniqueConcreteMethod(target);
if (concreteMethod == null) {
// Try to get the most accurate receiver type
if (intrinsicMethod == IntrinsicMethod.LINK_TO_VIRTUAL || intrinsicMethod == IntrinsicMethod.LINK_TO_INTERFACE) {
ValueNode receiver = getReceiver(originalArguments);
TypeReference receiverType = StampTool.typeReferenceOrNull(receiver.stamp(NodeView.DEFAULT));
if (receiverType != null) {
concreteMethod = receiverType.getType().findUniqueConcreteMethod(target);
}
}
}
if (concreteMethod != null && concreteMethod.canRecordTo(assumptions)) {
concreteMethod.recordTo(assumptions);
realTarget = concreteMethod.getResult();
}
}
if (realTarget != null) {
// Don't mutate the passed in arguments
ValueNode[] arguments = originalArguments.clone();
// Cast receiver to its type.
if (!isStatic) {
JavaType receiverType = target.getDeclaringClass();
maybeCastArgument(adder, arguments, 0, receiverType);
}
// Cast reference arguments to its type.
for (int index = 0; index < signature.getParameterCount(false); index++) {
JavaType parameterType = signature.getParameterType(index, target.getDeclaringClass());
maybeCastArgument(adder, arguments, receiverSkip + index, parameterType);
}
InvokeNode invoke = createTargetInvokeNode(assumptions, intrinsicMethod, realTarget, original, bci, returnStamp, arguments);
assert invoke != null : "graph has been modified so this must result an invoke";
return invoke;
}
return null;
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class PartialEvaluator method postPartialEvaluation.
private static void postPartialEvaluation(final StructuredGraph graph) {
NeverPartOfCompilationNode.verifyNotFoundIn(graph);
for (AllowMaterializeNode materializeNode : graph.getNodes(AllowMaterializeNode.TYPE).snapshot()) {
materializeNode.replaceAtUsages(materializeNode.getFrame());
graph.removeFixed(materializeNode);
}
TruffleCompilerRuntime rt = TruffleCompilerRuntime.getRuntime();
for (VirtualObjectNode virtualObjectNode : graph.getNodes(VirtualObjectNode.TYPE)) {
if (virtualObjectNode instanceof VirtualInstanceNode) {
VirtualInstanceNode virtualInstanceNode = (VirtualInstanceNode) virtualObjectNode;
ResolvedJavaType type = virtualInstanceNode.type();
if (rt.isValueType(type)) {
virtualInstanceNode.setIdentity(false);
}
}
}
if (!TruffleCompilerOptions.getValue(TruffleInlineAcrossTruffleBoundary)) {
// Do not inline across Truffle boundaries.
for (MethodCallTargetNode mct : graph.getNodes(MethodCallTargetNode.TYPE)) {
InlineInfo inlineInfo = rt.getInlineInfo(mct.targetMethod(), false);
if (!inlineInfo.allowsInlining()) {
mct.invoke().setUseForInlining(false);
}
}
}
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class TruffleCompilerImpl method getSkippedExceptionTypes.
private ResolvedJavaType[] getSkippedExceptionTypes(TruffleCompilerRuntime runtime) {
final MetaAccessProvider metaAccess = providers.getMetaAccess();
ResolvedJavaType[] head = metaAccess.lookupJavaTypes(new Class<?>[] { ArithmeticException.class, IllegalArgumentException.class, VirtualMachineError.class, IndexOutOfBoundsException.class, ClassCastException.class, BufferUnderflowException.class, BufferOverflowException.class });
ResolvedJavaType[] tail = { runtime.resolveType(metaAccess, "com.oracle.truffle.api.nodes.UnexpectedResultException"), runtime.resolveType(metaAccess, "com.oracle.truffle.api.nodes.SlowPathException") };
ResolvedJavaType[] skippedExceptionTypes = new ResolvedJavaType[head.length + tail.length];
System.arraycopy(head, 0, skippedExceptionTypes, 0, head.length);
System.arraycopy(tail, 0, skippedExceptionTypes, head.length, tail.length);
return skippedExceptionTypes;
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerOptimizedCallTargetPlugins.
public static void registerOptimizedCallTargetPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, boolean canDelayIntrinsification, KnownTruffleTypes types) {
final ResolvedJavaType optimizedCallTargetType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedCallTarget");
Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedCallTargetType));
r.register2("createFrame", new ResolvedJavaSymbol(types.classFrameDescriptor), Object[].class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode descriptor, ValueNode args) {
if (canDelayIntrinsification) {
return false;
}
if (!descriptor.isJavaConstant()) {
throw b.bailout("Parameter 'descriptor' is not a compile-time constant");
}
ValueNode nonNullArguments = b.add(PiNode.create(args, StampFactory.objectNonNull(StampTool.typeReferenceOrNull(args))));
b.addPush(JavaKind.Object, new NewFrameNode(b, descriptor, nonNullArguments, types));
return true;
}
});
r.register2("castArrayFixedLength", Object[].class, int.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode args, ValueNode length) {
b.addPush(JavaKind.Object, new PiArrayNode(args, length, args.stamp(NodeView.DEFAULT)));
return true;
}
});
registerUnsafeCast(r, canDelayIntrinsification);
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerOptimizedAssumptionPlugins.
public static void registerOptimizedAssumptionPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, KnownTruffleTypes types) {
ResolvedJavaType optimizedAssumptionType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedAssumption");
Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedAssumptionType), null);
InvocationPlugin plugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (receiver.isConstant() && b.getAssumptions() != null) {
JavaConstant assumption = (JavaConstant) receiver.get().asConstant();
if (b.getConstantReflection().readFieldValue(types.fieldOptimizedAssumptionIsValid, assumption).asBoolean()) {
if (targetMethod.getName().equals("isValid")) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
} else {
assert targetMethod.getName().equals("check") : targetMethod;
}
b.getAssumptions().record(new TruffleAssumption(assumption));
} else {
if (targetMethod.getName().equals("isValid")) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
} else {
assert targetMethod.getName().equals("check") : targetMethod;
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.None));
}
}
return true;
} else {
return false;
}
}
};
r.register1("isValid", Receiver.class, plugin);
r.register1("check", Receiver.class, plugin);
}
Aggregations