Skip to content

8380129: Remove AccessFlags::print_on in favor of context-specific printing#30746

Open
caspernorrbin wants to merge 3 commits intoopenjdk:masterfrom
caspernorrbin:accessflags-print_on
Open

8380129: Remove AccessFlags::print_on in favor of context-specific printing#30746
caspernorrbin wants to merge 3 commits intoopenjdk:masterfrom
caspernorrbin:accessflags-print_on

Conversation

@caspernorrbin
Copy link
Copy Markdown
Member

@caspernorrbin caspernorrbin commented Apr 15, 2026

Hi everyone,

AccessFlags::print_on is 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_on and split the printing into 3 separate helpers:

  • InstanceKlass::print_class_flags
  • Method::print_access_flags
  • fieldDescriptor::print_access_flags

As a part of that, I added the missing AccessFlags predicates used by each of the new printers, and updated each printer to check all the flags relevant for its type, as defined by jvm_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:

  • Oracle tiers 1-3
  • New gtests covering each of the printing helpers and each of the new flags


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8380129: Remove AccessFlags::print_on in favor of context-specific printing (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30746

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Apr 15, 2026

👋 Welcome back cnorrbin! 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
Copy Markdown

openjdk Bot commented Apr 15, 2026

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

8380129: Remove AccessFlags::print_on in favor of context-specific printing

Reviewed-by: liach, dholmes, coleenp

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 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 changed the title 8380129 8380129: Remove AccessFlags::print_on in favor of context-specific printing Apr 15, 2026
@openjdk openjdk Bot added serviceability serviceability-dev@openjdk.org hotspot hotspot-dev@openjdk.org labels Apr 15, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 15, 2026

@caspernorrbin The following labels will be automatically applied to this pull request:

  • hotspot
  • serviceability

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.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Apr 15, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge Bot commented Apr 15, 2026

Webrevs

Copy link
Copy Markdown
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.

This direction looks reasonable. Similar effort happens in core libraries in #30093.

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; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If "strict method" sounds too weird, we can call this "strictfp" following the original Java language modifier's name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will be short-lived either way as valhalla gets rid of the legacy strictfp notion for methods anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That is fine with me.

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; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
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.

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also do we need to handle ACC_MODULE, or do we not actually create an instanceKlass for those?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On jdk side we never have Class for modules. These classfiles are exclusively handled by Java code in ModuleDescriptor I think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

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; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will be short-lived either way as valhalla gets rid of the legacy strictfp notion for methods anyway.

@caspernorrbin
Copy link
Copy Markdown
Member Author

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.

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 16, 2026

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot. This can be overridden with the /reviewers command.

Comment on lines 3707 to 3709
if (flags.is_private ()) st->print("private ");
if (flags.is_protected ()) st->print("protected ");
if (flags.is_public ()) st->print("public ");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: use the same order as for fields and methods.

Copy link
Copy Markdown
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.

Nothing further from me. Thanks

Copy link
Copy Markdown
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

This looks really good!

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label Apr 23, 2026
Copy link
Copy Markdown
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.

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 ");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 ");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same SYNTHETIC remark here.

@liach
Copy link
Copy Markdown
Member

liach commented Apr 26, 2026

Created https://bugs.openjdk.org/browse/JDK-8380129 to track the synthetic flag problem instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org ready Pull request is ready to be integrated rfr Pull request is ready for review serviceability serviceability-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

4 participants