Intrinsics for MethodHandlesImpl

Halimi, Jean-Philippe jean-philippe.halimi at intel.com
Fri Nov 9 00:54:56 UTC 2018


Hi Tom,

I have not looked into the generated code, as I assumed there was enough guidance to implement the low-hanging fruit here. :-) Just to make sure we are on the same page, we want to look at the generated code of guardWithTest, correct?

Thanks,
Jp

-----Original Message-----
From: Tom Rodriguez [mailto:tom.rodriguez at oracle.com] 
Sent: Thursday, November 8, 2018 2:03 PM
To: Halimi, Jean-Philippe <jean-philippe.halimi at intel.com>
Cc: Yudi Zheng <yudi.zheng at oracle.com>; graal-dev <graal-dev at openjdk.java.net>
Subject: Re: Intrinsics for MethodHandlesImpl

Halimi, Jean-Philippe wrote on 11/8/18 11:47 AM:
> Hi Yudi,
> 
> Thanks for letting me know. I think we should make sure Tom is the assignee for JDK-8212670 if that is the case.

I'm addressing a specific problem which is that the current profileBoolean intrinsic only gets a chance to do it's work too early so sometimes it doesn't see the profiles.  Fixing that seems to address a small part of the performance difference but I think there's some other problems in there as even with my fix applied there's still a gap with that particular benchmark.  Have you looked into the generated code at all?

tom

> 
> Jp
> 
> -----Original Message-----
> From: Yudi Zheng [mailto:yudi.zheng at oracle.com]
> Sent: Thursday, November 8, 2018 2:38 AM
> To: Halimi, Jean-Philippe <jean-philippe.halimi at intel.com>
> Cc: graal-dev <graal-dev at openjdk.java.net>; Tom Rodriguez 
> <tom.rodriguez at oracle.com>
> Subject: Re: Intrinsics for MethodHandlesImpl
> 
> 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