summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2008-06-22 02:05:37 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2008-06-22 02:05:37 +0000
commit0f94535f1ca722f2f5fc2090d2dab2a666bff59c (patch)
treeea049cc19dd8be3fc7496cb5bb3827c06ff84bdd
parentd846cac5ac9a07e565e696ff5938800f70a04b00 (diff)
downloadclasspath-0f94535f1ca722f2f5fc2090d2dab2a666bff59c.tar.gz
2008-06-22 Andrew John Hughes <gnu_andrew@member.fsf.org>
PR classpath/28664: * gnu/java/math/GMP.java: Renamed from VMBigInteger.java and fixed to use GMP instances directly. * include/Makefile.am: Generate GMP.h not VMBigInteger.h. * java/math/BigInteger.java: Send instances of GMP in calls to GMP rather than the wrapping BigInteger class. * native/jni/java-math/Makefile.am: Fix filename of source code file. * native/jni/java-math/gnu_java_math_GMP.c: Renamed from java_math_VMBigInteger.c. * native/jni/java-math/java_math_VMBigInteger.c, * vm/reference/java/math/VMBigInteger.java: Removed.
-rw-r--r--ChangeLog19
-rw-r--r--gnu/java/math/GMP.java474
-rw-r--r--include/Makefile.am6
-rw-r--r--java/math/BigInteger.java109
-rw-r--r--native/jni/java-math/Makefile.am2
-rw-r--r--native/jni/java-math/gnu_java_math_GMP.c (renamed from native/jni/java-math/java_math_VMBigInteger.c)84
-rw-r--r--vm/reference/java/math/VMBigInteger.java474
7 files changed, 594 insertions, 574 deletions
diff --git a/ChangeLog b/ChangeLog
index 08500a6c6..d8471d53a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2008-06-22 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ PR classpath/28664:
+ * gnu/java/math/GMP.java:
+ Renamed from VMBigInteger.java and fixed to use
+ GMP instances directly.
+ * include/Makefile.am:
+ Generate GMP.h not VMBigInteger.h.
+ * java/math/BigInteger.java:
+ Send instances of GMP in calls to GMP rather than
+ the wrapping BigInteger class.
+ * native/jni/java-math/Makefile.am:
+ Fix filename of source code file.
+ * native/jni/java-math/gnu_java_math_GMP.c:
+ Renamed from java_math_VMBigInteger.c.
+ * native/jni/java-math/java_math_VMBigInteger.c,
+ * vm/reference/java/math/VMBigInteger.java:
+ Removed.
+
2008-06-21 Andrew John Hughes <gnu_andrew@member.fsf.org>
* configure.ac:
diff --git a/gnu/java/math/GMP.java b/gnu/java/math/GMP.java
new file mode 100644
index 000000000..6fb49363d
--- /dev/null
+++ b/gnu/java/math/GMP.java
@@ -0,0 +1,474 @@
+/* gnu.java.math.GMP -- Arbitary precision integers using GMP
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.math;
+
+import gnu.classpath.Pointer;
+
+/**
+ * Implement BigInteger using GMP
+ */
+public final class GMP
+{
+ private Pointer native_ptr;
+ private int refCount = 1;
+
+ public GMP()
+ {
+ super();
+
+ natInitialize();
+ }
+
+ private synchronized void acquireRef()
+ {
+ refCount++;
+ }
+
+ private synchronized void releaseRef()
+ {
+ refCount--;
+ if (refCount == 0)
+ {
+ natFinalize();
+ native_ptr = null;
+ }
+ }
+
+ protected void finalize()
+ {
+ releaseRef();
+ }
+
+
+ public void fromByteArray(byte[] v)
+ {
+ acquireRef();
+ natFromByteArray(v);
+ releaseRef();
+ }
+
+ public void fromBI(GMP x)
+ {
+ acquireRef();
+ x.acquireRef();
+ natFromBI(x.native_ptr);
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void fromLong(long n)
+ {
+ acquireRef();
+ natFromLong(n);
+ releaseRef();
+ }
+
+ public int fromString(String s, int rdx)
+ {
+ acquireRef();
+ int result = natFromString(s, rdx);
+ releaseRef();
+ return result;
+ }
+
+ public void fromSignedMagnitude(byte[] m, boolean isNegative)
+ {
+ acquireRef();
+ natFromSignedMagnitude(m, isNegative);
+ releaseRef();
+ }
+
+ public String toString(int b)
+ {
+ acquireRef();
+ String result = natToString(b);
+ releaseRef();
+ return result;
+ }
+
+ public void toByteArray(byte[] r)
+ {
+ acquireRef();
+ natToByteArray(r);
+ releaseRef();
+ }
+
+ public double doubleValue()
+ {
+ acquireRef();
+ double result = natDoubleValue();
+ releaseRef();
+ return result;
+ }
+
+ public int absIntValue()
+ {
+ acquireRef();
+ int result = natAbsIntValue();
+ releaseRef();
+ return result;
+ }
+
+ public int compare(GMP x)
+ {
+ acquireRef();
+ x.acquireRef();
+ int result = natCompare(x.native_ptr);
+ x.releaseRef();
+ releaseRef();
+ return result;
+ }
+
+ public void add(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natAdd(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void subtract(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natSubtract(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void multiply(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natMultiply(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void quotient(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natQuotient(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void remainder(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natRemainder(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void quotientAndRemainder(GMP x, GMP q, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ q.acquireRef();
+ r.acquireRef();
+ natQuotientAndRemainder(x.native_ptr, q.native_ptr, r.native_ptr);
+ r.releaseRef();
+ q.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void modulo(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natModulo(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void pow(int n, GMP r)
+ {
+ acquireRef();
+ r.acquireRef();
+ natPow(n, r.native_ptr);
+ r.releaseRef();
+ releaseRef();
+ }
+
+ public void modPow(GMP e, GMP m, GMP r)
+ {
+ acquireRef();
+ e.acquireRef();
+ m.acquireRef();
+ r.acquireRef();
+ natModPow(e.native_ptr, m.native_ptr, r.native_ptr);
+ r.releaseRef();
+ m.releaseRef();
+ e.releaseRef();
+ releaseRef();
+ }
+
+ public void modInverse(GMP m, GMP r)
+ {
+ acquireRef();
+ m.acquireRef();
+ r.acquireRef();
+ natModInverse(m.native_ptr, r.native_ptr);
+ r.releaseRef();
+ m.releaseRef();
+ releaseRef();
+ }
+
+ public void gcd(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natGCD(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void shiftLeft(int n, GMP r)
+ {
+ acquireRef();
+ r.acquireRef();
+ natShiftLeft(n, r.native_ptr);
+ r.releaseRef();
+ releaseRef();
+ }
+
+ public void shiftRight(int n, GMP r)
+ {
+ acquireRef();
+ r.acquireRef();
+ natShiftRight(n, r.native_ptr);
+ r.releaseRef();
+ releaseRef();
+ }
+
+ public void abs(GMP r)
+ {
+ acquireRef();
+ r.acquireRef();
+ natAbs(r.native_ptr);
+ r.releaseRef();
+ releaseRef();
+ }
+
+ public void negate(GMP r)
+ {
+ acquireRef();
+ r.acquireRef();
+ natNegate(r.native_ptr);
+ r.releaseRef();
+ releaseRef();
+ }
+
+ public int bitLength()
+ {
+ acquireRef();
+ int result = natBitLength();
+ releaseRef();
+ return result;
+ }
+
+ public int bitCount()
+ {
+ acquireRef();
+ int result = natSetBitCount();
+ releaseRef();
+ return result;
+ }
+
+ public void and(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natAnd(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void or(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natOr(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void xor(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natXor(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void andNot(GMP x, GMP r)
+ {
+ acquireRef();
+ x.acquireRef();
+ r.acquireRef();
+ natAndNot(x.native_ptr, r.native_ptr);
+ r.releaseRef();
+ x.releaseRef();
+ releaseRef();
+ }
+
+ public void not(GMP r)
+ {
+ acquireRef();
+ r.acquireRef();
+ natNot(r.native_ptr);
+ r.releaseRef();
+ releaseRef();
+ }
+
+ public void flipBit(int n, GMP r)
+ {
+ acquireRef();
+ r.acquireRef();
+ natFlipBit(n, r.native_ptr);
+ r.releaseRef();
+ releaseRef();
+ }
+
+ public int testBit(int n)
+ {
+ acquireRef();
+ int result = natTestBit(n);
+ releaseRef();
+ return result;
+ }
+
+ public void setBit(int n, boolean setIt, GMP r)
+ {
+ acquireRef();
+ r.acquireRef();
+ natSetBit(n, setIt, r.native_ptr);
+ r.releaseRef();
+ releaseRef();
+ }
+
+ public int testPrimality(int certainty)
+ {
+ acquireRef();
+ int result = natTestPrimality(certainty);
+ releaseRef();
+ return result;
+ }
+
+ public int lowestSetBit()
+ {
+ acquireRef();
+ int result = natLowestSetBit();
+ releaseRef();
+ return result;
+ }
+
+ // Native methods .........................................................
+
+ public static native void natInitializeLibrary();
+
+ private native void natInitialize();
+ private native void natFinalize();
+
+ private native void natFromLong(long n);
+ private native void natFromBI(Pointer x);
+ private native void natFromByteArray(byte[] v);
+ private native int natFromString(String s, int rdx);
+ private native void natFromSignedMagnitude(byte[] m, boolean isNegative);
+
+ private native String natToString(int base);
+ private native void natToByteArray(byte[] r);
+ private native int natAbsIntValue();
+ private native double natDoubleValue();
+
+ private native int natCompare(Pointer y);
+ private native void natAdd(Pointer x, Pointer r);
+ private native void natSubtract(Pointer x, Pointer r);
+ private native void natMultiply(Pointer x, Pointer r);
+ private native void natQuotient(Pointer x, Pointer r);
+ private native void natRemainder(Pointer x, Pointer r);
+ private native void natQuotientAndRemainder(Pointer x, Pointer q, Pointer r);
+ private native void natModulo(Pointer m, Pointer r);
+ private native void natPow(int n, Pointer r);
+ private native void natModPow(Pointer e, Pointer m, Pointer r);
+ private native void natModInverse(Pointer x, Pointer r);
+ private native void natGCD(Pointer x, Pointer r);
+ private native int natTestPrimality(int c);
+ private native void natShiftLeft(int n, Pointer r);
+ private native void natShiftRight(int n, Pointer r);
+ private native int natLowestSetBit();
+ private native void natAbs(Pointer r);
+ private native void natNegate(Pointer r);
+ private native int natBitLength();
+ private native int natSetBitCount();
+ private native void natXor(Pointer x, Pointer r);
+ private native void natOr(Pointer x, Pointer r);
+ private native void natAnd(Pointer x, Pointer r);
+ private native void natAndNot(Pointer x, Pointer r);
+ private native void natFlipBit(int n, Pointer r);
+ private native int natTestBit(int n);
+ private native void natSetBit(int n, boolean setIt, Pointer r);
+ private native void natNot(Pointer r);
+}
diff --git a/include/Makefile.am b/include/Makefile.am
index 2a2fc5dd4..1656c5c3f 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -132,6 +132,7 @@ $(XMLJ_H_FILES) \
$(GTKPEER_H_FILES) \
$(QTPEER_H_FILES) \
$(GCONF_PREFS_FILES) \
+gnu_java_math_GMP.h \
gnu_java_net_VMPlainSocketImpl.h \
gnu_java_net_local_LocalSocketImpl.h \
gnu_java_nio_EpollSelectorImpl.h \
@@ -152,7 +153,6 @@ java_lang_VMMath.h \
java_lang_VMProcess.h \
java_lang_VMSystem.h \
java_lang_reflect_VMArray.h \
-java_math_VMBigInteger.h \
java_net_VMInetAddress.h \
java_net_VMNetworkInterface.h \
java_net_VMURLConnection.h \
@@ -370,6 +370,8 @@ gnu_javax_sound_sampled_gstreamer_lines_GstNativeDataLine.h: $(top_builddir)/gnu
$(JAVAH) -o $@ gnu.javax.sound.sampled.gstreamer.lines.GstNativeDataLine
gnu_javax_sound_sampled_gstreamer_lines_GstPipeline.h: $(top_builddir)/gnu/javax/sound/sampled/gstreamer/lines/GstPipeline.java
$(JAVAH) -o $@ gnu.javax.sound.sampled.gstreamer.lines.GstPipeline
+gnu_java_math_GMP.h: $(top_srcdir)/gnu/java/math/GMP.java
+ $(JAVAH) -o $@ gnu.java.math.GMP
gnu_java_net_VMPlainSocketImpl.h: $(top_srcdir)/vm/reference/gnu/java/net/VMPlainSocketImpl.java
$(JAVAH) -o $@ gnu.java.net.VMPlainSocketImpl
gnu_java_net_local_LocalSocketImpl.h: $(top_srcdir)/gnu/java/net/local/LocalSocketImpl.java
@@ -400,8 +402,6 @@ java_lang_VMSystem.h: $(top_srcdir)/vm/reference/java/lang/VMSystem.java
$(JAVAH) -o $@ java.lang.VMSystem
java_lang_reflect_VMArray.h: $(top_srcdir)/vm/reference/java/lang/reflect/VMArray.java
$(JAVAH) -o $@ java.lang.reflect.VMArray
-java_math_VMBigInteger.h: $(top_srcdir)/vm/reference/java/math/VMBigInteger.java
- $(JAVAH) -o $@ java.math.VMBigInteger
java_net_VMInetAddress.h: $(top_srcdir)/vm/reference/java/net/VMInetAddress.java
$(JAVAH) -o $@ java.net.VMInetAddress
java_net_VMNetworkInterface.h: $(top_srcdir)/vm/reference/java/net/VMNetworkInterface.java
diff --git a/java/math/BigInteger.java b/java/math/BigInteger.java
index c6fb51471..9d7abc755 100644
--- a/java/math/BigInteger.java
+++ b/java/math/BigInteger.java
@@ -41,6 +41,7 @@ package java.math;
import gnu.classpath.Configuration;
import gnu.java.lang.CPStringBuilder;
+import gnu.java.math.GMP;
import gnu.java.math.MPN;
import java.io.IOException;
@@ -90,8 +91,8 @@ public class BigInteger extends Number implements Comparable<BigInteger>
private static final int numFixNum = maxFixNum-minFixNum+1;
private static final BigInteger[] smallFixNums;
- /** The alter-ego VMBigInteger instance for this. */
- transient VMBigInteger mpz;
+ /** The alter-ego GMP instance for this. */
+ private transient GMP mpz;
private static final boolean USING_NATIVE = Configuration.WANT_NATIVE_BIG_INTEGER
&& initializeLibrary();
@@ -161,7 +162,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
super();
if (USING_NATIVE)
- this.mpz = new VMBigInteger();
+ mpz = new GMP();
}
/* Create a new (non-shared) BigInteger, and initialize to an int. */
@@ -206,7 +207,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
bytes = null;
- if (this.mpz.fromString(s, radix) != 0)
+ if (mpz.fromString(s, radix) != 0)
throw new NumberFormatException("String \"" + s
+ "\" is NOT a valid number in base "
+ radix);
@@ -240,7 +241,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
throw new NumberFormatException();
if (USING_NATIVE)
- this.mpz.fromByteArray(val);
+ mpz.fromByteArray(val);
else
{
words = byteArrayToIntArray(val, val[0] < 0 ? -1 : 0);
@@ -268,7 +269,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
}
if (USING_NATIVE)
- this.mpz.fromSignedMagnitude(magnitude, signum == -1);
+ mpz.fromSignedMagnitude(magnitude, signum == -1);
else
{
// Magnitude is always positive, so don't ever pass a sign of -1.
@@ -305,7 +306,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
discardedBitCount = 8 - discardedBitCount;
magnitude[0] = (byte)((magnitude[0] & 0xFF) >>> discardedBitCount);
}
- this.mpz.fromSignedMagnitude(magnitude, false);
+ mpz.fromSignedMagnitude(magnitude, false);
magnitude = null;
return;
}
@@ -360,7 +361,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
}
if (USING_NATIVE)
- this.mpz.fromBI(result);
+ mpz.fromBI(result.mpz);
else
{
this.ival = result.ival;
@@ -417,7 +418,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
try
{
System.loadLibrary("javamath");
- VMBigInteger.natInitializeLibrary();
+ GMP.natInitializeLibrary();
result = true;
}
catch (Throwable x)
@@ -523,7 +524,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
public int signum()
{
if (USING_NATIVE)
- return this.mpz.compare(ZERO);
+ return mpz.compare(ZERO.mpz);
if (ival == 0 && words == null)
return 0;
@@ -536,7 +537,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
int dummy = y.signum; // force NPE check
- return x.mpz.compare(y);
+ return x.mpz.compare(y.mpz);
}
if (x.words == null && y.words == null)
@@ -747,7 +748,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
int dummy = val.signum; // force NPE check
BigInteger result = new BigInteger();
- this.mpz.add(val, result);
+ mpz.add(val.mpz, result.mpz);
return result;
}
@@ -760,7 +761,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
int dummy = val.signum; // force NPE check
BigInteger result = new BigInteger();
- this.mpz.subtract(val, result);
+ mpz.subtract(val.mpz, result.mpz);
return result;
}
@@ -849,7 +850,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
int dummy = y.signum; // force NPE check
BigInteger result = new BigInteger();
- this.mpz.multiply(y, result);
+ mpz.multiply(y.mpz, result.mpz);
return result;
}
@@ -1134,7 +1135,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
throw new ArithmeticException("divisor is zero");
BigInteger result = new BigInteger();
- this.mpz.quotient(val, result);
+ mpz.quotient(val.mpz, result.mpz);
return result;
}
@@ -1154,7 +1155,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
throw new ArithmeticException("divisor is zero");
BigInteger result = new BigInteger();
- this.mpz.remainder(val, result);
+ mpz.remainder(val.mpz, result.mpz);
return result;
}
@@ -1175,7 +1176,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
BigInteger q = new BigInteger();
BigInteger r = new BigInteger();
- this.mpz.quotientAndRemainder(val, q, r);
+ mpz.quotientAndRemainder(val.mpz, q.mpz, r.mpz);
return new BigInteger[] { q, r };
}
@@ -1200,7 +1201,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
throw new ArithmeticException("non-positive modulus");
BigInteger result = new BigInteger();
- this.mpz.modulo(m, result);
+ mpz.modulo(m.mpz, result.mpz);
return result;
}
@@ -1227,7 +1228,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
BigInteger result = new BigInteger();
- this.mpz.pow(exponent, result);
+ mpz.pow(exponent, result.mpz);
return result;
}
@@ -1331,11 +1332,11 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
int dummy = y.signum; // force NPE check
- if (this.mpz.compare(ZERO) < 1)
+ if (mpz.compare(ZERO.mpz) < 1)
throw new ArithmeticException("non-positive modulo");
BigInteger result = new BigInteger();
- this.mpz.modInverse(y, result);
+ mpz.modInverse(y.mpz, result.mpz);
return result;
}
@@ -1420,11 +1421,11 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
int dummy = exponent.signum; // force NPE check
- if (m.mpz.compare(ZERO) < 1)
+ if (m.mpz.compare(ZERO.mpz) < 1)
throw new ArithmeticException("non-positive modulo");
BigInteger result = new BigInteger();
- this.mpz.modPow(exponent, m, result);
+ mpz.modPow(exponent.mpz, m.mpz, result.mpz);
return result;
}
@@ -1485,7 +1486,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
int dummy = y.signum; // force NPE check
BigInteger result = new BigInteger();
- this.mpz.gcd(y, result);
+ mpz.gcd(y.mpz, result.mpz);
return result;
}
@@ -1543,7 +1544,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
return true;
if (USING_NATIVE)
- return this.mpz.testPrimality(certainty) != 0;
+ return mpz.testPrimality(certainty) != 0;
/** We'll use the Rabin-Miller algorithm for doing a probabilistic
* primality test. It is fast, easy and has faster decreasing odds of a
@@ -1731,9 +1732,9 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
BigInteger result = new BigInteger();
if (n < 0)
- this.mpz.shiftRight(-n, result);
+ mpz.shiftRight(-n, result.mpz);
else
- this.mpz.shiftLeft(n, result);
+ mpz.shiftLeft(n, result.mpz);
return result;
}
@@ -1749,9 +1750,9 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
BigInteger result = new BigInteger();
if (n < 0)
- this.mpz.shiftLeft(-n, result);
+ mpz.shiftLeft(-n, result.mpz);
else
- this.mpz.shiftRight(n, result);
+ mpz.shiftRight(n, result.mpz);
return result;
}
@@ -1828,7 +1829,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
public String toString(int radix)
{
if (USING_NATIVE)
- return this.mpz.toString(radix);
+ return mpz.toString(radix);
if (words == null)
return Integer.toString(ival, radix);
@@ -1844,8 +1845,8 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
if (USING_NATIVE)
{
- int result = this.mpz.absIntValue();
- return this.mpz.compare(ZERO) < 0 ? - result : result;
+ int result = mpz.absIntValue();
+ return mpz.compare(ZERO.mpz) < 0 ? - result : result;
}
if (words == null)
@@ -1858,9 +1859,9 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
long result;
- result = (this.abs().shiftRight(32)).mpz.absIntValue();
+ result = (abs().shiftRight(32)).mpz.absIntValue();
result <<= 32;
- result |= this.mpz.absIntValue() & 0xFFFFFFFFL;
+ result |= mpz.absIntValue() & 0xFFFFFFFFL;
return this.compareTo(ZERO) < 0 ? - result : result;
}
@@ -1891,7 +1892,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
private static boolean equals(BigInteger x, BigInteger y)
{
if (USING_NATIVE)
- return x.mpz.compare(y) == 0;
+ return x.mpz.compare(y.mpz) == 0;
if (x.words == null && y.words == null)
return x.ival == y.ival;
@@ -1931,7 +1932,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
public double doubleValue()
{
if (USING_NATIVE)
- return this.mpz.doubleValue();
+ return mpz.doubleValue();
if (words == null)
return (double) ival;
@@ -2117,7 +2118,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
BigInteger result = new BigInteger();
- this.mpz.abs(result);
+ mpz.abs(result.mpz);
return result;
}
@@ -2138,7 +2139,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
BigInteger result = new BigInteger();
- this.mpz.negate(result);
+ mpz.negate(result.mpz);
return result;
}
@@ -2151,7 +2152,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
public int bitLength()
{
if (USING_NATIVE)
- return this.mpz.bitLength();
+ return mpz.bitLength();
if (words == null)
return MPN.intLength(ival);
@@ -2171,11 +2172,11 @@ public class BigInteger extends Number implements Comparable<BigInteger>
// bit for its sign. we do this so if we construct a new MPI from the
// resulting byte array, we wouldn't mistake a positive number, whose
// bit-length is a multiple of 8, for a similar-length negative one.
- int bits = this.bitLength();
+ int bits = bitLength();
if (bits % 8 == 0 || this.signum() == 1)
bits++;
byte[] bytes = new byte[(bits + 7) / 8];
- this.mpz.toByteArray(bytes);
+ mpz.toByteArray(bytes);
return bytes;
}
@@ -2439,7 +2440,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
int dummy = y.signum; // force NPE check
BigInteger result = new BigInteger();
- this.mpz.and(y, result);
+ mpz.and(y.mpz, result.mpz);
return result;
}
@@ -2470,7 +2471,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
int dummy = y.signum; // force NPE check
BigInteger result = new BigInteger();
- this.mpz.or(y, result);
+ mpz.or(y.mpz, result.mpz);
return result;
}
@@ -2484,7 +2485,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
int dummy = y.signum; // force NPE check
BigInteger result = new BigInteger();
- this.mpz.xor(y, result);
+ mpz.xor(y.mpz, result.mpz);
return result;
}
@@ -2497,7 +2498,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
BigInteger result = new BigInteger();
- this.mpz.not(result);
+ mpz.not(result.mpz);
return result;
}
@@ -2510,7 +2511,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
int dummy = val.signum; // force NPE check
BigInteger result = new BigInteger();
- this.mpz.andNot(val, result);
+ mpz.andNot(val.mpz, result.mpz);
return result;
}
@@ -2525,7 +2526,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
BigInteger result = new BigInteger();
- this.mpz.setBit(n, false, result);
+ mpz.setBit(n, false, result.mpz);
return result;
}
@@ -2540,7 +2541,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
BigInteger result = new BigInteger();
- this.mpz.setBit(n, true, result);
+ mpz.setBit(n, true, result.mpz);
return result;
}
@@ -2553,7 +2554,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
throw new ArithmeticException();
if (USING_NATIVE)
- return this.mpz.testBit(n) != 0;
+ return mpz.testBit(n) != 0;
return !and(ONE.shiftLeft(n)).isZero();
}
@@ -2566,7 +2567,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
if (USING_NATIVE)
{
BigInteger result = new BigInteger();
- this.mpz.flipBit(n, result);
+ mpz.flipBit(n, result.mpz);
return result;
}
@@ -2576,7 +2577,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
public int getLowestSetBit()
{
if (USING_NATIVE)
- return this.mpz.compare(ZERO) == 0 ? -1 : this.mpz.lowestSetBit();
+ return mpz.compare(ZERO.mpz) == 0 ? -1 : mpz.lowestSetBit();
if (isZero())
return -1;
@@ -2615,7 +2616,7 @@ public class BigInteger extends Number implements Comparable<BigInteger>
public int bitCount()
{
if (USING_NATIVE)
- return this.mpz.bitCount();
+ return mpz.bitCount();
int i, x_len;
int[] x_words = words;
@@ -2637,10 +2638,10 @@ public class BigInteger extends Number implements Comparable<BigInteger>
{
if (USING_NATIVE)
{
- this.mpz = new VMBigInteger();
+ mpz = new GMP();
s.defaultReadObject();
if (signum != 0)
- this.mpz.fromByteArray(magnitude);
+ mpz.fromByteArray(magnitude);
// else it's zero and we need to do nothing
}
else
diff --git a/native/jni/java-math/Makefile.am b/native/jni/java-math/Makefile.am
index af675f0c3..9bc756b6d 100644
--- a/native/jni/java-math/Makefile.am
+++ b/native/jni/java-math/Makefile.am
@@ -1,6 +1,6 @@
nativeexeclib_LTLIBRARIES = libjavamath.la
-libjavamath_la_SOURCES = java_math_VMBigInteger.c
+libjavamath_la_SOURCES = gnu_java_math_GMP.c
libjavamath_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo
diff --git a/native/jni/java-math/java_math_VMBigInteger.c b/native/jni/java-math/gnu_java_math_GMP.c
index af274e8dd..85c2e6b0f 100644
--- a/native/jni/java-math/java_math_VMBigInteger.c
+++ b/native/jni/java-math/gnu_java_math_GMP.c
@@ -1,4 +1,4 @@
-/* java_math_BigInteger_NativeMPI.c -- Native MPI implemenetation over GNU MP
+/* gnu_java_math_GMP.c -- Native MPI implemenetation over GNU MP
Copyright (C) 2006 Free Software Foundation, Inc.
This file is a part of GNU Classpath.
@@ -43,7 +43,7 @@ exception statement from your version. */
#include "config.h"
#endif /* HAVE_CONFIG_H */
-#include "java_math_VMBigInteger.h"
+#include "gnu_java_math_GMP.h"
#include <jcl.h>
#if defined(HAVE_GMP_H)
@@ -105,7 +105,7 @@ static jfieldID native_ptr;
* field and acquire the native value associated with that Pointer instance.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natInitializeLibrary (JNIEnv *env,
+Java_gnu_java_math_GMP_natInitializeLibrary (JNIEnv *env,
jclass nativeMPI)
{
#if defined(WITH_GNU_MP)
@@ -126,7 +126,7 @@ Java_java_math_VMBigInteger_natInitializeLibrary (JNIEnv *env,
* @param this an instance of NativeMPI.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natInitialize(JNIEnv *env, jobject this)
+Java_gnu_java_math_GMP_natInitialize(JNIEnv *env, jobject this)
{
#if defined(WITH_GNU_MP)
mpz_ptr _this;
@@ -152,7 +152,7 @@ Java_java_math_VMBigInteger_natInitialize(JNIEnv *env, jobject this)
* @param this an instance of NativeMPI.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natFinalize(JNIEnv *env, jobject this)
+Java_gnu_java_math_GMP_natFinalize(JNIEnv *env, jobject this)
{
#if defined(WITH_GNU_MP)
mpz_ptr _this;
@@ -182,7 +182,7 @@ Java_java_math_VMBigInteger_natFinalize(JNIEnv *env, jobject this)
* @param n a Java long primitive value.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natFromLong(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natFromLong(JNIEnv *env, jobject this,
jlong n)
{
#if defined(WITH_GNU_MP)
@@ -229,7 +229,7 @@ Java_java_math_VMBigInteger_natFromLong(JNIEnv *env, jobject this,
* @param x an instance of a NativeMPI's Pointer.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natFromBI(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natFromBI(JNIEnv *env, jobject this,
jobject x)
{
#if defined(WITH_GNU_MP)
@@ -257,7 +257,7 @@ Java_java_math_VMBigInteger_natFromBI(JNIEnv *env, jobject this,
* complement of the signed value to assign to this.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natFromByteArray(JNIEnv *env,
+Java_gnu_java_math_GMP_natFromByteArray(JNIEnv *env,
jobject this,
jbyteArray v)
{
@@ -311,7 +311,7 @@ Java_java_math_VMBigInteger_natFromByteArray(JNIEnv *env,
* e.g. no white spaces in the middle, limited valid radix values, etc...
*/
JNIEXPORT jint JNICALL
-Java_java_math_VMBigInteger_natFromString(JNIEnv *env,
+Java_gnu_java_math_GMP_natFromString(JNIEnv *env,
jobject this, jstring s,
jint rdx)
{
@@ -348,7 +348,7 @@ Java_java_math_VMBigInteger_natFromString(JNIEnv *env,
* be positive.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natFromSignedMagnitude(JNIEnv *env,
+Java_gnu_java_math_GMP_natFromSignedMagnitude(JNIEnv *env,
jobject this,
jbyteArray m,
jboolean isnegative)
@@ -388,7 +388,7 @@ Java_java_math_VMBigInteger_natFromSignedMagnitude(JNIEnv *env,
* @return the Java string representing the value of this in base n.
*/
JNIEXPORT jstring JNICALL
-Java_java_math_VMBigInteger_natToString(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natToString(JNIEnv *env, jobject this,
jint n)
{
#if defined(WITH_GNU_MP)
@@ -419,7 +419,7 @@ Java_java_math_VMBigInteger_natToString(JNIEnv *env, jobject this,
* this.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natToByteArray(JNIEnv *env,
+Java_gnu_java_math_GMP_natToByteArray(JNIEnv *env,
jobject this,
jbyteArray r)
{
@@ -477,7 +477,7 @@ Java_java_math_VMBigInteger_natToByteArray(JNIEnv *env,
* as well.
*/
JNIEXPORT jint JNICALL
-Java_java_math_VMBigInteger_natAbsIntValue(JNIEnv *env,
+Java_gnu_java_math_GMP_natAbsIntValue(JNIEnv *env,
jobject this)
{
#if defined(WITH_GNU_MP)
@@ -499,7 +499,7 @@ Java_java_math_VMBigInteger_natAbsIntValue(JNIEnv *env,
* @return the, eventually truncated, double value of this NativeMPI.
*/
JNIEXPORT jdouble JNICALL
-Java_java_math_VMBigInteger_natDoubleValue(JNIEnv *env,
+Java_gnu_java_math_GMP_natDoubleValue(JNIEnv *env,
jobject this)
{
#if defined(WITH_GNU_MP)
@@ -523,7 +523,7 @@ Java_java_math_VMBigInteger_natDoubleValue(JNIEnv *env,
* than y.
*/
JNIEXPORT jint JNICALL
-Java_java_math_VMBigInteger_natCompare(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natCompare(JNIEnv *env, jobject this,
jobject x)
{
#if defined(WITH_GNU_MP)
@@ -557,7 +557,7 @@ Java_java_math_VMBigInteger_natCompare(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = this + x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natAdd(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natAdd(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -586,7 +586,7 @@ Java_java_math_VMBigInteger_natAdd(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = this - x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natSubtract(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natSubtract(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -615,7 +615,7 @@ Java_java_math_VMBigInteger_natSubtract(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = this * x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natMultiply(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natMultiply(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -644,7 +644,7 @@ Java_java_math_VMBigInteger_natMultiply(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = this div x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natQuotient(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natQuotient(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -673,7 +673,7 @@ Java_java_math_VMBigInteger_natQuotient(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = this mod x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natRemainder(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natRemainder(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -703,7 +703,7 @@ Java_java_math_VMBigInteger_natRemainder(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = this mod x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natQuotientAndRemainder(JNIEnv *env,
+Java_gnu_java_math_GMP_natQuotientAndRemainder(JNIEnv *env,
jobject this,
jobject x,
jobject q,
@@ -737,7 +737,7 @@ Java_java_math_VMBigInteger_natQuotientAndRemainder(JNIEnv *env,
* @param r a NativeMPI's Pointer such that r = this mod x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natModulo(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natModulo(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -766,7 +766,7 @@ Java_java_math_VMBigInteger_natModulo(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = this ** n.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natPow(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natPow(JNIEnv *env, jobject this,
jint n, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -798,7 +798,7 @@ Java_java_math_VMBigInteger_natPow(JNIEnv *env, jobject this,
* has no multiplicative inverse.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natModPow(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natModPow(JNIEnv *env, jobject this,
jobject e, jobject m,
jobject r)
{
@@ -861,7 +861,7 @@ Java_java_math_VMBigInteger_natModPow(JNIEnv *env, jobject this,
* multiplicative inverse.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natModInverse(JNIEnv *env,
+Java_gnu_java_math_GMP_natModInverse(JNIEnv *env,
jobject this,
jobject m, jobject r)
{
@@ -902,7 +902,7 @@ Java_java_math_VMBigInteger_natModInverse(JNIEnv *env,
* @param r a NativeMPI's Pointer such that r is the GCD of this and x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natGCD(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natGCD(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -931,7 +931,7 @@ Java_java_math_VMBigInteger_natGCD(JNIEnv *env, jobject this,
* composite.
*/
JNIEXPORT jint JNICALL
-Java_java_math_VMBigInteger_natTestPrimality(JNIEnv *env,
+Java_gnu_java_math_GMP_natTestPrimality(JNIEnv *env,
jobject this, jint n)
{
#if defined(WITH_GNU_MP)
@@ -957,7 +957,7 @@ Java_java_math_VMBigInteger_natTestPrimality(JNIEnv *env,
* @param r a NativeMPI's Pointer such that r = this * 2**n.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natShiftLeft(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natShiftLeft(JNIEnv *env, jobject this,
jint n, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -985,7 +985,7 @@ Java_java_math_VMBigInteger_natShiftLeft(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = floor(this / 2**n).
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natShiftRight(JNIEnv *env,
+Java_gnu_java_math_GMP_natShiftRight(JNIEnv *env,
jobject this, jint n,
jobject r)
{
@@ -1011,7 +1011,7 @@ Java_java_math_VMBigInteger_natShiftRight(JNIEnv *env,
* @return the 0-based index of the lowest significant bit set (to 1) in this.
*/
JNIEXPORT jint JNICALL
-Java_java_math_VMBigInteger_natLowestSetBit(JNIEnv *env,
+Java_gnu_java_math_GMP_natLowestSetBit(JNIEnv *env,
jobject this)
{
#if defined(WITH_GNU_MP)
@@ -1035,7 +1035,7 @@ Java_java_math_VMBigInteger_natLowestSetBit(JNIEnv *env,
* @param r a NativeMPI's Pointer such that r = abs(x).
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natAbs(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natAbs(JNIEnv *env, jobject this,
jobject r)
{
#if defined(WITH_GNU_MP)
@@ -1061,7 +1061,7 @@ Java_java_math_VMBigInteger_natAbs(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = -x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natNegate(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natNegate(JNIEnv *env, jobject this,
jobject r)
{
#if defined(WITH_GNU_MP)
@@ -1085,7 +1085,7 @@ Java_java_math_VMBigInteger_natNegate(JNIEnv *env, jobject this,
* @return the number of bits needed to represent this.
*/
JNIEXPORT jint JNICALL
-Java_java_math_VMBigInteger_natBitLength(JNIEnv *env, jobject this)
+Java_gnu_java_math_GMP_natBitLength(JNIEnv *env, jobject this)
{
#if defined(WITH_GNU_MP)
mpz_srcptr _this;
@@ -1106,7 +1106,7 @@ Java_java_math_VMBigInteger_natBitLength(JNIEnv *env, jobject this)
* @return the number of bits set (to 1) in this.
*/
JNIEXPORT jint JNICALL
-Java_java_math_VMBigInteger_natSetBitCount(JNIEnv *env,
+Java_gnu_java_math_GMP_natSetBitCount(JNIEnv *env,
jobject this)
{
#if defined(WITH_GNU_MP)
@@ -1153,7 +1153,7 @@ Java_java_math_VMBigInteger_natSetBitCount(JNIEnv *env,
* @param r a NativeMPI's Pointer such that r = this ^ x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natXor(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natXor(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -1182,7 +1182,7 @@ Java_java_math_VMBigInteger_natXor(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = this | x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natOr(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natOr(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -1211,7 +1211,7 @@ Java_java_math_VMBigInteger_natOr(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = this & x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natAnd(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natAnd(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -1240,7 +1240,7 @@ Java_java_math_VMBigInteger_natAnd(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = this & ~x.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natAndNot(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natAndNot(JNIEnv *env, jobject this,
jobject x, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -1271,7 +1271,7 @@ Java_java_math_VMBigInteger_natAndNot(JNIEnv *env, jobject this,
* @param r a copy of this NativeMPI's Pointer with its n-th bit flipped.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natFlipBit(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natFlipBit(JNIEnv *env, jobject this,
jint n, jobject r)
{
#if defined(WITH_GNU_MP)
@@ -1309,7 +1309,7 @@ Java_java_math_VMBigInteger_natFlipBit(JNIEnv *env, jobject this,
* respectively.
*/
JNIEXPORT jint JNICALL
-Java_java_math_VMBigInteger_natTestBit(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natTestBit(JNIEnv *env, jobject this,
jint n)
{
#if defined(WITH_GNU_MP)
@@ -1339,7 +1339,7 @@ Java_java_math_VMBigInteger_natTestBit(JNIEnv *env, jobject this,
* as requested.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natSetBit(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natSetBit(JNIEnv *env, jobject this,
jint n, jboolean setIt,
jobject r)
{
@@ -1376,7 +1376,7 @@ Java_java_math_VMBigInteger_natSetBit(JNIEnv *env, jobject this,
* @param r a NativeMPI's Pointer such that r = ~this.
*/
JNIEXPORT void JNICALL
-Java_java_math_VMBigInteger_natNot(JNIEnv *env, jobject this,
+Java_gnu_java_math_GMP_natNot(JNIEnv *env, jobject this,
jobject r)
{
#if defined(WITH_GNU_MP)
diff --git a/vm/reference/java/math/VMBigInteger.java b/vm/reference/java/math/VMBigInteger.java
deleted file mode 100644
index 6b5ab485d..000000000
--- a/vm/reference/java/math/VMBigInteger.java
+++ /dev/null
@@ -1,474 +0,0 @@
-/* java.math.VMBigInteger -- Arbitary precision integers using GMP
- Copyright (C) 2006 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.math;
-
-import gnu.classpath.Pointer;
-
-/**
- * Implement BigInteger using GMP
- */
-final class VMBigInteger
-{
- private Pointer native_ptr;
- private int refCount = 1;
-
- VMBigInteger()
- {
- super();
-
- natInitialize();
- }
-
- private synchronized void acquireRef()
- {
- refCount++;
- }
-
- private synchronized void releaseRef()
- {
- refCount--;
- if (refCount == 0)
- {
- natFinalize();
- native_ptr = null;
- }
- }
-
- protected void finalize()
- {
- releaseRef();
- }
-
-
- void fromByteArray(byte[] v)
- {
- this.acquireRef();
- natFromByteArray(v);
- this.releaseRef();
- }
-
- void fromBI(BigInteger x)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- natFromBI(x.mpz.native_ptr);
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void fromLong(long n)
- {
- this.acquireRef();
- natFromLong(n);
- this.releaseRef();
- }
-
- int fromString(String s, int rdx)
- {
- this.acquireRef();
- int result = natFromString(s, rdx);
- this.releaseRef();
- return result;
- }
-
- void fromSignedMagnitude(byte[] m, boolean isNegative)
- {
- this.acquireRef();
- natFromSignedMagnitude(m, isNegative);
- this.releaseRef();
- }
-
- String toString(int b)
- {
- this.acquireRef();
- String result = natToString(b);
- this.releaseRef();
- return result;
- }
-
- void toByteArray(byte[] r)
- {
- this.acquireRef();
- natToByteArray(r);
- this.releaseRef();
- }
-
- double doubleValue()
- {
- this.acquireRef();
- double result = natDoubleValue();
- this.releaseRef();
- return result;
- }
-
- int absIntValue()
- {
- this.acquireRef();
- int result = natAbsIntValue();
- this.releaseRef();
- return result;
- }
-
- int compare(BigInteger x)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- int result = natCompare(x.mpz.native_ptr);
- x.mpz.releaseRef();
- this.releaseRef();
- return result;
- }
-
- void add(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natAdd(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void subtract(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natSubtract(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void multiply(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natMultiply(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void quotient(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natQuotient(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void remainder(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natRemainder(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void quotientAndRemainder(BigInteger x, BigInteger q, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- q.mpz.acquireRef();
- r.mpz.acquireRef();
- natQuotientAndRemainder(x.mpz.native_ptr, q.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- q.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void modulo(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natModulo(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void pow(int n, BigInteger r)
- {
- this.acquireRef();
- r.mpz.acquireRef();
- natPow(n, r.mpz.native_ptr);
- r.mpz.releaseRef();
- this.releaseRef();
- }
-
- void modPow(BigInteger e, BigInteger m, BigInteger r)
- {
- this.acquireRef();
- e.mpz.acquireRef();
- m.mpz.acquireRef();
- r.mpz.acquireRef();
- natModPow(e.mpz.native_ptr, m.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- m.mpz.releaseRef();
- e.mpz.releaseRef();
- this.releaseRef();
- }
-
- void modInverse(BigInteger m, BigInteger r)
- {
- this.acquireRef();
- m.mpz.acquireRef();
- r.mpz.acquireRef();
- natModInverse(m.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- m.mpz.releaseRef();
- this.releaseRef();
- }
-
- void gcd(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natGCD(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void shiftLeft(int n, BigInteger r)
- {
- this.acquireRef();
- r.mpz.acquireRef();
- natShiftLeft(n, r.mpz.native_ptr);
- r.mpz.releaseRef();
- this.releaseRef();
- }
-
- void shiftRight(int n, BigInteger r)
- {
- this.acquireRef();
- r.mpz.acquireRef();
- natShiftRight(n, r.mpz.native_ptr);
- r.mpz.releaseRef();
- this.releaseRef();
- }
-
- void abs(BigInteger r)
- {
- this.acquireRef();
- r.mpz.acquireRef();
- natAbs(r.mpz.native_ptr);
- r.mpz.releaseRef();
- this.releaseRef();
- }
-
- void negate(BigInteger r)
- {
- this.acquireRef();
- r.mpz.acquireRef();
- natNegate(r.mpz.native_ptr);
- r.mpz.releaseRef();
- this.releaseRef();
- }
-
- int bitLength()
- {
- this.acquireRef();
- int result = natBitLength();
- this.releaseRef();
- return result;
- }
-
- int bitCount()
- {
- this.acquireRef();
- int result = natSetBitCount();
- this.releaseRef();
- return result;
- }
-
- void and(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natAnd(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void or(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natOr(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void xor(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natXor(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void andNot(BigInteger x, BigInteger r)
- {
- this.acquireRef();
- x.mpz.acquireRef();
- r.mpz.acquireRef();
- natAndNot(x.mpz.native_ptr, r.mpz.native_ptr);
- r.mpz.releaseRef();
- x.mpz.releaseRef();
- this.releaseRef();
- }
-
- void not(BigInteger r)
- {
- this.acquireRef();
- r.mpz.acquireRef();
- natNot(r.mpz.native_ptr);
- r.mpz.releaseRef();
- this.releaseRef();
- }
-
- void flipBit(int n, BigInteger r)
- {
- this.acquireRef();
- r.mpz.acquireRef();
- natFlipBit(n, r.mpz.native_ptr);
- r.mpz.releaseRef();
- this.releaseRef();
- }
-
- int testBit(int n)
- {
- this.acquireRef();
- int result = natTestBit(n);
- this.releaseRef();
- return result;
- }
-
- void setBit(int n, boolean setIt, BigInteger r)
- {
- this.acquireRef();
- r.mpz.acquireRef();
- natSetBit(n, setIt, r.mpz.native_ptr);
- r.mpz.releaseRef();
- this.releaseRef();
- }
-
- int testPrimality(int certainty)
- {
- this.acquireRef();
- int result = natTestPrimality(certainty);
- this.releaseRef();
- return result;
- }
-
- int lowestSetBit()
- {
- this.acquireRef();
- int result = natLowestSetBit();
- this.releaseRef();
- return result;
- }
-
- // Native methods .........................................................
-
- static native void natInitializeLibrary();
-
- native void natInitialize();
- native void natFinalize();
-
- native void natFromLong(long n);
- native void natFromBI(Pointer x);
- native void natFromByteArray(byte[] v);
- native int natFromString(String s, int rdx);
- native void natFromSignedMagnitude(byte[] m, boolean isNegative);
-
- native String natToString(int base);
- native void natToByteArray(byte[] r);
- native int natAbsIntValue();
- native double natDoubleValue();
-
- native int natCompare(Pointer y);
- native void natAdd(Pointer x, Pointer r);
- native void natSubtract(Pointer x, Pointer r);
- native void natMultiply(Pointer x, Pointer r);
- native void natQuotient(Pointer x, Pointer r);
- native void natRemainder(Pointer x, Pointer r);
- native void natQuotientAndRemainder(Pointer x, Pointer q, Pointer r);
- native void natModulo(Pointer m, Pointer r);
- native void natPow(int n, Pointer r);
- native void natModPow(Pointer e, Pointer m, Pointer r);
- native void natModInverse(Pointer x, Pointer r);
- native void natGCD(Pointer x, Pointer r);
- native int natTestPrimality(int c);
- native void natShiftLeft(int n, Pointer r);
- native void natShiftRight(int n, Pointer r);
- native int natLowestSetBit();
- native void natAbs(Pointer r);
- native void natNegate(Pointer r);
- native int natBitLength();
- native int natSetBitCount();
- native void natXor(Pointer x, Pointer r);
- native void natOr(Pointer x, Pointer r);
- native void natAnd(Pointer x, Pointer r);
- native void natAndNot(Pointer x, Pointer r);
- native void natFlipBit(int n, Pointer r);
- native int natTestBit(int n);
- native void natSetBit(int n, boolean setIt, Pointer r);
- native void natNot(Pointer r);
-}