为什么JVM具有最大内联深度? [英] Why does the JVM have a maximum inline depth?

查看:769
本文介绍了为什么JVM具有最大内联深度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java 有一个参数 -XX:MaxInlineLevel (默认值为9)控制最大数量嵌套调用内联。为什么会有这样的限制?为什么基于频率和代码大小的通常启发式算法不足以让JVM自行决定内联的深度?

java has an argument -XX:MaxInlineLevel (with a default value of 9) which controls the maximum number of nested calls to inline. Why is there any such limit? Why aren't the usual heuristics based on frequency and code size sufficient for the JVM to decide for itself how deeply to inline?

(这是由 JitWatch 显示的我,深度嵌套的Guava checkArgument 调用由于深度没有内联)

(this is prompted by JitWatch showing me that a deeply nested Guava checkArgument call was not being inlined due to depth)

推荐答案

一些重要的搜索揭示了这个有趣的小片段(我实际上已经到了页面 4 的Google搜索):

Some significant searching uncovers this interesting little fragment (I actually got as far as page 4 of the Google search):

    if (inline_depth() > MaxInlineLevel) {
        return "inlining too deep";
    }
    if (method() == callee_method
            && inline_depth() > MaxRecursiveInlineLevel) {
        return "recursively inlining too deep";
    }

这表明 MaxInlineLevel 正如预期的那样,在您停止内联之前,您的深度有限。它还建议 MaxRecursiveInlineLevel 仅指直接递归调用,而不是mutal递归调用,例如 foo()调用 bar()调用 foo()

Which suggest that the MaxInlineLevel is as expected a hard limit to how deep you go before you stop inlining. It also suggests that the MaxRecursiveInlineLevel refers only to direct recursive calls, not mutal recursive calls such as foo() calls bar() which calls foo().

所以我认为我的评论是正确的 - MaxInlineLevel 是为了防止相互递归,因为要检测你需要保持对完整的引用内联调用堆栈的深度。

So I think I was right in my guess comment - MaxInlineLevel is to protect against mutual recursion because to detect that you would need to keep references to the full depth of the inlining call stack.

MaxInlineResursionLevel 控制 foo()调用 foo()内联。

请注意,引用的代码可能不是真正的JVM。

Note that the referenced code may not be a real JVM.

@apangin的评论从Open JDK 8中找到一个更现代的热点版本,这表明它现在不再像那样简单了。看起来整个堆栈都在搜索递归调用,因此现在也可以阻止相互递归超过 MaxRecursiveInlineLevel

Comments by @apangin locates a more modern version of hotspot from Open JDK 8 suggest that it is nowadays no longer quite as simple as that. It looks like the full stack is searched for recursive calls so mutual recursion may also now be blocked from going past MaxRecursiveInlineLevel.

这篇关于为什么JVM具有最大内联深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆