OpenJDK / jdk / jdk
changeset 52190:4e04b7ab20a3
8209087: Clean up runtime code that compares 'this' to NULL
Summary: Remove 'this' to NULL comparisons from methods and check if calling objects of these methods could be NULL.
Reviewed-by: lfoltan, gziemski
author | hseigel |
---|---|
date | Thu, 18 Oct 2018 10:35:58 -0400 |
parents | 83b78c3c212b |
children | e5fab74748fb |
files | src/hotspot/share/classfile/verificationType.cpp src/hotspot/share/oops/symbol.cpp src/hotspot/share/runtime/perfData.cpp src/hotspot/share/runtime/perfData.inline.hpp |
diffstat | 4 files changed, 25 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/hotspot/share/classfile/verificationType.cpp Thu Oct 18 10:08:35 2018 -0400 +++ b/src/hotspot/share/classfile/verificationType.cpp Thu Oct 18 10:35:58 2018 -0400 @@ -172,7 +172,11 @@ } else if (is_uninitialized()) { st->print("uninitialized %d", bci()); } else { - name()->print_value_on(st); + if (name() != NULL) { + name()->print_value_on(st); + } else { + st->print_cr("NULL"); + } } } }
--- a/src/hotspot/share/oops/symbol.cpp Thu Oct 18 10:08:35 2018 -0400 +++ b/src/hotspot/share/oops/symbol.cpp Thu Oct 18 10:35:58 2018 -0400 @@ -294,28 +294,20 @@ } void Symbol::print_on(outputStream* st) const { - if (this == NULL) { - st->print_cr("NULL"); - } else { - st->print("Symbol: '"); - print_symbol_on(st); - st->print("'"); - st->print(" count %d", refcount()); - } + st->print("Symbol: '"); + print_symbol_on(st); + st->print("'"); + st->print(" count %d", refcount()); } // The print_value functions are present in all builds, to support the // disassembler and error reporting. void Symbol::print_value_on(outputStream* st) const { - if (this == NULL) { - st->print("NULL"); - } else { - st->print("'"); - for (int i = 0; i < utf8_length(); i++) { - st->print("%c", char_at(i)); - } - st->print("'"); + st->print("'"); + for (int i = 0; i < utf8_length(); i++) { + st->print("%c", char_at(i)); } + st->print("'"); } bool Symbol::is_valid(Symbol* s) {
--- a/src/hotspot/share/runtime/perfData.cpp Thu Oct 18 10:08:35 2018 -0400 +++ b/src/hotspot/share/runtime/perfData.cpp Thu Oct 18 10:35:58 2018 -0400 @@ -323,7 +323,12 @@ } PerfData* PerfDataManager::find_by_name(const char* name) { - return _all->find_by_name(name); + // if add_item hasn't been called the list won't be initialized + if (_all != NULL) { + return _all->find_by_name(name); + } else { + return NULL; + } } PerfDataList* PerfDataManager::all() { @@ -591,10 +596,6 @@ PerfData* PerfDataList::find_by_name(const char* name) { - // if add_item hasn't been called the list won't be initialized - if (this == NULL) - return NULL; - int i = _set->find((void*)name, PerfDataList::by_name); if (i >= 0 && i <= _set->length())
--- a/src/hotspot/share/runtime/perfData.inline.hpp Thu Oct 18 10:08:35 2018 -0400 +++ b/src/hotspot/share/runtime/perfData.inline.hpp Thu Oct 18 10:35:58 2018 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -58,7 +58,11 @@ } inline bool PerfDataManager::exists(const char* name) { - return _all->contains(name); + if (_all != NULL) { + return _all->contains(name); + } else { + return false; + } } #endif // SHARE_VM_RUNTIME_PERFDATA_INLINE_HPP