Date: Fri, 9 Jul 1999 16:52:19 -0600 From: Nate Williams <nate@mt.sri.com> To: Martin Dieringer <dieringe@zedat.fu-berlin.de> Cc: Nate Williams <nate@mt.sri.com>, Stephen McKay <syssgm@detir.qld.gov.au>, freebsd-java@FreeBSD.ORG, java-port@FreeBSD.ORG Subject: Re: strange java calculation errors Message-ID: <199907092252.QAA10373@mt.sri.com> In-Reply-To: <Pine.BSF.4.10.9907092353330.44163-100000@ThinkPad.nowhere.local> References: <199907091530.JAA05956@mt.sri.com> <Pine.BSF.4.10.9907092353330.44163-100000@ThinkPad.nowhere.local>
next in thread | previous in thread | raw e-mail | index | archive | help
> Ok, I set up a sample program. I think it needs to be an awt-application.
> I don't get any errors without setVisible(), but with a visible frame
> I get errors every few seconds. It has to be a Thread, too, I think.
> Probably you know how to track this down further.
I just spent a bit of time with this, and this is indeed a weird one.
It seems to depend on how the storage is allocated, since if I calculate
the value of denom as part of the local heap, it seems to work. Either
that or I'm just getting lucky, because the code works if I calculate
the exact same code and store it in a 'local' variable. (However, local
variables are treated almost exactly the same as global variables in
java.)
In any case, it is indeed a bug, and one that I don't see on Solaris.
Whether it's a bug in some FreeBSD library or in the way the VM operates
is still unknown. If I had to make a guess, I'd start looking at the C
interpreter, given that we are one of the only platforms that use it,
while others use the assembly version. However, it's just a wild guess.
Thanks again Martin!
Nate
> //BugTest.java ----------------------------------------------
>
> import java.awt.*;
> import java.util.Random;
>
> public class BugTest extends Frame implements Runnable
> {
>
> Random random = new Random();
>
> double weight;
> double denom;
> double meatEnergy;
> double weightgain;
>
> public BugTest(){
> setSize(100,100);
> setVisible(true);
> }
>
>
> public void run(){
> while (true){
> try{
> calc();
> } catch (ArithmeticException a) {
> System.err.println("weight: "+ weight + "\ndenom: "+ denom);
> a.printStackTrace();
> }
> }
> }
>
> void calc() throws ArithmeticException {
> weight = random.nextDouble()*10.;
> meatEnergy= 0.029994563969828213;
> denom = (.0836 * Math.pow(weight, 1.37));
> weightgain = .2849372 * meatEnergy * weight / denom;
> if (weightgain > 1000.)
> throw new ArithmeticException("weightgain "+weightgain);
> }
>
> public static void main(String args[]){
> BugTest bug = new BugTest();
> Thread bugThread = new Thread(bug);
> bugThread.setPriority(Thread.MIN_PRIORITY);
> bugThread.start();
> }
>
> }
>
> //------------------------------------------------------
>
>
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907092252.QAA10373>
