Intrinsics for MethodHandlesImpl

Yudi Zheng yudi.zheng at oracle.com
Thu Nov 8 10:37:33 UTC 2018


Hi Jean-Philippe,

This intrinsic is already implemented at StandardGraphBuilderPlugins.registerMethodHandleImplPlugins
Tom (CC'ed) is working on some patch around this intrinsic, hopefully would address the regression issue.
Anyway, you could find there how we register this kind of plugin.

Yudi

> On 8 Nov 2018, at 11:24, Gilles Duboscq <gilles.m.duboscq at oracle.com> wrote:
> 
> Hi Jean-Philippe,
> 
> The various intrinsification methods (aka plugins) can also be registered symbolically exactly for this reason.
> In particular, the `Registration` has constructors that take a String instead of a Class.
> 
> I'm a bit unsure about the snippet you have there: the class you pass to `Registration` is the one which defines the methods you want to intrinsify.
> 
> What type of plugin do you want? Is is really a method substitution?
>  Method substitutions are when you provide an alternative implementation using bytecodes (typically just Java code compiled to bytecodes).
>  An example of that can be found with `ArraysSubstitutions` and `StandardGraphBuilderPlugins#registerArraysPlugins`
> 
> Maybe you can use a simple `InvocationPlugin` which allows you to manually create some nodes to replace a call. This is usually easier when all you want is to replace a call with one node.
> For that you could take some inspiration from `GraalDirectives#injectBranchProbability`. You can see how it is intrinsified in `StandardGraphBuilderPlugins#registerGraalDirectivesPlugins`. As you can see we inject the probability rather than the counts but that's easy to convert. You'll just have to use the b.getConstantReflection() to get a `ConstantReflectionProvider` which should allow you to read the counters from the (hopefully) constant array.
> 
> I hope that helps.
> 
> Gilles
> 
> 
> 
> On 08/11/2018 05:38, Halimi, Jean-Philippe wrote:
>> Dear all,
>> 
>> I am currently looking into implementing an intrinsic in Graal, namely MethodHandleImpl::profileBoolean which is intrinsified in C2 (Work is tracked in https://bugs.openjdk.java.net/browse/JDK-8212670)
>> In C2, the matching is done as follows:
>> 
>>  do_class(java_lang_invoke_MethodHandleImpl,               "java/lang/invoke/MethodHandleImpl")                        \
>>  do_intrinsic(_profileBoolean, java_lang_invoke_MethodHandleImpl, profileBoolean_name, profileBoolean_signature, F_S)  \
>>   do_name(     profileBoolean_name,                             "profileBoolean")                                      \
>>   do_signature(profileBoolean_signature,                        "(Z[I)Z")
>> 
>> In Graal's Graph Plugin Builder, I was thinking of adding a match as follows:
>> 
>>    private static void registerMethodHandlesPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
>>        Registration r = new Registration(plugins, Arrays.class, bytecodeProvider);
>>        r.registerMethodSubstitution(MethodHandleImpl.class, "profileBoolean", boolean.class, int[].class);
>>    }
>> 
>> My problem is that I cannot find a proper way to import MethodHandleImpl, since it does not seem directly importable. Is this direction the right one, and if so which import should I use?
>> 
>> Thanks,
>> Jp
>> 
>> 



More information about the graal-dev mailing list