1 /* 2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.replacements.nodes; 24 25 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_3; 26 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1; 27 28 import org.graalvm.compiler.core.common.LocationIdentity; 29 import org.graalvm.compiler.core.common.type.StampFactory; 30 import org.graalvm.compiler.graph.NodeClass; 31 import org.graalvm.compiler.nodeinfo.NodeInfo; 32 import org.graalvm.compiler.nodes.ConstantNode; 33 import org.graalvm.compiler.nodes.FixedWithNextNode; 34 import org.graalvm.compiler.nodes.StateSplit; 35 import org.graalvm.compiler.nodes.ValueNode; 36 import org.graalvm.compiler.nodes.calc.AddNode; 37 import org.graalvm.compiler.nodes.extended.JavaWriteNode; 38 import org.graalvm.compiler.nodes.extended.UnsafeStoreNode; 39 import org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType; 40 import org.graalvm.compiler.nodes.memory.address.AddressNode; 41 import org.graalvm.compiler.nodes.memory.address.OffsetAddressNode; 42 import org.graalvm.compiler.nodes.spi.Lowerable; 43 import org.graalvm.compiler.nodes.spi.LoweringTool; 44 45 import jdk.vm.ci.meta.JavaKind; 46 47 /** 48 * A special purpose store node that differs from {@link UnsafeStoreNode} in that it is not a 49 * {@link StateSplit} and does not include a write barrier. Note that contrary to the sound of the 50 * name this node can be used for storing any kind. 51 */ 52 @NodeInfo(cycles = CYCLES_3, size = SIZE_1) 53 public final class DirectObjectStoreNode extends FixedWithNextNode implements Lowerable { 54 55 public static final NodeClass<DirectObjectStoreNode> TYPE = NodeClass.create(DirectObjectStoreNode.class); 56 @Input ValueNode object; 57 @Input ValueNode value; 58 @Input ValueNode offset; 59 protected final int displacement; 60 protected final LocationIdentity locationIdentity; 61 protected final JavaKind storeKind; 62 63 public DirectObjectStoreNode(ValueNode object, int displacement, ValueNode offset, ValueNode value, LocationIdentity locationIdentity, JavaKind storeKind) { 64 super(TYPE, StampFactory.forVoid()); 65 this.object = object; 66 this.value = value; 67 this.offset = offset; 68 this.displacement = displacement; 69 this.locationIdentity = locationIdentity; 70 this.storeKind = storeKind; 71 } 72 73 @NodeIntrinsic 74 public static native void storeObject(Object obj, @ConstantNodeParameter int displacement, long offset, Object value, @ConstantNodeParameter LocationIdentity locationIdentity, 75 @ConstantNodeParameter JavaKind storeKind); 76 77 @NodeIntrinsic 78 public static native void storeBoolean(Object obj, @ConstantNodeParameter int displacement, long offset, boolean value, @ConstantNodeParameter LocationIdentity locationIdenity, 79 @ConstantNodeParameter JavaKind storeKind); 80 81 @NodeIntrinsic 82 public static native void storeByte(Object obj, @ConstantNodeParameter int displacement, long offset, byte value, @ConstantNodeParameter LocationIdentity locationIdenity, 83 @ConstantNodeParameter JavaKind storeKind); 84 85 @NodeIntrinsic 86 public static native void storeChar(Object obj, @ConstantNodeParameter int displacement, long offset, char value, @ConstantNodeParameter LocationIdentity locationIdenity, 87 @ConstantNodeParameter JavaKind storeKind); 88 89 @NodeIntrinsic 90 public static native void storeShort(Object obj, @ConstantNodeParameter int displacement, long offset, short value, @ConstantNodeParameter LocationIdentity locationIdenity, 91 @ConstantNodeParameter JavaKind storeKind); 92 93 @NodeIntrinsic 94 public static native void storeInt(Object obj, @ConstantNodeParameter int displacement, long offset, int value, @ConstantNodeParameter LocationIdentity locationIdenity, 95 @ConstantNodeParameter JavaKind storeKind); 96 97 @NodeIntrinsic 98 public static native void storeLong(Object obj, @ConstantNodeParameter int displacement, long offset, long value, @ConstantNodeParameter LocationIdentity locationIdenity, 99 @ConstantNodeParameter JavaKind storeKind); 100 101 @NodeIntrinsic 102 public static native void storeFloat(Object obj, @ConstantNodeParameter int displacement, long offset, float value, @ConstantNodeParameter LocationIdentity locationIdenity, 103 @ConstantNodeParameter JavaKind storeKind); 104 105 @NodeIntrinsic 106 public static native void storeDouble(Object obj, @ConstantNodeParameter int displacement, long offset, double value, @ConstantNodeParameter LocationIdentity locationIdenity, 107 @ConstantNodeParameter JavaKind storeKind); 108 109 @Override 110 public void lower(LoweringTool tool) { 111 ValueNode off = graph().unique(new AddNode(offset, ConstantNode.forIntegerStamp(offset.stamp(), displacement, graph()))); 112 AddressNode address = graph().unique(new OffsetAddressNode(object, off)); 113 JavaWriteNode write = graph().add(new JavaWriteNode(storeKind, address, locationIdentity, value, BarrierType.NONE, storeKind == JavaKind.Object, false)); 114 graph().replaceFixedWithFixed(this, write); 115 116 tool.getLowerer().lower(write, tool); 117 } 118 }