1/* 2 * Copyright (c) 2013, 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 */ 23package org.graalvm.compiler.nodes.java; 24 25import static org.graalvm.compiler.nodeinfo.InputType.Memory; 26import static org.graalvm.compiler.nodeinfo.InputType.State; 27 28import org.graalvm.compiler.core.common.type.Stamp; 29import org.graalvm.compiler.graph.NodeClass; 30import org.graalvm.compiler.nodeinfo.InputType; 31import org.graalvm.compiler.nodeinfo.NodeInfo; 32import org.graalvm.compiler.nodes.FrameState; 33import org.graalvm.compiler.nodes.StateSplit; 34import org.graalvm.compiler.nodes.ValueNode; 35import org.graalvm.compiler.nodes.memory.FixedAccessNode; 36import org.graalvm.compiler.nodes.memory.LIRLowerableAccess; 37import org.graalvm.compiler.nodes.memory.MemoryCheckpoint; 38import org.graalvm.compiler.nodes.memory.address.AddressNode; 39import org.graalvm.word.LocationIdentity; 40 41/** 42 * Low-level atomic compare-and-swap operation. 43 */ 44@NodeInfo(allowedUsageTypes = {InputType.Value, Memory}) 45public abstract class AbstractCompareAndSwapNode extends FixedAccessNode implements StateSplit, LIRLowerableAccess, MemoryCheckpoint.Single { 46 public static final NodeClass<AbstractCompareAndSwapNode> TYPE = NodeClass.create(AbstractCompareAndSwapNode.class); 47 @Input ValueNode expectedValue; 48 @Input ValueNode newValue; 49 @OptionalInput(State) FrameState stateAfter; 50 51 @Override 52 public FrameState stateAfter() { 53 return stateAfter; 54 } 55 56 @Override 57 public void setStateAfter(FrameState x) { 58 assert x == null || x.isAlive() : "frame state must be in a graph"; 59 updateUsages(stateAfter, x); 60 stateAfter = x; 61 } 62 63 @Override 64 public boolean hasSideEffect() { 65 return true; 66 } 67 68 public ValueNode getExpectedValue() { 69 return expectedValue; 70 } 71 72 public ValueNode getNewValue() { 73 return newValue; 74 } 75 76 public AbstractCompareAndSwapNode(NodeClass<? extends AbstractCompareAndSwapNode> c, AddressNode address, LocationIdentity location, ValueNode expectedValue, ValueNode newValue, 77 BarrierType barrierType, Stamp stamp) { 78 super(c, address, location, stamp, barrierType); 79 assert expectedValue.getStackKind() == newValue.getStackKind(); 80 this.expectedValue = expectedValue; 81 this.newValue = newValue; 82 } 83 84 @Override 85 public boolean canNullCheck() { 86 return false; 87 } 88 89 @Override 90 public Stamp getAccessStamp() { 91 return expectedValue.stamp().meet(newValue.stamp()).unrestricted(); 92 } 93} 94