JDK-8238669 : Long.divideUnsigned is extremely slow for certain values (Needs to be Intrinsic)
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 13,14
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2020-02-03
  • Updated: 2021-12-27
  • Resolved: 2020-10-21
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 16
16 b21Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
MacOS Mojave 10.14.6
OpenJDK 64-Bit Server VM (build 13+33, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
Long.divideUnsigned is very slow for dividend values larger than the signed maximum of Long.MAX_VALUE. 10x slow down when the dividend is larger than Long.MAX_VALUE (eg a negative signed value).

This causes significant sporadic slow downs based on the data being processed

Steps to reproduce:

Using JMH... https://openjdk.java.net/projects/code-tools/jmh/

	@Benchmark public long divu64_slow(){
		return Long.divideUnsigned(Long.MAX_VALUE + 1, arg);
	}

	@Benchmark public long divu64_norm(){
		return Long.divideUnsigned(Long.MAX_VALUE, arg);
	}

Expected Result:

This should be just as fast or faster (some early CPUs execute IDIV faster than DIV) as java signed division. Just as important, speed should not show a 10x slow down based only slightly different dividend values.

Performance Workaround:

It would be very hard to meet the same performance in software as a native op provided by all modern CPUs.



Comments
Requested the submitter verify the fix with latest version of JDK 16.
13-11-2020

Changeset: 0efdde18 Author: Raffaello Giulietti <raffaello.giulietti@gmail.com> Committer: Brian Burkhalter <bpb@openjdk.org> Date: 2020-10-21 16:32:59 +0000 URL: https://git.openjdk.java.net/jdk/commit/0efdde18
21-10-2020

The performance drops described by the submitter are observed on Windows 10 using JMH benchmarks: JDK 14----- Benchmark Mode Cnt Score Error Units MyBenchmark.divu64_norm thrpt 25 421585805.934 ± 8527867.576 ops/s MyBenchmark.divu64_slow thrpt 25 12320904.970 ± 397861.502 ops/s JDK 13---- Benchmark Mode Cnt Score Error Units MyBenchmark.divu64_norm thrpt 25 406695049.790 ± 7713165.093 ops/s MyBenchmark.divu64_slow thrpt 25 9487407.266 ± 315344.898 ops/s
07-02-2020