-
Notifications
You must be signed in to change notification settings - Fork 6.3k
8380129: Remove AccessFlags::print_on in favor of context-specific printing #30746
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3702,13 +3702,27 @@ const char* InstanceKlass::init_state_name() const { | |
| return state_names[init_state()]; | ||
| } | ||
|
|
||
| void InstanceKlass::print_class_flags(outputStream* st) const { | ||
| AccessFlags flags(compute_modifier_flags()); | ||
| if (flags.is_public ()) st->print("public "); | ||
| if (flags.is_private ()) st->print("private "); | ||
| if (flags.is_protected ()) st->print("protected "); | ||
| if (flags.is_static ()) st->print("static "); | ||
| if (flags.is_final ()) st->print("final "); | ||
| if (flags.is_interface ()) st->print("interface "); | ||
| 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 "); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
|
|
||
| void InstanceKlass::print_on(outputStream* st) const { | ||
| assert(is_klass(), "must be klass"); | ||
| Klass::print_on(st); | ||
|
|
||
| st->print(BULLET"instance size: %d", size_helper()); st->cr(); | ||
| st->print(BULLET"klass size: %d", size()); st->cr(); | ||
| st->print(BULLET"access: "); access_flags().print_on(st); st->cr(); | ||
| st->print(BULLET"access: "); print_class_flags(st); st->cr(); | ||
| st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr(); | ||
| st->print(BULLET"state: "); st->print_cr("%s", init_state_name()); | ||
| st->print(BULLET"name: "); name()->print_value_on(st); st->cr(); | ||
|
|
@@ -3848,7 +3862,7 @@ void InstanceKlass::print_on(outputStream* st) const { | |
|
|
||
| void InstanceKlass::print_value_on(outputStream* st) const { | ||
| assert(is_klass(), "must be klass"); | ||
| if (Verbose || WizardMode) access_flags().print_on(st); | ||
| if (Verbose || WizardMode) print_class_flags(st); | ||
| name()->print_value_on(st); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2204,7 +2204,7 @@ void Method::print_on(outputStream* st) const { | |
| st->print (" - method holder: "); method_holder()->print_value_on(st); st->cr(); | ||
| 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(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| st->print (" - flags: 0x%x ", _flags.as_int()); _flags.print_on(st); st->cr(); | ||
| st->print (" - name: "); name()->print_value_on(st); st->cr(); | ||
| st->print (" - signature: "); signature()->print_value_on(st); st->cr(); | ||
|
|
@@ -2278,8 +2278,8 @@ void Method::print_on(outputStream* st) const { | |
| } | ||
| } | ||
|
|
||
| void Method::print_linkage_flags(outputStream* st) { | ||
| access_flags().print_on(st); | ||
| void Method::print_linkage_flags(outputStream* st) const { | ||
| print_access_flags(st); | ||
| if (is_default_method()) { | ||
| st->print("default "); | ||
| } | ||
|
|
@@ -2289,6 +2289,22 @@ void Method::print_linkage_flags(outputStream* st) { | |
| } | ||
| #endif //PRODUCT | ||
|
|
||
| void Method::print_access_flags(outputStream* st) const { | ||
| AccessFlags flags = access_flags(); | ||
| if (flags.is_public ()) st->print("public "); | ||
| if (flags.is_private ()) st->print("private "); | ||
| if (flags.is_protected ()) st->print("protected "); | ||
| if (flags.is_static ()) st->print("static "); | ||
| if (flags.is_final ()) st->print("final "); | ||
| if (flags.is_synchronized()) st->print("synchronized "); | ||
| if (flags.is_bridge ()) st->print("bridge "); | ||
| if (flags.is_varargs ()) st->print("varargs "); | ||
| if (flags.is_native ()) st->print("native "); | ||
| if (flags.is_abstract ()) st->print("abstract "); | ||
| if (flags.is_strictfp ()) st->print("strict "); | ||
| if (flags.is_synthetic ()) st->print("synthetic "); | ||
| } | ||
|
|
||
| void Method::print_value_on(outputStream* st) const { | ||
| assert(is_method(), "must be method"); | ||
| st->print("%s", internal_name()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
|
|
@@ -108,8 +108,21 @@ void fieldDescriptor::reinitialize(InstanceKlass* ik, const FieldInfo& fieldinfo | |
| guarantee(_fieldinfo.name_index() != 0 && _fieldinfo.signature_index() != 0, "bad constant pool index for fieldDescriptor"); | ||
| } | ||
|
|
||
| void fieldDescriptor::print_access_flags(outputStream* st) const { | ||
| AccessFlags flags = access_flags(); | ||
| if (flags.is_public ()) st->print("public "); | ||
| if (flags.is_private ()) st->print("private "); | ||
| if (flags.is_protected()) st->print("protected "); | ||
| if (flags.is_static ()) st->print("static "); | ||
| if (flags.is_final ()) st->print("final "); | ||
| 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 "); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same SYNTHETIC remark here. |
||
| } | ||
|
|
||
| void fieldDescriptor::print_on(outputStream* st) const { | ||
| access_flags().print_on(st); | ||
| print_access_flags(st); | ||
| if (field_flags().is_injected()) st->print("injected "); | ||
| name()->print_value_on(st); | ||
| st->print(" "); | ||
|
|
||
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
instanceKlassfor those?There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ofaccess_flags()directly. With this, we get member-class modifiers printed. I expanded the test which shows thatprivate/protected staticgets printed. This matches the class' modifiers, which feels like the correct behavior.ACC_MODULEis not needed here because it never becomes anInstanceKlass. It is rejected as a normal class during parsing.