general inlining
Raffaello Giulietti
raffaello.giulietti at gmail.com
Tue Feb 16 10:04:22 PST 2010
On 2010-02-16 17:09, Christian Thalinger wrote:
> On 02/16/10 03:07 PM, Raffaello Giulietti wrote:
>> A general question about inlining. Take the following code:
>>
>> void m() {
>> ensureSomething();
>> ...
>> }
>>
>> void ensureSomething() {
>> if (someTest()) return;
>> doSomething();
>> }
>>
>> boolean someTest() {
>> return ... // a simple boolean expression;
>> }
>>
>> void doSomething() {
>> // heavy and long code
>> ...
>> }
>>
>> I would like the lightweight test in ensureSomething(), but not the
>> heavy doSomething(), to be inlined at each call site, like that in m().
>> Is a general jvm (HotSpot in primis) smart enough to do the inlining by
>> itself or is it better to code the pattern more explicitly by using
>> method handles to factor out the test, e.g., using guarded method handles?
>
> If doSomething() is heavy enough to not be inlined (or cold) and
> someTest() is light enough to be inlined (or hot) in regard to the
> inlining heuristics, yes, the JVM should do the right thing for you.
>
> You can verify if HotSpot does what you want with:
>
> -XX:+PrintCompilation -XX:+PrintInlining
>
I asked because this kind of inlining seems quite clever to my
uneducated eyes. Inlining, in m() or at other call sites, only a part of
ensureSomething() while skipping the other heavier part and morphing it
to another callable method appears quite a wonder without hints from
part of the programmer in form of objects like method handles and the
guarded counterparts. Kudos to the implementors!
More information about the mlvm-dev
mailing list