"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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
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:
Abstract:
Mark Mayo explained this nicely.
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.
Well it works by continually analyzing the program's performance looking for 'hotspots' that might be frequently or repeatedly executed, which are then targeted for optimization for high performance execution with minimum overhead, for less performance-critical code.
So in theory if there is some bounds checking and it's evident through repeated and frequent execution that it's impossible for it to exceed the bounds, hotspots might optimize out those checks. Doesn't mean it's infallible, but that may be one reason why it happens.
From a 2007 article by Würthinger et al: "Whenever an array element is accessed, Java virtual machines execute a compare instruction to ensure that the index value is within the valid bounds. This reduces the execution speed of Java programs. Array bounds check elimination identifies situations in which such checks are redundant and can be removed. We present an array bounds check elimination algorithm for the Java HotSpot™ VM based on static analysis in the just-in-time compiler."