Method inlining: why does MaxInlineLevel exist?

222 views
Skip to first unread message

Peter Veentjer

unread,
Jan 7, 2017, 7:58:25 AM1/7/17
to mechanica...@googlegroups.com
perhaps a naive question, but why is there a the max inlining depth? 

I understand there is a limit on the maximum inline size of a method; AFAIK the reason behind this limitation is that you otherwise would get a huge amount of code. And this could e.g. reduce the effectiveness of the instruction cache and consumes more memory. Please correct me if I'm wrong.

But as long as the code size isn't exceeded; why not keep inlining?

So why should the following program:

int a1(int x){return a2(x);}
int a2(int x){return a3(x);}
....
int aN(int x){return x+1;}

not be allowed to simplify to the following, independent of N.

int a1(int x){return x+1;}

[edit]
Could it be related to limit the amount of state required for constructing a stacktrace in case of an exception?


Chris Newland

unread,
Jan 7, 2017, 6:20:52 PM1/7/17
to mechanical-sympathy
Hi Peter,


and in share/vm/opto/bytecodeInfo.cpp of the JDK8 HotSpot source code there is the comment

// ...  If it is truly

// a recursion (using the same "receiver") we limit inlining otherwise we can easily blow the

// compiler stack.


So it would appear part of the reason for the limit is to protect the native stack of the JIT compiler (as per Rickard's comment).


Additionally, without any limit on inlining, the time taken to compile very deep trees could hold up the compiler queues and negatively affect performance.


Cheers,


Chris

Reply all
Reply to author
Forward
0 new messages