JDK-8035974 : Refactor DigestBase.engineUpdate() method for better code generation by JIT compiler
  • Type: Enhancement
  • Component: security-libs
  • Sub-Component: java.security
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-02-27
  • Updated: 2019-07-17
  • Resolved: 2014-05-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9 Other
8u40Fixed 9 b15Fixed openjdk7uFixed
Related Reports
Relates :  
Relates :  
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) {

Comments
Please have someone from the security group review this and all changes in our area.
27-02-2014

I will sponsor the changes.
27-02-2014