United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6862945 conversion of jmethodID to methodOop in JVMTI is too expensive
6862945 : conversion of jmethodID to methodOop in JVMTI is too expensive

Details
Type:
Bug
Submit Date:
2009-07-22
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
hotspot
OS:
solaris_9,generic
Sub-Component:
jvmti
CPU:
sparc,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
hs16,6
Fixed Versions:
hs17

Related Reports
Backport:
Backport:
Backport:
Backport:
Relates:
Relates:

Sub Tasks

Description
While hacking on hprof I became intrigued by why it's so ridiculously slow when dumping traces.  Digging around a bit showed that the problem was that converting a jmethodID to a methodOop always uses JNIHandles::checked_resolve_jmethod_id which attempts to confirm that the JNI reference being used is weak.  Unfortunately this requires searching the entire set of weak JNI handles to see if it's in the table and since hprof is using a huge number of weak references this becomes very slow.  It's also not a very interesting thing to test for since it never actually checks that the underlying object is really a methodOop which seems a lot more important.  Making the following change:

diff --git a/src/share/vm/prims/jvmtiEnter.xsl b/src/share/vm/prims/jvmtiEnter.xsl
--- a/src/share/vm/prims/jvmtiEnter.xsl
+++ b/src/share/vm/prims/jvmtiEnter.xsl
@@ -896,7 +896,7 @@ static jvmtiError JNICALL

 <xsl:template match="jmethodID" mode="dochecks">
   <xsl:param name="name"/>
-  <xsl:text>  methodOop method_oop = JNIHandles::checked_resolve_jmethod_id(</xsl:text>
+  <xsl:text>  methodOop method_oop = JNIHandles::resolve_jmethod_id(</xsl:text>
   <xsl:value-of select="$name"/>
   <xsl:text>);&#xA;</xsl:text>
   <xsl:text>  if (method_oop == NULL) {&#xA;</xsl:text>

causes hprof to run noticeably faster.

                                    

Comments
EVALUATION

http://hg.openjdk.java.net/hsx/hsx16/master/rev/1760a1cbed36
                                     
2009-09-04
EVALUATION

http://hg.openjdk.java.net/hsx/hsx16/baseline/rev/1760a1cbed36
                                     
2009-08-28
SUGGESTED FIX

Please see attached 6862945-webrev-cr1.tgz for the proposed fix
after changes to address round 0 comments.
                                     
2009-08-11
EVALUATION

http://hg.openjdk.java.net/jdk7/hotspot-rt/hotspot/rev/1760a1cbed36
                                     
2009-08-11
SUGGESTED FIX

Please see attached 6862945-webrev-cr0.tgz for the proposed fix.
                                     
2009-08-10
EVALUATION

JNIHandles::checked_resolve_jmethod_id() is used at the
JVM/TI function layer to sanity check incoming jmethodID
values and is also used by the JNI sanity check logic
(-Xcheck:jni).

checked_resolve_jmethod_id() calls
JNIHandles::is_weak_global_handle() which gets more expensive
as the number of weak global handles increases. I think the
is_weak_global_handle() call is more appropriate for the
-Xcheck:jni code path where more caution is explicitly requested.

I plan to refactor checked_resolve_jmethod_id() and move the
is_weak_global_handle() call to jniCheck::validate_jmethod_id().
checked_resolve_jmethod_id() will do NULL checks and an "is this
a method?" check. Possibly other checks too.
                                     
2009-08-06



Hardware and Software, Engineered to Work Together