8207779: Method::is_valid_method() compares 'this' with NULL
authorhseigel
Mon, 30 Jul 2018 16:35:54 -0400
changeset 51263 b5aac518b097
parent 51262 d4b9a434af84
child 51264 cf34c71ca27c
8207779: Method::is_valid_method() compares 'this' with NULL Summary: Add Method* parameter and make method static to avoid 'thi's comparison with NULL Reviewed-by: lfoltan, coleenp
src/hotspot/cpu/aarch64/frame_aarch64.cpp
src/hotspot/cpu/arm/frame_arm.cpp
src/hotspot/cpu/sparc/frame_sparc.cpp
src/hotspot/cpu/x86/frame_x86.cpp
src/hotspot/share/jfr/periodic/sampling/jfrCallTrace.cpp
src/hotspot/share/jfr/recorder/stacktrace/jfrStackTraceRepository.cpp
src/hotspot/share/oops/method.cpp
src/hotspot/share/oops/method.hpp
src/hotspot/share/prims/forte.cpp
--- a/src/hotspot/cpu/aarch64/frame_aarch64.cpp	Mon Jul 30 14:08:30 2018 -0400
+++ b/src/hotspot/cpu/aarch64/frame_aarch64.cpp	Mon Jul 30 16:35:54 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -539,7 +539,7 @@
   Method* m = *interpreter_frame_method_addr();
 
   // validate the method we'd find in this potential sender
-  if (!m->is_valid_method()) return false;
+  if (!Method::is_valid_method(m)) return false;
 
   // stack frames shouldn't be much larger than max_stack elements
   // this test requires the use of unextended_sp which is the sp as seen by
--- a/src/hotspot/cpu/arm/frame_arm.cpp	Mon Jul 30 14:08:30 2018 -0400
+++ b/src/hotspot/cpu/arm/frame_arm.cpp	Mon Jul 30 16:35:54 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -500,7 +500,7 @@
   Method* m = *interpreter_frame_method_addr();
 
   // validate the method we'd find in this potential sender
-  if (!m->is_valid_method()) return false;
+  if (!Method::is_valid_method(m)) return false;
 
   // stack frames shouldn't be much larger than max_stack elements
 
--- a/src/hotspot/cpu/sparc/frame_sparc.cpp	Mon Jul 30 14:08:30 2018 -0400
+++ b/src/hotspot/cpu/sparc/frame_sparc.cpp	Mon Jul 30 16:35:54 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -648,7 +648,7 @@
   Method* m = *interpreter_frame_method_addr();
 
   // validate the method we'd find in this potential sender
-  if (!m->is_valid_method()) return false;
+  if (!Method::is_valid_method(m)) return false;
 
   // stack frames shouldn't be much larger than max_stack elements
 
--- a/src/hotspot/cpu/x86/frame_x86.cpp	Mon Jul 30 14:08:30 2018 -0400
+++ b/src/hotspot/cpu/x86/frame_x86.cpp	Mon Jul 30 16:35:54 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -526,7 +526,7 @@
   Method* m = *interpreter_frame_method_addr();
 
   // validate the method we'd find in this potential sender
-  if (!m->is_valid_method()) return false;
+  if (!Method::is_valid_method(m)) return false;
 
   // stack frames shouldn't be much larger than max_stack elements
   // this test requires the use the unextended_sp which is the sp as seen by
--- a/src/hotspot/share/jfr/periodic/sampling/jfrCallTrace.cpp	Mon Jul 30 14:08:30 2018 -0400
+++ b/src/hotspot/share/jfr/periodic/sampling/jfrCallTrace.cpp	Mon Jul 30 16:35:54 2018 -0400
@@ -50,7 +50,7 @@
       const bool known_valid = (state == _thread_in_native || state == _thread_in_vm || state == _thread_blocked);
       if (known_valid || candidate.is_interpreted_frame_valid(_thread)) {
         Method* im = candidate.interpreter_frame_method();
-        if (known_valid && !im->is_valid_method()) {
+        if (known_valid && !Method::is_valid_method(im)) {
           return false;
         }
         *method = im;
--- a/src/hotspot/share/jfr/recorder/stacktrace/jfrStackTraceRepository.cpp	Mon Jul 30 14:08:30 2018 -0400
+++ b/src/hotspot/share/jfr/recorder/stacktrace/jfrStackTraceRepository.cpp	Mon Jul 30 16:35:54 2018 -0400
@@ -431,7 +431,7 @@
       break;
     }
     const Method* method = st.method();
-    if (!method->is_valid_method()) {
+    if (!Method::is_valid_method(method)) {
       // we throw away everything we've gathered in this sample since
       // none of it is safe
       return false;
--- a/src/hotspot/share/oops/method.cpp	Mon Jul 30 14:08:30 2018 -0400
+++ b/src/hotspot/share/oops/method.cpp	Mon Jul 30 16:35:54 2018 -0400
@@ -1095,7 +1095,7 @@
 }
 
 void Method::restore_unshareable_info(TRAPS) {
-  assert(is_method() && is_valid_method(), "ensure C++ vtable is restored");
+  assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
 
   // Since restore_unshareable_info can be called more than once for a method, don't
   // redo any work.
@@ -2166,16 +2166,16 @@
 }
 
 // Check that this pointer is valid by checking that the vtbl pointer matches
-bool Method::is_valid_method() const {
-  if (this == NULL) {
+bool Method::is_valid_method(const Method* m) {
+  if (m == NULL) {
     return false;
-  } else if ((intptr_t(this) & (wordSize-1)) != 0) {
+  } else if ((intptr_t(m) & (wordSize-1)) != 0) {
     // Quick sanity check on pointer.
     return false;
-  } else if (is_shared()) {
-    return MetaspaceShared::is_valid_shared_method(this);
-  } else if (Metaspace::contains_non_shared(this)) {
-    return has_method_vptr((const void*)this);
+  } else if (m->is_shared()) {
+    return MetaspaceShared::is_valid_shared_method(m);
+  } else if (Metaspace::contains_non_shared(m)) {
+    return has_method_vptr((const void*)m);
   } else {
     return false;
   }
--- a/src/hotspot/share/oops/method.hpp	Mon Jul 30 14:08:30 2018 -0400
+++ b/src/hotspot/share/oops/method.hpp	Mon Jul 30 16:35:54 2018 -0400
@@ -984,7 +984,7 @@
 
   // Check for valid method pointer
   static bool has_method_vptr(const void* ptr);
-  bool is_valid_method() const;
+  static bool is_valid_method(const Method* m);
 
   // Verify
   void verify() { verify_on(tty); }
--- a/src/hotspot/share/prims/forte.cpp	Mon Jul 30 14:08:30 2018 -0400
+++ b/src/hotspot/share/prims/forte.cpp	Mon Jul 30 16:35:54 2018 -0400
@@ -248,7 +248,7 @@
     // a valid method. Then again we may have caught an interpreter
     // frame in the middle of construction and the bci field is
     // not yet valid.
-    if (!method->is_valid_method()) return false;
+    if (!Method::is_valid_method(method)) return false;
     *method_p = method; // If the Method* found is invalid, it is
                         // ignored by forte_fill_call_trace_given_top().
                         // So set method_p only if the Method is valid.
@@ -434,7 +434,7 @@
   // Check if a Java Method has been found.
   if (method == NULL) return;
 
-  if (!method->is_valid_method()) {
+  if (!Method::is_valid_method(method)) {
     trace->num_frames = ticks_GC_active; // -2
     return;
   }
@@ -445,7 +445,7 @@
     bci = st.bci();
     method = st.method();
 
-    if (!method->is_valid_method()) {
+    if (!Method::is_valid_method(method)) {
       // we throw away everything we've gathered in this sample since
       // none of it is safe
       trace->num_frames = ticks_GC_active; // -2