Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8032035

Consolidate common code across the BigInteger classes

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 9
    • core-libs
    • None

      In the various BigInteger classes sun.misc.FDBigInteger, java.math.BigInteger, and java.math.MultableBigInteger, there is a certain amount of code which if not exactly duplicative is quite similar. Consolidating this code where possible would at a minimum reduce the amount of code to support and improve test coverage.

      A major difficulty in all this is that FDBigInteger uses a little endian representation for its internal magnitude array (data[0] is least significant), whereas BigInteger uses a big big endian representation (mag[0] is most significant). The big endian representation in BigInteger has the advantage of being more tested, but the little endian implementation is simpler and more amenable to intrinsification on x86 and ARM architectures.

      One idea is to create a class such as sun.misc.BigArithmetic which would contain static methods implementing operations common to the classes, perhaps operating on int arrays. Another is to share operations between BigInteger and MutableBigInteger more effectively (cf. JDK-8031063). The present issue is concerned mainly with the former idea and with unifying endianness.

      Extant implementations to examine include:

      src/share/classes/java/math/BigInteger.java
      src/share/classes/java/math/MutableBigInteger.java
      src/share/classes/java/math/SignedMutableBigInteger.java
      src/share/classes/sun/misc/FDBigInteger.java

            bpb Brian Burkhalter
            bpb Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: