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

8183569: Assert the same limits are used in parse_xss and globals.hpp #2688

Closed

Conversation

iklam
Copy link
Member

@iklam iklam commented Feb 23, 2021

We have the following in Arguments::parse_xss():

  const julong min_ThreadStackSize = 0;
  const julong max_ThreadStackSize = 1 * M;
  const julong min_size = min_ThreadStackSize * K;
  const julong max_size = max_ThreadStackSize * K;

which duplicates the min/max range specified in globals.hpp:

  product_pd(intx, ThreadStackSize, \
          "Thread Stack Size (in Kbytes)") \
          range(0, 1 * M) \

I added an API to query the min/max range of a flag, so parse_xss can be rewritten as

  const JVMTypedFlagLimit<intx>* limit = 
    JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
  const julong min_size = limit->min() * K;
  const julong max_size = limit->max() * K;

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8183569: Assert the same limits are used in parse_xss and globals.hpp

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2688/head:pull/2688
$ git checkout pull/2688

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Feb 23, 2021

👋 Welcome back iklam! 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 openjdk bot commented Feb 23, 2021

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

  • hotspot-runtime

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-runtime label Feb 23, 2021
@iklam iklam marked this pull request as ready for review Feb 23, 2021
@openjdk openjdk bot added the rfr label Feb 23, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Feb 23, 2021

Webrevs

Copy link
Member

@tstuefe tstuefe left a comment

Hi Ioi,

Seems reasonable. Some remarks below.

..Thomas

}
#endif
}

Copy link
Member

@tstuefe tstuefe Feb 23, 2021

Choose a reason for hiding this comment

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

Do we need this? Seems an unused duplicate to the version in jvmFlagLimit.hpp.

Copy link
Member Author

@iklam iklam Feb 23, 2021

Choose a reason for hiding this comment

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

I left JVMFlagLimit::assert_compatible_type by mistake, so I deleted it. I think we can use JVMFlag::assert_compatible_type in other places as well to get rid of the 8x duplicated boilerplate functions such as JVMFlag::{get_bool, get_int, get_intx, etc}. I filed https://bugs.openjdk.java.net/browse/JDK-8262328.

For your other comments, I updated JVMFlag::assert_compatible_type to use macros, so there's less repetition and more uniform (no more special case for double). It's a little easier to maintain, but maybe not as obvious to read.

case JVMFlag::TYPE_intx: assert(sizeof(T) == sizeof(intx) && std::is_signed<T>::value == std::is_signed<intx> ::value, "must be"); break;
case JVMFlag::TYPE_uintx: assert(sizeof(T) == sizeof(uintx) && std::is_signed<T>::value == std::is_signed<uintx> ::value, "must be"); break;
case JVMFlag::TYPE_uint64_t: assert(sizeof(T) == sizeof(uint64_t) && std::is_signed<T>::value == std::is_signed<uint64_t>::value, "must be"); break;
case JVMFlag::TYPE_size_t: assert(sizeof(T) == sizeof(size_t) && std::is_signed<T>::value == std::is_signed<size_t> ::value, "must be"); break;
Copy link
Member

@tstuefe tstuefe Feb 23, 2021

Choose a reason for hiding this comment

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

Could we shorten the signed comparisons to the expected default? For most types the signedness wont be a surprise :) size_t is unsigned on all our platforms.

is_signed seems weird, isn't that UB?

default: ShouldNotReachHere();
}
} else {
assert(flag_enum == JVMFlag::TYPE_double, "must be double");
Copy link
Member

@tstuefe tstuefe Feb 23, 2021

Choose a reason for hiding this comment

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

Could the same comparisons not be made too here?

@iklam
Copy link
Member Author

@iklam iklam commented Feb 23, 2021

In rev 8c4b5cd:

I updated Arguments::parse_xss() to restore the original code -- I think it's important to see the 1 * M to make sense of what this comment is talking about:

  // The min and max sizes match the values in globals.hpp, but scaled
  // with K. The values have been chosen so that alignment with page
  // size doesn't change the max value, which makes the conversions
  // back and forth between Xss value and ThreadStackSize value easier.
  // The values have also been chosen to fit inside a 32-bit signed type.
  const julong min_ThreadStackSize = 0;
  const julong max_ThreadStackSize = 1 * M;

So instead of the PR's initially proposed changes, I added these to make sure that the value 1 * M matches with globals.hpp:

  // Make sure the above values match the range set in globals.hpp
  const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
  assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
  assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");

If people are OK with this, I will update the PR's initial comment, and the bug title as well.

@@ -68,6 +70,10 @@ class JVMFlagLimit {
char _phase;
char _kind;

#ifndef PRODUCT
int _type_enum;
#endif

Choose a reason for hiding this comment

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

I think all the #ifndef PRODUCT stuff around _type_enum should instead be #ifdef ASSERT. These belong in debug builds, but not in optimize builds.

@@ -290,6 +291,23 @@ class JVMFlag {

static const char* flag_error_str(JVMFlag::Error error);

// type checking
#define CHECK_COMPATIBLE(type) \

Choose a reason for hiding this comment

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

CHECK_COMPATIBLE doesn't appear to be used outside the following assertion function. Add an #undef afterward.

case TYPE_##type: \
assert(sizeof(T) == sizeof(type) && \
std::is_integral<T>::value == std::is_integral<type>::value && \
std::is_signed <T>::value == std::is_signed <type>::value, "must be"); break;

Choose a reason for hiding this comment

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

I'd prefer the break be on it's own source line, rather than after the assert form.

@iklam iklam changed the title 8183569: Remove duplicated flag limits in parse_xss and globals.hpp 8183569: Assert the same limits are used in parse_xss and globals.hpp Mar 1, 2021
@iklam
Copy link
Member Author

@iklam iklam commented Mar 1, 2021

I've updated the code per @kimbarrett's suggestions, and also changed the title to "Assert the same limits are used in parse_xss and globals.hpp"

@iklam iklam force-pushed the 8183569-duplicated-flag-limits-parse-xss branch from 77ca66c to e28c07c Compare Mar 2, 2021
Copy link

@kimbarrett kimbarrett left a comment

Looks good.

@openjdk
Copy link

@openjdk openjdk bot commented Mar 2, 2021

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

8183569: Assert the same limits are used in parse_xss and globals.hpp

Reviewed-by: stuefe, kbarrett

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

  • 93ffe6a: 8262892: minor typo in implSpec comment
  • 4f4d0f5: 8261969: SNIHostName should check if the encoded hostname conform to RFC 3490

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 label Mar 2, 2021
tstuefe
tstuefe approved these changes Mar 2, 2021
Copy link
Member

@tstuefe tstuefe left a comment

Looks good to me. Sorry for the delay.

Cheers, Thomas

@iklam
Copy link
Member Author

@iklam iklam commented Mar 3, 2021

Thanks @kimbarrett and @tstuefe for the review!
/integrate

@openjdk openjdk bot closed this Mar 3, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Mar 3, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Mar 3, 2021

@iklam Since your change was applied there have been 5 commits pushed to the master branch:

  • 5de0f4b: 8260869: Test java/foreign/TestHandshake.java fails intermittently
  • c9097a6: 8262893: Enable more doclint checks in javadoc build
  • 40bdf52: 8262096: Vector API fails to work due to VectorShape initialization exception
  • 93ffe6a: 8262892: minor typo in implSpec comment
  • 4f4d0f5: 8261969: SNIHostName should check if the encoded hostname conform to RFC 3490

Your commit was automatically rebased without conflicts.

Pushed as commit 044e2a2.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime integrated
4 participants