LogicCompareAndSwapNode.java revision 13083:b9a173f12fe6
190792Sgshapiro/* 2261363Sgshapiro * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. 390792Sgshapiro * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 490792Sgshapiro * 590792Sgshapiro * This code is free software; you can redistribute it and/or modify it 690792Sgshapiro * under the terms of the GNU General Public License version 2 only, as 790792Sgshapiro * published by the Free Software Foundation. 890792Sgshapiro * 990792Sgshapiro * This code is distributed in the hope that it will be useful, but WITHOUT 1090792Sgshapiro * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11266692Sgshapiro * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1290792Sgshapiro * version 2 for more details (a copy is included in the LICENSE file that 1390792Sgshapiro * accompanied this code). 1490792Sgshapiro * 1590792Sgshapiro * You should have received a copy of the GNU General Public License version 1690792Sgshapiro * 2 along with this work; if not, write to the Free Software Foundation, 1790792Sgshapiro * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1890792Sgshapiro * 1990792Sgshapiro * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2090792Sgshapiro * or visit www.oracle.com if you need additional information or have any 2190792Sgshapiro * questions. 2290792Sgshapiro */ 2390792Sgshapiropackage org.graalvm.compiler.nodes.java; 2490792Sgshapiro 2590792Sgshapiroimport static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_8; 2690792Sgshapiroimport static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_8; 2790792Sgshapiro 2890792Sgshapiroimport org.graalvm.api.word.LocationIdentity; 2990792Sgshapiroimport org.graalvm.compiler.core.common.LIRKind; 3090792Sgshapiroimport org.graalvm.compiler.core.common.type.StampFactory; 3190792Sgshapiroimport org.graalvm.compiler.graph.NodeClass; 3290792Sgshapiroimport org.graalvm.compiler.lir.gen.LIRGeneratorTool; 3390792Sgshapiroimport org.graalvm.compiler.nodeinfo.NodeInfo; 3490792Sgshapiroimport org.graalvm.compiler.nodes.ValueNode; 3590792Sgshapiroimport org.graalvm.compiler.nodes.memory.address.AddressNode; 3690792Sgshapiroimport org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; 3790792Sgshapiro 3890792Sgshapiroimport jdk.vm.ci.meta.JavaConstant; 3990792Sgshapiroimport jdk.vm.ci.meta.JavaKind; 4090792Sgshapiroimport jdk.vm.ci.meta.Value; 4190792Sgshapiro 4290792Sgshapiro/** 4390792Sgshapiro * Represents the low-level version of an atomic compare-and-swap operation. 4490792Sgshapiro * 4590792Sgshapiro * This version returns a boolean indicating is the CAS was successful or not. 4690792Sgshapiro */ 4790792Sgshapiro@NodeInfo(cycles = CYCLES_8, size = SIZE_8) 4890792Sgshapiropublic final class LogicCompareAndSwapNode extends AbstractCompareAndSwapNode { 4990792Sgshapiro public static final NodeClass<LogicCompareAndSwapNode> TYPE = NodeClass.create(LogicCompareAndSwapNode.class); 5090792Sgshapiro 5190792Sgshapiro public LogicCompareAndSwapNode(ValueNode address, ValueNode expectedValue, ValueNode newValue, LocationIdentity location) { 5290792Sgshapiro this((AddressNode) address, location, expectedValue, newValue, BarrierType.NONE); 5390792Sgshapiro } 5490792Sgshapiro 5590792Sgshapiro public LogicCompareAndSwapNode(AddressNode address, LocationIdentity location, ValueNode expectedValue, ValueNode newValue, BarrierType barrierType) { 5690792Sgshapiro super(TYPE, address, location, expectedValue, newValue, barrierType, StampFactory.forKind(JavaKind.Boolean.getStackKind())); 5790792Sgshapiro } 5890792Sgshapiro 5990792Sgshapiro @Override 6090792Sgshapiro public void generate(NodeLIRBuilderTool gen) { 6190792Sgshapiro assert getNewValue().stamp().isCompatible(getExpectedValue().stamp()); 6290792Sgshapiro assert !this.canDeoptimize(); 6390792Sgshapiro LIRGeneratorTool tool = gen.getLIRGeneratorTool(); 6490792Sgshapiro 6590792Sgshapiro LIRKind resultKind = tool.getLIRKind(stamp()); 6690792Sgshapiro Value trueResult = tool.emitConstant(resultKind, JavaConstant.TRUE); 6790792Sgshapiro Value falseResult = tool.emitConstant(resultKind, JavaConstant.FALSE); 6890792Sgshapiro Value result = tool.emitLogicCompareAndSwap(gen.operand(getAddress()), gen.operand(getExpectedValue()), gen.operand(getNewValue()), trueResult, falseResult); 6990792Sgshapiro 7090792Sgshapiro gen.setResult(this, result); 7190792Sgshapiro } 7290792Sgshapiro} 7390792Sgshapiro