6862945: 4/3 conversion of jmethodID to methodOop in JVMTI is too expensive
authordcubed
Tue, 11 Aug 2009 11:57:51 -0600
changeset 3672 65e946046d1e
parent 3581 c84159af60dd
child 3673 322b523b9123
child 5530 bc95d7f52f82
6862945: 4/3 conversion of jmethodID to methodOop in JVMTI is too expensive Summary: Refactor JNIHandles::checked_resolve_jmethod_id() into fast and paranoid parts. Reviewed-by: never, alanb
hotspot/src/share/vm/prims/jniCheck.cpp
hotspot/src/share/vm/runtime/jniHandles.hpp
--- a/hotspot/src/share/vm/prims/jniCheck.cpp	Tue Jul 28 13:50:07 2009 -0600
+++ b/hotspot/src/share/vm/prims/jniCheck.cpp	Tue Aug 11 11:57:51 2009 -0600
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2001-2009 Sun Microsystems, Inc.  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
@@ -96,6 +96,7 @@
 static const char * fatal_class_not_a_class = "JNI received a class argument that is not a class";
 static const char * fatal_class_not_a_throwable_class = "JNI Throw or ThrowNew received a class argument that is not a Throwable or Throwable subclass";
 static const char * fatal_wrong_class_or_method = "Wrong object class or methodID passed to JNI call";
+static const char * fatal_non_weak_method = "non-weak methodID passed to JNI call";
 static const char * fatal_unknown_array_object = "Unknown array object passed to JNI array operations";
 static const char * fatal_object_array_expected = "Object array expected but not received for JNI array operation";
 static const char * fatal_non_array  = "Non-array passed to JNI array operations";
@@ -291,10 +292,16 @@
 
 methodOop jniCheck::validate_jmethod_id(JavaThread* thr, jmethodID method_id) {
   ASSERT_OOPS_ALLOWED;
+  // do the fast jmethodID check first
   methodOop moop = JNIHandles::checked_resolve_jmethod_id(method_id);
   if (moop == NULL) {
     ReportJNIFatalError(thr, fatal_wrong_class_or_method);
   }
+  // jmethodIDs are supposed to be weak global handles, but that
+  // can be expensive so check it last
+  else if (!JNIHandles::is_weak_global_handle((jobject) method_id)) {
+    ReportJNIFatalError(thr, fatal_non_weak_method);
+  }
   return moop;
 }
 
--- a/hotspot/src/share/vm/runtime/jniHandles.hpp	Tue Jul 28 13:50:07 2009 -0600
+++ b/hotspot/src/share/vm/runtime/jniHandles.hpp	Tue Aug 11 11:57:51 2009 -0600
@@ -1,5 +1,5 @@
 /*
- * Copyright 1998-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1998-2009 Sun Microsystems, Inc.  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
@@ -196,12 +196,16 @@
 };
 
 inline methodOop JNIHandles::checked_resolve_jmethod_id(jmethodID mid) {
-  jobject handle = (jobject)mid;
-  if (is_weak_global_handle(handle)) {
-    return (methodOop) resolve_non_null(handle);
-  } else {
+  if (mid == NULL) {
     return (methodOop) NULL;
   }
+
+  oop o = resolve_non_null((jobject) mid);
+  if (!o->is_method()) {
+    return (methodOop) NULL;
+  }
+
+  return (methodOop) o;
 };