Skip to content
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

JDK-8312395: Improve assertions in growableArray #14946

Closed
wants to merge 3 commits into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Jul 20, 2023

There are a number of assertions in growableArray , for example to check for a valid index to access/remove elements.
Those assertions can be improved, e.g. by showing the bad index value used in case of failure.

Example for an assertion in the 'at(index i)' access method
old assertion looks like
assert(0 <= i && i < _len) failed: illegal index

new assertion looks like
assert(0 <= i && i < _len) failed: illegal index -559030609, 1 accessible elements


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-8312395: Improve assertions in growableArray (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14946

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 20, 2023

👋 Welcome back mbaesken! 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 Jul 20, 2023
@openjdk
Copy link

openjdk bot commented Jul 20, 2023

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

  • hotspot

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 hotspot hotspot-dev@openjdk.org label Jul 20, 2023
@mlbridge
Copy link

mlbridge bot commented Jul 20, 2023

Webrevs

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Approval in principle but I have a suggestion.

Thanks

@@ -142,17 +142,17 @@ class GrowableArrayView : public GrowableArrayBase {
}

E& at(int i) {
assert(0 <= i && i < _len, "illegal index");
assert(0 <= i && i < _len, "illegal index %d, %d accessible elements", i, _len);
Copy link
Member

Choose a reason for hiding this comment

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

How about:

"Illegal index %d for length %d"

?

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds like a good suggestions !

@MBaesken
Copy link
Member Author

I adjusted the output following your suggestion and also added some output to a few more asserts.

Btw any idea why so much 'this->_len' syntax is used at some places and not just _len or other field names ?

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

Looks good!

@openjdk
Copy link

openjdk bot commented Jul 20, 2023

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

8312395: Improve assertions in growableArray

Reviewed-by: dholmes, stuefe

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

  • 8d29329: 8312320: Remove javax/rmi/ssl/SSLSocketParametersTest.sh from ProblemList
  • 94eb44b: 8312394: [linux] SIGSEGV if kernel was built without hugepage support
  • 3283328: 8311130: AArch64: Sync SVE related CPU features with VM options
  • a742767: 8312246: NPE when HSDB visits bad oop

Please see this link for an up-to-date comparison between the source branch of this pull request and 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 ready Pull request is ready to be integrated label Jul 20, 2023
@tstuefe
Copy link
Member

tstuefe commented Jul 20, 2023

looks

I adjusted the output following your suggestion and also added some output to a few more asserts.

Btw any idea why so much 'this->_len' syntax is used at some places and not just _len or other field names ?

Probably some IDE-code-completion-related artifacts. E.g. typing "this->" in CDT gives me all members, and maybe someone just hit Enter then and took the full completion

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

One further suggestion but approving anyway.

I think the use of this->xxx is just personal style. I find it unnecessary especially given the other uses in this file.

Thanks.

assert(0 <= start, "illegal index");
assert(start < end && end <= _len, "erase called with invalid range");
assert(0 <= start, "illegal start index %d", start);
assert(start < end && end <= _len, "erase called with invalid range %d, %d", start, end);
Copy link
Member

Choose a reason for hiding this comment

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

I think you'd want to see _len here too - suggestion:

"erase called with invalid range (%d, %d) for length %d", start, end, _len

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi David, I agree !

@tstuefe
Copy link
Member

tstuefe commented Jul 20, 2023

I think the use of this->xxx is just personal style. I find it unnecessary especially given the other uses in this file.

Interestingly enough I get compiler errors when leaving out "this->" (GCC 10.3). It may be because the member is part of a templatized base class. Odd, though.

Thanks.

@MBaesken
Copy link
Member Author

Hi David and Thomas, thanks for the reviews !

/integrate

@openjdk
Copy link

openjdk bot commented Jul 20, 2023

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

  • 9fa944e: 8312019: Simplify and modernize java.util.BitSet.equals
  • fe41910: 8312459: Problem list java/awt/GraphicsDevice/DisplayModes/CycleDMImage.java for macOS
  • 8d29329: 8312320: Remove javax/rmi/ssl/SSLSocketParametersTest.sh from ProblemList
  • 94eb44b: 8312394: [linux] SIGSEGV if kernel was built without hugepage support
  • 3283328: 8311130: AArch64: Sync SVE related CPU features with VM options
  • a742767: 8312246: NPE when HSDB visits bad oop

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jul 20, 2023

@MBaesken Pushed as commit b772e67.

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

@kimbarrett
Copy link

I think the use of this->xxx is just personal style. I find it unnecessary especially given the other uses in this file.

Interestingly enough I get compiler errors when leaving out "this->" (GCC 10.3). It may be because the member is part of a templatized base class. Odd, though.

Qualification with this-> is needed in a bunch of places here because of the
C++ name lookup rules. Unqualified name lookup does not search dependent base
classes. For example, in GrowableArrayWithAllocator an unqualified use of
_len won't find that member in the base class, but will instead (probably)
fail to find it in namespace scope during phase1 (pre-instantiation) template
checking lookup (of 2 phase lookup), and so fail to compile. It isn't possible
to resolve it in phase1 because the dependent base class definition isn't
known until instantiation.

@dholmes-ora
Copy link
Member

Thanks @kimbarrett !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants