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.java;
26
27 import jdk.vm.ci.meta.JavaKind;
28 import org.graalvm.compiler.core.common.type.Stamp;
29 import org.graalvm.compiler.graph.NodeClass;
30 import org.graalvm.compiler.nodeinfo.NodeInfo;
31 import org.graalvm.compiler.nodes.NodeView;
32 import org.graalvm.compiler.nodes.ValueNode;
33 import org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint;
34 import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
35 import org.graalvm.compiler.nodes.spi.Lowerable;
36 import org.graalvm.compiler.nodes.spi.LoweringTool;
37 import jdk.internal.vm.compiler.word.LocationIdentity;
38
39 import static org.graalvm.compiler.nodeinfo.InputType.Memory;
40 import static org.graalvm.compiler.nodeinfo.InputType.Value;
41 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_8;
42 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_8;
43
44 /**
45 * Represents an atomic compare-and-swap operation. The result is the current value of the memory
46 * location that was compared.
47 */
48 @NodeInfo(allowedUsageTypes = {Value, Memory}, cycles = CYCLES_8, size = SIZE_8)
49 public final class UnsafeCompareAndExchangeNode extends AbstractMemoryCheckpoint implements Lowerable, MemoryCheckpoint.Single {
50
51 public static final NodeClass<UnsafeCompareAndExchangeNode> TYPE = NodeClass.create(UnsafeCompareAndExchangeNode.class);
52 @Input ValueNode object;
53 @Input ValueNode offset;
54 @Input ValueNode expected;
55 @Input ValueNode newValue;
56
57 private final JavaKind valueKind;
58 private final LocationIdentity locationIdentity;
59
60 public UnsafeCompareAndExchangeNode(ValueNode object, ValueNode offset, ValueNode expected, ValueNode newValue, JavaKind valueKind, LocationIdentity locationIdentity) {
61 super(TYPE, meetInputs(expected.stamp(NodeView.DEFAULT), newValue.stamp(NodeView.DEFAULT)));
62 this.object = object;
63 this.offset = offset;
64 this.expected = expected;
65 this.newValue = newValue;
66 this.valueKind = valueKind;
67 this.locationIdentity = locationIdentity;
68 }
69
70 private static Stamp meetInputs(Stamp expected, Stamp newValue) {
71 assert expected.isCompatible(newValue);
72 return expected.unrestricted().meet(newValue.unrestricted());
73 }
74
75 public ValueNode object() {
76 return object;
77 }
78
79 public ValueNode offset() {
80 return offset;
81 }
82
83 public ValueNode expected() {
84 return expected;
85 }
86
87 public ValueNode newValue() {
88 return newValue;
89 }
90
91 public JavaKind getValueKind() {
92 return valueKind;
93 }
94
95 @Override
96 public LocationIdentity getLocationIdentity() {
97 return locationIdentity;
98 }
99
100 @Override
101 public void lower(LoweringTool tool) {
102 tool.getLowerer().lower(this, tool);
103 }
104 }
|
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.java;
26
27 import org.graalvm.compiler.core.common.type.Stamp;
28 import org.graalvm.compiler.graph.NodeClass;
29 import org.graalvm.compiler.nodeinfo.NodeInfo;
30 import org.graalvm.compiler.nodes.LogicNode;
31 import org.graalvm.compiler.nodes.NodeView;
32 import org.graalvm.compiler.nodes.ValueNode;
33 import org.graalvm.compiler.nodes.spi.VirtualizerTool;
34 import jdk.internal.vm.compiler.word.LocationIdentity;
35
36 import jdk.vm.ci.meta.JavaKind;
37
38 /**
39 * Represents an atomic compare-and-swap operation. The result is the current value of the memory
40 * location that was compared.
41 */
42 @NodeInfo
43 public final class UnsafeCompareAndExchangeNode extends AbstractUnsafeCompareAndSwapNode {
44
45 public static final NodeClass<UnsafeCompareAndExchangeNode> TYPE = NodeClass.create(UnsafeCompareAndExchangeNode.class);
46
47 public UnsafeCompareAndExchangeNode(ValueNode object, ValueNode offset, ValueNode expected, ValueNode newValue, JavaKind valueKind, LocationIdentity locationIdentity) {
48 super(TYPE, meetInputs(expected.stamp(NodeView.DEFAULT), newValue.stamp(NodeView.DEFAULT)), object, offset, expected, newValue, valueKind, locationIdentity);
49 }
50
51 private static Stamp meetInputs(Stamp expected, Stamp newValue) {
52 assert expected.isCompatible(newValue);
53 return expected.unrestricted().meet(newValue.unrestricted());
54 }
55
56 @Override
57 protected void finishVirtualize(VirtualizerTool tool, LogicNode equalsNode, ValueNode currentValue) {
58 tool.replaceWith(currentValue);
59 }
60 }
|