MethodSubstitution non-static methods

Gilles Duboscq duboscq at
Tue Dec 17 08:39:33 PST 2013

About "forced" you can look at the Javadoc on MethodSubstitution#forced:

* Determines if this method should be substituted in all cases, even if
inlining thinks it isnot important.

Are you sure the call site where you expect the substitution to happen can
be de-virtualized?

Are you sure your substitution is registered? For an example about how this
is achieved for other substitutions, have a look
You need to implement the
interface and have the @ServiceProvider(ReplacementsProvider.class)

The magic behind the @ServiceProvider annotation can be a bit brittle when
building using eclipse. To be sure, you can do a mx clean and mx build.


On Tue, Dec 17, 2013 at 5:24 PM, Curt Albert <falbert9 at> wrote:

> Is it possible to preform a method substitution on a non static method?
> When I try and use @MethodSubstitution followed by a non static method I
> get the error " Context obj
> Substitution methods must be static:" I was looking at
> and for encryptBlock and decryptBlock those
> methods are not static in com.sun.crypto.provider.AESCrypt and they have
> (isStatic = false) after the @MethodSubstitution then static and the method
> with an additional Object in the parameters. A similar thing is true for
> the for several methods the @MethodSubstitution is
> followed by (isStatic = false) and have an extra object in the parameters
> and some have forced = true, but when I try adding (isStatic = false) and
> static in front of my MethodSubstitution and an object in the parameters
> graal never substitutes the method.
> How do you substitute a non-static method in graal and what does forced =
> true mean?
> //In VectorSubstitutions,java and tested that substitutions are registered
> and does substitute for static test methods
> @MethodSubstitution(isStatic = false, forced = true)
>     static void vecExecution(Object thisObj, int vec) {
> System.out.println("vect");
>     }
> //The method I am trying to substitute
> public void vecExecution(int vec)
>    {
>       for(int i = 0; i < vec; i++)
>       {
>          run();
>          //increment group id
>          kernelState.setGroupId(0,(kernelState.getGroupIds()[0] + 1));
>          //increment global id
>          kernelState.setGlobalId(0,(kernelState.getGlobalIds()[0] + 1));
>       }
>    }
> Thanks,
> Curt Albert

More information about the graal-dev mailing list