[kaffe] Bug Report: BigInteger.toString() fails for large numbers

Guilhem Lavaux guilhem at kaffe.org
Tue Apr 20 00:08:03 PDT 2004


Hi,

Thanks for the excellent bug report. I fear this is the return of the
GCTest regression failure. After having passed the code through gdb it
seems kaffe hangs in getHeavyLock while trying to do some garbage
collection. The most interresting is that we have a pointer for
lk->holder which is beyond stack limits. So there is definitely
something wrong here.

Cheers,

Guilhem.

On Tue, 2004-04-20 at 08:12, Alan Eliasen wrote:
>    Here's an additional testcase for the BigInteger.toString() problem.
> Again, it requires the GMP libraries to be compiled in.
> 
>    The following sample creates larger and larger numbers.  At some point, the
> thread either silently stops running (but the process doesn't exit), or
> segfaults.  The exact behavior can be changed (somewhat randomly) by tweaking
> the "1.1" number in the code below.
> 
>    Surprisingly, when larger and larger numbers are created gradually, the
> largest number that can be calculated is bigger than in the last testcase.
> (The last testcase barfs at about 2^13,000,000, while this case can get up to
> about 2^16,000,000 (or sometimes much less.))  This may hint at a memory
> allocation/reallocation bug, or memory corruption, but the behavior seems to
> be very repeatable for any given parameters.
> 
>    Here are some things I've tried:
> 
>    * Increasing heap and stack space.  No change in behavior.
> 
>    * Adding null checks to the bi_malloc and bi_realloc routines in
> libraries/clib/math/BigInteger.c.  These don't seem to return null values
> before the crash.  Could memory allocation be failing more subtly?
> 
>    In any case, I'm hoping that we can resolve this, as Kaffe w/GMP literally
> works *thousands* of times faster than other Java VMs when calculating large
> BigIntegers, and this would be a huge success story, and a reason for many
> people to prefer Kaffe for large integer work.
> 
> 
> ----------------------------------------------
> import java.math.BigInteger;
> 
> public class BigIntTest2
> {
>    public static void main(String[] args)
>    {
>       System.out.println("Starting");
>       BigInteger b = new BigInteger("1");
>       BigInteger p;
>       String s;
> 
>       int bits = 1;
>       int shift = 10;
>       long start, end;
> 
>       while (bits<100000000)
>       {
>          p = b.shiftLeft(bits-1);
>          System.out.print("2^" + (bits-1));
> 
>          start = System.currentTimeMillis();
>          s = p.toString();
>          end = System.currentTimeMillis();
> 
>          System.out.println("\tformatted in\t" + (end-start) + " ms");
> 
>          if (bits<1000000)
>             bits *= 2;
>          else
>             bits = (int) ((double) bits * 1.1);
>       }
>    }
> }
> 
> ----------------------------------------------------





More information about the kaffe mailing list