This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: More __builtin_expect fun


I identified a few places where __builtin_expect should be worthwhile in
the Class implementation.

FYI, I have enabled  __builtin_expect in my local tree with these
changes, and it does seem to make a measurable performance improvement
(1% and better according to my unscientific testing).

regards

  [ bryce ]

Index: natClass.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natClass.cc,v
retrieving revision 1.23
diff -u -r1.23 natClass.cc
--- natClass.cc	2000/03/21 05:54:42	1.23
+++ natClass.cc	2000/05/01 10:00:29
@@ -622,7 +622,7 @@
 inline jboolean
 java::lang::Class::isInstance (jobject obj)
 {
-  if (! obj || isPrimitive ())
+  if (__builtin_expect (! obj || isPrimitive (), 0))
     return false;
   _Jv_InitClass (this);
   return _Jv_IsAssignableFrom (this, JV_CLASS (obj));
@@ -923,7 +923,7 @@
     {
       _Jv_IDispatchTable *cl_idt = source->idt;
       _Jv_IDispatchTable *if_idt = target->idt;
-      if (if_idt == NULL)
+      if (__builtin_expect ((if_idt == NULL), 0))
 	return false; // No class implementing TARGET has been loaded.    
       jshort cl_iindex = cl_idt->cls.iindex;
       if (cl_iindex <= if_idt->iface.ioffsets[0])
@@ -941,13 +941,16 @@
 jboolean
 _Jv_IsInstanceOf(jobject obj, jclass cl)
 {
-  return (obj ? _Jv_IsAssignableFrom (cl, JV_CLASS (obj)) : false);
+  if (__builtin_expect (!obj, 0))
+    return false;
+  return (_Jv_IsAssignableFrom (cl, JV_CLASS (obj)));
 }
 
 void *
 _Jv_CheckCast (jclass c, jobject obj)
 {
-  if (obj != NULL && ! _Jv_IsAssignableFrom(c, JV_CLASS (obj)))
+  if (__builtin_expect 
+       (obj != NULL && ! _Jv_IsAssignableFrom(c, JV_CLASS (obj)), 0))
     JvThrow (new java::lang::ClassCastException);
   return obj;
 }
@@ -960,7 +963,8 @@
       JvAssert (arr != NULL);
       jclass elt_class = (JV_CLASS (arr))->getComponentType();
       jclass obj_class = JV_CLASS (obj);
-      if (! _Jv_IsAssignableFrom (elt_class, obj_class))
+      if (__builtin_expect 
+           (! _Jv_IsAssignableFrom (elt_class, obj_class), 0))
 	JvThrow (new java::lang::ArrayStoreException);
     }
 }
Index: Class.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/Class.h,v
retrieving revision 1.19
diff -u -r1.19 Class.h
--- Class.h	2000/04/20 22:24:33	1.19
+++ Class.h	2000/05/01 10:00:29
@@ -203,7 +203,7 @@
   inline friend void 
   _Jv_InitClass (jclass klass)
   {
-    if (klass->state != JV_STATE_DONE)
+    if (__builtin_expect (klass->state != JV_STATE_DONE, 0))
       klass->initializeClass ();
   }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]