Skip to content

8202449: overflow handling in Random.doubles #8791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

rgiulietti
Copy link
Contributor

@rgiulietti rgiulietti commented May 19, 2022

Extend the range of Random.doubles(double, double) and similar methods.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires a CSR request to be approved

Issues

  • JDK-8202449: overflow handling in Random.doubles
  • JDK-8287026: Changes related to overflow handling in Random.doubles (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/8791/head:pull/8791
$ git checkout pull/8791

Update a local copy of the PR:
$ git checkout pull/8791
$ git pull https://git.openjdk.java.net/jdk pull/8791/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 8791

View PR using the GUI difftool:
$ git pr show -t 8791

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/8791.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 19, 2022

👋 Welcome back rgiulietti! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label May 19, 2022
@openjdk
Copy link

openjdk bot commented May 19, 2022

@rgiulietti The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label May 19, 2022
@mlbridge
Copy link

mlbridge bot commented May 19, 2022

Webrevs

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label May 19, 2022
@rgiulietti
Copy link
Contributor Author

Random.doubles(double, double) and similar methods depend on RandomGenerator.nextDouble(double, double).

Currently, this method is specified to throw when the range [origin, bound) given by the arguments is so large that its size (bound - origin) overflows. Since the proposed implementation doesn't suffer from this limitation, the specification needs to be modified, thus the need for a CSR.

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Jun 2, 2022
@rgiulietti
Copy link
Contributor Author

Hi,

the major code changes are in RandomSupport in methods

checkRange(float,float)
checkRange(double,double)

where the checks are more tolerant, and in

boundedNextDouble(RandomGenerator,double,double)
boundedNextFloat(RandomGenerator,float,float)

that extend the accepted range. In case the range size overflows, the methods half the range, generate a value inside the reduced range and finally double the outcome.

} else {
/* avoids overflow at the cost of 3 more multiplications */
float halfOrigin = 0.5f * origin;
r = (r * (0.5f * bound - halfOrigin) + halfOrigin) * 2.0f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done in double arithmetic, but I think it is better to keep it in float arithmetic for similarity with the code in the double version of the method.

@openjdk
Copy link

openjdk bot commented Jun 8, 2022

@rgiulietti This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8202449: overflow handling in Random.doubles

Reviewed-by: darcy

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 298 new commits pushed to the master branch:

  • 230726e: 8287735: Provide separate event category for dll operations
  • ecf0078: 8287442: Reduce list to array conversions in java.lang.invoke.MethodHandles
  • 5c39a36: 8287522: StringConcatFactory: Add in prependers and mixers in batches
  • 47d3c2a: 8287980: Build is broken due to SuperWordMaxVectorSize when C2 is disabled after JDK-8287697
  • bf0e625: 8286451: C2: assert(nb == 1) failed: only when the head is not shared
  • 0960ecc: 8287700: C2 Crash running eclipse benchmark from Dacapo
  • 590337e: 8286625: C2 fails with assert(!n->is_Store() && !n->is_LoadStore()) failed: no node with a side effect
  • 4662e06: 8277307: Pre shared key sent under both session_ticket and pre_shared_key extensions
  • 7df48f9: 8287353: Use snippet tag instead of pre tag in Javadoc of InterruptedException
  • 32dd1ee: 8287967: Update golden test files after JDK-8287886
  • ... and 288 more: https://git.openjdk.java.net/jdk/compare/47500b2429c8e09f322ec3ff95ff09293db26a9a...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@jddarcy) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 8, 2022
@rgiulietti
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 8, 2022
@openjdk
Copy link

openjdk bot commented Jun 8, 2022

@rgiulietti
Your change (at version 954d1ea) is now ready to be sponsored by a Committer.

@jddarcy
Copy link
Member

jddarcy commented Jun 8, 2022

/sponsor

@openjdk
Copy link

openjdk bot commented Jun 8, 2022

Going to push as commit c8cff1b.
Since your change was applied there have been 310 commits pushed to the master branch:

  • c15e10f: 8233760: Result of BigDecimal.toString throws overflow exception on new BigDecimal(str)
  • b92ce26: 8281001: Class::forName(String) defaults to system class loader if the caller is null
  • c68419f: 8286990: Add compiler name to warning messages in Compiler Directive
  • 6fb84e2: 8287541: Files.writeString fails to throw IOException for charset "windows-1252"
  • a9b9831: 8286663: Resolve IDE warnings in WTrayIconPeer and SystemTray
  • b021d37: 8283383: [macos] a11y : Screen magnifier shows extra characters (0) at the end JButton accessibility name
  • 78d3712: 8287432: C2: assert(tn->in(0) != __null) failed: must have live top node
  • f7791ad: 8287895: Some langtools tests fail on msys2
  • 5ad6286: 8287970: riscv: jdk/incubator/vector/*VectorTests failing
  • a9d46f3: 8287894: Use fixed timestamp as an alternative of DATE macro in jdk.jdi to make Windows build reproducible
  • ... and 300 more: https://git.openjdk.java.net/jdk/compare/47500b2429c8e09f322ec3ff95ff09293db26a9a...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 8, 2022
@openjdk openjdk bot closed this Jun 8, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Jun 8, 2022
@openjdk
Copy link

openjdk bot commented Jun 8, 2022

@jddarcy @rgiulietti Pushed as commit c8cff1b.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@rgiulietti rgiulietti deleted the JDK-8202449 branch June 27, 2022 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants