1/*
2 * Copyright (c) 2011, 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.Value;
27import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_8;
28import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_8;
29
30import org.graalvm.compiler.core.common.type.StampFactory;
31import org.graalvm.compiler.graph.NodeClass;
32import org.graalvm.compiler.nodeinfo.NodeInfo;
33import org.graalvm.compiler.nodes.ValueNode;
34import org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint;
35import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
36import org.graalvm.compiler.nodes.spi.Lowerable;
37import org.graalvm.compiler.nodes.spi.LoweringTool;
38import org.graalvm.word.LocationIdentity;
39
40import jdk.vm.ci.meta.JavaKind;
41
42/**
43 * Represents an atomic compare-and-swap operation The result is a boolean that contains whether the
44 * value matched the expected value.
45 */
46@NodeInfo(allowedUsageTypes = {Value, Memory}, cycles = CYCLES_8, size = SIZE_8)
47public final class UnsafeCompareAndSwapNode extends AbstractMemoryCheckpoint implements Lowerable, MemoryCheckpoint.Single {
48
49    public static final NodeClass<UnsafeCompareAndSwapNode> TYPE = NodeClass.create(UnsafeCompareAndSwapNode.class);
50    @Input ValueNode object;
51    @Input ValueNode offset;
52    @Input ValueNode expected;
53    @Input ValueNode newValue;
54
55    protected final JavaKind valueKind;
56    protected final LocationIdentity locationIdentity;
57
58    public UnsafeCompareAndSwapNode(ValueNode object, ValueNode offset, ValueNode expected, ValueNode newValue, JavaKind valueKind, LocationIdentity locationIdentity) {
59        super(TYPE, StampFactory.forKind(JavaKind.Boolean.getStackKind()));
60        assert expected.stamp().isCompatible(newValue.stamp());
61        this.object = object;
62        this.offset = offset;
63        this.expected = expected;
64        this.newValue = newValue;
65        this.valueKind = valueKind;
66        this.locationIdentity = locationIdentity;
67    }
68
69    public ValueNode object() {
70        return object;
71    }
72
73    public ValueNode offset() {
74        return offset;
75    }
76
77    public ValueNode expected() {
78        return expected;
79    }
80
81    public ValueNode newValue() {
82        return newValue;
83    }
84
85    public JavaKind getValueKind() {
86        return valueKind;
87    }
88
89    @Override
90    public LocationIdentity getLocationIdentity() {
91        return locationIdentity;
92    }
93
94    @Override
95    public void lower(LoweringTool tool) {
96        tool.getLowerer().lower(this, tool);
97    }
98}
99