Skip to content

Commit 7d04a31

Browse files
author
Harold Seigel
committed
8208399: Metadata methods print_(value_)on_maybe_null() compare 'this' to NULL
Add Method* parameter and make method static to avoid 'this' comparison with NULL Reviewed-by: lfoltan, gziemski, coleenp
1 parent c9d5060 commit 7d04a31

3 files changed

Lines changed: 10 additions & 17 deletions

File tree

src/hotspot/share/code/nmethod.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,7 @@ void nmethod::print_recorded_metadata() {
23462346
if (m == (Metadata*)Universe::non_oop_word()) {
23472347
tty->print("non-metadata word");
23482348
} else {
2349-
m->print_value_on_maybe_null(tty);
2349+
Metadata::print_value_on_maybe_null(tty, m);
23502350
}
23512351
tty->cr();
23522352
}

src/hotspot/share/oops/instanceKlass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,7 +3072,7 @@ void InstanceKlass::print_on(outputStream* st) const {
30723072
st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
30733073
st->print(BULLET"state: "); st->print_cr("%s", state_names[_init_state]);
30743074
st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3075-
st->print(BULLET"super: "); super()->print_value_on_maybe_null(st); st->cr();
3075+
st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
30763076
st->print(BULLET"sub: ");
30773077
Klass* sub = subklass();
30783078
int n;
@@ -3095,7 +3095,7 @@ void InstanceKlass::print_on(outputStream* st) const {
30953095
}
30963096
}
30973097

3098-
st->print(BULLET"arrays: "); array_klasses()->print_value_on_maybe_null(st); st->cr();
3098+
st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
30993099
st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr();
31003100
if (Verbose || WizardMode) {
31013101
Array<Method*>* method_array = methods();
@@ -3122,7 +3122,7 @@ void InstanceKlass::print_on(outputStream* st) const {
31223122
class_loader_data()->print_value_on(st);
31233123
st->cr();
31243124
}
3125-
st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr();
3125+
st->print(BULLET"host class: "); Metadata::print_value_on_maybe_null(st, host_klass()); st->cr();
31263126
if (source_file_name() != NULL) {
31273127
st->print(BULLET"source file: ");
31283128
source_file_name()->print_value_on(st);
@@ -3229,11 +3229,11 @@ void InstanceKlass::oop_print_on(oop obj, outputStream* st) {
32293229
st->cr();
32303230
Klass* mirrored_klass = java_lang_Class::as_Klass(obj);
32313231
st->print(BULLET"fake entry for mirror: ");
3232-
mirrored_klass->print_value_on_maybe_null(st);
3232+
Metadata::print_value_on_maybe_null(st, mirrored_klass);
32333233
st->cr();
32343234
Klass* array_klass = java_lang_Class::array_klass_acquire(obj);
32353235
st->print(BULLET"fake entry for array: ");
3236-
array_klass->print_value_on_maybe_null(st);
3236+
Metadata::print_value_on_maybe_null(st, array_klass);
32373237
st->cr();
32383238
st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj));
32393239
st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj));

src/hotspot/share/oops/metadata.hpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -56,18 +56,11 @@ class Metadata : public MetaspaceObj {
5656
void print() const { print_on(tty); }
5757
void print_value() const { print_value_on(tty); }
5858

59-
void print_maybe_null() const { print_on_maybe_null(tty); }
60-
void print_on_maybe_null(outputStream* st) const {
61-
if (this == NULL)
59+
static void print_value_on_maybe_null(outputStream* st, const Metadata* m) {
60+
if (NULL == m)
6261
st->print("NULL");
6362
else
64-
print_on(st);
65-
}
66-
void print_value_on_maybe_null(outputStream* st) const {
67-
if (this == NULL)
68-
st->print("NULL");
69-
else
70-
print_value_on(st);
63+
m->print_value_on(st);
7164
}
7265

7366
virtual void print_on(outputStream* st) const; // First level print

0 commit comments

Comments
 (0)