--- old/src/share/vm/oops/method.cpp Sat Jan 30 14:33:39 2016 +++ new/src/share/vm/oops/method.cpp Sat Jan 30 14:33:38 2016 @@ -2096,12 +2096,16 @@ } bool Method::has_method_vptr(const void* ptr) { - Method m; + // Use SafeFetch to check if this is a valid pointer first // This assumes that the vtbl pointer is the first word of a C++ object. - // This assumption is also in universe.cpp patch_klass_vtble - void* vtbl2 = dereference_vptr((const void*)&m); - void* this_vtbl = dereference_vptr(ptr); - return vtbl2 == this_vtbl; + // This assumption is also in universe.cpp patch_klass_vtable + intptr_t this_vptr = SafeFetchN((intptr_t*)ptr, intptr_t(1)); + if (this_vptr == 1) { + return false; + } + Method m; + void* vptr2 = dereference_vptr((const void*)&m); + return (intptr_t)vptr2 == this_vptr; } // Check that this pointer is valid by checking that the vtbl pointer matches @@ -2108,10 +2112,13 @@ bool Method::is_valid_method() const { if (this == NULL) { return false; - } else if (!is_metaspace_object()) { - return false; } else { - return has_method_vptr((const void*)this); + // Quick sanity check on pointer. + if ((intptr_t(this) & (wordSize-1)) != 0) { + return false; + } else { + return has_method_vptr(this); + } } }