libgcj performance: _Jv_LookupInterfaceMethod

Bryce McKinlay bryce@albatross.co.nz
Wed Nov 24 01:30:00 GMT 1999


Jeff Sturm wrote:

> I also experimented with a small patch (below) that cuts down the string
> compare times drastically in some programs.  Specifically, for Bryce's
> simple benchmark it cuts the time spent in interface calls roughly in
> half, at the cost of slightly higher memory utilization.

It also helps slightly to declare_Jv_FindMethodInCache and
_Jv_AddMethodToCache as "inline" (afterall, they are only called from one
place). BTW, your patch didn't compile and didn't give me the performance
results you indicated. Were you trying to do something like the patch
below? With this one I'm getting a more than 50% improvement on interface
calls in my simple benchmark now.

regards

  [ bryce ]

Index: natClass.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natClass.cc,v
retrieving revision 1.8
diff -u -r1.8 natClass.cc
--- natClass.cc 1999/11/18 07:19:00 1.8
+++ natClass.cc 1999/11/24 09:29:46
@@ -513,12 +513,14 @@
 struct _Jv_mcache
 {
   jclass klass;
+  _Jv_Utf8Const *name;
+  _Jv_Utf8Const *signature;
   _Jv_Method *method;
 };

 static _Jv_mcache method_cache[MCACHE_SIZE + 1];

-static void *
+inline static void *
 _Jv_FindMethodInCache (jclass klass,
          _Jv_Utf8Const *name,
          _Jv_Utf8Const *signature)
@@ -526,25 +528,32 @@
   int index = name->hash & MCACHE_SIZE;
   _Jv_mcache *mc = method_cache + index;
   _Jv_Method *m = mc->method;
+
+  if (mc->klass == klass && m != NULL)
+    {
+      if ((mc->name == name && mc->signature == signature)
+          || (_Jv_equalUtf8Consts (mc->name, name)
+              && _Jv_equalUtf8Consts (mc->signature, signature)))
+ return m->ncode;
+    }

-  if (mc->klass == klass
-      && m != NULL  // thread safe check
-      && _Jv_equalUtf8Consts (m->name, name)
-      && _Jv_equalUtf8Consts (m->signature, signature))
-    return mc->method->ncode;
   return NULL;
 }

-static void
+inline static void
 _Jv_AddMethodToCache (jclass klass,
-   _Jv_Method *method)
+                       _Jv_Method *method,
+                       _Jv_Utf8Const *name,
+                       _Jv_Utf8Const *signature)
 {
   _Jv_MonitorEnter (&ClassClass);

   int index = method->name->hash & MCACHE_SIZE;

-  method_cache[index].method = method;
   method_cache[index].klass = klass;
+  method_cache[index].method = method;
+  method_cache[index].name = name;
+  method_cache[index].signature = signature;

   _Jv_MonitorExit (&ClassClass);
 }
@@ -580,7 +589,7 @@
       if (! java::lang::reflect::Modifier::isPublic(meth->accflags))
  JvThrow (new java::lang::IllegalAccessError);

-      _Jv_AddMethodToCache (klass, meth);
+      _Jv_AddMethodToCache (klass, meth, name, signature);

       return meth->ncode;
     }




More information about the Java mailing list