use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class BranchProbabilityNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
if (!hasUsages()) {
return;
}
if (probability.isConstant()) {
double probabilityValue = probability.asJavaConstant().asDouble();
if (probabilityValue < 0.0) {
throw new GraalError("A negative probability of " + probabilityValue + " is not allowed!");
} else if (probabilityValue > 1.0) {
throw new GraalError("A probability of more than 1.0 (" + probabilityValue + ") is not allowed!");
} else if (Double.isNaN(probabilityValue)) {
/*
* We allow NaN if the node is in unreachable code that will eventually fall away,
* or else an error will be thrown during lowering since we keep the node around.
*/
return;
}
boolean usageFound = false;
for (IntegerEqualsNode node : this.usages().filter(IntegerEqualsNode.class)) {
assert node.condition() == CanonicalCondition.EQ;
ValueNode other = node.getX();
if (node.getX() == this) {
other = node.getY();
}
if (other.isConstant()) {
double probabilityToSet = probabilityValue;
if (other.asJavaConstant().asInt() == 0) {
probabilityToSet = 1.0 - probabilityToSet;
}
for (IfNode ifNodeUsages : node.usages().filter(IfNode.class)) {
usageFound = true;
ifNodeUsages.setTrueSuccessorProbability(probabilityToSet);
}
if (!usageFound) {
usageFound = node.usages().filter(NodePredicates.isA(FixedGuardNode.class).or(ConditionalNode.class)).isNotEmpty();
}
}
}
if (usageFound) {
ValueNode currentCondition = condition;
replaceAndDelete(currentCondition);
if (tool != null) {
tool.addToWorkList(currentCondition.usages());
}
} else {
if (!isSubstitutionGraph()) {
throw new GraalError("Wrong usage of branch probability injection!");
}
}
}
}
use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class MethodSubstitutionPlugin method getJavaSubstitute.
/**
* Gets the reflection API version of the substitution method.
*/
Method getJavaSubstitute() throws GraalError {
Method substituteMethod = lookupSubstitute();
int modifiers = substituteMethod.getModifiers();
if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
throw new GraalError("Substitution method must not be abstract or native: " + substituteMethod);
}
if (!Modifier.isStatic(modifiers)) {
throw new GraalError("Substitution method must be static: " + substituteMethod);
}
return substituteMethod;
}
use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class LoadJavaMirrorWithKlassPhase method getClassConstantReplacement.
private ValueNode getClassConstantReplacement(StructuredGraph graph, PhaseContext context, JavaConstant constant) {
if (constant instanceof HotSpotObjectConstant) {
ConstantReflectionProvider constantReflection = context.getConstantReflection();
ResolvedJavaType type = constantReflection.asJavaType(constant);
if (type != null) {
MetaAccessProvider metaAccess = context.getMetaAccess();
Stamp stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(Class.class)));
if (type instanceof HotSpotResolvedObjectType) {
ConstantNode klass = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), ((HotSpotResolvedObjectType) type).klass(), metaAccess, graph);
ValueNode getClass = graph.unique(new HubGetClassNode(metaAccess, klass));
if (((HotSpotObjectConstant) constant).isCompressed()) {
return HotSpotCompressionNode.compress(getClass, oopEncoding);
} else {
return getClass;
}
} else {
/*
* Primitive classes are more difficult since they don't have a corresponding
* Klass* so get them from Class.TYPE for the java box type.
*/
HotSpotResolvedPrimitiveType primitive = (HotSpotResolvedPrimitiveType) type;
ResolvedJavaType boxingClass = metaAccess.lookupJavaType(primitive.getJavaKind().toBoxedJavaClass());
ConstantNode clazz = ConstantNode.forConstant(context.getConstantReflection().asJavaClass(boxingClass), metaAccess, graph);
HotSpotResolvedJavaField[] a = (HotSpotResolvedJavaField[]) boxingClass.getStaticFields();
HotSpotResolvedJavaField typeField = null;
for (HotSpotResolvedJavaField f : a) {
if (f.getName().equals("TYPE")) {
typeField = f;
break;
}
}
if (typeField == null) {
throw new GraalError("Can't find TYPE field in class");
}
if (oopEncoding != null) {
stamp = HotSpotNarrowOopStamp.compressed((AbstractObjectStamp) stamp, oopEncoding);
}
AddressNode address = graph.unique(new OffsetAddressNode(clazz, ConstantNode.forLong(typeField.offset(), graph)));
ValueNode read = graph.unique(new FloatingReadNode(address, FINAL_LOCATION, null, stamp));
if (oopEncoding == null || ((HotSpotObjectConstant) constant).isCompressed()) {
return read;
} else {
return HotSpotCompressionNode.uncompress(read, oopEncoding);
}
}
}
}
return null;
}
use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class WriteBarrierAdditionPhase method addAtomicReadWriteNodeBarriers.
private void addAtomicReadWriteNodeBarriers(LoweredAtomicReadAndWriteNode node, StructuredGraph graph) {
BarrierType barrierType = node.getBarrierType();
switch(barrierType) {
case NONE:
// nothing to do
break;
case IMPRECISE:
case PRECISE:
boolean precise = barrierType == BarrierType.PRECISE;
if (config.useG1GC) {
addG1PreWriteBarrier(node, node.getAddress(), null, true, node.getNullCheck(), graph);
addG1PostWriteBarrier(node, node.getAddress(), node.getNewValue(), precise, graph);
} else {
addSerialPostWriteBarrier(node, node.getAddress(), node.getNewValue(), precise, graph);
}
break;
default:
throw new GraalError("unexpected barrier type: " + barrierType);
}
}
use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class WriteBarrierAdditionPhase method addCASBarriers.
private void addCASBarriers(AbstractCompareAndSwapNode node, StructuredGraph graph) {
BarrierType barrierType = node.getBarrierType();
switch(barrierType) {
case NONE:
// nothing to do
break;
case IMPRECISE:
case PRECISE:
boolean precise = barrierType == BarrierType.PRECISE;
if (config.useG1GC) {
addG1PreWriteBarrier(node, node.getAddress(), node.getExpectedValue(), false, false, graph);
addG1PostWriteBarrier(node, node.getAddress(), node.getNewValue(), precise, graph);
} else {
addSerialPostWriteBarrier(node, node.getAddress(), node.getNewValue(), precise, graph);
}
break;
default:
throw new GraalError("unexpected barrier type: " + barrierType);
}
}
Aggregations