use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class MethodCallTargetNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
// attempt to devirtualize the call
if (invoke().getContextMethod() == null) {
// avoid invokes that have placeholder bcis: they do not have a valid contextType
assert (invoke().stateAfter() != null && BytecodeFrame.isPlaceholderBci(invoke().stateAfter().bci)) || BytecodeFrame.isPlaceholderBci(invoke().stateDuring().bci);
return;
}
ResolvedJavaType contextType = (invoke().stateAfter() == null && invoke().stateDuring() == null) ? null : invoke().getContextType();
ResolvedJavaMethod specialCallTarget = findSpecialCallTarget(invokeKind, receiver(), targetMethod, contextType);
if (specialCallTarget != null) {
this.setTargetMethod(specialCallTarget);
setInvokeKind(InvokeKind.Special);
return;
}
Assumptions assumptions = graph().getAssumptions();
/*
* Even though we are not registering an assumption (see comment below), the optimization is
* only valid when speculative optimizations are enabled.
*/
if (invokeKind().isIndirect() && invokeKind().isInterface() && assumptions != null) {
// check if the type of the receiver can narrow the result
ValueNode receiver = receiver();
// try to turn a interface call into a virtual call
ResolvedJavaType declaredReceiverType = targetMethod().getDeclaringClass();
/*
* We need to check the invoke kind to avoid recursive simplification for virtual
* interface methods calls.
*/
if (declaredReceiverType.isInterface()) {
ResolvedJavaType singleImplementor = declaredReceiverType.getSingleImplementor();
if (singleImplementor != null && !singleImplementor.equals(declaredReceiverType)) {
TypeReference speculatedType = TypeReference.createTrusted(assumptions, singleImplementor);
if (tryCheckCastSingleImplementor(receiver, speculatedType)) {
return;
}
}
}
if (receiver instanceof UncheckedInterfaceProvider) {
UncheckedInterfaceProvider uncheckedInterfaceProvider = (UncheckedInterfaceProvider) receiver;
Stamp uncheckedStamp = uncheckedInterfaceProvider.uncheckedStamp();
if (uncheckedStamp != null) {
TypeReference speculatedType = StampTool.typeReferenceOrNull(uncheckedStamp);
if (speculatedType != null) {
tryCheckCastSingleImplementor(receiver, speculatedType);
}
}
}
}
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class ClassIsAssignableFromNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
if (forX.isConstant() && forY.isConstant()) {
ConstantReflectionProvider constantReflection = tool.getConstantReflection();
ResolvedJavaType thisType = constantReflection.asJavaType(forX.asJavaConstant());
ResolvedJavaType otherType = constantReflection.asJavaType(forY.asJavaConstant());
if (thisType != null && otherType != null) {
return LogicConstantNode.forBoolean(thisType.isAssignableFrom(otherType));
}
}
return this;
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class RawLoadNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool) {
if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
ValueNode targetObject = object();
if (offset().isConstant() && targetObject.isConstant() && !targetObject.isNullConstant()) {
ConstantNode objectConstant = (ConstantNode) targetObject;
ResolvedJavaType type = StampTool.typeOrNull(objectConstant);
if (type != null && type.isArray()) {
JavaConstant arrayConstant = objectConstant.asJavaConstant();
if (arrayConstant != null) {
int stableDimension = objectConstant.getStableDimension();
if (stableDimension > 0) {
NodeView view = NodeView.from(tool);
long constantOffset = offset().asJavaConstant().asLong();
Constant constant = stamp(view).readConstant(tool.getConstantReflection().getMemoryAccessProvider(), arrayConstant, constantOffset);
boolean isDefaultStable = objectConstant.isDefaultStable();
if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
return ConstantNode.forConstant(stamp(view), constant, stableDimension - 1, isDefaultStable, tool.getMetaAccess());
}
}
}
}
}
}
return super.canonical(tool);
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class UnsafeAccessNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool) {
if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
if (offset().isConstant()) {
long constantOffset = offset().asJavaConstant().asLong();
// Try to canonicalize to a field access.
ResolvedJavaType receiverType = StampTool.typeOrNull(object());
if (receiverType != null) {
ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(constantOffset, accessKind());
// never a valid access of an arbitrary address.
if (field != null && field.getJavaKind() == this.accessKind()) {
assert !graph().isAfterFloatingReadPhase() : "cannot add more precise memory location after floating read phase";
return cloneAsFieldAccess(graph().getAssumptions(), field);
}
}
}
ResolvedJavaType receiverType = StampTool.typeOrNull(object());
// Try to build a better location identity.
if (receiverType != null && receiverType.isArray()) {
LocationIdentity identity = NamedLocationIdentity.getArrayLocation(receiverType.getComponentType().getJavaKind());
assert !graph().isAfterFloatingReadPhase() : "cannot add more precise memory location after floating read phase";
return cloneAsArrayAccess(offset(), identity);
}
}
return this;
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerExactMathPlugins.
public static void registerExactMathPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess) {
final ResolvedJavaType exactMathType = getRuntime().resolveType(metaAccess, "com.oracle.truffle.api.ExactMath");
Registration r = new Registration(plugins, new ResolvedJavaSymbol(exactMathType));
for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long }) {
Class<?> type = kind.toJavaClass();
r.register2("multiplyHigh", type, type, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
b.addPush(kind, new IntegerMulHighNode(x, y));
return true;
}
});
r.register2("multiplyHighUnsigned", type, type, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
b.addPush(kind, new UnsignedMulHighNode(x, y));
return true;
}
});
}
}
Aggregations