[Mono-list] patch: jit cleanups
Dietmar Maurer
dietmar@ximian.com
06 Nov 2001 14:51:48 +0100
Index: mono/dis/main.c
===================================================================
RCS file: /cvs/public/mono/mono/dis/main.c,v
retrieving revision 1.42
diff -u -r1.42 main.c
--- mono/dis/main.c 2001/11/05 11:31:20 1.42
+++ mono/dis/main.c 2001/11/06 09:44:00
@@ -32,10 +32,10 @@
int dump_table = -1;
-gpointer arch_create_jit_trampoline (MonoMethod *method, gboolean virtual);
+gpointer arch_create_jit_trampoline (MonoMethod *method);
gpointer
-arch_create_jit_trampoline (MonoMethod *method, gboolean virtual)
+arch_create_jit_trampoline (MonoMethod *method)
{
return method;
}
Index: mono/interpreter/interp.c
===================================================================
RCS file: /cvs/public/mono/mono/interpreter/interp.c,v
retrieving revision 1.91
diff -u -r1.91 interp.c
--- mono/interpreter/interp.c 2001/11/05 11:31:20 1.91
+++ mono/interpreter/interp.c 2001/11/06 09:44:00
@@ -86,10 +86,10 @@
typedef void (*ICallMethod) (MonoInvocation *frame);
-gpointer arch_create_jit_trampoline (MonoMethod *method, gboolean virtual);
+gpointer arch_create_jit_trampoline (MonoMethod *method);
gpointer
-arch_create_jit_trampoline (MonoMethod *method, gboolean virtual)
+arch_create_jit_trampoline (MonoMethod *method)
{
return method;
}
Index: mono/jit/ChangeLog
===================================================================
RCS file: /cvs/public/mono/mono/jit/ChangeLog,v
retrieving revision 1.34
diff -u -r1.34 ChangeLog
--- mono/jit/ChangeLog 2001/11/05 11:31:20 1.34
+++ mono/jit/ChangeLog 2001/11/06 09:44:00
@@ -1,3 +1,10 @@
+2001-11-06 Dietmar Maurer <dietmar@ximian.com>
+
+ * emit-x86.c (arch_create_jit_trampoline): optimised trampoline to
+ use less the 16 bytes.
+
+ * x86.brg: code cleanup
+
2001-11-05 Dietmar Maurer <dietmar@ximian.com>
* testjit.c: bug fixes.
Index: mono/jit/emit-x86.c
===================================================================
RCS file: /cvs/public/mono/mono/jit/emit-x86.c,v
retrieving revision 1.12
diff -u -r1.12 emit-x86.c
--- mono/jit/emit-x86.c 2001/11/05 11:31:20 1.12
+++ mono/jit/emit-x86.c 2001/11/06 09:44:00
@@ -141,15 +141,6 @@
x86_ret (cfg->code);
}
-static void
-arch_vtable_trampoline ()
-{
- //guint8 *code, *buf;
-
- g_assert_not_reached ();
-}
-
-
/**
* arch_create_jit_trampoline:
* @method: pointer to the method info
@@ -163,46 +154,21 @@
* Returns: a pointer to the newly created code
*/
gpointer
-arch_create_jit_trampoline (MonoMethod *method, gboolean vtable)
+arch_create_jit_trampoline (MonoMethod *method)
{
guint8 *code, *buf;
-/*
- if (vtable)
- return arch_vtable_trampoline;
-*/
if (method->addr)
return method->addr;
-
- code = buf = g_malloc (64);
- x86_push_reg (buf, X86_EBP);
- x86_mov_reg_reg (buf, X86_EBP, X86_ESP, 4);
-
+ /* we never free the allocated code buffer */
+ code = buf = g_malloc (16);
x86_push_imm (buf, method);
x86_call_code (buf, arch_compile_method);
-
- /* free the allocated code buffer */
- /* unfortunately this does not work, because we store the
- * trampoline in various places (for example the vtable of classes,
- * and vtables are copied to inherited classes, there may be also
- * several references in compiled code) - so we dont
- * know how many references to the trampoline exists :-(
- */
- /*
- x86_push_reg (buf, X86_EAX);
- x86_push_imm (buf, code);
- x86_call_code (buf, g_free);
x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 4);
- x86_pop_reg (buf, X86_EAX);
- */
-
- x86_leave (buf);
-
/* jump to the compiled method */
x86_jump_reg (buf, X86_EAX);
-
- g_assert ((buf - code) < 64);
+ g_assert ((buf - code) < 16);
return code;
}
Index: mono/jit/jit.h
===================================================================
RCS file: /cvs/public/mono/mono/jit/jit.h,v
retrieving revision 1.9
diff -u -r1.9 jit.h
--- mono/jit/jit.h 2001/11/05 11:31:20 1.9
+++ mono/jit/jit.h 2001/11/06 09:44:00
@@ -91,7 +91,7 @@
arch_compile_method (MonoMethod *method);
gpointer
-arch_create_jit_trampoline (MonoMethod *method, gboolean virtual);
+arch_create_jit_trampoline (MonoMethod *method);
/* some handy debugging functions */
Index: mono/jit/testjit.c
===================================================================
RCS file: /cvs/public/mono/mono/jit/testjit.c,v
retrieving revision 1.36
diff -u -r1.36 testjit.c
--- mono/jit/testjit.c 2001/11/05 11:31:20 1.36
+++ mono/jit/testjit.c 2001/11/06 09:44:01
@@ -91,7 +91,7 @@
++ip; \
sp -= 2; \
t1 = mono_ctree_new (mp, MB_TERM_LDELEMA, sp [0], sp [1]); \
- t1->size = s; \
+ t1->data.i = s; \
t1 = mono_ctree_new (mp, op, t1, NULL); \
PUSH_TREE (t1, svt); \
break; \
@@ -111,7 +111,7 @@
++ip; \
sp -= 3; \
t1 = mono_ctree_new (mp, MB_TERM_LDELEMA, sp [0], sp [1]); \
- t1->size = s; \
+ t1->data.i = s; \
t1 = mono_ctree_new (mp, op, t1, sp [2]); \
ADD_TREE (t1); \
break; \
@@ -1563,20 +1563,15 @@
if (!cm->klass->metadata_inited)
mono_class_metadata_init (cm->klass);
- if (cm->klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
+ if (cm->klass->flags & TYPE_ATTRIBUTE_INTERFACE)
t2 = mono_ctree_new (mp, MB_TERM_INTF_ADDR, t2, NULL);
- t2->data.i = cm->klass->interface_id << 2;
- printf ("SLOT %s.%s::%s %d %d\n", cm->klass->name_space,
- cm->klass->name, cm->name, cm->klass->metadata_inited,
- cm->slot);
- t2->size = cm->slot << 2;
- } else {
+ else
t2 = mono_ctree_new (mp, MB_TERM_VFUNC_ADDR, t2, NULL);
- t2->data.i = cm->slot << 2;
- }
+
+ t2->data.m = cm;
} else {
if (!cm->addr)
- cm->addr = arch_create_jit_trampoline (cm, FALSE);
+ cm->addr = arch_create_jit_trampoline (cm);
t2 = mono_ctree_new_leaf (mp, MB_TERM_ADDR_G);
t2->data.p = (char *)cm + G_STRUCT_OFFSET (MonoMethod, addr);
@@ -1604,7 +1599,7 @@
}
t1 = mono_ctree_new (mp, map_call_type (csig->ret, &svt), t2, NULL);
- t1->size = args_size;
+ t1->data.i = args_size;
t1->svt = svt;
if (csig->ret->type != MONO_TYPE_VOID) {
Index: mono/jit/x86.brg
===================================================================
RCS file: /cvs/public/mono/mono/jit/x86.brg,v
retrieving revision 1.29
diff -u -r1.29 x86.brg
--- mono/jit/x86.brg 2001/11/05 11:31:20 1.29
+++ mono/jit/x86.brg 2001/11/06 09:44:01
@@ -61,13 +61,12 @@
gint8 reg1;
gint8 reg2;
- gint32 size;
-
union {
gint32 i;
gint64 l;
gpointer p;
MonoBBlock *bb;
+ MonoMethod *m;
X86AddressInfo ainfo;
} data;
};
@@ -498,7 +497,7 @@
reg: LDELEMA (reg, reg) {
x86_mov_reg_membase (s->code, tree->reg1, tree->left->reg1,
G_STRUCT_OFFSET (MonoArray, vector), 4);
- x86_imul_reg_reg_imm (s->code, tree->right->reg1, tree->right->reg1, tree->size);
+ x86_imul_reg_reg_imm (s->code, tree->right->reg1, tree->right->reg1, tree->data.i);
x86_alu_reg_reg (s->code, X86_ADD, tree->reg1, tree->right->reg1);
}
@@ -825,8 +824,8 @@
x86_call_mem (s->code, tree->left->data.p);
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
g_assert (tree->reg1 == X86_EAX);
}
@@ -837,11 +836,11 @@
x86_mov_reg_membase (s->code, reg1, reg1, 0, 4);
x86_mov_reg_membase (s->code, reg1, reg1,
G_STRUCT_OFFSET (MonoClass, interface_offsets), 4);
- x86_mov_reg_memba_e (s->code, reg1, reg1, tree->left->data.i, 4);
- x86_call_membase (s->code, reg1, tree->left->size);
+ x86_mov_reg_membase (s->code, reg1, reg1, tree->left->data.m->klass->interface_id << 2, 4);
+ x86_call_membase (s->code, reg1, tree->left->data.m->slot << 2);
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
g_assert (tree->reg1 == X86_EAX);
}
@@ -851,10 +850,10 @@
x86_mov_reg_membase (s->code, reg1, reg1, 0, 4);
x86_call_membase (s->code, reg1,
- G_STRUCT_OFFSET (MonoClass, vtable + tree->left->data.i));
+ G_STRUCT_OFFSET (MonoClass, vtable) + (tree->left->data.m->slot << 2));
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
g_assert (tree->reg1 == X86_EAX);
}
@@ -862,8 +861,8 @@
stmt: CALL_I4 (ADDR_G) {
x86_call_mem (s->code, tree->left->data.p);
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
}
stmt: CALL_I4 (INTF_ADDR (reg)) {
@@ -872,11 +871,11 @@
x86_mov_reg_membase (s->code, reg1, reg1, 0, 4);
x86_mov_reg_membase (s->code, reg1, reg1,
G_STRUCT_OFFSET (MonoClass, interface_offsets), 4);
- x86_mov_reg_membase (s->code, reg1, reg1, tree->left->data.i, 4);
- x86_call_membase (s->code, reg1, tree->left->size);
+ x86_mov_reg_membase (s->code, reg1, reg1, tree->left->data.m->klass->interface_id << 2, 4);
+ x86_call_membase (s->code, reg1, tree->left->data.m->slot << 2);
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
}
stmt: CALL_I4 (VFUNC_ADDR (reg)) {
@@ -884,17 +883,17 @@
x86_mov_reg_membase (s->code, reg1, reg1, 0, 4);
x86_call_membase (s->code, reg1,
- G_STRUCT_OFFSET (MonoClass, vtable + tree->left->data.i));
+ G_STRUCT_OFFSET (MonoClass, vtable) + (tree->left->data.m->slot << 2));
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
}
stmt: CALL_I4 (ADDR_G) {
x86_call_mem (s->code, tree->left->data.p);
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
}
stmt: SWITCH (reg) {
@@ -1159,8 +1158,8 @@
g_assert_not_reached ();
}
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
g_assert (tree->reg1 == X86_EAX);
g_assert (tree->reg2 == X86_EDX);
@@ -1546,8 +1545,8 @@
g_assert_not_reached ();
}
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
}
freg: CALL_R8 (INTF_ADDR (reg)) {
@@ -1556,11 +1555,11 @@
x86_mov_reg_membase (s->code, reg1, reg1, 0, 4);
x86_mov_reg_membase (s->code, reg1, reg1,
G_STRUCT_OFFSET (MonoClass, interface_offsets), 4);
- x86_mov_reg_membase (s->code, reg1, reg1, tree->left->data.i, 4);
- x86_call_membase (s->code, reg1, tree->left->size);
+ x86_mov_reg_membase (s->code, reg1, reg1, tree->left->data.m->klass->interface_id << 2, 4);
+ x86_call_membase (s->code, reg1, tree->left->data.m->slot << 2);
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
}
freg: CALL_R8 (VFUNC_ADDR (reg)) {
@@ -1568,10 +1567,10 @@
x86_mov_reg_membase (s->code, reg1, reg1, 0, 4);
x86_call_membase (s->code, reg1,
- G_STRUCT_OFFSET (MonoClass, vtable + tree->left->data.i));
+ G_STRUCT_OFFSET (MonoClass, vtable) + (tree->left->data.m->slot << 2));
- if (tree->size)
- x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->size);
+ if (tree->data.i)
+ x86_alu_reg_imm (s->code, X86_ADD, X86_ESP, tree->data.i);
}
stmt: RETV (freg) {
Index: mono/metadata/class.c
===================================================================
RCS file: /cvs/public/mono/mono/metadata/class.c,v
retrieving revision 1.47
diff -u -r1.47 class.c
--- mono/metadata/class.c 2001/11/05 11:31:20 1.47
+++ mono/metadata/class.c 2001/11/06 09:44:01
@@ -26,7 +26,7 @@
#define CSIZE(x) (sizeof (x) / 4)
-gpointer arch_create_jit_trampoline (MonoMethod *method, gboolean virtual);
+gpointer arch_create_jit_trampoline (MonoMethod *method);
static MonoClass *
mono_class_create_from_typeref (MonoImage *image, guint32 type_token)
@@ -343,7 +343,7 @@
if (im && !(im->flags & METHOD_ATTRIBUTE_ABSTRACT)) {
im->slot = io + l;
//printf (" ASLOT%d %s.%s:%s\n", io + l, ic->name_space, ic->name, im->name);
- vtable [io + l] = arch_create_jit_trampoline (im, TRUE);
+ vtable [io + l] = arch_create_jit_trampoline (im);
}
}
}
@@ -380,7 +380,7 @@
cm->slot = cur_slot++;
if (!(cm->flags & METHOD_ATTRIBUTE_ABSTRACT))
- vtable [cm->slot] = arch_create_jit_trampoline (cm, TRUE);
+ vtable [cm->slot] = arch_create_jit_trampoline (cm);
}
/*
Index: mono/metadata/pedump.c
===================================================================
RCS file: /cvs/public/mono/mono/metadata/pedump.c,v
retrieving revision 1.16
diff -u -r1.16 pedump.c
--- mono/metadata/pedump.c 2001/11/05 11:31:20 1.16
+++ mono/metadata/pedump.c 2001/11/06 09:44:01
@@ -19,10 +19,10 @@
gboolean dump_data = TRUE;
gboolean dump_tables = FALSE;
-gpointer arch_create_jit_trampoline (MonoMethod *method, gboolean virtual);
+gpointer arch_create_jit_trampoline (MonoMethod *method);
gpointer
-arch_create_jit_trampoline (MonoMethod *method, gboolean virtual)
+arch_create_jit_trampoline (MonoMethod *method)
{
return method;
}