Search in sources :

Example 1 with GraalError

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!");
            }
        }
    }
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) GraalError(org.graalvm.compiler.debug.GraalError) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IfNode(org.graalvm.compiler.nodes.IfNode)

Example 2 with GraalError

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;
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with GraalError

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;
}
Also used : KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotNarrowOopStamp(org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode) HotSpotResolvedPrimitiveType(jdk.vm.ci.hotspot.HotSpotResolvedPrimitiveType) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) GraalError(org.graalvm.compiler.debug.GraalError) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 4 with GraalError

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);
    }
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError) BarrierType(org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType)

Example 5 with GraalError

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);
    }
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError) BarrierType(org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType)

Aggregations

GraalError (org.graalvm.compiler.debug.GraalError)42 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)9 ValueNode (org.graalvm.compiler.nodes.ValueNode)8 DebugContext (org.graalvm.compiler.debug.DebugContext)7 Indent (org.graalvm.compiler.debug.Indent)5 IOException (java.io.IOException)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 Node (org.graalvm.compiler.graph.Node)4 OptionValues (org.graalvm.compiler.options.OptionValues)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 ArrayList (java.util.ArrayList)3 CompilationResult (org.graalvm.compiler.code.CompilationResult)3 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 Invoke (org.graalvm.compiler.nodes.Invoke)3 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)3 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)3 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)2 InstalledCode (jdk.vm.ci.code.InstalledCode)2