Skip to content

8343829: Unify decimal and hexadecimal parsing in FloatingDecimal #22737

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 15 commits into from

Conversation

rgiulietti
Copy link
Contributor

@rgiulietti rgiulietti commented Dec 13, 2024

See the JBS bug for some details.


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

Issue

  • JDK-8343829: Unify decimal and hexadecimal parsing in FloatingDecimal (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22737/head:pull/22737
$ git checkout pull/22737

Update a local copy of the PR:
$ git checkout pull/22737
$ git pull https://git.openjdk.org/jdk.git pull/22737/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22737

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22737.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 13, 2024

👋 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
Copy link

openjdk bot commented Dec 13, 2024

@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:

8343829: Unify decimal and hexadecimal parsing in FloatingDecimal

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 29 new commits pushed to the master branch:

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 13, 2024
@openjdk
Copy link

openjdk bot commented Dec 13, 2024

@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 Dec 13, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 13, 2024

// private static final int BINARY_256_IX = 4;

/* The precision of the format. */
private static final int[] P = {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about organizing these constants as as a record - something like this:

record FloatFmt(int ix, int p, int epMin, int epMax, int w, int eMin, int eMax, int qMin, int hexCount) {

    public static final FloatFmt BINARY_16 = build(0, 11, -8, 6);
    public static final FloatFmt BINARY_32 = build(1, 24, -46, 40);
    public static final FloatFmt BINARY_64 = build(2, 53, -324, 310);
    public static final FloatFmt BINARY_128 = build(3, 113, -4_966, 4934);
    public static final FloatFmt BINARY_256 = build(4, 237, -78_985, 78_915);

    private static FloatFmt build(int ix, int p, int epMin, int epMax) {
        int w = (1 << 4 + ix) - p;
        int eMin = (-1 << w - 1) + 2;
        int eMax = (1 << w - 1) - 1;
        int qMin = eMin - p + 1;
        int hexCount = p / 4 + 2;

        return new FloatFmt(ix, p, epMin, epMax, w, eMin, eMax, qMin, hexCount);
    }
}

Methods could then be parameterized with the static instances rather than integers. I believe these values would inline well as constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion @j3graham.
I'll consider it for the next commits.

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 13, 2025

@rgiulietti This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 10, 2025

@rgiulietti This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Feb 10, 2025
@rgiulietti
Copy link
Contributor Author

/open Still in review

@openjdk openjdk bot reopened this Feb 10, 2025
@openjdk
Copy link

openjdk bot commented Feb 10, 2025

@rgiulietti This pull request is now open

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 10, 2025

@rgiulietti This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@rgiulietti
Copy link
Contributor Author

Ping

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 7, 2025

@rgiulietti This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@rgiulietti
Copy link
Contributor Author

Comment added...

@wenshao
Copy link
Contributor

wenshao commented May 2, 2025

static final int BIG_DECIMAL_EXPONENT = 324;

The BIG_DECIMAL_EXPONENT in line 50 is no longer used and can be removed.

// private static final int BINARY_256_IX = 4;

/* The precision of the format. */
private static final int[] P = {
Copy link
Contributor

Choose a reason for hiding this comment

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

private static final int[] P
private static final int[] EP_MIN
private static final int[] EP_MAX
private static final int[] W
private static final int[] E_MAX
private static final int[] E_MIN
private static final int[] Q_MIN
private static final int[] HEX_COUNT

These should all be added with @stable

@wenshao
Copy link
Contributor

wenshao commented May 2, 2025

We can do some cleanup before this PR, such as #24999

@rgiulietti
Copy link
Contributor Author

rgiulietti commented May 2, 2025

This is just the first step of a planned overhaul of conversions from decimal strings to floating-point values. There are more steps to come.
So I'm not sure that #24999 turns out to be useful at this stage.

@wenshao
Copy link
Contributor

wenshao commented May 2, 2025

Q_MIN -> E_MIN -> E_MAX -> W -> P Five layers of Stable, I don't know if C2 can work correctly, maybe need to confirm

@rgiulietti
Copy link
Contributor Author

@wenshao Do you mean that C2 might generate erroneous code (bad situation!), or that it might not take advantage of @Stable in optimized code?

@wenshao
Copy link
Contributor

wenshao commented May 2, 2025

@wenshao Do you mean that C2 might generate erroneous code (bad situation!), or that it might not take advantage of @Stable in optimized code?

I am worried that too many layers will cause C2 to not be optimized, but I am not sure, and I also hope to learn how to know that @Stable works

@rgiulietti
Copy link
Contributor Author

I'm not worried if C2 cannot optimize too many levels of @Stable here. The values are used in an unusually long method, so I don't think there are measurable benefits anyway.
In contrast, I would be much concerned if there are real risks of erroneous code being generated.

@jaikiran
Copy link
Member

jaikiran commented May 2, 2025

If I understand correctly, we are talking about several (primitive) array type fields having a @Stable annotation, in a single class, right? So we aren't really talking about levels?
If so, given what @Stable is documented to do, I don't think the number of fields annotated as @Stable plays any role in the C2 compiler generating the resultant code.

@rgiulietti
Copy link
Contributor Author

@jaikiran "Levels" in the sense that Q_MIN depends on E_MIN, which depends on E_MAX, which depends on W, which depends on P.
If @Stable helps, which I think it does, great. If it doesn't, it shouldn't matter in practice.

@jddarcy
Copy link
Member

jddarcy commented May 7, 2025

Generally good cleanup @rgiulietti.

I'd like to see some kind of representation of the grammar of strings being recognized included in this file, for example a cut-and-paste of the grammar from Double.valueOf(String) (with leading and trailing spaces):

FloatValue:
    Sign_opt NaN 
    Sign_opt Infinity 
    Sign_opt FloatingPointLiteral 
    Sign_opt HexFloatingPointLiteral 
    SignedInteger 

HexFloatingPointLiteral:
    HexSignificand BinaryExponent FloatTypeSuffixopt 

HexSignificand:
    HexNumeral 
    HexNumeral . 
    0x HexDigitsopt . HexDigits 
    0X HexDigitsopt . HexDigits 

BinaryExponent:
    BinaryExponentIndicator SignedInteger 

BinaryExponentIndicator:
    p 
    P 

Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

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

Took a look over the string parsing part. Not professional enough about floating numbers.

}

/*
* In some places the idiom
Copy link
Member

Choose a reason for hiding this comment

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

Might be easier to read the code if this logic were refactored into a method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right.
I'll take this note into account in the next phase of the cleanup.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 13, 2025
@rgiulietti
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented May 14, 2025

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

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 14, 2025
@openjdk openjdk bot closed this May 14, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 14, 2025
@openjdk
Copy link

openjdk bot commented May 14, 2025

@rgiulietti Pushed as commit d1032d7.

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

@rgiulietti rgiulietti deleted the 8343829 branch May 14, 2025 08: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.

6 participants