43972
|
1 |
/*
|
58877
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.nodes.java;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.nodeinfo.InputType.Memory;
|
|
28 |
import static org.graalvm.compiler.nodeinfo.InputType.State;
|
|
29 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_8;
|
|
30 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_2;
|
|
31 |
|
50330
|
32 |
import jdk.vm.ci.meta.ValueKind;
|
46344
|
33 |
import org.graalvm.compiler.core.common.type.Stamp;
|
43972
|
34 |
import org.graalvm.compiler.graph.NodeClass;
|
|
35 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
36 |
import org.graalvm.compiler.nodes.FrameState;
|
48190
|
37 |
import org.graalvm.compiler.nodes.NodeView;
|
43972
|
38 |
import org.graalvm.compiler.nodes.StateSplit;
|
|
39 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
40 |
import org.graalvm.compiler.nodes.memory.FixedAccessNode;
|
46344
|
41 |
import org.graalvm.compiler.nodes.memory.LIRLowerableAccess;
|
43972
|
42 |
import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
|
|
43 |
import org.graalvm.compiler.nodes.memory.address.AddressNode;
|
|
44 |
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
49873
|
45 |
import jdk.internal.vm.compiler.word.LocationIdentity;
|
43972
|
46 |
|
|
47 |
import jdk.vm.ci.meta.Value;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Represents the lowered version of an atomic read-and-write operation like
|
48861
|
51 |
* {@link sun.misc.Unsafe#getAndSetInt(Object, long, int)}.
|
43972
|
52 |
*/
|
|
53 |
@NodeInfo(allowedUsageTypes = {Memory}, cycles = CYCLES_8, size = SIZE_2)
|
46344
|
54 |
public final class LoweredAtomicReadAndWriteNode extends FixedAccessNode implements StateSplit, LIRLowerableAccess, MemoryCheckpoint.Single {
|
43972
|
55 |
|
|
56 |
public static final NodeClass<LoweredAtomicReadAndWriteNode> TYPE = NodeClass.create(LoweredAtomicReadAndWriteNode.class);
|
|
57 |
@Input ValueNode newValue;
|
|
58 |
@OptionalInput(State) FrameState stateAfter;
|
50330
|
59 |
private final ValueKind<?> valueKind;
|
43972
|
60 |
|
50330
|
61 |
public LoweredAtomicReadAndWriteNode(AddressNode address, LocationIdentity location, ValueNode newValue, ValueKind<?> valueKind, BarrierType barrierType) {
|
48190
|
62 |
super(TYPE, address, location, newValue.stamp(NodeView.DEFAULT).unrestricted(), barrierType);
|
43972
|
63 |
this.newValue = newValue;
|
50330
|
64 |
this.valueKind = valueKind;
|
43972
|
65 |
}
|
|
66 |
|
|
67 |
@Override
|
|
68 |
public FrameState stateAfter() {
|
|
69 |
return stateAfter;
|
|
70 |
}
|
|
71 |
|
|
72 |
@Override
|
|
73 |
public void setStateAfter(FrameState x) {
|
|
74 |
assert x == null || x.isAlive() : "frame state must be in a graph";
|
|
75 |
updateUsages(stateAfter, x);
|
|
76 |
stateAfter = x;
|
|
77 |
}
|
|
78 |
|
|
79 |
@Override
|
|
80 |
public boolean hasSideEffect() {
|
|
81 |
return true;
|
|
82 |
}
|
|
83 |
|
|
84 |
@Override
|
|
85 |
public void generate(NodeLIRBuilderTool gen) {
|
50330
|
86 |
Value emitted = gen.operand(getNewValue());
|
|
87 |
// In case this node works with compressed objects, the newValue's kind must be used.
|
|
88 |
ValueKind<? extends ValueKind<?>> actualKind = newValue.stamp(NodeView.DEFAULT).getStackKind().isObject() ? emitted.getValueKind() : this.valueKind;
|
|
89 |
Value result = gen.getLIRGeneratorTool().emitAtomicReadAndWrite(gen.operand(getAddress()), actualKind, emitted);
|
43972
|
90 |
gen.setResult(this, result);
|
|
91 |
}
|
|
92 |
|
|
93 |
@Override
|
|
94 |
public boolean canNullCheck() {
|
|
95 |
return false;
|
|
96 |
}
|
|
97 |
|
|
98 |
public ValueNode getNewValue() {
|
|
99 |
return newValue;
|
|
100 |
}
|
46344
|
101 |
|
|
102 |
@Override
|
|
103 |
public Stamp getAccessStamp() {
|
48190
|
104 |
return stamp(NodeView.DEFAULT);
|
46344
|
105 |
}
|
58877
|
106 |
|
|
107 |
@Override
|
|
108 |
public LocationIdentity getKilledLocationIdentity() {
|
|
109 |
return getLocationIdentity();
|
|
110 |
}
|
43972
|
111 |
}
|