8202171: Some oopDesc functions compare this with NULL

Add Method* parameter and made verify* methods static to avoid 'this' comparison with NULL, Added NULL checks before calling print_on() methods.

Reviewed-by: kbarrett, coleenp
This commit is contained in:
Harold Seigel 2018-07-31 14:24:10 -04:00
parent b71f3e7104
commit 38db1d1620
15 changed files with 73 additions and 39 deletions

View File

@ -182,7 +182,7 @@ class DictionaryEntry : public HashtableEntry<InstanceKlass*, mtClass> {
for (ProtectionDomainEntry* current = pd_set(); // accessed at a safepoint
current != NULL;
current = current->_next) {
current->_pd_cache->object_no_keepalive()->verify();
oopDesc::verify(current->_pd_cache->object_no_keepalive());
}
}

View File

@ -443,8 +443,18 @@ void SystemDictionary::validate_protection_domain(InstanceKlass* klass,
// Print out trace information
LogStream ls(lt);
ls.print_cr("Checking package access");
ls.print("class loader: "); class_loader()->print_value_on(&ls);
ls.print(" protection domain: "); protection_domain()->print_value_on(&ls);
if (class_loader() != NULL) {
ls.print("class loader: ");
class_loader()->print_value_on(&ls);
} else {
ls.print_cr("class loader: NULL");
}
if (protection_domain() != NULL) {
ls.print(" protection domain: ");
protection_domain()->print_value_on(&ls);
} else {
ls.print_cr(" protection domain: NULL");
}
ls.print(" loading: "); klass->print_value_on(&ls);
ls.cr();
}

View File

@ -251,7 +251,11 @@ void ConstantOopReadValue::write_on(DebugInfoWriteStream* stream) {
}
void ConstantOopReadValue::print_on(outputStream* st) const {
value()()->print_value_on(st);
if (value()() != NULL) {
value()()->print_value_on(st);
} else {
st->print_cr("NULL");
}
}

View File

@ -2332,7 +2332,11 @@ void nmethod::print_recorded_oops() {
if (o == (oop)Universe::non_oop_word()) {
tty->print("non-oop word");
} else {
o->print_value();
if (o != NULL) {
o->print_value();
} else {
tty->print_cr("NULL");
}
}
tty->cr();
}

View File

@ -2406,7 +2406,7 @@ class VerifyAllBlksClosure: public BlkClosure {
res = _sp->adjustObjectSize(p->size());
if (_sp->obj_is_alive(addr)) {
was_live = true;
p->verify();
oopDesc::verify(p);
}
} else {
FreeChunk* fc = (FreeChunk*)addr;
@ -2455,7 +2455,7 @@ class VerifyAllOopsClosure: public BasicOopIterateClosure {
_sp->block_is_obj((HeapWord*)obj),
"Should be an object");
guarantee(oopDesc::is_oop(obj), "Should be an oop");
obj->verify();
oopDesc::verify(obj);
if (_past_remark) {
// Remark has been completed, the object should be marked
_bit_map->isMarked((HeapWord*)obj);
@ -2472,7 +2472,7 @@ class VerifyAllOopsClosure: public BasicOopIterateClosure {
} else if (_sp->is_in_reserved(p)) {
// the reference is from FLS, and points out of FLS
guarantee(oopDesc::is_oop(obj), "Should be an oop");
obj->verify();
oopDesc::verify(obj);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, 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
@ -75,7 +75,7 @@ void ImmutableSpace::verify() {
HeapWord* t = end();
HeapWord* prev_p = NULL;
while (p < t) {
oop(p)->verify();
oopDesc::verify(oop(p));
prev_p = p;
p += oop(p)->size();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, 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
@ -250,7 +250,7 @@ void MutableSpace::verify() {
HeapWord* t = top();
HeapWord* prev_p = NULL;
while (p < t) {
oop(p)->verify();
oopDesc::verify(oop(p));
prev_p = p;
p += oop(p)->size();
}

View File

@ -461,7 +461,7 @@ void ContiguousSpace::verify() const {
HeapWord* t = top();
HeapWord* prev_p = NULL;
while (p < t) {
oop(p)->verify();
oopDesc::verify(oop(p));
prev_p = p;
p += oop(p)->size();
}
@ -708,7 +708,7 @@ void OffsetTableContigSpace::verify() const {
}
if (objs == OBJ_SAMPLE_INTERVAL) {
oop(p)->verify();
oopDesc::verify(oop(p));
objs = 0;
} else {
objs++;

View File

@ -311,7 +311,7 @@ void ThreadLocalAllocBuffer::verify() {
HeapWord* t = top();
HeapWord* prev_p = NULL;
while (p < t) {
oop(p)->verify();
oopDesc::verify(oop(p));
prev_p = p;
p += oop(p)->size();
}

View File

@ -3158,7 +3158,13 @@ void InstanceKlass::print_on(outputStream* st) const {
}
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();
st->print(BULLET"java mirror: "); java_mirror()->print_value_on(st); st->cr();
if (java_mirror() != NULL) {
st->print(BULLET"java mirror: ");
java_mirror()->print_value_on(st);
st->cr();
} else {
st->print_cr(BULLET"java mirror: NULL");
}
st->print(BULLET"vtable length %d (start addr: " INTPTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
st->print(BULLET"itable length %d (start addr: " INTPTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();

View File

@ -477,8 +477,12 @@ void ObjArrayKlass::oop_print_on(oop obj, outputStream* st) {
int print_len = MIN2((intx) oa->length(), MaxElementPrintSize);
for(int index = 0; index < print_len; index++) {
st->print(" - %3d : ", index);
oa->obj_at(index)->print_value_on(st);
st->cr();
if (oa->obj_at(index) != NULL) {
oa->obj_at(index)->print_value_on(st);
st->cr();
} else {
st->print_cr("NULL");
}
}
int remaining = oa->length() - print_len;
if (remaining > 0) {
@ -494,7 +498,11 @@ void ObjArrayKlass::oop_print_value_on(oop obj, outputStream* st) {
element_klass()->print_value_on(st);
int len = objArrayOop(obj)->length();
st->print("[%d] ", len);
obj->print_address_on(st);
if (obj != NULL) {
obj->print_address_on(st);
} else {
st->print_cr("NULL");
}
}
const char* ObjArrayKlass::internal_name() const {

View File

@ -36,11 +36,7 @@
bool always_do_update_barrier = false;
void oopDesc::print_on(outputStream* st) const {
if (this == NULL) {
st->print_cr("NULL");
} else {
klass()->oop_print_on(oop(this), st);
}
klass()->oop_print_on(oop(this), st);
}
void oopDesc::print_address_on(outputStream* st) const {
@ -71,9 +67,7 @@ char* oopDesc::print_value_string() {
void oopDesc::print_value_on(outputStream* st) const {
oop obj = oop(this);
if (this == NULL) {
st->print("NULL");
} else if (java_lang_String::is_instance(obj)) {
if (java_lang_String::is_instance(obj)) {
java_lang_String::print(obj, st);
print_address_on(st);
} else {
@ -82,15 +76,15 @@ void oopDesc::print_value_on(outputStream* st) const {
}
void oopDesc::verify_on(outputStream* st) {
if (this != NULL) {
klass()->oop_verify_on(this, st);
void oopDesc::verify_on(outputStream* st, oopDesc* oop_desc) {
if (oop_desc != NULL) {
oop_desc->klass()->oop_verify_on(oop_desc, st);
}
}
void oopDesc::verify() {
verify_on(tty);
void oopDesc::verify(oopDesc* oop_desc) {
verify_on(tty, oop_desc);
}
intptr_t oopDesc::slow_identity_hash() {

View File

@ -226,8 +226,8 @@ class oopDesc {
void release_address_field_put(int offset, address contents);
// printing functions for VM debugging
void print_on(outputStream* st) const; // First level print
void print_value_on(outputStream* st) const; // Second level print.
void print_on(outputStream* st) const; // First level print
void print_value_on(outputStream* st) const; // Second level print.
void print_address_on(outputStream* st) const; // Address printing
// printing on default output stream
@ -240,8 +240,8 @@ class oopDesc {
char* print_value_string();
// verification operations
void verify_on(outputStream* st);
void verify();
static void verify_on(outputStream* st, oopDesc* oop_desc);
static void verify(oopDesc* oopDesc);
// locking operations
inline bool is_locked() const;

View File

@ -188,12 +188,20 @@ void fieldDescriptor::print_on_for(outputStream* st, oop obj) {
case T_ARRAY:
st->print(" ");
NOT_LP64(as_int = obj->int_field(offset()));
obj->obj_field(offset())->print_value_on(st);
if (obj->obj_field(offset()) != NULL) {
obj->obj_field(offset())->print_value_on(st);
} else {
st->print_cr("NULL");
}
break;
case T_OBJECT:
st->print(" ");
NOT_LP64(as_int = obj->int_field(offset()));
obj->obj_field(offset())->print_value_on(st);
if (obj->obj_field(offset()) != NULL) {
obj->obj_field(offset())->print_value_on(st);
} else {
st->print_cr("NULL");
}
break;
default:
ShouldNotReachHere();

View File

@ -318,7 +318,7 @@ void JNIHandles::print_on(outputStream* st) {
class VerifyJNIHandles: public OopClosure {
public:
virtual void do_oop(oop* root) {
(*root)->verify();
oopDesc::verify(*root);
}
virtual void do_oop(narrowOop* root) { ShouldNotReachHere(); }
};