general inlining
Christian Thalinger
Christian.Thalinger at Sun.COM
Tue Feb 16 08:09:46 PST 2010
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
-- Christian
More information about the mlvm-dev
mailing list