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