31 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG; |
31 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG; |
32 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG10; |
32 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG10; |
33 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.SIN; |
33 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.SIN; |
34 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.TAN; |
34 import static org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.TAN; |
35 import static org.graalvm.compiler.serviceprovider.GraalServices.JAVA_SPECIFICATION_VERSION; |
35 import static org.graalvm.compiler.serviceprovider.GraalServices.JAVA_SPECIFICATION_VERSION; |
|
36 import static org.graalvm.compiler.serviceprovider.GraalServices.Java11OrEarlier; |
36 import static org.graalvm.compiler.serviceprovider.GraalServices.Java8OrEarlier; |
37 import static org.graalvm.compiler.serviceprovider.GraalServices.Java8OrEarlier; |
37 |
38 |
38 import java.util.Arrays; |
39 import java.util.Arrays; |
39 |
40 |
40 import org.graalvm.compiler.bytecode.BytecodeProvider; |
41 import org.graalvm.compiler.bytecode.BytecodeProvider; |
228 } |
229 } |
229 } |
230 } |
230 } |
231 } |
231 |
232 |
232 private static void registerUnsafePlugins(InvocationPlugins plugins, BytecodeProvider replacementsBytecodeProvider, boolean explicitUnsafeNullChecks) { |
233 private static void registerUnsafePlugins(InvocationPlugins plugins, BytecodeProvider replacementsBytecodeProvider, boolean explicitUnsafeNullChecks) { |
233 registerUnsafePlugins(new Registration(plugins, Unsafe.class), explicitUnsafeNullChecks, new JavaKind[]{JavaKind.Int, JavaKind.Long, JavaKind.Object}); |
234 registerUnsafePlugins(new Registration(plugins, Unsafe.class), explicitUnsafeNullChecks, new JavaKind[]{JavaKind.Int, JavaKind.Long, JavaKind.Object}, true); |
234 if (!Java8OrEarlier) { |
235 if (!Java8OrEarlier) { |
235 registerUnsafePlugins(new Registration(plugins, "jdk.internal.misc.Unsafe", replacementsBytecodeProvider), explicitUnsafeNullChecks, |
236 registerUnsafePlugins(new Registration(plugins, "jdk.internal.misc.Unsafe", replacementsBytecodeProvider), explicitUnsafeNullChecks, |
236 new JavaKind[]{JavaKind.Boolean, JavaKind.Byte, JavaKind.Char, JavaKind.Short, JavaKind.Int, JavaKind.Long, JavaKind.Object}); |
237 new JavaKind[]{JavaKind.Boolean, JavaKind.Byte, JavaKind.Char, JavaKind.Short, JavaKind.Int, JavaKind.Long, JavaKind.Object}, Java11OrEarlier); |
237 } |
238 } |
238 } |
239 } |
239 |
240 |
240 private static void registerUnsafePlugins(Registration r, boolean explicitUnsafeNullChecks, JavaKind[] unsafeJavaKinds) { |
241 private static void registerUnsafePlugins(Registration r, boolean explicitUnsafeNullChecks, JavaKind[] unsafeJavaKinds, boolean java11OrEarlier) { |
241 for (JavaKind kind : unsafeJavaKinds) { |
242 for (JavaKind kind : unsafeJavaKinds) { |
242 Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass(); |
243 Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass(); |
243 |
244 String kindName = (kind == JavaKind.Object && !java11OrEarlier) ? "Reference" : kind.name(); |
244 r.register4("getAndSet" + kind.name(), Receiver.class, Object.class, long.class, javaClass, new UnsafeAccessPlugin(kind, explicitUnsafeNullChecks) { |
245 r.register4("getAndSet" + kindName, Receiver.class, Object.class, long.class, javaClass, new UnsafeAccessPlugin(kind, explicitUnsafeNullChecks) { |
245 @Override |
246 @Override |
246 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode value) { |
247 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode value) { |
247 // Emits a null-check for the otherwise unused receiver |
248 // Emits a null-check for the otherwise unused receiver |
248 unsafe.get(); |
249 unsafe.get(); |
249 createUnsafeAccess(object, b, (obj, loc) -> new AtomicReadAndWriteNode(obj, offset, value, kind, loc)); |
250 createUnsafeAccess(object, b, (obj, loc) -> new AtomicReadAndWriteNode(obj, offset, value, kind, loc)); |
250 return true; |
251 return true; |
251 } |
252 } |
252 }); |
253 }); |
253 if (kind != JavaKind.Boolean && kind.isNumericInteger()) { |
254 if (kind != JavaKind.Boolean && kind.isNumericInteger()) { |
254 r.register4("getAndAdd" + kind.name(), Receiver.class, Object.class, long.class, javaClass, new UnsafeAccessPlugin(kind, explicitUnsafeNullChecks) { |
255 r.register4("getAndAdd" + kindName, Receiver.class, Object.class, long.class, javaClass, new UnsafeAccessPlugin(kind, explicitUnsafeNullChecks) { |
255 @Override |
256 @Override |
256 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode delta) { |
257 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode delta) { |
257 // Emits a null-check for the otherwise unused receiver |
258 // Emits a null-check for the otherwise unused receiver |
258 unsafe.get(); |
259 unsafe.get(); |
259 createUnsafeAccess(object, b, (obj, loc) -> new AtomicReadAndAddNode(b.add(new OffsetAddressNode(obj, offset)), delta, kind, loc)); |
260 createUnsafeAccess(object, b, (obj, loc) -> new AtomicReadAndAddNode(b.add(new OffsetAddressNode(obj, offset)), delta, kind, loc)); |