Updates for fast checkcast implementation performance-optimizations
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 10 May 2013 18:33:57 +0100
branchperformance-optimizations
changeset 2592 2139919f0f85
parent 2591 17d9c39d3ab4
child 2593 adf8741afdf1
Updates for fast checkcast implementation
JavaVM.st
--- a/JavaVM.st	Tue May 07 13:31:03 2013 +0100
+++ b/JavaVM.st	Fri May 10 18:33:57 2013 +0100
@@ -4927,12 +4927,29 @@
      This method *MUST* return the object for this may lead
      into GC. See ___checkcast() VM function
      "
+    
+    | oclass |
 
     object isNil ifTrue: [ ^ object ].
-    (self canCast: object class to: class) ifFalse: [
+    oclass := object class.
+    (self canCast: oclass to: class) ifFalse: [
         self throwClassCastException.
         ^ nil "Not reached"
-    ].
+    ]. 
+%{
+    /* Now the nasty trick - if succeeded, bind to fast ___checkcast().
+     * abusing ilc's ilc_class to store obj class (!!!). See ___checkcast()
+     * in jinterpret.c 
+     */
+    if ((__ILC_FLAGS(__pilc) & 0x0F) != I_PERF) {
+        if ( __qSpace(oclass) < NEWSPACE ) {   
+            extern OBJ ___checkcast();
+            extern void ___ilcBindPrimitive();
+            /* printf("CHECKCAST: __pilc == 0x%x\n", __pilc); */
+            __ilcBindPrimitive(__pilc, oclass, &___checkcast, 2, __selector);
+        }
+    }
+%}.
     ^ object
 
     "Created: / 08-01-1999 / 14:53:51 / cg"