Search in sources :

Example 36 with AddressNode

use of org.graalvm.compiler.nodes.memory.address.AddressNode in project graal by oracle.

the class HotSpotGraphBuilderPlugins method registerConstantPoolPlugins.

private static void registerConstantPoolPlugins(InvocationPlugins plugins, WordTypes wordTypes, GraalHotSpotVMConfig config, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins, constantPoolClass, bytecodeProvider);
    r.register2("getSize0", Receiver.class, Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode constantPoolOop) {
            boolean notCompressible = false;
            ValueNode constants = getMetaspaceConstantPool(b, constantPoolOop, wordTypes, config);
            AddressNode lengthAddress = b.add(new OffsetAddressNode(constants, b.add(ConstantNode.forLong(config.constantPoolLengthOffset))));
            ValueNode length = WordOperationPlugin.readOp(b, JavaKind.Int, lengthAddress, CONSTANT_POOL_LENGTH, BarrierType.NONE, notCompressible);
            b.addPush(JavaKind.Int, length);
            return true;
        }
    });
    r.register3("getIntAt0", Receiver.class, Object.class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode constantPoolOop, ValueNode index) {
            return readMetaspaceConstantPoolElement(b, constantPoolOop, index, JavaKind.Int, wordTypes, config);
        }
    });
    r.register3("getLongAt0", Receiver.class, Object.class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode constantPoolOop, ValueNode index) {
            return readMetaspaceConstantPoolElement(b, constantPoolOop, index, JavaKind.Long, wordTypes, config);
        }
    });
    r.register3("getFloatAt0", Receiver.class, Object.class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode constantPoolOop, ValueNode index) {
            return readMetaspaceConstantPoolElement(b, constantPoolOop, index, JavaKind.Float, wordTypes, config);
        }
    });
    r.register3("getDoubleAt0", Receiver.class, Object.class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode constantPoolOop, ValueNode index) {
            return readMetaspaceConstantPoolElement(b, constantPoolOop, index, JavaKind.Double, wordTypes, config);
        }
    });
}
Also used : OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 37 with AddressNode

use of org.graalvm.compiler.nodes.memory.address.AddressNode in project graal by oracle.

the class HotSpotGraphBuilderPlugins method readMetaspaceConstantPoolElement.

/**
 * Emits a node representing an element in a metaspace {@code ConstantPool}.
 *
 * @param constantPoolOop value of the {@code constantPoolOop} field in a ConstantPool value
 */
private static boolean readMetaspaceConstantPoolElement(GraphBuilderContext b, ValueNode constantPoolOop, ValueNode index, JavaKind elementKind, WordTypes wordTypes, GraalHotSpotVMConfig config) {
    ValueNode constants = getMetaspaceConstantPool(b, constantPoolOop, wordTypes, config);
    int shift = CodeUtil.log2(wordTypes.getWordKind().getByteCount());
    ValueNode scaledIndex = b.add(new LeftShiftNode(IntegerConvertNode.convert(index, StampFactory.forKind(JavaKind.Long), NodeView.DEFAULT), b.add(ConstantNode.forInt(shift))));
    ValueNode offset = b.add(new AddNode(scaledIndex, b.add(ConstantNode.forLong(config.constantPoolSize))));
    AddressNode elementAddress = b.add(new OffsetAddressNode(constants, offset));
    boolean notCompressible = false;
    ValueNode elementValue = WordOperationPlugin.readOp(b, elementKind, elementAddress, NamedLocationIdentity.getArrayLocation(elementKind), BarrierType.NONE, notCompressible);
    b.addPush(elementKind, elementValue);
    return true;
}
Also used : OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 38 with AddressNode

use of org.graalvm.compiler.nodes.memory.address.AddressNode 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();
    WordFactory.FactoryOperation factoryOperation = BridgeMethodUtils.getAnnotation(WordFactory.FactoryOperation.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:
            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(operation.node(), left, right));
            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();
                    location = snippetReflection.asObject(LocationIdentity.class, args[2].asJavaConstant());
                }
                b.push(returnKind, readOp(b, readKind, address, location, operation.opcode()));
                break;
            }
        case READ_HEAP:
            {
                assert args.length == 3;
                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());
                b.push(returnKind, readOp(b, readKind, address, any(), barrierType, true));
                break;
            }
        case WRITE_POINTER:
        case WRITE_OBJECT:
        case WRITE_BARRIERED:
        case INITIALIZE:
            {
                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 : WordFactory(org.graalvm.word.WordFactory) Operation(org.graalvm.compiler.word.Word.Operation) XorNode(org.graalvm.compiler.nodes.calc.XorNode) BarrierType(org.graalvm.compiler.nodes.memory.HeapAccess.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) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 39 with AddressNode

use of org.graalvm.compiler.nodes.memory.address.AddressNode in project graal by oracle.

the class HotSpotWordOperationPlugin method processHotSpotWordOperation.

protected void processHotSpotWordOperation(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, HotSpotOperation operation) {
    JavaKind returnKind = method.getSignature().getReturnKind();
    switch(operation.opcode()) {
        case POINTER_EQ:
        case POINTER_NE:
            assert args.length == 2;
            HotspotOpcode opcode = operation.opcode();
            ValueNode left = args[0];
            ValueNode right = args[1];
            assert left.stamp(NodeView.DEFAULT) instanceof MetaspacePointerStamp : left + " " + left.stamp(NodeView.DEFAULT);
            assert right.stamp(NodeView.DEFAULT) instanceof MetaspacePointerStamp : right + " " + right.stamp(NodeView.DEFAULT);
            assert opcode == POINTER_EQ || opcode == POINTER_NE;
            PointerEqualsNode comparison = b.add(new PointerEqualsNode(left, right));
            ValueNode eqValue = b.add(forBoolean(opcode == POINTER_EQ));
            ValueNode neValue = b.add(forBoolean(opcode == POINTER_NE));
            b.addPush(returnKind, ConditionalNode.create(comparison, eqValue, neValue, NodeView.DEFAULT));
            break;
        case IS_NULL:
            assert args.length == 1;
            ValueNode pointer = args[0];
            assert pointer.stamp(NodeView.DEFAULT) instanceof MetaspacePointerStamp;
            LogicNode isNull = b.addWithInputs(IsNullNode.create(pointer));
            b.addPush(returnKind, ConditionalNode.create(isNull, b.add(forBoolean(true)), b.add(forBoolean(false)), NodeView.DEFAULT));
            break;
        case FROM_POINTER:
            assert args.length == 1;
            b.addPush(returnKind, new PointerCastNode(StampFactory.forKind(wordKind), args[0]));
            break;
        case TO_KLASS_POINTER:
            assert args.length == 1;
            b.addPush(returnKind, new PointerCastNode(KlassPointerStamp.klass(), args[0]));
            break;
        case TO_METHOD_POINTER:
            assert args.length == 1;
            b.addPush(returnKind, new PointerCastNode(MethodPointerStamp.method(), args[0]));
            break;
        case READ_KLASS_POINTER:
            assert args.length == 2 || args.length == 3;
            Stamp readStamp = KlassPointerStamp.klass();
            AddressNode address = makeAddress(b, args[0], args[1]);
            LocationIdentity location;
            if (args.length == 2) {
                location = any();
            } else {
                assert args[2].isConstant();
                location = snippetReflection.asObject(LocationIdentity.class, args[2].asJavaConstant());
            }
            ReadNode read = b.add(new ReadNode(address, location, readStamp, BarrierType.NONE));
            b.push(returnKind, read);
            break;
        default:
            throw GraalError.shouldNotReachHere("unknown operation: " + operation.opcode());
    }
}
Also used : HotspotOpcode(org.graalvm.compiler.hotspot.word.HotSpotOperation.HotspotOpcode) MethodPointerStamp(org.graalvm.compiler.hotspot.nodes.type.MethodPointerStamp) MetaspacePointerStamp(org.graalvm.compiler.hotspot.nodes.type.MetaspacePointerStamp) KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) MetaspacePointerStamp(org.graalvm.compiler.hotspot.nodes.type.MetaspacePointerStamp) PointerEqualsNode(org.graalvm.compiler.nodes.calc.PointerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LocationIdentity(org.graalvm.word.LocationIdentity) LogicNode(org.graalvm.compiler.nodes.LogicNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) PointerCastNode(org.graalvm.compiler.hotspot.word.PointerCastNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 40 with AddressNode

use of org.graalvm.compiler.nodes.memory.address.AddressNode in project graal by oracle.

the class DefaultJavaLoweringProvider method createReadArrayLength.

/**
 * Creates a read node that read the array length and is guarded by a null-check.
 *
 * The created node is placed before {@code before} in the CFG.
 */
protected ReadNode createReadArrayLength(ValueNode array, FixedNode before, LoweringTool tool) {
    StructuredGraph graph = array.graph();
    ValueNode canonicalArray = this.createNullCheckedValue(skipPiWhileNonNull(array), before, tool);
    AddressNode address = createOffsetAddress(graph, canonicalArray, arrayLengthOffset());
    ReadNode readArrayLength = graph.add(new ReadNode(address, ARRAY_LENGTH_LOCATION, StampFactory.positiveInt(), BarrierType.NONE));
    graph.addBeforeFixed(before, readArrayLength);
    return readArrayLength;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) JavaReadNode(org.graalvm.compiler.nodes.extended.JavaReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode)

Aggregations

AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)43 ValueNode (org.graalvm.compiler.nodes.ValueNode)35 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)25 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)16 JavaKind (jdk.vm.ci.meta.JavaKind)13 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)12 Stamp (org.graalvm.compiler.core.common.type.Stamp)9 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)9 ComputeObjectAddressNode (org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode)8 GetObjectAddressNode (org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode)8 AMD64AddressNode (org.graalvm.compiler.core.amd64.AMD64AddressNode)7 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)7 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)7 JavaReadNode (org.graalvm.compiler.nodes.extended.JavaReadNode)7 WriteNode (org.graalvm.compiler.nodes.memory.WriteNode)7 Test (org.junit.Test)7 LeftShiftNode (org.graalvm.compiler.nodes.calc.LeftShiftNode)6 JavaWriteNode (org.graalvm.compiler.nodes.extended.JavaWriteNode)6 AtomicReadAndWriteNode (org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode)6 LoweredAtomicReadAndWriteNode (org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode)6