use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class IntrinsifyMethodHandlesInvocationPlugin method registerInvocationPlugins.
private static void registerInvocationPlugins(InvocationPlugins plugins, Replacements replacements) {
Registration r = new Registration(plugins, "java.lang.invoke.DirectMethodHandle", replacements);
r.register(new RequiredInvocationPlugin("ensureInitialized", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
/*
* Method handles for static methods have a guard that initializes the class (if the
* class was not yet initialized when the method handle was created). We emit the
* class initialization check manually later on when appending nodes to the target
* graph.
*/
return true;
}
});
r = new Registration(plugins, "java.lang.invoke.Invokers", replacements);
r.register(new OptionalInvocationPlugin("maybeCustomize", MethodHandle.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode mh) {
/*
* JDK 8 update 60 added an additional customization possibility for method handles.
* For all use cases that we care about, that seems to be unnecessary, so we can
* just do nothing.
*/
return true;
}
});
r = new Registration(plugins, Objects.class, replacements);
r.register(new RequiredInvocationPlugin("requireNonNull", Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode object) {
/*
* Instead of inlining the method, intrinsify it to a pattern that we can easily
* detect when looking at the parsed graph.
*/
b.push(JavaKind.Object, b.addNonNullCast(object));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerSizeOfPlugins.
private static void registerSizeOfPlugins(SnippetReflectionProvider snippetReflection, InvocationPlugins plugins) {
Registration r = new Registration(plugins, SizeOf.class);
r.register(new RequiredInvocationPlugin("get", Class.class) {
@SuppressWarnings("unchecked")
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode classNode) {
Class<? extends PointerBase> clazz = constantObjectParameter(b, snippetReflection, targetMethod, 0, Class.class, classNode);
int result = SizeOf.get(clazz);
b.addPush(JavaKind.Int, ConstantNode.forInt(result));
return true;
}
});
r.register(new RequiredInvocationPlugin("unsigned", Class.class) {
@SuppressWarnings("unchecked")
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode classNode) {
Class<? extends PointerBase> clazz = constantObjectParameter(b, snippetReflection, targetMethod, 0, Class.class, classNode);
UnsignedWord result = SizeOf.unsigned(clazz);
b.addPush(JavaKind.Object, ConstantNode.forConstant(snippetReflection.forObject(result), b.getMetaAccess()));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerAtomicUpdaterPlugins.
private static void registerAtomicUpdaterPlugins(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection, InvocationPlugins plugins, ParsingReason reason) {
Registration referenceUpdaterRegistration = new Registration(plugins, AtomicReferenceFieldUpdater.class);
referenceUpdaterRegistration.register(new RequiredInvocationPlugin("newUpdater", Class.class, Class.class, String.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode tclassNode, ValueNode vclassNode, ValueNode fieldNameNode) {
interceptUpdaterInvoke(metaAccess, snippetReflection, reason, tclassNode, fieldNameNode);
/* Always return false; the call is not replaced. */
return false;
}
});
Registration integerUpdaterRegistration = new Registration(plugins, AtomicIntegerFieldUpdater.class);
integerUpdaterRegistration.register(new RequiredInvocationPlugin("newUpdater", Class.class, String.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode tclassNode, ValueNode fieldNameNode) {
interceptUpdaterInvoke(metaAccess, snippetReflection, reason, tclassNode, fieldNameNode);
/* Always return false; the call is not replaced. */
return false;
}
});
Registration longUpdaterRegistration = new Registration(plugins, AtomicLongFieldUpdater.class);
longUpdaterRegistration.register(new RequiredInvocationPlugin("newUpdater", Class.class, String.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode tclassNode, ValueNode fieldNameNode) {
interceptUpdaterInvoke(metaAccess, snippetReflection, reason, tclassNode, fieldNameNode);
/* Always return false; the call is not replaced. */
return false;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerPlatformPlugins.
private static void registerPlatformPlugins(SnippetReflectionProvider snippetReflection, InvocationPlugins plugins) {
Registration r = new Registration(plugins, Platform.class);
r.register(new RequiredInvocationPlugin("includedIn", Class.class) {
@SuppressWarnings("unchecked")
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode classNode) {
Class<? extends Platform> platform = constantObjectParameter(b, snippetReflection, targetMethod, 0, Class.class, classNode);
boolean result = Platform.includedIn(platform);
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(result));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerReferenceAccessPlugins.
private static void registerReferenceAccessPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, ReferenceAccessImpl.class);
r.register(new RequiredInvocationPlugin("getCompressedRepresentation", Receiver.class, Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode objectNode) {
if (ReferenceAccess.singleton().haveCompressedReferences()) {
ValueNode compressedObj = SubstrateCompressionNode.compress(objectNode, ImageSingletons.lookup(CompressEncoding.class));
JavaKind compressedIntKind = JavaKind.fromWordSize(ConfigurationValues.getObjectLayout().getReferenceSize());
ValueNode compressedValue = b.add(WordCastNode.narrowOopToUntrackedWord(compressedObj, compressedIntKind));
b.addPush(JavaKind.Object, ZeroExtendNode.convertUnsigned(compressedValue, FrameAccess.getWordStamp(), NodeView.DEFAULT));
} else {
b.addPush(JavaKind.Object, WordCastNode.objectToUntrackedPointer(objectNode, FrameAccess.getWordKind()));
}
return true;
}
});
r.register(new RequiredInvocationPlugin("uncompressReference", Receiver.class, UnsignedWord.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode wordNode) {
if (ReferenceAccess.singleton().haveCompressedReferences()) {
CompressEncoding encoding = ImageSingletons.lookup(CompressEncoding.class);
JavaKind compressedIntKind = JavaKind.fromWordSize(ConfigurationValues.getObjectLayout().getReferenceSize());
NarrowOopStamp compressedStamp = (NarrowOopStamp) SubstrateNarrowOopStamp.compressed((AbstractObjectStamp) StampFactory.object(), encoding);
ValueNode narrowNode = b.add(NarrowNode.convertUnsigned(wordNode, StampFactory.forKind(compressedIntKind), NodeView.DEFAULT));
WordCastNode compressedObj = b.add(WordCastNode.wordToNarrowObject(narrowNode, compressedStamp));
b.addPush(JavaKind.Object, SubstrateCompressionNode.uncompress(compressedObj, encoding));
} else {
b.addPush(JavaKind.Object, WordCastNode.wordToObject(wordNode, FrameAccess.getWordKind()));
}
return true;
}
});
}
Aggregations