1 /*
   2  * Copyright (c) 2011, 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.nodes.memory;
  24 
  25 import org.graalvm.compiler.core.common.LocationIdentity;
  26 import org.graalvm.compiler.core.common.type.Stamp;
  27 import org.graalvm.compiler.graph.NodeClass;
  28 import org.graalvm.compiler.nodeinfo.InputType;
  29 import org.graalvm.compiler.nodeinfo.NodeInfo;
  30 import org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode;
  31 import org.graalvm.compiler.nodes.FrameState;
  32 import org.graalvm.compiler.nodes.extended.GuardingNode;
  33 import org.graalvm.compiler.nodes.memory.address.AddressNode;
  34 
  35 /**
  36  * Accesses a value at an memory address specified by an {@linkplain #address address}. The access
  37  * does not include a null check on the object.
  38  */
  39 @NodeInfo
  40 public abstract class FixedAccessNode extends DeoptimizingFixedWithNextNode implements Access {
  41     public static final NodeClass<FixedAccessNode> TYPE = NodeClass.create(FixedAccessNode.class);
  42 
  43     @OptionalInput(InputType.Guard) protected GuardingNode guard;
  44 
  45     @Input(InputType.Association) AddressNode address;
  46     protected final LocationIdentity location;
  47 
  48     protected boolean nullCheck;
  49     protected BarrierType barrierType;
  50 
  51     @Override
  52     public AddressNode getAddress() {
  53         return address;
  54     }
  55 
  56     public void setAddress(AddressNode address) {
  57         updateUsages(this.address, address);
  58         this.address = address;
  59     }
  60 
  61     @Override
  62     public LocationIdentity getLocationIdentity() {
  63         return location;
  64     }
  65 
  66     public boolean getNullCheck() {
  67         return nullCheck;
  68     }
  69 
  70     public void setNullCheck(boolean check) {
  71         this.nullCheck = check;
  72     }
  73 
  74     protected FixedAccessNode(NodeClass<? extends FixedAccessNode> c, AddressNode address, LocationIdentity location, Stamp stamp) {
  75         this(c, address, location, stamp, BarrierType.NONE);
  76     }
  77 
  78     protected FixedAccessNode(NodeClass<? extends FixedAccessNode> c, AddressNode address, LocationIdentity location, Stamp stamp, BarrierType barrierType) {
  79         this(c, address, location, stamp, null, barrierType, false, null);
  80     }
  81 
  82     protected FixedAccessNode(NodeClass<? extends FixedAccessNode> c, AddressNode address, LocationIdentity location, Stamp stamp, GuardingNode guard, BarrierType barrierType, boolean nullCheck,
  83                     FrameState stateBefore) {
  84         super(c, stamp, stateBefore);
  85         this.address = address;
  86         this.location = location;
  87         this.guard = guard;
  88         this.barrierType = barrierType;
  89         this.nullCheck = nullCheck;
  90     }
  91 
  92     @Override
  93     public boolean canDeoptimize() {
  94         return nullCheck;
  95     }
  96 
  97     @Override
  98     public GuardingNode getGuard() {
  99         return guard;
 100     }
 101 
 102     @Override
 103     public void setGuard(GuardingNode guard) {
 104         updateUsagesInterface(this.guard, guard);
 105         this.guard = guard;
 106     }
 107 
 108     @Override
 109     public BarrierType getBarrierType() {
 110         return barrierType;
 111     }
 112 }