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

Refactor DigestBase.engineUpdate() method for better code generation by JIT compiler

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: security-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b15
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        To use intrinsics to accelerate SHA operations on multiple blocks, it is
        needed to pull a loop out of DigestBase.engineUpdate(byte[] b, int ofs, int len)
        and make it a new method, implCompressMultiBlock(byte[] b, int ofs, int n),
        which doesn't throw any exceptions so can be intrinsified.

        It is believed that the compiler should inline this new method, so no
        performance regression with the pure Java SUN provider is expected.

        Here is the proposed change:

        diff -r 43386cc9a017 src/share/classes/sun/security/provider/DigestBase.java
        --- a/src/share/classes/sun/security/provider/DigestBase.java Thu Feb 06 17:35:19 2014 -0800
        +++ b/src/share/classes/sun/security/provider/DigestBase.java Wed Feb 12 19:34:25 2014 -0800
        @@ -122,11 +122,13 @@
                     }
                 }
                 // compress complete blocks
        - while (len >= blockSize) {
        - implCompress(b, ofs);
        - len -= blockSize;
        - ofs += blockSize;
        + if (len >= blockSize) {
        + int n = len/blockSize;
        + implCompressMultiBlock(b, ofs, n);
        + len -= n*blockSize;
        + ofs += n*blockSize;
                 }
        +
                 // copy remainder to buffer
                 if (len > 0) {
                     System.arraycopy(b, ofs, buffer, 0, len);
        @@ -134,6 +136,14 @@
                 }
             }

        + // compress complete blocks
        + protected final void implCompressMultiBlock(byte[] b, int ofs, int n) {
        + for (int i = 0; i < n; i++) {
        + implCompress(b, ofs);
        + ofs += blockSize;
        + }
        + }
        +
             // reset this object. See JCA doc.
             protected final void engineReset() {
                 if (bytesProcessed == 0) {

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  kvn Vladimir Kozlov
                  Reporter:
                  kvn Vladimir Kozlov
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: