author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58533 | 46b0b7fe255c |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
54601 | 2 |
* Copyright (c) 2015, 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.replacements.aarch64; |
26 |
||
50858 | 27 |
import static org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.registerPlatformSpecificUnsafePlugins; |
46344 | 28 |
import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.COS; |
29 |
import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.EXP; |
|
30 |
import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG; |
|
31 |
import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG10; |
|
32 |
import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.SIN; |
|
33 |
import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.TAN; |
|
34 |
||
43972 | 35 |
import org.graalvm.compiler.bytecode.BytecodeProvider; |
50330 | 36 |
import org.graalvm.compiler.lir.aarch64.AArch64ArithmeticLIRGeneratorTool.RoundingMode; |
43972 | 37 |
import org.graalvm.compiler.nodes.ValueNode; |
38 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; |
|
39 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; |
|
40 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; |
|
50330 | 41 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver; |
43972 | 42 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; |
43 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; |
|
50330 | 44 |
import org.graalvm.compiler.nodes.java.AtomicReadAndAddNode; |
50609 | 45 |
import org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode; |
50330 | 46 |
import org.graalvm.compiler.nodes.memory.address.AddressNode; |
47 |
import org.graalvm.compiler.nodes.memory.address.OffsetAddressNode; |
|
58299 | 48 |
import org.graalvm.compiler.replacements.TargetGraphBuilderPlugins; |
46344 | 49 |
import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode; |
58533 | 50 |
import org.graalvm.compiler.replacements.nodes.FusedMultiplyAddNode; |
46344 | 51 |
import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode; |
52 |
import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation; |
|
55509 | 53 |
import org.graalvm.compiler.serviceprovider.JavaVersionUtil; |
50330 | 54 |
import jdk.internal.vm.compiler.word.LocationIdentity; |
43972 | 55 |
|
58299 | 56 |
import jdk.vm.ci.code.Architecture; |
43972 | 57 |
import jdk.vm.ci.meta.JavaKind; |
58 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
|
50330 | 59 |
import sun.misc.Unsafe; |
43972 | 60 |
|
58299 | 61 |
public class AArch64GraphBuilderPlugins implements TargetGraphBuilderPlugins { |
62 |
@Override |
|
63 |
public void register(Plugins plugins, BytecodeProvider replacementsBytecodeProvider, Architecture arch, boolean explicitUnsafeNullChecks, boolean registerMathPlugins, |
|
64 |
boolean emitJDK9StringSubstitutions, boolean useFMAIntrinsics) { |
|
58533 | 65 |
register(plugins, replacementsBytecodeProvider, explicitUnsafeNullChecks, registerMathPlugins, emitJDK9StringSubstitutions, useFMAIntrinsics); |
58299 | 66 |
} |
43972 | 67 |
|
54724 | 68 |
public static void register(Plugins plugins, BytecodeProvider bytecodeProvider, boolean explicitUnsafeNullChecks, |
58533 | 69 |
boolean registerMathPlugins, boolean emitJDK9StringSubstitutions, boolean useFMAIntrinsics) { |
43972 | 70 |
InvocationPlugins invocationPlugins = plugins.getInvocationPlugins(); |
71 |
invocationPlugins.defer(new Runnable() { |
|
72 |
@Override |
|
73 |
public void run() { |
|
54601 | 74 |
registerIntegerLongPlugins(invocationPlugins, JavaKind.Int, bytecodeProvider); |
75 |
registerIntegerLongPlugins(invocationPlugins, JavaKind.Long, bytecodeProvider); |
|
54328 | 76 |
if (registerMathPlugins) { |
58533 | 77 |
registerMathPlugins(invocationPlugins, useFMAIntrinsics); |
54328 | 78 |
} |
54724 | 79 |
if (emitJDK9StringSubstitutions) { |
80 |
registerStringLatin1Plugins(invocationPlugins, bytecodeProvider); |
|
81 |
registerStringUTF16Plugins(invocationPlugins, bytecodeProvider); |
|
82 |
} |
|
50609 | 83 |
registerUnsafePlugins(invocationPlugins, bytecodeProvider); |
50330 | 84 |
// This is temporarily disabled until we implement correct emitting of the CAS |
85 |
// instructions of the proper width. |
|
50858 | 86 |
registerPlatformSpecificUnsafePlugins(invocationPlugins, bytecodeProvider, explicitUnsafeNullChecks, |
50330 | 87 |
new JavaKind[]{JavaKind.Int, JavaKind.Long, JavaKind.Object}); |
43972 | 88 |
} |
89 |
}); |
|
90 |
} |
|
91 |
||
54601 | 92 |
private static void registerIntegerLongPlugins(InvocationPlugins plugins, JavaKind kind, BytecodeProvider bytecodeProvider) { |
43972 | 93 |
Class<?> declaringClass = kind.toBoxedJavaClass(); |
94 |
Class<?> type = kind.toJavaClass(); |
|
95 |
Registration r = new Registration(plugins, declaringClass, bytecodeProvider); |
|
96 |
r.register1("numberOfLeadingZeros", type, new InvocationPlugin() { |
|
97 |
@Override |
|
98 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { |
|
99 |
ValueNode folded = AArch64CountLeadingZerosNode.tryFold(value); |
|
100 |
if (folded != null) { |
|
101 |
b.addPush(JavaKind.Int, folded); |
|
102 |
} else { |
|
103 |
b.addPush(JavaKind.Int, new AArch64CountLeadingZerosNode(value)); |
|
104 |
} |
|
105 |
return true; |
|
106 |
} |
|
107 |
}); |
|
108 |
r.register1("numberOfTrailingZeros", type, new InvocationPlugin() { |
|
109 |
@Override |
|
110 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { |
|
46344 | 111 |
ValueNode folded = AArch64CountTrailingZerosNode.tryFold(value); |
43972 | 112 |
if (folded != null) { |
113 |
b.addPush(JavaKind.Int, folded); |
|
114 |
} else { |
|
46344 | 115 |
b.addPush(JavaKind.Int, new AArch64CountTrailingZerosNode(value)); |
43972 | 116 |
} |
117 |
return true; |
|
118 |
} |
|
119 |
}); |
|
54601 | 120 |
r.register1("bitCount", type, new InvocationPlugin() { |
121 |
@Override |
|
122 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { |
|
123 |
b.push(JavaKind.Int, b.append(new AArch64BitCountNode(value).canonical(null))); |
|
124 |
return true; |
|
125 |
} |
|
126 |
}); |
|
43972 | 127 |
} |
128 |
||
58533 | 129 |
private static void registerMathPlugins(InvocationPlugins plugins, boolean useFMAIntrinsics) { |
46344 | 130 |
Registration r = new Registration(plugins, Math.class); |
131 |
registerUnaryMath(r, "sin", SIN); |
|
132 |
registerUnaryMath(r, "cos", COS); |
|
133 |
registerUnaryMath(r, "tan", TAN); |
|
134 |
registerUnaryMath(r, "exp", EXP); |
|
135 |
registerUnaryMath(r, "log", LOG); |
|
136 |
registerUnaryMath(r, "log10", LOG10); |
|
137 |
r.register2("pow", Double.TYPE, Double.TYPE, new InvocationPlugin() { |
|
138 |
@Override |
|
139 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) { |
|
46393 | 140 |
b.push(JavaKind.Double, b.append(BinaryMathIntrinsicNode.create(x, y, BinaryMathIntrinsicNode.BinaryOperation.POW))); |
46344 | 141 |
return true; |
142 |
} |
|
143 |
}); |
|
50330 | 144 |
registerRound(r, "rint", RoundingMode.NEAREST); |
145 |
registerRound(r, "ceil", RoundingMode.UP); |
|
146 |
registerRound(r, "floor", RoundingMode.DOWN); |
|
58533 | 147 |
if (useFMAIntrinsics && JavaVersionUtil.JAVA_SPEC > 8) { |
148 |
registerFMA(r); |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
private static void registerFMA(Registration r) { |
|
153 |
r.register3("fma", Double.TYPE, Double.TYPE, Double.TYPE, new InvocationPlugin() { |
|
154 |
@Override |
|
155 |
public boolean apply(GraphBuilderContext b, |
|
156 |
ResolvedJavaMethod targetMethod, |
|
157 |
Receiver receiver, |
|
158 |
ValueNode na, |
|
159 |
ValueNode nb, |
|
160 |
ValueNode nc) { |
|
161 |
b.push(JavaKind.Double, b.append(new FusedMultiplyAddNode(na, nb, nc))); |
|
162 |
return true; |
|
163 |
} |
|
164 |
}); |
|
165 |
r.register3("fma", Float.TYPE, Float.TYPE, Float.TYPE, new InvocationPlugin() { |
|
166 |
@Override |
|
167 |
public boolean apply(GraphBuilderContext b, |
|
168 |
ResolvedJavaMethod targetMethod, |
|
169 |
Receiver receiver, |
|
170 |
ValueNode na, |
|
171 |
ValueNode nb, |
|
172 |
ValueNode nc) { |
|
173 |
b.push(JavaKind.Float, b.append(new FusedMultiplyAddNode(na, nb, nc))); |
|
174 |
return true; |
|
175 |
} |
|
176 |
}); |
|
46344 | 177 |
} |
178 |
||
179 |
private static void registerUnaryMath(Registration r, String name, UnaryOperation operation) { |
|
180 |
r.register1(name, Double.TYPE, new InvocationPlugin() { |
|
181 |
@Override |
|
182 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { |
|
46393 | 183 |
b.push(JavaKind.Double, b.append(UnaryMathIntrinsicNode.create(value, operation))); |
46344 | 184 |
return true; |
185 |
} |
|
186 |
}); |
|
43972 | 187 |
} |
49873 | 188 |
|
50330 | 189 |
private static void registerRound(Registration r, String name, RoundingMode mode) { |
190 |
r.register1(name, Double.TYPE, new InvocationPlugin() { |
|
191 |
@Override |
|
192 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) { |
|
193 |
b.push(JavaKind.Double, b.append(new AArch64RoundNode(arg, mode))); |
|
194 |
return true; |
|
195 |
} |
|
196 |
}); |
|
197 |
} |
|
198 |
||
49873 | 199 |
private static void registerStringLatin1Plugins(InvocationPlugins plugins, BytecodeProvider replacementsBytecodeProvider) { |
55509 | 200 |
if (JavaVersionUtil.JAVA_SPEC >= 9) { |
49873 | 201 |
Registration r = new Registration(plugins, "java.lang.StringLatin1", replacementsBytecodeProvider); |
202 |
r.setAllowOverwrite(true); |
|
203 |
r.registerMethodSubstitution(AArch64StringLatin1Substitutions.class, "compareTo", byte[].class, byte[].class); |
|
204 |
r.registerMethodSubstitution(AArch64StringLatin1Substitutions.class, "compareToUTF16", byte[].class, byte[].class); |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
private static void registerStringUTF16Plugins(InvocationPlugins plugins, BytecodeProvider replacementsBytecodeProvider) { |
|
55509 | 209 |
if (JavaVersionUtil.JAVA_SPEC >= 9) { |
49873 | 210 |
Registration r = new Registration(plugins, "java.lang.StringUTF16", replacementsBytecodeProvider); |
211 |
r.setAllowOverwrite(true); |
|
212 |
r.registerMethodSubstitution(AArch64StringUTF16Substitutions.class, "compareTo", byte[].class, byte[].class); |
|
213 |
r.registerMethodSubstitution(AArch64StringUTF16Substitutions.class, "compareToLatin1", byte[].class, byte[].class); |
|
214 |
} |
|
215 |
} |
|
216 |
||
50609 | 217 |
private static void registerUnsafePlugins(InvocationPlugins plugins, BytecodeProvider replacementsBytecodeProvider) { |
52910 | 218 |
registerUnsafePlugins(new Registration(plugins, Unsafe.class), |
219 |
new JavaKind[]{JavaKind.Int, JavaKind.Long, JavaKind.Object}, "Object"); |
|
55509 | 220 |
if (JavaVersionUtil.JAVA_SPEC > 8) { |
52910 | 221 |
registerUnsafePlugins(new Registration(plugins, "jdk.internal.misc.Unsafe", replacementsBytecodeProvider), |
222 |
new JavaKind[]{JavaKind.Int, JavaKind.Long, JavaKind.Object}, |
|
55509 | 223 |
JavaVersionUtil.JAVA_SPEC <= 11 ? "Object" : "Reference"); |
50330 | 224 |
} |
52578 | 225 |
} |
226 |
||
52910 | 227 |
private static void registerUnsafePlugins(Registration r, JavaKind[] unsafeJavaKinds, String objectKindName) { |
50330 | 228 |
|
50609 | 229 |
for (JavaKind kind : unsafeJavaKinds) { |
50330 | 230 |
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass(); |
52910 | 231 |
String kindName = kind == JavaKind.Object ? objectKindName : kind.name(); |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
50858
diff
changeset
|
232 |
r.register4("getAndSet" + kindName, Receiver.class, Object.class, long.class, javaClass, new InvocationPlugin() { |
50609 | 233 |
@Override |
234 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode value) { |
|
235 |
// Emits a null-check for the otherwise unused receiver |
|
236 |
unsafe.get(); |
|
237 |
b.addPush(kind, new AtomicReadAndWriteNode(object, offset, value, kind, LocationIdentity.any())); |
|
238 |
b.getGraph().markUnsafeAccess(); |
|
239 |
return true; |
|
240 |
} |
|
241 |
}); |
|
242 |
||
243 |
if (kind != JavaKind.Boolean && kind.isNumericInteger()) { |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
50858
diff
changeset
|
244 |
r.register4("getAndAdd" + kindName, Receiver.class, Object.class, long.class, javaClass, new InvocationPlugin() { |
50330 | 245 |
@Override |
246 |
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode delta) { |
|
247 |
// Emits a null-check for the otherwise unused receiver |
|
248 |
unsafe.get(); |
|
249 |
AddressNode address = b.add(new OffsetAddressNode(object, offset)); |
|
250 |
b.addPush(kind, new AtomicReadAndAddNode(address, delta, kind, LocationIdentity.any())); |
|
251 |
b.getGraph().markUnsafeAccess(); |
|
252 |
return true; |
|
253 |
} |
|
254 |
}); |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
43972 | 258 |
} |