From fb63c5a72501ad367d49cc2dbf149ce3ebb934c0 Mon Sep 17 00:00:00 2001 From: MBaesken Date: Wed, 26 Jun 2024 13:23:43 +0200 Subject: [PATCH] introduce print_on_maybe_null --- src/hotspot/share/oops/instanceKlass.cpp | 51 +++++------------------- src/hotspot/share/oops/metadata.hpp | 9 +++++ 2 files changed, 19 insertions(+), 41 deletions(-) diff --git a/src/hotspot/share/oops/instanceKlass.cpp b/src/hotspot/share/oops/instanceKlass.cpp index dbb3925619194..ce564c7926ad1 100644 --- a/src/hotspot/share/oops/instanceKlass.cpp +++ b/src/hotspot/share/oops/instanceKlass.cpp @@ -3560,9 +3560,7 @@ void InstanceKlass::print_on(outputStream* st) const { } } } - if (default_vtable_indices() != nullptr) { - st->print(BULLET"default vtable indices: "); default_vtable_indices()->print_value_on(st); st->cr(); - } + print_on_maybe_null(st, BULLET"default vtable indices: ", default_vtable_indices()); st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr(); st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr(); @@ -3589,41 +3587,18 @@ void InstanceKlass::print_on(outputStream* st) const { } } st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr(); - if (class_loader_data() != nullptr) { - st->print(BULLET"class loader data: "); - class_loader_data()->print_value_on(st); - st->cr(); - } - if (source_file_name() != nullptr) { - st->print(BULLET"source file: "); - source_file_name()->print_value_on(st); - st->cr(); - } + + print_on_maybe_null(st, BULLET"class loader data: ", class_loader_data()); + print_on_maybe_null(st, BULLET"source file: ", source_file_name()); if (source_debug_extension() != nullptr) { st->print(BULLET"source debug extension: "); st->print("%s", source_debug_extension()); st->cr(); } - if (class_annotations() != nullptr) { - st->print(BULLET"class annotations: "); - class_annotations()->print_value_on(st); - st->cr(); - } - if (class_type_annotations() != nullptr) { - st->print(BULLET"class type annotations: "); - class_type_annotations()->print_value_on(st); - st->cr(); - } - if (fields_annotations() != nullptr) { - st->print(BULLET"field annotations: "); - fields_annotations()->print_value_on(st); - st->cr(); - } - if (fields_type_annotations() != nullptr) { - st->print(BULLET"field type annotations: "); - fields_type_annotations()->print_value_on(st); - st->cr(); - } + print_on_maybe_null(st, BULLET"class annotations: ", class_annotations()); + print_on_maybe_null(st, BULLET"class type annotations: ", class_type_annotations()); + print_on_maybe_null(st, BULLET"field annotations: ", fields_annotations()); + print_on_maybe_null(st, BULLET"field type annotations: ", fields_type_annotations()); { bool have_pv = false; // previous versions are linked together through the InstanceKlass @@ -3638,16 +3613,10 @@ void InstanceKlass::print_on(outputStream* st) const { if (have_pv) st->cr(); } - if (generic_signature() != nullptr) { - st->print(BULLET"generic signature: "); - generic_signature()->print_value_on(st); - st->cr(); - } + print_on_maybe_null(st, BULLET"generic signature: ", generic_signature()); st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr(); st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr(); - if (record_components() != nullptr) { - st->print(BULLET"record components: "); record_components()->print_value_on(st); st->cr(); - } + print_on_maybe_null(st, BULLET"record components: ", record_components()); st->print(BULLET"permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr(); if (java_mirror() != nullptr) { st->print(BULLET"java mirror: "); diff --git a/src/hotspot/share/oops/metadata.hpp b/src/hotspot/share/oops/metadata.hpp index c118ade8586e1..f5aee34c80da7 100644 --- a/src/hotspot/share/oops/metadata.hpp +++ b/src/hotspot/share/oops/metadata.hpp @@ -76,4 +76,13 @@ class Metadata : public MetaspaceObj { static void mark_on_stack(Metadata* m) { m->set_on_stack(true); } }; +template +static void print_on_maybe_null(outputStream* st, const char* str, const M* m) { + if (nullptr != m) { + st->print_raw(str); + m->print_value_on(st); + st->cr(); + } +} + #endif // SHARE_OOPS_METADATA_HPP