* src/vm/jit/builtin.hpp (builtintable_entry): Added function pointer to
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Wed, 16 Sep 2009 07:48:44 +0000 (09:48 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Wed, 16 Sep 2009 07:48:44 +0000 (09:48 +0200)
fast-path emitter. At the moment we have lock fast-path on x86_64.
* src/vm/jit/builtin.cpp: Builtin table now needs emit-common.hpp included.
* src/vm/jit/builtintable.inc: Adapted to above change.
* src/threads/lock.hpp: Moved builtin function defines to where they belong.
* src/vm/jit/codegen-common.cpp (codegen_emit): Added preliminary fast-path
generation implementation. Yet to be fully optimized.
* src/vm/jit/emit-common.hpp: Added prototypes for lock fast-path emitters.
* src/vm/jit/x86_64/emit.c: Added stubs for lock fast-path emitters.

src/threads/lock.hpp
src/vm/jit/builtin.cpp
src/vm/jit/builtin.hpp
src/vm/jit/builtintable.inc
src/vm/jit/codegen-common.cpp
src/vm/jit/emit-common.hpp
src/vm/jit/x86_64/emit.c

index 07bd54b671a885a5a41ccf1524578c201ff0dcfc..4a84604e6ec8689a73c08ec4a53b03ce28a9e7fd 100644 (file)
@@ -88,9 +88,6 @@ void lock_init(void);
 bool lock_monitor_enter(java_handle_t *);
 bool lock_monitor_exit(java_handle_t *);
 
-#define LOCK_monitor_enter    (functionptr) lock_monitor_enter
-#define LOCK_monitor_exit     (functionptr) lock_monitor_exit
-
 bool lock_is_held_by_current_thread(java_handle_t *o);
 
 void lock_wait_for_object(java_handle_t *o, s8 millis, s4 nanos);
index ff1e2dd9c9c7ae9532d8cfa1a30241fa7d361cc9..46945ada4a0d21e6163602cf5cb7cacd1a598287 100644 (file)
@@ -75,6 +75,7 @@
 #include "vm/string.hpp"
 
 #include "vm/jit/asmpart.h"
+#include "vm/jit/emit-common.hpp"
 #include "vm/jit/stubs.hpp"
 #include "vm/jit/trace.hpp"
 
index af81aced2d3c8adbc2d5cced00f3f0eae663ddb3..0be24ea74bb2be5a3f4be7ff511dafacb35deb5c 100644 (file)
@@ -77,6 +77,7 @@ struct builtintable_entry {
        utf         *name;                  /* name of the function               */
        utf         *descriptor;            /* descriptor of the function         */
        methoddesc  *md;
+       functionptr  emit_fastpath;         /* emitter for fast-path code         */
 };
 
 
@@ -129,6 +130,22 @@ bool builtintable_replace_function(void *iptr);
 bool fast_subtype_check(struct _vftbl *, struct _vftbl *);
 #endif
 
+/* From lock.hpp: bool lock_monitor_enter(java_handle_t *); */
+#define LOCK_monitor_enter          (functionptr) lock_monitor_enter
+#if defined(__X86_64__)
+# define EMIT_FASTPATH_monitor_enter (functionptr) emit_fastpath_monitor_enter
+#else
+# define EMIT_FASTPATH_monitor_enter (functionptr) NULL
+#endif
+
+/* From lock.hpp: bool lock_monitor_exit(java_handle_t *); */
+#define LOCK_monitor_exit          (functionptr) lock_monitor_exit
+#if defined(__X86_64__)
+# define EMIT_FASTPATH_monitor_exit (functionptr) emit_fastpath_monitor_exit
+#else
+# define EMIT_FASTPATH_monitor_exit (functionptr) NULL
+#endif
+
 bool builtin_instanceof(java_handle_t *obj, classinfo *c);
 /* NOT AN OP */
 bool builtin_checkcast(java_handle_t *obj, classinfo *c);
index 30807db25363951173597ecfc29d7b62aa8b1b00..32d20945bf8f629de9247c6b168eceb0d35caa4e 100644 (file)
@@ -49,6 +49,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -62,6 +63,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -75,6 +77,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -88,6 +91,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -104,6 +108,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -117,6 +122,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -133,6 +139,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -146,6 +153,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -161,6 +169,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -174,6 +183,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 
@@ -191,6 +201,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 
@@ -206,6 +217,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -222,6 +234,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -237,6 +250,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -250,6 +264,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -263,6 +278,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -276,6 +292,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -289,6 +306,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -302,6 +320,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -315,6 +334,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -328,6 +348,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -341,6 +362,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -354,6 +376,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -368,6 +391,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -381,6 +405,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -394,6 +419,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -407,6 +433,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 
@@ -422,7 +449,8 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
-               NULL
+               NULL,
+               EMIT_FASTPATH_monitor_enter
        },
        {
                ICMD_MONITOREXIT,
@@ -435,7 +463,8 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
-               NULL
+               NULL,
+               EMIT_FASTPATH_monitor_exit
        },
 #endif
 
@@ -453,6 +482,7 @@ static builtintable_entry builtintable_internal[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 };
@@ -474,6 +504,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -490,6 +521,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -503,6 +535,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -516,6 +549,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif /* !(SUPPORT_LONG && SUPPORT_LONG_LOGICAL) */
@@ -532,6 +566,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -545,6 +580,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -558,6 +594,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif /* !(SUPPORT_LONG && SUPPORT_LONG_SHIFT) */
@@ -574,6 +611,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -587,6 +625,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -600,6 +639,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif /* !(SUPPORT_LONG && SUPPORT_LONG_ADD) */
@@ -616,6 +656,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -632,6 +673,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -648,6 +690,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -664,6 +707,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -680,6 +724,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -696,6 +741,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -712,6 +758,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -728,6 +775,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -744,6 +792,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -763,6 +812,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -776,6 +826,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -789,6 +840,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -802,6 +854,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -815,6 +868,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif /* !SUPPORT_FLOAT */
@@ -831,6 +885,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -844,6 +899,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif /* !SUPPORT_FLOAT || !SUPPORT_FLOAT_CMP */
@@ -863,6 +919,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -876,6 +933,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -889,6 +947,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -902,6 +961,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -915,6 +975,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif /* !SUPPORT_DOUBLE */
@@ -931,6 +992,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -944,6 +1006,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif /* !SUPPORT_DOUBLE || !SUPPORT_DOUBLE_CMP */
@@ -963,6 +1026,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
        {
@@ -976,6 +1040,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif /* !(SUPPORT_FLOAT && SUPPORT_DOUBLE) */
@@ -994,6 +1059,7 @@ static builtintable_entry builtintable_automatic[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 };
@@ -1017,6 +1083,7 @@ static builtintable_entry builtintable_function[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 
@@ -1037,6 +1104,7 @@ static builtintable_entry builtintable_function[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 #endif
@@ -1054,6 +1122,7 @@ static builtintable_entry builtintable_function[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 
@@ -1070,6 +1139,7 @@ static builtintable_entry builtintable_function[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 
@@ -1088,6 +1158,7 @@ static builtintable_entry builtintable_function[] = {
                NULL,
                NULL,
                NULL,
+               NULL,
                NULL
        },
 };
index 76ec50c82438087d40a97895ed14fcc7443d1b92..9920715b1c8d52b982c87f1cebc4db25c39afada 100644 (file)
@@ -1887,6 +1887,32 @@ nowperformreturn:
                                }
 #endif
 
+                               // Emit the fast-path if available.
+                               if (bte->emit_fastpath != NULL) {
+                                       void (*emit_fastpath)(jitdata* jd, instruction* iptr, int d);
+                                       emit_fastpath = (void (*)(jitdata* jd, instruction* iptr, int d)) bte->emit_fastpath;
+
+                                       assert(md->returntype.type == TYPE_VOID);
+                                       d = REG_ITMP1;
+
+                                       // Actually call the fast-path emitter.
+                                       emit_fastpath(jd, iptr, d);
+
+                                       // If fast-path succeeded, jump to the end of the builtin
+                                       // invocation.
+                                       // XXX Actually the slow-path block below should be moved
+                                       // out of the instruction stream and the jump below should be
+                                       // inverted.
+#if SUPPORT_BRANCH_CONDITIONAL_ONE_INTEGER_REGISTER
+                                       os::abort("codegen_emit: Implement jump over slow-path for this configuration.");
+#elif SUPPORT_BRANCH_CONDITIONAL_CONDITION_REGISTER
+                                       M_TEST(d);
+                                       emit_label_bne(cd, BRANCH_LABEL_10);
+#else
+# error Unable to generate code for this configuration!
+#endif
+                               }
+
                                goto gen_method;
 
                        case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ...        */
@@ -2066,6 +2092,12 @@ if (!md->params[s3].inmemory) {
                                        break;
                                }
 
+                               // If we are emitting a fast-path block, this is the label for
+                               // successful fast-path execution.
+                               if ((iptr->opc == ICMD_BUILTIN) && (bte->emit_fastpath != NULL)) {
+                                       emit_label(cd, BRANCH_LABEL_10);
+                               }
+
                                break;
 
                        case ICMD_TABLESWITCH:  /* ..., index ==> ...                     */
index 0d467fc11658f096f1839254e6a34431cc925236..88d3f1df4ca2a8202b63048105beef447848fa03 100644 (file)
@@ -213,6 +213,10 @@ void emit_patcher_traps(jitdata *jd);
 
 void emit_recompute_pv(codegendata* cd);
 
+/* machine dependent faspath-emitting functions */
+void emit_fastpath_monitor_enter(jitdata* jd, instruction* iptr, int d);
+void emit_fastpath_monitor_exit(jitdata* jd, instruction* iptr, int d);
+
 #if defined(ENABLE_THREADS)
 void emit_monitor_enter(jitdata* jd, int32_t syncslot_offset);
 void emit_monitor_exit(jitdata* jd, int32_t syncslot_offset);
index 830024cc01ce6b00f9fb54f42fdd96ba17389498..9f1a35f957927e066c8dffc525698325ef438688 100644 (file)
@@ -471,6 +471,38 @@ uint32_t emit_trap(codegendata *cd)
 }
 
 
+/**
+ * Generates fast-path code for the below builtin.
+ *   Function:  LOCK_monitor_enter
+ *   Signature: (Ljava/lang/Object;)V
+ *   Slow-path: bool lock_monitor_enter(java_handle_t*);
+ */
+void emit_fastpath_monitor_enter(jitdata* jd, instruction* iptr, int d)
+{
+       // Get required compiler data.
+       codegendata* cd = jd->cd;
+
+       // XXX Currently the fast-path always fails. Implement me!
+       M_CLR(d);
+}
+
+
+/**
+ * Generates fast-path code for the below builtin.
+ *   Function:  LOCK_monitor_exit
+ *   Signature: (Ljava/lang/Object;)V
+ *   Slow-path: bool lock_monitor_exit(java_handle_t*);
+ */
+void emit_fastpath_monitor_exit(jitdata* jd, instruction* iptr, int d)
+{
+       // Get required compiler data.
+       codegendata* cd = jd->cd;
+
+       // XXX Currently the fast-path always fails. Implement me!
+       M_CLR(d);
+}
+
+
 /**
  * Generates synchronization code to enter a monitor.
  */