Wrong statement on Sun JDK

13 views
Skip to first unread message

opinali

unread,
Jan 11, 2008, 12:51:27 PM1/11/08
to tirania.org blog comments.
"...while the Java version uses the C/assembly language GMP library
that has been tuned with hand-coded assembly language"

This is extremely incorrect, btw you're not the first person I had to
correct wrt Sun Java's BigInteger/BigDecimal performance. Sun's JVM
doesn't use libgmp. It used a native library many years ago (I don't
know if that was libgmp but I suppose it might be), but <a
href="http://java.sun.com/javase/6/docs/technotes/guides/math/
enhancements.html">it was reimplemented in pureJava code by JDK 5.0</
a>. This new implementation was contributed by IBM, so it's also
available on older IBM JDKs as well (I think as old as 1.2.2). Sun
adopted this new code because it was actually *5X faster* than the
native library - very good algorithms on top of C-level optimization
of low-level math code, and no more JNI overhead (that is a huge cost
of any native BigInteger/BigDecimal impl).

Open source Java projects like Classpath used to call libgmp, but even
these have changed. Just look at the sources of the latest Classpath,
it's pure Java (the code is based on MPN, which is a Java port of
gmp).

P.S.: Sun JDK's source code is available under the GPL (minus those
encumbered pieces - which don't include java.math), so there's no
excuse for not checking this up...

Miguel de Icaza

unread,
Jan 14, 2008, 12:23:14 PM1/14/08
to tiraniaorg-b...@googlegroups.com, opi...@gmail.com
Hello,

> "...while the Java version uses the C/assembly language GMP library
> that has been tuned with hand-coded assembly language"
>
> This is extremely incorrect, btw you're not the first person I had to
> correct wrt Sun Java's BigInteger/BigDecimal performance. Sun's JVM
> doesn't use libgmp.

Nobody said that Sun's JVM used libgmp.

The pidigits program in the language shootout *uses* libgmp, read the
source code:

http://shootout.alioth.debian.org/gp4/benchmark.php?test=pidigits&lang=java&id=2

Here is a small snippet, in case the implementation later changes:

static {
System.loadLibrary("jgmplib");
}
private native void mpz_init();
private native void mpz_clear(long src);
private static native void mpz_mul_si(long dest, long src, int val);

Not worth replying to the rest, as it is clearly talking about
something different.

Miguel

opinali

unread,
Jan 14, 2008, 5:24:40 PM1/14/08
to tirania.org blog comments.
Hi Miguel,

Sorry for my mistake. The problem is that you wrote "the Java version
uses the C/assembly language GMP library"... which would normally be a
clear statement, but it's just ambiguous enough that I could read as
"the Java version uses [java.math APIs implemented with] the C/
assembly language GMP library". I may have read too much, but consider
that this is a really weird implementation option (either for a
benchmark or for any Java program); I never, ever heard about a Java
program that used an alternate BigInteger implementation, especially
since in the last several years, the standard java.math implementation
can't be beaten (except with tricks like mutable BigIntegers). I
should have checked the benchmark before bashing you...

A+
Osvaldo

On Jan 14, 2:23 pm, "Miguel de Icaza" <miguel.de.ic...@gmail.com>
wrote:
> Hello,
>
> > "...while the Java version uses the C/assembly language GMP library
> > that has been tuned with hand-coded  assembly language"
>
> > This is extremely incorrect, btw you're not the first person I had to
> > correct wrt Sun Java's BigInteger/BigDecimal performance. Sun's JVM
> > doesn't use libgmp.
>
> Nobody said that Sun's JVM used libgmp.
>
> The pidigits program in the language shootout *uses* libgmp, read the
> source code:
>
> http://shootout.alioth.debian.org/gp4/benchmark.php?test=pidigits&lan...

Isaac Gouy

unread,
Jan 14, 2008, 1:13:27 PM1/14/08
to tirania.org blog comments.


On Jan 14, 9:23 am, "Miguel de Icaza" <miguel.de.ic...@gmail.com>
wrote:
> Hello,
>
> > "...while the Java version uses the C/assembly language GMP library
> > that has been tuned with hand-coded assembly language"
>
> > This is extremely incorrect, btw you're not the first person I had to
> > correct wrt Sun Java's BigInteger/BigDecimal performance. Sun's JVM
> > doesn't use libgmp.
>
> Nobody said that Sun's JVM used libgmp.
>
> The pidigits program in the language shootout *uses* libgmp, read the
> source code:
-snip-

And look at the Java and C# programs that use GMP and those that don't

http://shootout.alioth.debian.org/gp4/fulldata.php?test=pidigits&p1=java-0&p2=java-2&p3=csharp-3&p4=csharp-2#cpuchart
Reply all
Reply to author
Forward
0 new messages