use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class VerifyUpdateUsages method verify.
@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
if (graph.method().isConstructor()) {
return true;
}
/*
* There are only two acceptable patterns for methods which update Node inputs, either a
* single StoreField node and invoke of updateUsages or updateUsagesInterface, or 2
* StoreFields that come from LoadFields on the same object. Other patterns can be added as
* needed but it would be best to keep things simple so that verification can be simple.
*/
List<StoreFieldNode> stores = graph.getNodes().filter(StoreFieldNode.class).snapshot();
ResolvedJavaType declaringClass = graph.method().getDeclaringClass();
ResolvedJavaType nodeInputList = context.getMetaAccess().lookupJavaType(NodeInputList.class);
StoreFieldNode storeField1 = null;
StoreFieldNode storeField2 = null;
for (StoreFieldNode store : stores) {
if (isNodeInput(store.field(), declaringClass, nodeInputList)) {
if (storeField1 == null) {
storeField1 = store;
} else if (storeField2 == null) {
storeField2 = store;
} else {
return false;
}
}
}
if (storeField1 == null) {
return true;
}
if (storeField2 == null) {
// Single input field update so just check for updateUsages or updateUsagesInterface
// call
ResolvedJavaType node = context.getMetaAccess().lookupJavaType(Node.class);
for (MethodCallTargetNode call : graph.getNodes().filter(MethodCallTargetNode.class)) {
ResolvedJavaMethod callee = call.targetMethod();
if (callee.getDeclaringClass().equals(node) && (callee.getName().equals("updateUsages") || callee.getName().equals("updateUsagesInterface"))) {
return true;
}
}
} else {
if (storeField1.value() instanceof LoadFieldNode && storeField2.value() instanceof LoadFieldNode) {
LoadFieldNode load1 = (LoadFieldNode) storeField1.value();
LoadFieldNode load2 = (LoadFieldNode) storeField2.value();
// Check for swapping values within the same object
if (load1.object() == storeField1.object() && load2.object() == storeField2.object() && storeField1.object() == storeField2.object() && load1.field().equals(storeField2.field()) && load2.field().equals(storeField1.field())) {
return true;
}
}
}
return false;
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class VerifyVirtualizableUsage method verifyVirtualizableEffectArguments.
private static void verifyVirtualizableEffectArguments(ResolvedJavaType constantNodeType, ResolvedJavaMethod caller, ResolvedJavaMethod callee, int bciCaller, NodeInputList<? extends Node> arguments, int startIdx) {
/*
* Virtualizable.virtualize should never apply effects on the graph during the execution of
* the call as the handling of loops during pea might be speculative and does not hold. We
* should only allow nodes changing the graph that do no harm like constants.
*/
int i = 0;
for (Node arg : arguments) {
if (i >= startIdx) {
Stamp argStamp = ((ValueNode) arg).stamp(NodeView.DEFAULT);
if (argStamp instanceof ObjectStamp) {
ObjectStamp objectStamp = (ObjectStamp) argStamp;
ResolvedJavaType argStampType = objectStamp.type();
if (!(argStampType.equals(constantNodeType))) {
StackTraceElement e = caller.asStackTraceElement(bciCaller);
throw new VerificationError("%s:Parameter %d in call to %s (which has effects on the graph) is not a " + "constant and thus not safe to apply during speculative virtualization.", e, i, callee.format("%H.%n(%p)"));
}
}
}
i++;
}
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class VerifyBailoutUsage method verify.
@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
final ResolvedJavaType bailoutType = context.getMetaAccess().lookupJavaType(BailoutException.class);
ResolvedJavaMethod caller = graph.method();
String holderQualified = caller.format("%H");
String holderUnqualified = caller.format("%h");
String packageName = holderQualified.substring(0, holderQualified.length() - holderUnqualified.length() - 1);
if (!matchesPrefix(packageName)) {
for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
ResolvedJavaMethod callee = t.targetMethod();
if (callee.getDeclaringClass().equals(bailoutType)) {
// we only allow the getter
if (!callee.getName().equals("isPermanent")) {
throw new VerificationError("Call to %s at callsite %s is prohibited. Consider using %s for permanent bailouts or %s for retryables.", callee.format("%H.%n(%p)"), caller.format("%H.%n(%p)"), PermanentBailoutException.class.getName(), RetryableBailoutException.class.getName());
}
}
}
}
return true;
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class VerifyGetOptionsUsage method verify.
@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
MetaAccessProvider metaAccess = context.getMetaAccess();
ResolvedJavaType canonicalizerToolClass = metaAccess.lookupJavaType(CanonicalizerTool.class);
boolean hasTool = false;
try {
for (ResolvedJavaMethod.Parameter parameter : graph.method().getParameters()) {
if (parameter.getType().getName().equals(canonicalizerToolClass.getName())) {
hasTool = true;
break;
}
}
} catch (MalformedParametersException e) {
// Lambdas sometimes have malformed parameters so ignore this.
}
if (hasTool) {
ResolvedJavaMethod getOptionsMethod = metaAccess.lookupJavaMethod(lookupMethod(Node.class, "getOptions"));
for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
ResolvedJavaMethod callee = t.targetMethod();
if (callee.equals(getOptionsMethod)) {
if (hasTool) {
throw new VerificationError("Must use CanonicalizerTool.getOptions() instead of Node.getOptions() in method '%s' of class '%s'.", graph.method().getName(), graph.method().getDeclaringClass().getName());
}
}
}
}
return true;
}
use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.
the class VerifyGraphAddUsage method verify.
@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
boolean allowed = false;
for (Class<?> cls : ALLOWED_CLASSES) {
ResolvedJavaType declaringClass = graph.method().getDeclaringClass();
if (context.getMetaAccess().lookupJavaType(cls).isAssignableFrom(declaringClass)) {
allowed = true;
}
}
if (!allowed) {
ResolvedJavaMethod addOrUniqueMethod = context.getMetaAccess().lookupJavaMethod(ADD_OR_UNIQUE);
for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
ResolvedJavaMethod callee = t.targetMethod();
if (callee.equals(addOrUniqueMethod)) {
ValueNode nodeArgument = t.arguments().get(1);
EconomicSet<Node> seen = EconomicSet.create();
checkNonFactory(graph, seen, context, nodeArgument);
}
}
}
return true;
}
Aggregations