[kaffe] Bug Report: BigInteger.toString() fails for large numbers
Alan Eliasen
eliasen at mindspring.com
Wed Apr 21 21:49:02 PDT 2004
I've uncovered more information on the locks and crashes we've been getting
with BigInteger.toString() when Kaffe is compiled with the GMP libraries. I
think that the problem is fixed, and here are the steps that we'll probably
need to document.
In the GMP documentation at
http://www.gnu.org/software/gmp/manual/html_node/Build-Options.html
I found the following:
"alloca is reentrant and fast, and is recommended, but when working with
large numbers it can overflow the available stack space, in which case one of
the two malloc methods will need to be used. Alternately it might be possible
to increase available stack with limit, ulimit or setrlimit, or under DJGPP
with stubedit or _stklen. Note that depending on the system the only
indication of stack overflow might be a segmentation violation."
Since using alloca is the default build option for GMP, it's bound to fail
for very large numbers by overflowing the stack. (alloca is used for
allocating internal GMP temporary data.) So, if you're going to use large
numbers, GMP *must* be built using the configure option:
./configure --enable-alloca=malloc-reentrant
In addition, I found that I had two versions of the GMP libraries on my
system. One was in /usr/lib, but the default when building and installing GMP
is to put it in /usr/local/lib. Kaffe was picking up the version in /usr/lib.
So, after installing to /usr/local/lib, I had to change the options passed to
the Kaffe configure script to:
./configure --with-includes=/usr/local/include --with-libraries=/usr/local/lib
(or wherever your GMP header files and libraries are.)
And then did a make (clean) of Kaffe. (Is there a better way to specify
the location of the GMP libraries?)
I can now run the test programs I posted before without halts or crashes.
The size of the numbers that can be computed appears to be only limited by the
heap space--adding more heap space by using -Xmx128M allows me to calculate
very large numbers (2^33,000,000 and above) (It seems to fail with a
NullPointerException when the numbers get too big for memory, which is
probably not the right error, but it seems to work otherwise.)
I think this information should be added to the documentation about
compiling with GMP, probably to
http://www.kaffe.org/doc/kaffe/FAQ.requiredlibraries
(which should probably go into more detail about whether Kaffe needs GMP
libraries at compile-time or .so files at runtime. Can this vary depending on
how you build Kaffe?)
Anyone building a Kaffe package should be sure to compile GMP with these
options. I can write something up--just let me know who to send it to.
Thanks to everyone for your help.
By the way, using Kaffe, Frink ( http://futureboy.homeip.net/frinkdocs/ )
can calculate things in less than a minute that require days or weeks
(literally) using Sun's VM. Now that's a success story.
--
Alan Eliasen | "You cannot reason a person out of a
eliasen at mindspring.com | position he did not reason himself
http://futureboy.homeip.net/ | into in the first place."
| --Jonathan Swift
More information about the kaffe
mailing list