Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Arithmetic overflow checking (http://www.velocityreviews.com/forums/t751016-arithmetic-overflow-checking.html)

rop rop 07-06-2011 03:35 PM

Arithmetic overflow checking
 
Hi,

If I want to have arithmetic-overflow checking in all parts of an
application,
what is the most practical, simple, efficient way to achieve this?
Id like to clutter the code as little a possible...
Is there any way to instruct the JVM to include it?

Stefan Ram 07-06-2011 04:41 PM

Re: Arithmetic overflow checking
 
rop rop <rop049@gmail.com> writes:
>If I want to have arithmetic-overflow checking in all parts of an
>application,
>what is the most practical, simple, efficient way to achieve this?
>Id like to clutter the code as little a possible...


One could use a JVM-based language with operator overloading.

>Is there any way to instruct the JVM to include it?


One also could write a bytecode-to-bytecode transformer
that modifies arithmetic operations accordingly.


markspace 07-06-2011 04:42 PM

Re: Arithmetic overflow checking
 
On 7/6/2011 8:35 AM, rop rop wrote:
> Hi,
>
> If I want to have arithmetic-overflow checking in all parts of an
> application,
> what is the most practical, simple, efficient way to achieve this?
> Id like to clutter the code as little a possible...
> Is there any way to instruct the JVM to include it?



Nope, can't be done. And yes I've griped about this myself, so you're
in good (well, average at least) company.



stefan@nyniva.se 07-06-2011 06:30 PM

Re: Arithmetic overflow checking
 
On Jul 6, 6:42*pm, markspace <-@.> wrote:
> On 7/6/2011 8:35 AM, rop rop wrote:
>
> > Hi,

>
> > If I want to have arithmetic-overflow checking in all parts of an
> > application,
> > what is the most practical, simple, efficient way to achieve this?
> > Id like to clutter the code as little a possible...
> > Is there any way to instruct the JVM to include it?

>
> Nope, can't be done. *And yes I've griped about this myself, so you're
> in good (well, average at least) company.


OK...
What about patching the JVM to add this (sadly missing) "feature"?
It is open-source, isnt it?

Nobody has done this already?
Doesnt seems like a terribly big project, once I can locate the right
place to do it...

Any license aspects to consider, if I do it myself?

markspace 07-06-2011 06:36 PM

Re: Arithmetic overflow checking
 
On 7/6/2011 11:30 AM, stefan@nyniva.se wrote:

> Doesnt seems like a terribly big project, once I can locate the right
> place to do it...



lol. Yeah right.

http://openjdk.java.net/

Good luck kid.


Tom Anderson 07-06-2011 09:32 PM

Re: Arithmetic overflow checking
 
On Wed, 6 Jul 2011, Wanja Gayk wrote:

> In article <015aeb15-57db-48ab-9cd4-
> 77f8448b632f@w24g2000yqw.googlegroups.com>, rop049@gmail.com says...
>
>> If I want to have arithmetic-overflow checking in all parts of an
>> application, what is the most practical, simple, efficient way to
>> achieve this? Id like to clutter the code as little a possible... Is
>> there any way to instruct the JVM to include it?

>
> Not automagically, at least if you want to avoid building a sourcecode-
> preprocessor or tool that instruments your bytecode at class loading
> time.


Actually, a load-time bytecode manipulator might be the most practical way
to do this. Modding the JVM is a non-starter for a few reasons, using an
alternative language is not even a solution, using a library or a set of
functions by convention is error-prone, but a bytecode weaver (using the
java.lang.instrument API, to be clear) could do the job, and would be a
fairly focused way of doing it - after the fairly small amount of
boilerplate, it would just be a matter of decoding all targeted bytecode
and rewriting it to check for overflow.

I didn't say it would be easy, just focused.

tom

--
History, I believe, furnishes no example of a priest-ridden people
maintaining a free civil government. -- Thomas Jefferson

Roedy Green 07-07-2011 05:41 AM

Re: Arithmetic overflow checking
 
On Wed, 6 Jul 2011 08:35:01 -0700 (PDT), rop rop <rop049@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>If I want to have arithmetic-overflow checking in all parts of an
>application,
>what is the most practical, simple, efficient way to achieve this?
>Id like to clutter the code as little a possible...
>Is there any way to instruct the JVM to include it?


the JVM does not detect it because most hardware does not. You pretty
well have to use long instead of int and mask off and check overflow.
--
Roedy Green Canadian Mind Products
http://mindprod.com
One thing I love about having a website, is that when I complain about
something, I only have to do it once. It saves me endless hours of grumbling.

Roedy Green 07-07-2011 05:43 AM

Re: Arithmetic overflow checking
 
On Wed, 6 Jul 2011 08:35:01 -0700 (PDT), rop rop <rop049@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>If I want to have arithmetic-overflow checking in all parts of an
>application,
>what is the most practical, simple, efficient way to achieve this?
>Id like to clutter the code as little a possible...


If your hardware detects it, you could use some JNI and test the
status codes and return a object containing the result and overflow
info. Slow though.
--
Roedy Green Canadian Mind Products
http://mindprod.com
One thing I love about having a website, is that when I complain about
something, I only have to do it once. It saves me endless hours of grumbling.

John B. Matthews 07-07-2011 06:26 AM

Re: Arithmetic overflow checking
 
In article <2rydnez7l-H5BYnTnZ2dnUVZ_vGdnZ2d@earthlink.com>,
Patricia Shanahan <pats@acm.org> wrote:

> On 7/6/2011 8:35 AM, rop rop wrote:
> >
> > If I want to have arithmetic-overflow checking in all parts of an
> > application, what is the most practical, simple, efficient way to
> > achieve this?

>
> Write the application in Ada.


In one popular implementation, the -gnato compiler option enables
numeric overflow checking:

<http://gcc.gnu.org/onlinedocs/gcc-4.6.1/gnat_ugn_unw/Switches-for-gcc.html#Switches-for-gcc>

The language defined attribute 'Machine_Overflows will indicate if
checking is available for fixed or floating point types:

<http://www.adaic.org/resources/add_content/standards/05rm/html/RM-K.html>

JGNAT targets the JVM, but I haven't used it.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

rop rop 07-07-2011 07:30 AM

Re: Arithmetic overflow checking
 
On Jul 6, 11:32*pm, Tom Anderson <t...@urchin.earth.li> wrote:
> Modding the JVM is a non-starter for a few reasons...


Hi Tom,
Thanks for input.
Could you just elaborate on this, please... what is the main-problem
with actually patching the JVM?
Why is it so hard?
Without having looked into the source-code, this seems like the most
straight-forward and robust way to do it...
Is the code so hard to penetrate or what?


All times are GMT. The time now is 11:41 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.