Inlining primitive targets?
John Rose
John.Rose at Sun.COM
Mon Jul 20 19:33:05 PDT 2009
On Jul 17, 2009, at 3:10 AM, Chanwit Kaewkasi wrote:
> Hi all,
> I just would like to see if the Hotspot is possible to inline this
> call site:
>
> InvokeDynamic.<Object>"plus"(Object, Object)
>
> with this target:
>
> public static final int plus(int, int) {
> return a + b;
> }
>
> I tested calling InvokeDynamic.<int>"plus"(Object, Object) with the
> above target
> and it is running fine, although it's not inlined. C2 was trying to
> inline it, but it failed.
> See the log here [1].
Thatnks; that's a bad bug. There's no way int and Integer can be
implicitly interconverted at that level. The inliner should never
have presented that bad IR to the code matcher. Note in the dump that
o658 and o674 are Integer-valued IR nodes, while the operator is
AddI, the ideal 32-bit add instruction.
> Then, I tested calling InvokeDynamic.<Object>"plus"(Object, Object)
> also with the above target.
> This time I used the Fibonacci program, and JVM crashed. Although it
> crashed, the inlining
> information is really interesting to me. You cal see the full log
> from [2].
>
> [Stub Code]
> 0xb3e78b00: jmp 0xb3e76e60 ; {no_reloc}
> 0xb3e78b05: push 0xb3e78b05 ; {section_word}
> 0xb3e78b0a: jmp 0xb3e4eb80 ; {runtime_call}
> [Constants]
> 0xb3e78b0f: int3
> @ 11 java.dyn.MethodHandle::invoke native method
> @ 14 sun.dyn.FromGeneric$Adapter::convert_I inline (hot)
> sun.dyn.FromGeneric$A2::invoke_I2 -> @ 14
> sun.dyn.FromGeneric$Adapter::convert_I >>TypeProfile (32782/32782
> counts) = sun/dyn/FromGeneric$A2 (9 bytes)
> @ 5 java.dyn.MethodHandle::invoke native method
> @ 33 java.dyn.MethodHandle::invoke native method
> @ 33 g7.tests.classgen.Fib::fib inline (hot)
> @ 2 java.lang.Integer::valueOf inline (hot)
> @ 5 java.dyn.MethodHandle::invoke native method
> @ 5 com.chanwit.g7.runtime.DefaultNumberMethods::__lt__
> inline (hot)
> @ 1 java.lang.Integer::intValue inline (hot)
> @ 5 java.lang.Integer::intValue inline (hot)
> @ 16 java.lang.Boolean::valueOf inline (hot)
> @ 13 java.lang.Boolean::booleanValue inline (hot)
> @ 25 java.lang.Integer::valueOf inline (hot)
> @ 28 java.dyn.MethodHandle::invoke native method
> @ 28 sun.dyn.FromGeneric$A2::invoke_I2 inline (hot)
> @ 11 java.dyn.MethodHandle::invoke native method
> @ 14 sun.dyn.FromGeneric$Adapter::convert_I inline (hot)
> sun.dyn.FromGeneric$A2::invoke_I2 -> @ 14
> sun.dyn.FromGeneric$Adapter::convert_I >>TypeProfile (32782/32782
> counts) = sun/dyn/FromGeneric$A2 (9 bytes)
> @ 5 java.dyn.MethodHandle::invoke native method
> @ 33 java.dyn.MethodHandle::invoke native method
> @ 33 g7.tests.classgen.Fib::fib recursively inlining too
> deep
> @ 40 java.lang.Integer::valueOf inline (hot)
> @ 43 java.dyn.MethodHandle::invoke native method
> @ 43 sun.dyn.FromGeneric$A2::invoke_I2 inline (hot)
>
> So my questions are (sorry if they look very newbie-ish):
All that sun.dyn stuff is the method handle tree used to manage the
boxing and unboxing of the operands.
> I think in several cases, we need binary operators to be primitives.
That's true. Your own plus(int,int) method handle will (almost
certainly) be inlined into a single instruction. That's what you
want, right?
> So is it possible to by-pass this call sun.dyn.FromGeneric
> $A2::invoke_I2 ?
> Or is it possible to have a call like
> sun.dyn.FromGeneric$A2::invoke_I2, but with (II)I.
After inlining it doesn't matter how the pieces were factored in the
sun.dyn internals. You should always get the code for unbox-unbox-add-
box.
> BTW, as the last time the target (Integer, Integer)Integer is
> successfully inlined,
> If I would like to do a simple boxing/unboxing pairs removal on
> generated assembly codes,
> which part of C2 can I start looking at?
That's already in C2, at least partly. Look at
LoadNode::eliminate_autobox and related functions.
To see if that's what you want, make some test cases that do *not* use
JSR 292 features, and look at the code to make sure your desired
optimizations happen.
When method handle inlining works, the same optimizations will apply
to the inlined method handle IR.
-- John
More information about the mlvm-dev
mailing list