changeset 51960:4ac20e5f96ce

8202171: Some oopDesc functions compare this with NULL Summary: 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
author hseigel
date Tue, 31 Jul 2018 14:24:10 -0400
parents 2cd8bbccbd2d
children b53d1f96b8c4
files src/hotspot/share/classfile/dictionary.hpp src/hotspot/share/classfile/systemDictionary.cpp src/hotspot/share/code/debugInfo.cpp src/hotspot/share/code/nmethod.cpp src/hotspot/share/gc/cms/compactibleFreeListSpace.cpp src/hotspot/share/gc/parallel/immutableSpace.cpp src/hotspot/share/gc/parallel/mutableSpace.cpp src/hotspot/share/gc/shared/space.cpp src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp src/hotspot/share/oops/instanceKlass.cpp src/hotspot/share/oops/objArrayKlass.cpp src/hotspot/share/oops/oop.cpp src/hotspot/share/oops/oop.hpp src/hotspot/share/runtime/fieldDescriptor.cpp src/hotspot/share/runtime/jniHandles.cpp
diffstat 15 files changed, 73 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/dictionary.hpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/classfile/dictionary.hpp	Tue Jul 31 14:24:10 2018 -0400
@@ -182,7 +182,7 @@
     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());
     }
   }
 
--- a/src/hotspot/share/classfile/systemDictionary.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/classfile/systemDictionary.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -443,8 +443,18 @@
     // 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();
   }
--- a/src/hotspot/share/code/debugInfo.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/code/debugInfo.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -251,7 +251,11 @@
 }
 
 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");
+  }
 }
 
 
--- a/src/hotspot/share/code/nmethod.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/code/nmethod.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -2332,7 +2332,11 @@
     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();
   }
--- a/src/hotspot/share/gc/cms/compactibleFreeListSpace.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/gc/cms/compactibleFreeListSpace.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -2406,7 +2406,7 @@
       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 @@
                   _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 @@
     } 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);
     }
   }
 
--- a/src/hotspot/share/gc/parallel/immutableSpace.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/gc/parallel/immutableSpace.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -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 @@
   HeapWord* t = end();
   HeapWord* prev_p = NULL;
   while (p < t) {
-    oop(p)->verify();
+    oopDesc::verify(oop(p));
     prev_p = p;
     p += oop(p)->size();
   }
--- a/src/hotspot/share/gc/parallel/mutableSpace.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/gc/parallel/mutableSpace.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -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 @@
   HeapWord* t = top();
   HeapWord* prev_p = NULL;
   while (p < t) {
-    oop(p)->verify();
+    oopDesc::verify(oop(p));
     prev_p = p;
     p += oop(p)->size();
   }
--- a/src/hotspot/share/gc/shared/space.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/gc/shared/space.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -461,7 +461,7 @@
   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 @@
     }
 
     if (objs == OBJ_SAMPLE_INTERVAL) {
-      oop(p)->verify();
+      oopDesc::verify(oop(p));
       objs = 0;
     } else {
       objs++;
--- a/src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -311,7 +311,7 @@
   HeapWord* t = top();
   HeapWord* prev_p = NULL;
   while (p < t) {
-    oop(p)->verify();
+    oopDesc::verify(oop(p));
     prev_p = p;
     p += oop(p)->size();
   }
--- a/src/hotspot/share/oops/instanceKlass.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -3158,7 +3158,13 @@
   }
   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();
--- a/src/hotspot/share/oops/objArrayKlass.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/oops/objArrayKlass.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -477,8 +477,12 @@
   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 @@
   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 {
--- a/src/hotspot/share/oops/oop.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/oops/oop.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -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 @@
 
 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::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() {
--- a/src/hotspot/share/oops/oop.hpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/oops/oop.hpp	Tue Jul 31 14:24:10 2018 -0400
@@ -226,8 +226,8 @@
   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 @@
   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;
--- a/src/hotspot/share/runtime/fieldDescriptor.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/runtime/fieldDescriptor.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -188,12 +188,20 @@
     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();
--- a/src/hotspot/share/runtime/jniHandles.cpp	Tue Jul 31 13:12:06 2018 -0400
+++ b/src/hotspot/share/runtime/jniHandles.cpp	Tue Jul 31 14:24:10 2018 -0400
@@ -318,7 +318,7 @@
 class VerifyJNIHandles: public OopClosure {
 public:
   virtual void do_oop(oop* root) {
-    (*root)->verify();
+    oopDesc::verify(*root);
   }
   virtual void do_oop(narrowOop* root) { ShouldNotReachHere(); }
 };