Re:Efficient Integer Overflow Checking in LLVM (2016)
by tom_mellior on Thursday September 24, 2020 @05:50AM
(#24576969)
Why would OpenJDK do integer overflow checking? Java integers have well-defined two's complement wrapping semantics. When you add two positive numbers and get a negative result, this might not be what the programmer wanted, but it is not undefined behavior like it is in C.
Are you maybe mixing this up with array bounds checking?
Re:Efficient Integer Overflow Checking in LLVM (2016)
by MaxBarraclough on Thursday September 24, 2020 @06:06AM
(#24577047)
Oops, you're right! I forgot Java arithmetic wraps, offering (rarely used) methods for overflow-checked arithmetic. [0]
I was right about .Net though. Assuming a checked context, .Net (and C#) throw on overflow, rather than wrapping. [1]
[0] https://docs.oracle.com/en/java/javase/11/docs/api/java.base...
[1] https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
Re:Efficient Integer Overflow Checking in LLVM (2016)
by chrisseaton on Thursday September 24, 2020 @06:05AM
(#24577039)
OpenJDK only does overflow checking in a tiny number of cases.
Re:Efficient Integer Overflow Checking in LLVM (2016)
by MaxBarraclough on Thursday September 24, 2020 @06:10AM
(#24577070)
Cunningham's Law strikes again!
You're right of course. Please see my response to tom_mellior.
Presumably .Net goes to great lengths to optimise overflow-checking, as the checks are enabled for production use. I wonder if they manage to get the overhead to below the 8.7% mentioned in the article.
edit: I had put OpenJDK and .Net but tom_mellior is right to point out that Java has wrapping arithmetic