Search in sources :

Example 6 with BarrierType

use of org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType in project graal by oracle.

the class WordOperationPlugin method writeOp.

protected void writeOp(GraphBuilderContext b, JavaKind writeKind, AddressNode address, LocationIdentity location, ValueNode value, Opcode op) {
    assert op == Opcode.WRITE_POINTER || op == Opcode.WRITE_POINTER_SIDE_EFFECT_FREE || op == Opcode.WRITE_OBJECT || op == Opcode.WRITE_BARRIERED || op == Opcode.INITIALIZE || op == Opcode.WRITE_POINTER_VOLATILE;
    assert op != Opcode.INITIALIZE || location.isInit() : "must use init location for initializing";
    final BarrierType barrier = (op == Opcode.WRITE_BARRIERED ? BarrierType.UNKNOWN : BarrierType.NONE);
    final boolean compressible = (op == Opcode.WRITE_OBJECT || op == Opcode.WRITE_BARRIERED);
    final boolean hasSideEffect = (op != Opcode.WRITE_POINTER_SIDE_EFFECT_FREE);
    final MemoryOrderMode memoryOrder = op == Opcode.WRITE_POINTER_VOLATILE ? MemoryOrderMode.VOLATILE : MemoryOrderMode.PLAIN;
    b.add(new JavaWriteNode(writeKind, address, location, value, barrier, compressible, hasSideEffect, memoryOrder));
}
Also used : JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode) MemoryOrderMode(org.graalvm.compiler.core.common.memory.MemoryOrderMode) BarrierType(org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType)

Example 7 with BarrierType

use of org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType in project graal by oracle.

the class WordOperationPlugin method processWordOperation.

protected void processWordOperation(GraphBuilderContext b, ValueNode[] args, ResolvedJavaMethod wordMethod) throws GraalError {
    JavaKind returnKind = wordMethod.getSignature().getReturnKind();
    WordFactoryOperation factoryOperation = BridgeMethodUtils.getAnnotation(WordFactoryOperation.class, wordMethod);
    if (factoryOperation != null) {
        switch(factoryOperation.opcode()) {
            case ZERO:
                assert args.length == 0;
                b.addPush(returnKind, forIntegerKind(wordKind, 0L));
                return;
            case FROM_UNSIGNED:
                assert args.length == 1;
                b.push(returnKind, fromUnsigned(b, args[0]));
                return;
            case FROM_SIGNED:
                assert args.length == 1;
                b.push(returnKind, fromSigned(b, args[0]));
                return;
        }
    }
    Word.Operation operation = BridgeMethodUtils.getAnnotation(Word.Operation.class, wordMethod);
    if (operation == null) {
        throw bailout(b, "Cannot call method on a word value: " + wordMethod.format("%H.%n(%p)"));
    }
    switch(operation.opcode()) {
        case NODE_CLASS:
        case INTEGER_DIVISION_NODE_CLASS:
            assert args.length == 2;
            ValueNode left = args[0];
            ValueNode right = operation.rightOperandIsInt() ? toUnsigned(b, args[1], JavaKind.Int) : fromSigned(b, args[1]);
            b.addPush(returnKind, createBinaryNodeInstance(b, operation.node(), left, right, operation.opcode() == Opcode.INTEGER_DIVISION_NODE_CLASS));
            break;
        case COMPARISON:
            assert args.length == 2;
            b.push(returnKind, comparisonOp(b, operation.condition(), args[0], fromSigned(b, args[1])));
            break;
        case IS_NULL:
            assert args.length == 1;
            b.push(returnKind, comparisonOp(b, Condition.EQ, args[0], ConstantNode.forIntegerKind(wordKind, 0L)));
            break;
        case IS_NON_NULL:
            assert args.length == 1;
            b.push(returnKind, comparisonOp(b, Condition.NE, args[0], ConstantNode.forIntegerKind(wordKind, 0L)));
            break;
        case NOT:
            assert args.length == 1;
            b.addPush(returnKind, new XorNode(args[0], b.add(forIntegerKind(wordKind, -1))));
            break;
        case READ_POINTER:
        case READ_OBJECT:
        case READ_BARRIERED:
            {
                assert args.length == 2 || args.length == 3;
                JavaKind readKind = wordTypes.asKind(wordMethod.getSignature().getReturnType(wordMethod.getDeclaringClass()));
                AddressNode address = makeAddress(b, args[0], args[1]);
                LocationIdentity location;
                if (args.length == 2) {
                    location = any();
                } else {
                    assert args[2].isConstant() : args[2];
                    location = snippetReflection.asObject(LocationIdentity.class, args[2].asJavaConstant());
                    assert location != null : snippetReflection.asObject(Object.class, args[2].asJavaConstant());
                }
                b.push(returnKind, readOp(b, readKind, address, location, operation.opcode()));
                break;
            }
        case READ_POINTER_VOLATILE:
        case READ_BARRIERED_VOLATILE:
            {
                assert args.length == 2 || args.length == 3;
                JavaKind readKind = wordTypes.asKind(wordMethod.getSignature().getReturnType(wordMethod.getDeclaringClass()));
                AddressNode address = makeAddress(b, args[0], args[1]);
                LocationIdentity location;
                if (args.length == 2) {
                    location = any();
                } else {
                    assert args[2].isConstant() : args[2];
                    location = snippetReflection.asObject(LocationIdentity.class, args[2].asJavaConstant());
                    assert location != null : snippetReflection.asObject(Object.class, args[2].asJavaConstant());
                }
                b.push(returnKind, readVolatileOp(b, readKind, address, location, operation.opcode()));
                break;
            }
        case READ_HEAP:
            {
                assert args.length == 3 || args.length == 4;
                JavaKind readKind = wordTypes.asKind(wordMethod.getSignature().getReturnType(wordMethod.getDeclaringClass()));
                AddressNode address = makeAddress(b, args[0], args[1]);
                BarrierType barrierType = snippetReflection.asObject(BarrierType.class, args[2].asJavaConstant());
                LocationIdentity location;
                if (args.length == 3) {
                    location = any();
                } else {
                    assert args[3].isConstant();
                    location = snippetReflection.asObject(LocationIdentity.class, args[3].asJavaConstant());
                }
                b.push(returnKind, readOp(b, readKind, address, location, barrierType, true));
                break;
            }
        case WRITE_POINTER:
        case WRITE_OBJECT:
        case WRITE_BARRIERED:
        case INITIALIZE:
        case WRITE_POINTER_SIDE_EFFECT_FREE:
        case WRITE_POINTER_VOLATILE:
            {
                assert args.length == 3 || args.length == 4;
                JavaKind writeKind = wordTypes.asKind(wordMethod.getSignature().getParameterType(wordMethod.isStatic() ? 2 : 1, wordMethod.getDeclaringClass()));
                AddressNode address = makeAddress(b, args[0], args[1]);
                LocationIdentity location;
                if (args.length == 3) {
                    location = any();
                } else {
                    assert args[3].isConstant();
                    location = snippetReflection.asObject(LocationIdentity.class, args[3].asJavaConstant());
                }
                writeOp(b, writeKind, address, location, args[2], operation.opcode());
                break;
            }
        case TO_RAW_VALUE:
            assert args.length == 1;
            b.push(returnKind, toUnsigned(b, args[0], JavaKind.Long));
            break;
        case OBJECT_TO_TRACKED:
            assert args.length == 1;
            WordCastNode objectToTracked = b.add(WordCastNode.objectToTrackedPointer(args[0], wordKind));
            b.push(returnKind, objectToTracked);
            break;
        case OBJECT_TO_UNTRACKED:
            assert args.length == 1;
            WordCastNode objectToUntracked = b.add(WordCastNode.objectToUntrackedPointer(args[0], wordKind));
            b.push(returnKind, objectToUntracked);
            break;
        case FROM_ADDRESS:
            assert args.length == 1;
            WordCastNode addressToWord = b.add(WordCastNode.addressToWord(args[0], wordKind));
            b.push(returnKind, addressToWord);
            break;
        case TO_OBJECT:
            assert args.length == 1;
            WordCastNode wordToObject = b.add(WordCastNode.wordToObject(args[0], wordKind));
            b.push(returnKind, wordToObject);
            break;
        case TO_OBJECT_NON_NULL:
            assert args.length == 1;
            WordCastNode wordToObjectNonNull = b.add(WordCastNode.wordToObjectNonNull(args[0], wordKind));
            b.push(returnKind, wordToObjectNonNull);
            break;
        case CAS_POINTER:
            assert args.length == 5;
            AddressNode address = makeAddress(b, args[0], args[1]);
            JavaKind valueKind = wordTypes.asKind(wordMethod.getSignature().getParameterType(1, wordMethod.getDeclaringClass()));
            assert valueKind.equals(wordTypes.asKind(wordMethod.getSignature().getParameterType(2, wordMethod.getDeclaringClass()))) : wordMethod.getSignature();
            assert args[4].isConstant() : Arrays.toString(args);
            LocationIdentity location = snippetReflection.asObject(LocationIdentity.class, args[4].asJavaConstant());
            JavaType returnType = wordMethod.getSignature().getReturnType(wordMethod.getDeclaringClass());
            b.addPush(returnKind, casOp(valueKind, wordTypes.asKind(returnType), address, location, args[2], args[3]));
            break;
        default:
            throw new GraalError("Unknown opcode: %s", operation.opcode());
    }
}
Also used : Operation(org.graalvm.compiler.word.Word.Operation) XorNode(org.graalvm.compiler.nodes.calc.XorNode) BarrierType(org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) GraalError(org.graalvm.compiler.debug.GraalError) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LocationIdentity(org.graalvm.word.LocationIdentity) WordFactoryOperation(org.graalvm.word.impl.WordFactoryOperation) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 8 with BarrierType

use of org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType in project graal by oracle.

the class WordOperationPlugin method readOp.

protected ValueNode readOp(GraphBuilderContext b, JavaKind readKind, AddressNode address, LocationIdentity location, Opcode op) {
    assert op == Opcode.READ_POINTER || op == Opcode.READ_OBJECT || op == Opcode.READ_BARRIERED;
    final BarrierType barrier = (op == Opcode.READ_BARRIERED ? BarrierType.UNKNOWN : BarrierType.NONE);
    final boolean compressible = (op == Opcode.READ_OBJECT || op == Opcode.READ_BARRIERED);
    return readOp(b, readKind, address, location, barrier, compressible);
}
Also used : BarrierType(org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType)

Example 9 with BarrierType

use of org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType in project graal by oracle.

the class WordOperationPlugin method readVolatileOp.

protected ValueNode readVolatileOp(GraphBuilderContext b, JavaKind readKind, AddressNode address, LocationIdentity location, Opcode op) {
    assert op == Opcode.READ_POINTER_VOLATILE || op == Opcode.READ_BARRIERED_VOLATILE;
    final BarrierType barrier = op == Opcode.READ_BARRIERED_VOLATILE ? BarrierType.UNKNOWN : BarrierType.NONE;
    final boolean compressible = op == Opcode.READ_BARRIERED_VOLATILE;
    /*
         * A JavaOrderedReadNode is lowered to an OrderedReadNode that will not float. This means it
         * cannot float above an explicit zero check on its base address or any other test that
         * ensures the read is safe.
         */
    JavaReadNode read = b.add(new JavaOrderedReadNode(readKind, address, location, barrier, MemoryOrderMode.VOLATILE, compressible));
    return read;
}
Also used : JavaReadNode(org.graalvm.compiler.nodes.extended.JavaReadNode) JavaOrderedReadNode(org.graalvm.compiler.nodes.extended.JavaOrderedReadNode) BarrierType(org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType)

Example 10 with BarrierType

use of org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType in project graal by oracle.

the class DefaultJavaLoweringProvider method lowerAtomicReadAndWriteNode.

protected void lowerAtomicReadAndWriteNode(AtomicReadAndWriteNode n) {
    StructuredGraph graph = n.graph();
    JavaKind valueKind = n.getValueKind();
    ValueNode newValue = implicitStoreConvert(graph, valueKind, n.newValue());
    AddressNode address = graph.unique(new OffsetAddressNode(n.object(), n.offset()));
    BarrierType barrierType = barrierSet.guessStoreBarrierType(n.object(), newValue);
    LIRKind lirAccessKind = LIRKind.fromJavaKind(target.arch, valueKind);
    LoweredAtomicReadAndWriteNode memoryRead = graph.add(new LoweredAtomicReadAndWriteNode(address, n.getKilledLocationIdentity(), newValue, lirAccessKind, barrierType));
    memoryRead.setStateAfter(n.stateAfter());
    ValueNode readValue = implicitLoadConvert(graph, valueKind, memoryRead);
    n.stateAfter().replaceFirstInput(n, memoryRead);
    n.replaceAtUsages(readValue);
    graph.replaceFixedWithFixed(n, memoryRead);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) GetObjectAddressNode(org.graalvm.compiler.nodes.GetObjectAddressNode) IndexAddressNode(org.graalvm.compiler.nodes.memory.address.IndexAddressNode) ComputeObjectAddressNode(org.graalvm.compiler.nodes.ComputeObjectAddressNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LIRKind(org.graalvm.compiler.core.common.LIRKind) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) BarrierType(org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

BarrierType (org.graalvm.compiler.nodes.memory.OnHeapMemoryAccess.BarrierType)13 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)9 ValueNode (org.graalvm.compiler.nodes.ValueNode)9 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)9 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)9 ComputeObjectAddressNode (org.graalvm.compiler.nodes.ComputeObjectAddressNode)8 GetObjectAddressNode (org.graalvm.compiler.nodes.GetObjectAddressNode)8 IndexAddressNode (org.graalvm.compiler.nodes.memory.address.IndexAddressNode)8 JavaKind (jdk.vm.ci.meta.JavaKind)7 JavaWriteNode (org.graalvm.compiler.nodes.extended.JavaWriteNode)4 LoweredAtomicReadAndWriteNode (org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode)4 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)3 AtomicReadAndWriteNode (org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode)3 OrderedWriteNode (org.graalvm.compiler.nodes.memory.OrderedWriteNode)3 WriteNode (org.graalvm.compiler.nodes.memory.WriteNode)3 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 LIRKind (org.graalvm.compiler.core.common.LIRKind)2 GraalError (org.graalvm.compiler.debug.GraalError)2 JavaReadNode (org.graalvm.compiler.nodes.extended.JavaReadNode)2 ArrayList (java.util.ArrayList)1