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