< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/RawLoadNode.java

Print this page




  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.nodes.extended;
  24 
  25 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_2;
  26 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1;
  27 
  28 import org.graalvm.compiler.core.common.type.PrimitiveStamp;
  29 import org.graalvm.compiler.core.common.type.Stamp;
  30 import org.graalvm.compiler.core.common.type.StampFactory;
  31 import org.graalvm.compiler.graph.Node;
  32 import org.graalvm.compiler.graph.NodeClass;


  33 import org.graalvm.compiler.nodeinfo.NodeInfo;

  34 import org.graalvm.compiler.nodes.ValueNode;
  35 import org.graalvm.compiler.nodes.calc.ReinterpretNode;
  36 import org.graalvm.compiler.nodes.java.LoadFieldNode;
  37 import org.graalvm.compiler.nodes.spi.Lowerable;
  38 import org.graalvm.compiler.nodes.spi.LoweringTool;
  39 import org.graalvm.compiler.nodes.spi.Virtualizable;
  40 import org.graalvm.compiler.nodes.spi.VirtualizerTool;

  41 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
  42 import org.graalvm.word.LocationIdentity;
  43 
  44 import jdk.vm.ci.meta.Assumptions;


  45 import jdk.vm.ci.meta.JavaKind;
  46 import jdk.vm.ci.meta.ResolvedJavaField;

  47 
  48 /**
  49  * Load of a value from a location specified as an offset relative to an object. No null check is
  50  * performed before the load.
  51  */
  52 @NodeInfo(cycles = CYCLES_2, size = SIZE_1)
  53 public class RawLoadNode extends UnsafeAccessNode implements Lowerable, Virtualizable {
  54     public static final NodeClass<RawLoadNode> TYPE = NodeClass.create(RawLoadNode.class);
  55 
  56     /**
  57      * This constructor exists for node intrinsics that need a stamp based on {@code accessKind}.
  58      */
  59     public RawLoadNode(ValueNode object, ValueNode offset, JavaKind accessKind, LocationIdentity locationIdentity) {
  60         this(object, offset, accessKind, locationIdentity, false);
  61     }
  62 
  63     public RawLoadNode(ValueNode object, ValueNode offset, JavaKind accessKind, LocationIdentity locationIdentity, boolean forceAnyLocation) {
  64         super(TYPE, StampFactory.forKind(accessKind.getStackKind()), object, offset, accessKind, locationIdentity, forceAnyLocation);
  65     }
  66 
  67     /**
  68      * This constructor exists for node intrinsics that need a stamp based on the return type of the
  69      * {@link org.graalvm.compiler.graph.Node.NodeIntrinsic} annotated method.
  70      */
  71     public RawLoadNode(@InjectedNodeParameter Stamp stamp, ValueNode object, ValueNode offset, LocationIdentity locationIdentity, JavaKind accessKind) {
  72         super(TYPE, stamp, object, offset, accessKind, locationIdentity, false);
  73     }


 103                                 int width1 = p1.getBits();
 104                                 int width2 = p2.getBits();
 105                                 if (width1 == width2) {
 106                                     Node replacement = new ReinterpretNode(p2, entry);
 107                                     tool.replaceWith((ValueNode) replacement);
 108                                     return;
 109                                 } else {
 110                                     // different bit width
 111                                     return;
 112                                 }
 113                             } else {
 114                                 // cannot reinterpret for arbitrary objects
 115                                 return;
 116                             }
 117                         }
 118                         tool.replaceWith(entry);
 119                     }
 120                 }
 121             }
 122         }


























 123     }
 124 
 125     @Override
 126     protected ValueNode cloneAsFieldAccess(Assumptions assumptions, ResolvedJavaField field) {
 127         return LoadFieldNode.create(assumptions, object(), field);
 128     }
 129 
 130     @Override
 131     protected ValueNode cloneAsArrayAccess(ValueNode location, LocationIdentity identity) {
 132         return new RawLoadNode(object(), location, accessKind(), identity);
 133     }
 134 
 135     @NodeIntrinsic
 136     public static native Object load(Object object, long offset, @ConstantNodeParameter JavaKind kind, @ConstantNodeParameter LocationIdentity locationIdentity);
 137 }


  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.nodes.extended;
  24 
  25 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_2;
  26 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1;
  27 
  28 import org.graalvm.compiler.core.common.type.PrimitiveStamp;
  29 import org.graalvm.compiler.core.common.type.Stamp;
  30 import org.graalvm.compiler.core.common.type.StampFactory;
  31 import org.graalvm.compiler.graph.Node;
  32 import org.graalvm.compiler.graph.NodeClass;
  33 import org.graalvm.compiler.graph.spi.Canonicalizable;
  34 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  35 import org.graalvm.compiler.nodeinfo.NodeInfo;
  36 import org.graalvm.compiler.nodes.ConstantNode;
  37 import org.graalvm.compiler.nodes.ValueNode;
  38 import org.graalvm.compiler.nodes.calc.ReinterpretNode;
  39 import org.graalvm.compiler.nodes.java.LoadFieldNode;
  40 import org.graalvm.compiler.nodes.spi.Lowerable;
  41 import org.graalvm.compiler.nodes.spi.LoweringTool;
  42 import org.graalvm.compiler.nodes.spi.Virtualizable;
  43 import org.graalvm.compiler.nodes.spi.VirtualizerTool;
  44 import org.graalvm.compiler.nodes.type.StampTool;
  45 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
  46 import org.graalvm.word.LocationIdentity;
  47 
  48 import jdk.vm.ci.meta.Assumptions;
  49 import jdk.vm.ci.meta.Constant;
  50 import jdk.vm.ci.meta.JavaConstant;
  51 import jdk.vm.ci.meta.JavaKind;
  52 import jdk.vm.ci.meta.ResolvedJavaField;
  53 import jdk.vm.ci.meta.ResolvedJavaType;
  54 
  55 /**
  56  * Load of a value from a location specified as an offset relative to an object. No null check is
  57  * performed before the load.
  58  */
  59 @NodeInfo(cycles = CYCLES_2, size = SIZE_1)
  60 public class RawLoadNode extends UnsafeAccessNode implements Lowerable, Virtualizable, Canonicalizable {
  61     public static final NodeClass<RawLoadNode> TYPE = NodeClass.create(RawLoadNode.class);
  62 
  63     /**
  64      * This constructor exists for node intrinsics that need a stamp based on {@code accessKind}.
  65      */
  66     public RawLoadNode(ValueNode object, ValueNode offset, JavaKind accessKind, LocationIdentity locationIdentity) {
  67         this(object, offset, accessKind, locationIdentity, false);
  68     }
  69 
  70     public RawLoadNode(ValueNode object, ValueNode offset, JavaKind accessKind, LocationIdentity locationIdentity, boolean forceAnyLocation) {
  71         super(TYPE, StampFactory.forKind(accessKind.getStackKind()), object, offset, accessKind, locationIdentity, forceAnyLocation);
  72     }
  73 
  74     /**
  75      * This constructor exists for node intrinsics that need a stamp based on the return type of the
  76      * {@link org.graalvm.compiler.graph.Node.NodeIntrinsic} annotated method.
  77      */
  78     public RawLoadNode(@InjectedNodeParameter Stamp stamp, ValueNode object, ValueNode offset, LocationIdentity locationIdentity, JavaKind accessKind) {
  79         super(TYPE, stamp, object, offset, accessKind, locationIdentity, false);
  80     }


 110                                 int width1 = p1.getBits();
 111                                 int width2 = p2.getBits();
 112                                 if (width1 == width2) {
 113                                     Node replacement = new ReinterpretNode(p2, entry);
 114                                     tool.replaceWith((ValueNode) replacement);
 115                                     return;
 116                                 } else {
 117                                     // different bit width
 118                                     return;
 119                                 }
 120                             } else {
 121                                 // cannot reinterpret for arbitrary objects
 122                                 return;
 123                             }
 124                         }
 125                         tool.replaceWith(entry);
 126                     }
 127                 }
 128             }
 129         }
 130     }
 131 
 132     @Override
 133     public Node canonical(CanonicalizerTool tool) {
 134         if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
 135             ValueNode targetObject = object();
 136             if (offset().isConstant() && targetObject.isConstant() && !targetObject.isNullConstant()) {
 137                 ConstantNode objectConstant = (ConstantNode) targetObject;
 138                 ResolvedJavaType type = StampTool.typeOrNull(objectConstant);
 139                 if (type != null && type.isArray()) {
 140                     JavaConstant arrayConstant = objectConstant.asJavaConstant();
 141                     if (arrayConstant != null) {
 142                         int stableDimension = objectConstant.getStableDimension();
 143                         if (stableDimension > 0) {
 144                             long constantOffset = offset().asJavaConstant().asLong();
 145                             Constant constant = stamp().readConstant(tool.getConstantReflection().getMemoryAccessProvider(), arrayConstant, constantOffset);
 146                             boolean isDefaultStable = objectConstant.isDefaultStable();
 147                             if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
 148                                 return ConstantNode.forConstant(stamp(), constant, stableDimension - 1, isDefaultStable, tool.getMetaAccess());
 149                             }
 150                         }
 151                     }
 152                 }
 153             }
 154         }
 155         return super.canonical(tool);
 156     }
 157 
 158     @Override
 159     protected ValueNode cloneAsFieldAccess(Assumptions assumptions, ResolvedJavaField field) {
 160         return LoadFieldNode.create(assumptions, object(), field);
 161     }
 162 
 163     @Override
 164     protected ValueNode cloneAsArrayAccess(ValueNode location, LocationIdentity identity) {
 165         return new RawLoadNode(object(), location, accessKind(), identity);
 166     }
 167 
 168     @NodeIntrinsic
 169     public static native Object load(Object object, long offset, @ConstantNodeParameter JavaKind kind, @ConstantNodeParameter LocationIdentity locationIdentity);
 170 }
< prev index next >