[Mono-list] Benchmark information needed.
Miguel de Icaza
miguel@ximian.com
16 Aug 2002 18:01:38 -0400
--=-asE4ZPwU8qbmEKbNKj0T
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hello guys,
I have this patch that implements spurious jump elimination in the
Mono runtime, but on my P4 computer I never get any actual improvements
on the execution time.
I would appreciate if people can patch their Mono runtime with this
patch and run the enclosed test and report back the times as well as the
machine type they are using.
Miguel.
--=-asE4ZPwU8qbmEKbNKj0T
Content-Disposition: attachment; filename=jump-removal.patch
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=jump-removal.patch; charset=ISO-8859-1
Index: mono/jit/jit.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/mono/mono/jit/jit.c,v
retrieving revision 1.244
diff -u -r1.244 jit.c
--- mono/jit/jit.c 13 Aug 2002 09:10:38 -0000 1.244
+++ mono/jit/jit.c 16 Aug 2002 22:00:01 -0000
@@ -66,10 +66,11 @@
tbb =3D &cfg->bblocks [bcinfo [target].block_id]; \
create_outstack (cfg, bb, stack, sp - stack); \
mark_reached (cfg, tbb, bb->outstack, bb->outdepth); \
- t1->data.bi.target =3D tbb; \
- t1->data.bi.cond =3D CEE_##name; \
- ADD_TREE (t1, cli_addr); \
ip +=3D near_jump ? 1: 4; \
+ t1->data.bi.target =3D mono_follow_jumps (cfg, tbb, ip); \
+ if (t1->data.bi.target) \
+ ADD_TREE (t1, cli_addr); \
+ t1->data.bi.cond =3D CEE_##name; \
break; \
}
=20
@@ -1316,6 +1317,39 @@
=20
#define MARK_REACHED(bb) do { if (!bb->reached) { bb->reached =3D 1; }} wh=
ile (0)
=20
+static MonoBBlock *
+mono_follow_jumps (MonoFlowGraph *cfg, MonoBBlock *bb, const unsigned char=
*next_ip)
+{
+ MonoMethod *method =3D cfg->method;
+ MonoMethodHeader *header =3D ((MonoMethodNormal *)method)->header;
+ MonoBytecodeInfo *bcinfo =3D cfg->bcinfo;
+ MonoBBlock *newbb;
+ const unsigned char *ip =3D header->code + bb->cli_addr;
+ unsigned char op =3D *ip;
+ gint32 target;
+
+ if (ip =3D=3D next_ip)
+ return NULL;
+=09
+ ip++;
+ if (op =3D=3D CEE_BR){
+ mono_jit_stats.jumps_followed++;
+ target =3D bb->cli_addr + 5 + (gint32) read32 (ip);
+ newbb =3D &cfg->bblocks [bcinfo [target].block_id];
+ if (bb->cli_addr =3D=3D target)
+ return bb;
+ return mono_follow_jumps (cfg, newbb, next_ip);
+ } else if (op =3D=3D CEE_BR_S){
+ mono_jit_stats.jumps_followed++;
+ target =3D bb->cli_addr + 2 + (signed char) *ip;
+ newbb =3D &cfg->bblocks [bcinfo [target].block_id];
+ if (bb->cli_addr =3D=3D target)
+ return bb;
+ return mono_follow_jumps (cfg, newbb, next_ip);
+ }
+ return bb;
+}
+ =20
/**
* mono_analyze_stack:
* @cfg: control flow graph
@@ -2676,14 +2710,15 @@
mark_reached (cfg, tbb, bb->outstack, bb->outdepth);
=20
t1 =3D mono_ctree_new_leaf (mp, MB_TERM_BR);
- t1->data.p =3D tbb;
- ADD_TREE (t1, cli_addr);
-
if (br_s)
++ip;
else
ip +=3D 4;
=20
+ t1->data.p =3D mono_follow_jumps (cfg, tbb, ip);
+ if (t1->data.p !=3D NULL)
+ ADD_TREE (t1, cli_addr);
+
superblock_end =3D TRUE;
break;
}
@@ -2797,9 +2832,10 @@
create_outstack (cfg, bb, stack, sp - stack);
mark_reached (cfg, tbb, bb->outstack, bb->outdepth);
=20
- t1->data.p =3D tbb;
ip +=3D near_jump ? 1: 4;
- ADD_TREE (t1, cli_addr);
+ t1->data.p =3D mono_follow_jumps (cfg, tbb, ip);
+ if (t1->data.p !=3D NULL)
+ ADD_TREE (t1, cli_addr);
break;
}
case CEE_BRFALSE:
@@ -2822,9 +2858,10 @@
create_outstack (cfg, bb, stack, sp - stack);
mark_reached (cfg, tbb, bb->outstack, bb->outdepth);
=20
- t1->data.p =3D tbb;
ip +=3D near_jump ? 1: 4;
- ADD_TREE (t1, cli_addr);
+ t1->data.p =3D mono_follow_jumps (cfg, tbb, ip);
+ if (t1->data.p !=3D NULL)
+ ADD_TREE (t1, cli_addr);
break;
}
case CEE_RET: {
@@ -4183,6 +4220,7 @@
g_print ("Allocated code size: %ld\n", mono_jit_stats.allocated_code_=
size);
g_print ("Inlineable methods: %ld\n", mono_jit_stats.inlineable_meth=
ods);
g_print ("Inlined methods: %ld\n", mono_jit_stats.inlined_methods=
);
+ g_print ("Jumps followed: %ld\n", mono_jit_stats.jumps_followed)=
;
=09
g_print ("\nCreated object count: %ld\n", mono_stats.new_object_count)=
;
g_print ("Initialized classes: %ld\n", mono_stats.initialized_class_c=
ount);
Index: mono/jit/jit.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/mono/mono/jit/jit.h,v
retrieving revision 1.84
diff -u -r1.84 jit.h
--- mono/jit/jit.h 2 Aug 2002 14:16:20 -0000 1.84
+++ mono/jit/jit.h 16 Aug 2002 22:00:01 -0000
@@ -211,6 +211,7 @@
gulong inlined_methods;
gulong basic_blocks;
gulong max_basic_blocks;
+ gulong jumps_followed;
MonoMethod *max_ratio_method;
MonoMethod *biggest_method;
gboolean enabled;
--=-asE4ZPwU8qbmEKbNKj0T
Content-Disposition: attachment; filename=a.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=a.cs; charset=ISO-8859-1
using System;
class X {
static void Main ()
{
X x =3D new X();
x.J ();
}
void J ()
{
int j =3D 100;
int i;
int d =3D 100;
int r =3D 100;
DateTime start =3D DateTime.Now;
=09
for (i =3D 0; i < 1000; i++){
while (j > 0){
while (d > 0){
while (r > 0){
r--;
}
r =3D 100;
d--;
}
d =3D 1000;
j--;
}
j =3D 100;
}
DateTime end =3D DateTime.Now;
Console.WriteLine ("Elapsed: {0}", end - start);
}
}
--=-asE4ZPwU8qbmEKbNKj0T--