8380129: Remove AccessFlags::print_on in favor of context-specific printing#30746
8380129: Remove AccessFlags::print_on in favor of context-specific printing#30746caspernorrbin wants to merge 3 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back cnorrbin! A progress list of the required criteria for merging this PR into |
|
@caspernorrbin 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: 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 172 new commits pushed to the
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 |
|
@caspernorrbin The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
| bool is_annotation () const { return (_flags & JVM_ACC_ANNOTATION ) != 0; } | ||
| bool is_interface () const { return (_flags & JVM_ACC_INTERFACE ) != 0; } | ||
| bool is_abstract () const { return (_flags & JVM_ACC_ABSTRACT ) != 0; } | ||
| bool is_strict_method() const { return (_flags & JVM_ACC_STRICT ) != 0; } |
There was a problem hiding this comment.
If "strict method" sounds too weird, we can call this "strictfp" following the original Java language modifier's name.
There was a problem hiding this comment.
This will be short-lived either way as valhalla gets rid of the legacy strictfp notion for methods anyway.
There was a problem hiding this comment.
Renamed to is_strictfp instead.
| void print() const; | ||
| void print_on(outputStream* st) const; | ||
| void print_on_for(outputStream* st, oop obj); | ||
| #if !defined(PRODUCT) || INCLUDE_JVMTI |
There was a problem hiding this comment.
The new !defined(PRODUCT) seems to be only for the gtest. I wonder if gtest can run the test for print_access_flags based on INCLUDE_JVMTI flag instead; the macro condition tweak seems weird.
There was a problem hiding this comment.
I am surprised that we only ever print access flags in relation to JVMTI - I would have expected logging or crash reporting to do so. In any case I also find the !PRODUCT a little jarring. Given we always have JVMTI it makes no different to our binaries.
There was a problem hiding this comment.
After some thought, I have removed all the #if guards on the printers. To me, these are now ordinary printing utilities belonging to either Method, InstanceKlass, or fieldDescriptor. They are not directly tied to JVMTI, so should not be guarded by it. Let me know if you agree.
| bool is_volatile () const { return (_flags & JVM_ACC_VOLATILE ) != 0; } | ||
| bool is_bridge () const { return (_flags & JVM_ACC_BRIDGE ) != 0; } | ||
| bool is_transient () const { return (_flags & JVM_ACC_TRANSIENT ) != 0; } | ||
| bool has_vararg () const { return (_flags & JVM_ACC_VARARGS ) != 0; } |
There was a problem hiding this comment.
I recommend is_varargs, this flag is not enforced by the VM so technically users can create class files that declare varargs methods without a trailing array argument.
There was a problem hiding this comment.
I renamed it to is_varargs. I originally picked has_varargs because that is the name on the valhalla branch, but I am fine with this too.
dholmes-ora
left a comment
There was a problem hiding this comment.
I think this is a reasonable approach though I have little doubt something somewhere will be tripped up by these changes. There's an existing issue with inner classes that we may, or may not want to address (not necessarily in this PR).
Thanks
| } | ||
|
|
||
| #if !defined(PRODUCT) || INCLUDE_JVMTI | ||
| void InstanceKlass::print_class_flags(outputStream* st) const { |
There was a problem hiding this comment.
This is incomplete. If the class is an inner class then additional access flags are possible (private, protected, static).
EDIT: Hmm jvm_constants.h does not recognise this either via JVM_RECOGNIZED_CLASS_MODIFIERS. Not sure how this should be handled.
There was a problem hiding this comment.
Also do we need to handle ACC_MODULE, or do we not actually create an instanceKlass for those?
There was a problem hiding this comment.
On jdk side we never have Class for modules. These classfiles are exclusively handled by Java code in ModuleDescriptor I think?
There was a problem hiding this comment.
I have now changed it to use compute_modifier_flags() instead of access_flags() directly. With this, we get member-class modifiers printed. I expanded the test which shows that private/protected static gets printed. This matches the class' modifiers, which feels like the correct behavior.
ACC_MODULE is not needed here because it never becomes an InstanceKlass. It is rejected as a normal class during parsing.
| st->print (" - constants: " PTR_FORMAT " ", p2i(constants())); | ||
| constants()->print_value_on(st); st->cr(); | ||
| st->print (" - access: 0x%x ", access_flags().as_method_flags()); access_flags().print_on(st); st->cr(); | ||
| st->print (" - access: 0x%x ", access_flags().as_method_flags()); print_access_flags(st); st->cr(); |
There was a problem hiding this comment.
There is an existing inconsistency here in that we print the raw flags as "method flags" only but then we print them all. Your new code implicitly filters the flags by only printing the expected method flags.
There was a problem hiding this comment.
as_method_flags() asserts that only recognized method modifiers are set, so these are not arbitrary raw flags. Previously, the generic printer could misinterpret overlapping bits, whereas the new method-specific printer prints them correctly. This looks like the right behavior to me.
| void print() const; | ||
| void print_on(outputStream* st) const; | ||
| void print_on_for(outputStream* st, oop obj); | ||
| #if !defined(PRODUCT) || INCLUDE_JVMTI |
There was a problem hiding this comment.
I am surprised that we only ever print access flags in relation to JVMTI - I would have expected logging or crash reporting to do so. In any case I also find the !PRODUCT a little jarring. Given we always have JVMTI it makes no different to our binaries.
| bool is_volatile () const { return (_flags & JVM_ACC_VOLATILE ) != 0; } | ||
| bool is_bridge () const { return (_flags & JVM_ACC_BRIDGE ) != 0; } | ||
| bool is_transient () const { return (_flags & JVM_ACC_TRANSIENT ) != 0; } | ||
| bool has_vararg () const { return (_flags & JVM_ACC_VARARGS ) != 0; } |
| bool is_annotation () const { return (_flags & JVM_ACC_ANNOTATION ) != 0; } | ||
| bool is_interface () const { return (_flags & JVM_ACC_INTERFACE ) != 0; } | ||
| bool is_abstract () const { return (_flags & JVM_ACC_ABSTRACT ) != 0; } | ||
| bool is_strict_method() const { return (_flags & JVM_ACC_STRICT ) != 0; } |
There was a problem hiding this comment.
This will be short-lived either way as valhalla gets rid of the legacy strictfp notion for methods anyway.
|
Thank you for the reviews! I pushed some changes from your feedback. I am also running some more testing into more tiers to ensure nothing new comes up. |
|
The total number of required reviews for this PR has been set to 2 based on the presence of this label: |
| if (flags.is_private ()) st->print("private "); | ||
| if (flags.is_protected ()) st->print("protected "); | ||
| if (flags.is_public ()) st->print("public "); |
There was a problem hiding this comment.
Nit: use the same order as for fields and methods.
dholmes-ora
left a comment
There was a problem hiding this comment.
Nothing further from me. Thanks
liach
left a comment
There was a problem hiding this comment.
Looks good besides an unrelated issue not for this patch.
| if (flags.is_abstract ()) st->print("abstract "); | ||
| if (flags.is_annotation()) st->print("annotation "); | ||
| if (flags.is_enum ()) st->print("enum "); | ||
| if (flags.is_synthetic ()) st->print("synthetic "); |
There was a problem hiding this comment.
The bit for SYNTHETIC, 0x1000, comes before ANNOTATION, 0x2000, and ENUM, 0x4000. That should be tracked in a separate issue though.
| if (flags.is_volatile ()) st->print("volatile "); | ||
| if (flags.is_transient()) st->print("transient "); | ||
| if (flags.is_enum ()) st->print("enum "); | ||
| if (flags.is_synthetic()) st->print("synthetic "); |
|
Created https://bugs.openjdk.org/browse/JDK-8380129 to track the synthetic flag problem instead. |
Hi everyone,
AccessFlags::print_onis used for class, field and method printing, but those entities do not share the same modifier set. The current helper hard-codes a single mixed list of access flags for all 3 and is thus unaware of the type of the printed value. Instead of using a single shared printing function, we should move the printing to the relevant class, field, and method call sites. This makes the printer aware of the type it is printing and lets us check only the flags that are relevant for that type.For this change, I remove
AccessFlags::print_onand split the printing into 3 separate helpers:InstanceKlass::print_class_flagsMethod::print_access_flagsfieldDescriptor::print_access_flagsAs a part of that, I added the missing
AccessFlagspredicates used by each of the new printers, and updated each printer to check all the flags relevant for its type, as defined byjvm_constants.h. This lets us cover class-specific, method-specific, and field-specific modifiers that were not handled before.I also added new gtests covering each of the 3 printing helpers and the previously missing flags.
Testing:
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30746/head:pull/30746$ git checkout pull/30746Update a local copy of the PR:
$ git checkout pull/30746$ git pull https://git.openjdk.org/jdk.git pull/30746/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 30746View PR using the GUI difftool:
$ git pr show -t 30746Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30746.diff
Using Webrev
Link to Webrev Comment