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

8262328: Templatize JVMFlag boilerplate access methods #3318

Conversation

iklam
Copy link
Member

@iklam iklam commented Apr 1, 2021

We have a bunch of boilerplate method like:

JVMFlagAccess::boolAtPut (JVMFlag* f, bool* v, JVMFlagOrigin origin)
JVMFlagAccess::intAtPut (JVMFlag* f, int* v, JVMFlagOrigin origin)
JVMFlagAccess::uintAtPut (JVMFlag* f, uint* v, JVMFlagOrigin origin)
...

Similarly, we also have 8 different functions: JVMFlag::{set_bool, set_int, set_intx, ...}

We should replace such patterns with

template <typename T>
JVMFlagAccess::set(JVMFlag* f, T* value, JVMFlagOrigin origin)

This would allow us to templatize the 8x boilerplate functions in writeableFlags.cpp.

The flag access code in whitebox.cpp can also be improved.


Progress

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

Issue

  • JDK-8262328: Templatize JVMFlag boilerplate access methods

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3318

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 1, 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 bot commented Apr 1, 2021

@iklam 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 label Apr 1, 2021
@iklam iklam marked this pull request as ready for review Apr 1, 2021
@iklam iklam changed the title 8262328 Templatize JVMFlag boilerplate access methods 8262328: Templatize JVMFlag boilerplate access methods Apr 1, 2021
@openjdk openjdk bot added the rfr label Apr 1, 2021
@mlbridge
Copy link

mlbridge bot commented Apr 1, 2021

Webrevs

@iklam
Copy link
Member Author

iklam commented Apr 2, 2021

I need to work on this PR some more. Closing it for now.

@iklam iklam closed this Apr 2, 2021
ioilam added 2 commits Apr 3, 2021
…ypes (i.e., cannot mix size_t and uintx even they might be the same type of some platforms)
@iklam iklam reopened this Apr 5, 2021
@iklam
Copy link
Member Author

iklam commented Apr 5, 2021

I've updated the patch and the JVMFlagAccess API should have identical behavior as before. Now it's ready to be reviewed again.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Hi Ioi,

In terms of readability and writeability I prefer <type>AtPut() over set<JVM_FLAG_TYPE(type)>(). Is there any way to push the JVM_FLAG_TYPE down a level so it doesn't shout at you when reading the code? set<type>() would look much much better.

Thanks,
David

@iklam
Copy link
Member Author

iklam commented Apr 6, 2021

Hi Ioi,

In terms of readability and writeability I prefer AtPut() over set<JVM_FLAG_TYPE(type)>(). Is there any way to push the JVM_FLAG_TYPE down a level so it doesn't shout at you when reading the code? set() would look much much better.

Thanks,
David

I added the JVMFlagAccess::set_<type>() functions back (they are the same as the old <type>AtPut functions, but with a more consistent naming style).

Now I use the more low-level set<JVM_FLAG_TYPE(type)>() only in templates where the type is not statically known. E.g, WriteableFlags::set_flag_impl().


A related note: in an earlier version, I tried to get rid of the <JVM_FLAG_TYPE(type)> altogether, where the code is much cleaner with template type inference.

JVMFlag* flag = someSizetFlag;
size_t s = 0;
JVMFlagAccess::set(flag, &s, origin);

However, this may allow type mismatch like the following, on platforms that use the exact same type for size_t and uint:

JVMFlag* flag = someSizetFlag;
uint s = 0;
JVMFlagAccess::set(flag, &s, origin);

but you will get a runtime failure on platforms where size_t is not the same as uint. So I decided against this design due to non-portability.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Hi Ioi,

This latest version looks good to me.

Thanks,
David

@openjdk
Copy link

openjdk bot commented Apr 8, 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:

8262328: Templatize JVMFlag boilerplate access methods

Reviewed-by: dholmes, gziemski

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 Apr 8, 2021
@gerard-ziemski
Copy link

gerard-ziemski commented Apr 8, 2021

I'm taking a look at your fix Ioi. Building it locally, wanted to check out a few things...

Copy link

@gerard-ziemski gerard-ziemski left a comment

Very nice! With all this reduction and "templatization" effort, soon we will be left with one line of a template code at this rate :-)

The only feedback I have is that I wish we could replace int type_enum with FlagType type_enum

@iklam
Copy link
Member Author

iklam commented Apr 9, 2021

Very nice! With all this reduction and "templatization" effort, soon we will be left with one line of a template code at this rate :-)

The only feedback I have is that I wish we could replace int type_enum with FlagType type_enum

Hi Gerard, thanks for the review. Replacing the int with enum will cause quite a bit of changes, so I would probably do that in a separate RFE.

@iklam
Copy link
Member Author

iklam commented Apr 10, 2021

Thanks @dholmes-ora and @gerard-ziemski for the review!
/integrate

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

openjdk bot commented Apr 10, 2021

@iklam Pushed as commit 627ad9f.

💡 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 integrated
4 participants