use of jdk.vm.ci.meta.Assumptions in project graal by oracle.
the class PEGraphDecoder method doInline.
protected LoopScope doInline(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, InlineInfo inlineInfo, ValueNode[] arguments) {
ResolvedJavaMethod inlineMethod = inlineInfo.getMethodToInline();
EncodedGraph graphToInline = lookupEncodedGraph(inlineMethod, inlineInfo.getOriginalMethod(), inlineInfo.getIntrinsicBytecodeProvider(), graph.trackNodeSourcePosition());
if (graphToInline == null) {
return null;
}
assert !graph.trackNodeSourcePosition() || graphToInline.trackNodeSourcePosition() : graph + " " + graphToInline;
if (methodScope.inliningDepth > Options.InliningDepthError.getValue(options)) {
throw tooDeepInlining(methodScope);
}
for (InlineInvokePlugin plugin : inlineInvokePlugins) {
plugin.notifyBeforeInline(inlineMethod);
}
Invoke invoke = invokeData.invoke;
FixedNode invokeNode = invoke.asNode();
FixedWithNextNode predecessor = (FixedWithNextNode) invokeNode.predecessor();
invokeNode.replaceAtPredecessor(null);
PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, graphToInline, inlineMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
if (!inlineMethod.isStatic()) {
if (StampTool.isPointerAlwaysNull(arguments[0])) {
/*
* The receiver is null, so we can unconditionally throw a NullPointerException
* instead of performing any inlining.
*/
DeoptimizeNode deoptimizeNode = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.NullCheckException));
predecessor.setNext(deoptimizeNode);
finishInlining(inlineScope);
/* Continue decoding in the caller. */
return loopScope;
} else if (!StampTool.isPointerNonNull(arguments[0])) {
/* The receiver might be null, so we need to insert a null check. */
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, predecessor);
arguments[0] = graphBuilderContext.nullCheckedValue(arguments[0]);
predecessor = graphBuilderContext.lastInstr;
}
}
LoopScope inlineLoopScope = createInitialLoopScope(inlineScope, predecessor);
/*
* The GraphEncoder assigns parameters a nodeId immediately after the fixed nodes.
* Initializing createdNodes here avoid decoding and immediately replacing the
* ParameterNodes.
*/
int firstArgumentNodeId = inlineScope.maxFixedNodeOrderId + 1;
for (int i = 0; i < arguments.length; i++) {
inlineLoopScope.createdNodes[firstArgumentNodeId + i] = arguments[i];
}
// Copy assumptions from inlinee to caller
Assumptions assumptions = graph.getAssumptions();
Assumptions inlinedAssumptions = graphToInline.getAssumptions();
if (assumptions != null) {
if (inlinedAssumptions != null) {
assumptions.record(inlinedAssumptions);
}
} else {
assert inlinedAssumptions == null : String.format("cannot inline graph (%s) which makes assumptions into a graph (%s) that doesn't", inlineMethod, graph);
}
// Copy inlined methods from inlinee to caller
List<ResolvedJavaMethod> inlinedMethods = graphToInline.getInlinedMethods();
if (inlinedMethods != null) {
graph.getMethods().addAll(inlinedMethods);
}
if (graphToInline.getFields() != null) {
for (ResolvedJavaField field : graphToInline.getFields()) {
graph.recordField(field);
}
}
if (graphToInline.hasUnsafeAccess()) {
graph.markUnsafeAccess();
}
/*
* Do the actual inlining by returning the initial loop scope for the inlined method scope.
*/
return inlineLoopScope;
}
use of jdk.vm.ci.meta.Assumptions 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.Assumptions in project graal by oracle.
the class LoadMethodNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool) {
if (hub instanceof LoadHubNode) {
ValueNode object = ((LoadHubNode) hub).getValue();
TypeReference type = StampTool.typeReferenceOrNull(object);
if (type != null) {
if (type.isExact()) {
return resolveExactMethod(tool, type.getType());
}
Assumptions assumptions = graph().getAssumptions();
AssumptionResult<ResolvedJavaMethod> resolvedMethod = type.getType().findUniqueConcreteMethod(method);
if (resolvedMethod != null && resolvedMethod.canRecordTo(assumptions) && !type.getType().isInterface() && method.getDeclaringClass().isAssignableFrom(type.getType())) {
NodeView view = NodeView.from(tool);
resolvedMethod.recordTo(assumptions);
return ConstantNode.forConstant(stamp(view), resolvedMethod.getResult().getEncoding(), tool.getMetaAccess());
}
}
}
if (hub.isConstant()) {
return resolveExactMethod(tool, tool.getConstantReflection().asJavaType(hub.asConstant()));
}
return this;
}
use of jdk.vm.ci.meta.Assumptions in project graal by oracle.
the class TypeReference method createTrusted.
/**
* Create a type reference using the given type with assumptions and trusting interface types.
*/
public static TypeReference createTrusted(Assumptions assumptions, ResolvedJavaType type) {
if (type == null) {
return null;
}
ResolvedJavaType exactType = type.isLeaf() ? type : null;
if (exactType == null) {
Assumptions.AssumptionResult<ResolvedJavaType> leafConcreteSubtype = type.findLeafConcreteSubtype();
if (leafConcreteSubtype != null && leafConcreteSubtype.canRecordTo(assumptions)) {
leafConcreteSubtype.recordTo(assumptions);
exactType = leafConcreteSubtype.getResult();
}
}
if (exactType == null) {
return new TypeReference(type, false);
}
return new TypeReference(exactType, true);
}
Aggregations