Hotspot loves PHP.reboot
John Rose
john.r.rose at oracle.com
Tue Sep 6 16:10:56 PDT 2011
On Sep 6, 2011, at 1:18 PM, Charles Oliver Nutter wrote:
> On Tue, Sep 6, 2011 at 3:04 PM, John Rose <john.r.rose at oracle.com> wrote:
>> (1) Write a compelling API for something like Integer.addDetectingOverflow.
>> (2) Roll it into JDK 8+epsilon.
>> (3) Do the JIT work.
>> People have thought on and off about (1) for many years, but with no clear
>> winner. Exceptions or boxed objects have unpleasant interactions and are
>> hard to use, while smuggling out the 33rd bit some other way (TLS, a long or
>> double, a return-by-reference, a sentinel value) is painful.
>> (This is a case where tuples would make things simple, but it is not enough
>> to motivate introducing tuples.)
>
> Not that it matters, but JRuby's integer math is all 64-bit...so we
> want a 65th bit of data out of maths :)
Most of the tricks apply to both 32- and 64-bit ints.
> ...that's a fun little
> API design problem to solve. Hmm.
Yes. Your request for "JO" makes me think some users would be happy with a boolean test, a la addWouldOverflow.
It's what happens after the test that differs widely among applications, so why not just standardize the test.
if (addWouldOverflow(p, q)) { throw or return BigInt or ... }
return new Integer(p + q);
The p+q, if it occurs within addWouldOverflow(p, q), will value-number to the explicit p+q, allowing the expected assembly code which computes p+q and then checks the overflow bit.
(Actually, it's likely that the "addl p',q" instruction would occur twice, because hotspot not very good at tracking condition codes.)
On Sep 6, 2011, at 1:36 PM, Rémi Forax wrote:
> An exception is perhaps more easier to use,
> because if it overflow you may have to deoptimize, for that you need the stack and local values,
> it's easier to jump to a exception handler that will push all these values and call the interpreter.
That's true, except that exceptions tend to be imprecise: It's hard to tell which sub-expression cause the exception, out of a complex statement.
Addressing both the precision and pre-allocation problems, you could ask the application to create the exception:
public static <X extends Throwable>
int addDetectingOverflow(int x, int y, X onOverflow) throws X
-- John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20110906/63e2769a/attachment.html
More information about the mlvm-dev
mailing list