本文介绍了Java 中的边界检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

热点可以移除 Java 中的边界检查."任何人都可以解释这一点吗?实际上我正在分析 C++ 和 Java 之间的差异.这不是家庭作业,我在分析自己的兴趣.

"Hotspot can remove bounds checking in Java." Can any one explain this please? Actually im analysing the differences between C++ and Java. It is not a homework and im analysing on my own interest.

推荐答案

谷歌搜索热点边界检查"后,一篇题为Java HotSpot™ 客户端编译器的数组边界检查消除" 的论文出现了(作为第一个结果)并为我们提供了一些见解:

After googling "hotspot bounds checking", a Paper with the Title "Array Bounds Check Elimination for the Java HotSpot™ Client Compiler" shows up (as the first result) and gives us some insight:

摘要:

每当访问数组元素时,Java 虚拟机执行一个比较指令以确保索引值在有效范围内界限.这减少了执行Java 程序的速度.数组边界检查消除标识此类检查的情况多余的,可以删除.我们呈现数组边界检查Java的消除算法基于静态分析的 HotSpot™ VM在即时编译器中.

该算法适用于中间体静态单一表示分配表并维护索引表达式的条件.它如果可以,完全删除边界检查被证明他们永远不会失败.只要有可能,它就会移动边界检查出循环.静态数检查次数保持不变,但一个检查循环内很可能是更频繁地执行.如果这样的检查失败,执行程序失败回到解释模式,避免抛出异常的问题错误的地方.

The algorithm works on an intermediate representation in static single assignment form and maintains conditions for index expressions. It fully removes bounds checks if it can be proven that they never fail. Whenever possible, it moves bounds checks out of loops. The static number of checks remains the same, but a check inside a loop is likely to be executed more often. If such a check fails, the executing program falls back to interpreted mode, avoiding the problem that an exception is thrown at the wrong place.

评估显示加速接近于的理论最大值科学 SciMark 基准测试套件(平均 40%).该算法还提高了执行速度SPECjvm98 基准测试套件(2%平均,最高 12%).

The evaluation shows a speedup near to the theoretical maximum for the scientific SciMark benchmark suite (40% on average). The algorithm also improves the execution speed for the SPECjvm98 benchmark suite (2% on average, 12% maximum).

Mark Mayo 很好地解释了这一点.

Mark Mayo explained this nicely.

底线:如果 Hotspot 检测到不需要检查数组的边界,它会将其视为禁用该数组的边界检查的机会,从而提高性能.

Bottom line: if Hotspot detects that it isn't necessary to check bounds for an array, it sees this as an oportunity to disable bounds checking for that array and therefore increase performance.

这篇关于Java 中的边界检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 07:21