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