RFR: 8256523: Streamline Java SHA2 implementation
Aleksey Shipilev
shade at openjdk.java.net
Wed Nov 18 10:15:10 UTC 2020
Current `sun/security/provider/SHA2` implementation is written with lots of small method invocations on the fastpath in `implCompress0`. Normally it does not matter much, because compilers are able to inline through it, and then some compilers even intrinsify the entire `implCompress0`.
But it comes as major downside for platforms that do not have SHA2 intrinsics, or those VM configs that blindly interpret the bytecode. Zero, for example, keeps re-entering the small methods when computing SHA2 digests during jmod/jlink generation during the build, and spends significant time there. Linux x86_64 Zero fastdebug builds **improve from 18.5 minutes to 11.0 minutes** with this change, which is a major win for development experience.
Note that SHA1 is already written in similar streamlined style. SHA5 is written with helper functions. This patch moves SHA2 to be closer to SHA1 style-wise.
Performance improvement in interpreted modes is substantial, about 4x..5x, while compiler modes are not affected. As measured by: `make test TEST="micro:MessageDigests" MICRO="FORK=1;ITER=5;WARMUP_ITER=5;WARMUP_TIME=1s;TIME=1s;OPTIONS=-p digesterName=sha256 -p provider=SUN"`
Before:
Benchmark (digesterName) (length) (provider) Mode Cnt Score Error Units
# Server, Default
MessageDigests.digest sha256 64 SUN thrpt 5 8585.532 ± 219.896 ops/ms
MessageDigests.digest sha256 1024 SUN thrpt 5 1545.994 ± 73.325 ops/ms
MessageDigests.digest sha256 16384 SUN thrpt 5 110.550 ± 1.576 ops/ms
# Server, -XX:+UnlockDiagnosticVMOptions -XX:-UseSHA256Intrinsics
MessageDigests.digest sha256 64 SUN thrpt 5 1426.117 ± 48.320 ops/ms
MessageDigests.digest sha256 1024 SUN thrpt 5 188.779 ± 0.097 ops/ms
MessageDigests.digest sha256 16384 SUN thrpt 5 12.512 ± 1.371 ops/ms
# Server, -Xint
MessageDigests.digest sha256 64 SUN thrpt 5 6.143 ± 0.126 ops/ms
MessageDigests.digest sha256 1024 SUN thrpt 5 0.769 ± 0.008 ops/ms
MessageDigests.digest sha256 16384 SUN thrpt 5 0.051 ± 0.001 ops/ms
# Zero
MessageDigests.digest sha256 64 SUN thrpt 5 5.358 ± 0.664 ops/ms
MessageDigests.digest sha256 1024 SUN thrpt 5 0.686 ± 0.003 ops/ms
MessageDigests.digest sha256 16384 SUN thrpt 5 0.046 ± 0.001 ops/ms
After:
Benchmark (digesterName) (length) (provider) Mode Cnt Score Error Units
# Server, Default
MessageDigests.digest sha256 64 SUN thrpt 5 8564.689 ± 1459.552 ops/ms
MessageDigests.digest sha256 1024 SUN thrpt 5 1548.582 ± 78.888 ops/ms
MessageDigests.digest sha256 16384 SUN thrpt 5 110.800 ± 0.057 ops/ms
# Server, -XX:+UnlockDiagnosticVMOptions -XX:-UseSHA256Intrinsics
MessageDigests.digest sha256 64 SUN thrpt 5 1471.399 ± 66.622 ops/ms
MessageDigests.digest sha256 1024 SUN thrpt 5 186.297 ± 0.127 ops/ms
MessageDigests.digest sha256 16384 SUN thrpt 5 12.448 ± 0.099 ops/ms
# Server, -Xint
MessageDigests.digest sha256 64 SUN thrpt 5 27.046 ± 0.304 ops/ms
MessageDigests.digest sha256 1024 SUN thrpt 5 3.538 ± 0.060 ops/ms
MessageDigests.digest sha256 16384 SUN thrpt 5 0.238 ± 0.002 ops/ms
# Zero
MessageDigests.digest sha256 64 SUN thrpt 5 26.696 ± 0.968 ops/ms
MessageDigests.digest sha256 1024 SUN thrpt 5 3.655 ± 0.024 ops/ms
MessageDigests.digest sha256 16384 SUN thrpt 5 0.241 ± 0.002 ops/ms
Addtional testing:
- [x] `jdk/security` with Linux x86_64 server fastdebug
- [x] `jdk/security` with Linux x86_64 zero fastdebug
-------------
Commit messages:
- 8256523: Streamline Java SHA2 implementation
Changes: https://git.openjdk.java.net/jdk/pull/1283/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=1283&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8256523
Stats: 123 lines in 1 file changed: 41 ins; 78 del; 4 mod
Patch: https://git.openjdk.java.net/jdk/pull/1283.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/1283/head:pull/1283
PR: https://git.openjdk.java.net/jdk/pull/1283
More information about the security-dev
mailing list