001/*
002 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.replacements.nodes;
024
025import jdk.internal.jvmci.meta.*;
026
027import com.oracle.graal.compiler.common.type.*;
028import com.oracle.graal.graph.*;
029import com.oracle.graal.nodeinfo.*;
030import com.oracle.graal.nodes.*;
031import com.oracle.graal.nodes.calc.*;
032import com.oracle.graal.nodes.extended.*;
033import com.oracle.graal.nodes.memory.HeapAccess.BarrierType;
034import com.oracle.graal.nodes.memory.address.*;
035import com.oracle.graal.nodes.spi.*;
036
037/**
038 * A special purpose store node that differs from {@link UnsafeStoreNode} in that it is not a
039 * {@link StateSplit} and does not include a write barrier. Note that contrary to the sound of the
040 * name this node can be used for storing any kind.
041 */
042@NodeInfo
043public final class DirectObjectStoreNode extends FixedWithNextNode implements Lowerable {
044
045    public static final NodeClass<DirectObjectStoreNode> TYPE = NodeClass.create(DirectObjectStoreNode.class);
046    @Input ValueNode object;
047    @Input ValueNode value;
048    @Input ValueNode offset;
049    protected final int displacement;
050    protected final LocationIdentity locationIdentity;
051    protected final Kind storeKind;
052
053    public DirectObjectStoreNode(ValueNode object, int displacement, ValueNode offset, ValueNode value, LocationIdentity locationIdentity, Kind storeKind) {
054        super(TYPE, StampFactory.forVoid());
055        this.object = object;
056        this.value = value;
057        this.offset = offset;
058        this.displacement = displacement;
059        this.locationIdentity = locationIdentity;
060        this.storeKind = storeKind;
061    }
062
063    @NodeIntrinsic
064    public static native void storeObject(Object obj, @ConstantNodeParameter int displacement, long offset, Object value, @ConstantNodeParameter LocationIdentity locationIdentity,
065                    @ConstantNodeParameter Kind storeKind);
066
067    @NodeIntrinsic
068    public static native void storeBoolean(Object obj, @ConstantNodeParameter int displacement, long offset, boolean value, @ConstantNodeParameter LocationIdentity locationIdenity,
069                    @ConstantNodeParameter Kind storeKind);
070
071    @NodeIntrinsic
072    public static native void storeByte(Object obj, @ConstantNodeParameter int displacement, long offset, byte value, @ConstantNodeParameter LocationIdentity locationIdenity,
073                    @ConstantNodeParameter Kind storeKind);
074
075    @NodeIntrinsic
076    public static native void storeChar(Object obj, @ConstantNodeParameter int displacement, long offset, char value, @ConstantNodeParameter LocationIdentity locationIdenity,
077                    @ConstantNodeParameter Kind storeKind);
078
079    @NodeIntrinsic
080    public static native void storeShort(Object obj, @ConstantNodeParameter int displacement, long offset, short value, @ConstantNodeParameter LocationIdentity locationIdenity,
081                    @ConstantNodeParameter Kind storeKind);
082
083    @NodeIntrinsic
084    public static native void storeInt(Object obj, @ConstantNodeParameter int displacement, long offset, int value, @ConstantNodeParameter LocationIdentity locationIdenity,
085                    @ConstantNodeParameter Kind storeKind);
086
087    @NodeIntrinsic
088    public static native void storeLong(Object obj, @ConstantNodeParameter int displacement, long offset, long value, @ConstantNodeParameter LocationIdentity locationIdenity,
089                    @ConstantNodeParameter Kind storeKind);
090
091    @NodeIntrinsic
092    public static native void storeFloat(Object obj, @ConstantNodeParameter int displacement, long offset, float value, @ConstantNodeParameter LocationIdentity locationIdenity,
093                    @ConstantNodeParameter Kind storeKind);
094
095    @NodeIntrinsic
096    public static native void storeDouble(Object obj, @ConstantNodeParameter int displacement, long offset, double value, @ConstantNodeParameter LocationIdentity locationIdenity,
097                    @ConstantNodeParameter Kind storeKind);
098
099    @Override
100    public void lower(LoweringTool tool) {
101        ValueNode off = graph().unique(new AddNode(offset, ConstantNode.forIntegerStamp(offset.stamp(), displacement, graph())));
102        AddressNode address = graph().unique(new OffsetAddressNode(object, off));
103        JavaWriteNode write = graph().add(new JavaWriteNode(storeKind, address, locationIdentity, value, BarrierType.NONE, storeKind == Kind.Object, false));
104        graph().replaceFixedWithFixed(this, write);
105
106        tool.getLowerer().lower(write, tool);
107    }
108}