-
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 1 commit
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,26 @@ const char* InstanceKlass::init_state_name() const { | |
| return state_names[init_state()]; | ||
| } | ||
|
|
||
| #if !defined(PRODUCT) || INCLUDE_JVMTI | ||
| void InstanceKlass::print_class_flags(outputStream* st) const { | ||
| AccessFlags flags = access_flags(); | ||
| if (flags.is_public ()) st->print("public "); | ||
| 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. |
||
| } | ||
| #endif // !defined(PRODUCT) || INCLUDE_JVMTI | ||
|
|
||
| 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 +3861,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,24 @@ void Method::print_linkage_flags(outputStream* st) { | |
| } | ||
| #endif //PRODUCT | ||
|
|
||
| #if !defined(PRODUCT) || INCLUDE_JVMTI | ||
| 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.has_vararg ()) st->print("varargs "); | ||
| if (flags.is_native ()) st->print("native "); | ||
| if (flags.is_abstract ()) st->print("abstract "); | ||
| if (flags.is_strict_method()) st->print("strict "); | ||
| if (flags.is_synthetic ()) st->print("synthetic "); | ||
| } | ||
| #endif // !defined(PRODUCT) || INCLUDE_JVMTI | ||
|
|
||
| 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,23 @@ void fieldDescriptor::reinitialize(InstanceKlass* ik, const FieldInfo& fieldinfo | |
| guarantee(_fieldinfo.name_index() != 0 && _fieldinfo.signature_index() != 0, "bad constant pool index for fieldDescriptor"); | ||
| } | ||
|
|
||
| #if !defined(PRODUCT) || INCLUDE_JVMTI | ||
| 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. |
||
| } | ||
| #endif // !defined(PRODUCT) || INCLUDE_JVMTI | ||
|
|
||
| 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(" "); | ||
|
|
||
| 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 | ||
|
|
@@ -111,6 +111,11 @@ class fieldDescriptor { | |
| void print() const; | ||
| void print_on(outputStream* st) const; | ||
| void print_on_for(outputStream* st, oop obj); | ||
| #if !defined(PRODUCT) || INCLUDE_JVMTI | ||
|
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 new
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. 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
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. After some thought, I have removed all the
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. That is fine with me. |
||
| void print_access_flags(outputStream* st) const; | ||
| #else | ||
| void print_access_flags(outputStream* st) const PRODUCT_RETURN; | ||
| #endif | ||
| }; | ||
|
|
||
| #endif // SHARE_RUNTIME_FIELDDESCRIPTOR_HPP | ||
| 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 | ||
|
|
@@ -53,10 +53,15 @@ class AccessFlags { | |
| bool is_synchronized() const { return (_flags & JVM_ACC_SYNCHRONIZED) != 0; } | ||
| bool is_super () const { return (_flags & JVM_ACC_SUPER ) != 0; } | ||
| 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; } | ||
|
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. I recommend
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. +1
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. I renamed it to |
||
| bool is_native () const { return (_flags & JVM_ACC_NATIVE ) != 0; } | ||
| bool is_enum () const { return (_flags & JVM_ACC_ENUM ) != 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; } | ||
|
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. If "strict method" sounds too weird, we can call this "strictfp" following the original Java language modifier's name.
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. This will be short-lived either way as valhalla gets rid of the legacy strictfp notion for methods anyway.
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. Renamed to |
||
|
|
||
| // Attribute flags | ||
| bool is_synthetic () const { return (_flags & JVM_ACC_SYNTHETIC ) != 0; } | ||
|
|
@@ -92,13 +97,6 @@ class AccessFlags { | |
| assert((_flags & JVM_RECOGNIZED_CLASS_MODIFIERS) == _flags, "only recognized flags"); | ||
| return _flags; | ||
| } | ||
|
|
||
| // Printing/debugging | ||
| #if INCLUDE_JVMTI | ||
| void print_on(outputStream* st) const; | ||
| #else | ||
| void print_on(outputStream* st) const PRODUCT_RETURN; | ||
| #endif | ||
| }; | ||
|
|
||
| inline AccessFlags accessFlags_from(u2 flags) { | ||
|
|
||
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.