Author: lupus
Date: 2006-05-23 07:55:20 -0400 (Tue, 23 May 2006)
New Revision: 60993
Modified:
trunk/mono/mono/mini/ChangeLog
trunk/mono/mono/mini/mini.c
Log:
Tue May 23 13:47:28 CEST 2006 Paolo Molaro <[EMAIL PROTECTED]>
* mini.c: write barrier support.
Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog 2006-05-23 11:46:35 UTC (rev 60992)
+++ trunk/mono/mono/mini/ChangeLog 2006-05-23 11:55:20 UTC (rev 60993)
@@ -1,3 +1,8 @@
+
+Tue May 23 13:47:28 CEST 2006 Paolo Molaro <[EMAIL PROTECTED]>
+
+ * mini.c: write barrier support.
+
2006-05-23 Martin Baulig <[EMAIL PROTECTED]>
* debug-debugger.c: Revert Paolo's change. Add comment and #error
Modified: trunk/mono/mono/mini/mini.c
===================================================================
--- trunk/mono/mono/mini/mini.c 2006-05-23 11:46:35 UTC (rev 60992)
+++ trunk/mono/mono/mini/mini.c 2006-05-23 11:55:20 UTC (rev 60993)
@@ -89,7 +89,7 @@
static gpointer mono_create_jit_trampoline_in_domain (MonoDomain *domain,
MonoMethod *method);
static void handle_stobj (MonoCompile *cfg, MonoBasicBlock *bblock, MonoInst
*dest, MonoInst *src,
- const unsigned char *ip, MonoClass *klass, gboolean
to_end, gboolean native);
+ const unsigned char *ip, MonoClass *klass, gboolean
to_end, gboolean native, gboolean write_barrier);
static void dec_foreach (MonoInst *tree, MonoCompile *cfg);
@@ -1721,7 +1721,7 @@
NEW_TEMPSTORE (cfg, inst, dest, load);
if (inst->opcode == CEE_STOBJ) {
NEW_TEMPLOADA (cfg, inst, dest);
- handle_stobj (cfg, bb, inst, load, NULL, inst->klass, TRUE,
FALSE);
+ handle_stobj (cfg, bb, inst, load, NULL, inst->klass, TRUE,
FALSE, FALSE);
} else {
inst->cil_code = NULL;
mono_add_ins_to_end (bb, inst);
@@ -1843,7 +1843,7 @@
NEW_TEMPSTORE (cfg, inst, locals [i]->inst_c0, sp [i]);
if (inst->opcode == CEE_STOBJ) {
NEW_TEMPLOADA (cfg, inst, locals [i]->inst_c0);
- handle_stobj (cfg, bb, inst, sp [i], sp [i]->cil_code,
inst->klass, TRUE, FALSE);
+ handle_stobj (cfg, bb, inst, sp [i], sp [i]->cil_code,
inst->klass, TRUE, FALSE, FALSE);
} else {
inst->cil_code = sp [i]->cil_code;
mono_add_ins_to_end (bb, inst);
@@ -1984,7 +1984,7 @@
store->cil_code = ins->cil_code;
if (store->opcode == CEE_STOBJ) {
NEW_TEMPLOADA (cfg, store, temp->inst_c0);
- handle_stobj (cfg, bblock, store, ins,
ins->cil_code, temp->klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, store, ins,
ins->cil_code, temp->klass, FALSE, FALSE, FALSE);
} else
MONO_ADD_INS (bblock, store);
NEW_TEMPLOAD (cfg, load, temp->inst_c0);
@@ -2519,7 +2519,7 @@
}
static void
-handle_stobj (MonoCompile *cfg, MonoBasicBlock *bblock, MonoInst *dest,
MonoInst *src, const unsigned char *ip, MonoClass *klass, gboolean to_end,
gboolean native) {
+handle_stobj (MonoCompile *cfg, MonoBasicBlock *bblock, MonoInst *dest,
MonoInst *src, const unsigned char *ip, MonoClass *klass, gboolean to_end,
gboolean native, gboolean write_barrier) {
MonoInst *iargs [3];
int n;
guint32 align = 0;
@@ -2536,6 +2536,19 @@
else
n = mono_class_value_size (klass, &align);
+#if HAVE_WRITE_BARRIERS
+ /* if native is true there should be no references in the struct */
+ if (write_barrier && klass->has_references && !native) {
+ iargs [0] = dest;
+ iargs [1] = src;
+ NEW_PCONST (cfg, iargs [2], klass);
+
+ mono_emit_jit_icall (cfg, bblock, mono_value_copy, iargs, ip);
+ return;
+ }
+#endif
+
+ /* FIXME: add write barrier handling */
if ((cfg->opt & MONO_OPT_INTRINS) && !to_end && n <= sizeof (gpointer)
* 5) {
MonoInst *inst;
if (dest->opcode == OP_LDADDR) {
@@ -2695,7 +2708,7 @@
vstore->inst_right = val;
if (vstore->opcode == CEE_STOBJ) {
- handle_stobj (cfg, bblock, add, val, ip, klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, add, val, ip, klass, FALSE, FALSE,
TRUE);
} else
MONO_ADD_INS (bblock, vstore);
@@ -3104,7 +3117,7 @@
store->cil_code = sp [0]->cil_code;
if (store->opcode == CEE_STOBJ) {
NEW_TEMPLOADA (cfg, store, temp->inst_c0);
- handle_stobj (cfg, bblock, store, *sp, sp
[0]->cil_code, temp->klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, store, *sp, sp
[0]->cil_code, temp->klass, FALSE, FALSE, FALSE);
} else {
MONO_ADD_INS (bblock, store);
}
@@ -3923,7 +3936,7 @@
UNVERIFIED;
if (ins->opcode == CEE_STOBJ) {
NEW_LOCLOADA (cfg, ins, n);
- handle_stobj (cfg, bblock, ins, *sp, ip,
ins->klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, ins, *sp, ip,
ins->klass, FALSE, FALSE, FALSE);
} else
MONO_ADD_INS (bblock, ins);
++ip;
@@ -3959,7 +3972,7 @@
UNVERIFIED;
if (ins->opcode == CEE_STOBJ) {
NEW_ARGLOADA (cfg, ins, ip [1]);
- handle_stobj (cfg, bblock, ins, *sp, ip,
ins->klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, ins, *sp, ip,
ins->klass, FALSE, FALSE, FALSE);
} else
MONO_ADD_INS (bblock, ins);
ip += 2;
@@ -3994,7 +4007,7 @@
UNVERIFIED;
if (ins->opcode == CEE_STOBJ) {
NEW_LOCLOADA (cfg, ins, ip [1]);
- handle_stobj (cfg, bblock, ins, *sp, ip,
ins->klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, ins, *sp, ip,
ins->klass, FALSE, FALSE, FALSE);
} else
MONO_ADD_INS (bblock, ins);
ip += 2;
@@ -4119,7 +4132,7 @@
store->cil_code = ip;
if (store->opcode == CEE_STOBJ) {
NEW_TEMPLOADA (cfg, store,
temp->inst_c0);
- handle_stobj (cfg, bblock, store, sp
[0], sp [0]->cil_code, store->klass, TRUE, FALSE);
+ handle_stobj (cfg, bblock, store, sp
[0], sp [0]->cil_code, store->klass, TRUE, FALSE, FALSE);
} else {
MONO_ADD_INS (bblock, store);
}
@@ -4335,7 +4348,7 @@
ins->cil_code = ip;
if (ins->opcode == CEE_STOBJ) {
NEW_ARGLOADA (cfg, ins, i);
- handle_stobj (cfg, bblock, ins,
sp [i], sp [i]->cil_code, ins->klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, ins,
sp [i], sp [i]->cil_code, ins->klass, FALSE, FALSE, FALSE);
}
else
MONO_ADD_INS (bblock, ins);
@@ -4489,7 +4502,7 @@
NEW_INDSTORE (cfg, ins, addr, sp
[fsig->param_count], fsig->params [fsig->param_count - 1]);
ins->cil_code = ip;
if (ins->opcode == CEE_STOBJ) {
- handle_stobj (cfg, bblock,
addr, sp [fsig->param_count], ip, mono_class_from_mono_type (fsig->params
[fsig->param_count-1]), FALSE, FALSE);
+ handle_stobj (cfg, bblock,
addr, sp [fsig->param_count], ip, mono_class_from_mono_type (fsig->params
[fsig->param_count-1]), FALSE, FALSE, TRUE);
} else {
MONO_ADD_INS (bblock, ins);
}
@@ -4541,7 +4554,8 @@
if (store->opcode == CEE_STOBJ) {
g_assert_not_reached ();
NEW_TEMPLOADA (cfg, store,
return_var->inst_c0);
- handle_stobj (cfg, bblock,
store, *sp, sp [0]->cil_code, return_var->klass, FALSE, FALSE);
+ /* FIXME: it is possible some
optimization will pass the a heap pointer for the struct address, so we'll need
the write barrier */
+ handle_stobj (cfg, bblock,
store, *sp, sp [0]->cil_code, return_var->klass, FALSE, FALSE, FALSE);
} else
MONO_ADD_INS (bblock, store);
}
@@ -4554,7 +4568,8 @@
ins->opcode = mono_type_to_stind
(mono_method_signature (method)->ret);
if (ins->opcode == CEE_STOBJ) {
NEW_RETLOADA (cfg, ins);
- handle_stobj (cfg, bblock, ins,
*sp, ip, ins->klass, FALSE, FALSE);
+ /* FIXME: it is possible some
optimization will pass the a heap pointer for the struct address, so we'll need
the write barrier */
+ handle_stobj (cfg, bblock, ins,
*sp, ip, ins->klass, FALSE, FALSE, FALSE);
} else {
ins->opcode = OP_SETRET;
ins->cil_code = ip;
@@ -4753,6 +4768,16 @@
case CEE_STIND_R4:
case CEE_STIND_R8:
CHECK_STACK (2);
+#if HAVE_WRITE_BARRIERS
+ if (*ip == CEE_STIND_REF && method->wrapper_type !=
MONO_WRAPPER_WRITE_BARRIER) {
+ /* insert call to write barrier */
+ MonoMethod *write_barrier =
mono_marshal_get_write_barrier ();
+ sp -= 2;
+ mono_emit_method_call_spilled (cfg, bblock,
write_barrier, mono_method_signature (write_barrier), sp, ip, NULL);
+ ip++;
+ break;
+ }
+#endif
MONO_INST_NEW (cfg, ins, *ip);
ins->cil_code = ip++;
sp -= 2;
@@ -4983,7 +5008,7 @@
ins->cil_code = ip;
g_assert (ins->opcode == CEE_STOBJ);
NEW_LOCLOADA (cfg, ins, loc_index);
- handle_stobj (cfg, bblock, ins, *sp,
ip, ins->klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, ins, *sp,
ip, ins->klass, FALSE, FALSE, FALSE);
ip += 5;
ip += stloc_len;
break;
@@ -5537,6 +5562,21 @@
} else {
mono_emit_method_call_spilled
(cfg, bblock, stfld_wrapper, mono_method_signature (stfld_wrapper), iargs, ip,
NULL);
}
+#if HAVE_WRITE_BARRIERS
+ } else if (mono_type_to_stind (field->type) ==
CEE_STIND_REF) {
+ /* insert call to write barrier */
+ MonoMethod *write_barrier =
mono_marshal_get_write_barrier ();
+ MonoInst *iargs [2];
+ NEW_ICONST (cfg, offset_ins, foffset);
+ MONO_INST_NEW (cfg, ins, OP_PADD);
+ ins->cil_code = ip;
+ ins->inst_left = *sp;
+ ins->inst_right = offset_ins;
+ ins->type = STACK_MP;
+ iargs [0] = ins;
+ iargs [1] = sp [1];
+ mono_emit_method_call_spilled (cfg,
bblock, write_barrier, mono_method_signature (write_barrier), iargs, ip, NULL);
+#endif
} else {
MonoInst *store;
NEW_ICONST (cfg, offset_ins, foffset);
@@ -5555,7 +5595,7 @@
ins_flag = 0;
if (store->opcode == CEE_STOBJ) {
handle_stobj (cfg, bblock, ins,
sp [1], ip,
-
mono_class_from_mono_type (field->type), FALSE, FALSE);
+
mono_class_from_mono_type (field->type), FALSE, FALSE, TRUE);
} else
MONO_ADD_INS (bblock, store);
}
@@ -5721,7 +5761,7 @@
ins_flag = 0;
if (store->opcode == CEE_STOBJ) {
- handle_stobj (cfg, bblock, ins, sp [0],
ip, mono_class_from_mono_type (field->type), FALSE, FALSE);
+ handle_stobj (cfg, bblock, ins, sp [0],
ip, mono_class_from_mono_type (field->type), FALSE, FALSE, FALSE);
} else
MONO_ADD_INS (bblock, store);
} else {
@@ -5764,6 +5804,7 @@
NEW_ICONST (cfg, *sp,
*((guint32 *)addr));
sp++;
break;
+#ifndef HAVE_MOVING_COLLECTOR
case MONO_TYPE_I:
case MONO_TYPE_U:
case MONO_TYPE_STRING:
@@ -5777,6 +5818,7 @@
type_to_eval_stack_type
(field->type, *sp);
sp++;
break;
+#endif
case MONO_TYPE_I8:
case MONO_TYPE_U8:
MONO_INST_NEW (cfg, *sp,
OP_I8CONST);
@@ -5820,7 +5862,7 @@
goto load_error;
n = mono_type_to_stind (&klass->byval_arg);
if (n == CEE_STOBJ) {
- handle_stobj (cfg, bblock, sp [0], sp [1], ip,
klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, sp [0], sp [1], ip,
klass, FALSE, FALSE, TRUE);
} else {
/* FIXME: should check item at sp [1] is
compatible with the type of the store. */
MonoInst *store;
@@ -6095,7 +6137,7 @@
n = mono_type_to_stind (&klass->byval_arg);
if (n == CEE_STOBJ)
- handle_stobj (cfg, bblock, load, sp
[2], ip, klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, load, sp
[2], ip, klass, FALSE, FALSE, TRUE);
else {
MONO_INST_NEW (cfg, ins, n);
ins->cil_code = ip;
@@ -6519,7 +6561,7 @@
klass = (MonoClass
*)mono_method_get_wrapper_data (method, token);
NEW_RETLOADA (cfg, ins);
- handle_stobj (cfg, bblock, ins, *sp, ip, klass,
FALSE, TRUE);
+ handle_stobj (cfg, bblock, ins, *sp, ip, klass,
FALSE, TRUE, FALSE);
if (sp != stack_start)
UNVERIFIED;
@@ -6733,7 +6775,7 @@
UNVERIFIED;
if (ins->opcode == CEE_STOBJ) {
NEW_ARGLOADA (cfg, ins, n);
- handle_stobj (cfg, bblock, ins, *sp,
ip, ins->klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, ins, *sp,
ip, ins->klass, FALSE, FALSE, FALSE);
} else
MONO_ADD_INS (bblock, ins);
ip += 4;
@@ -6771,7 +6813,7 @@
ins->cil_code = ip;
if (ins->opcode == CEE_STOBJ) {
NEW_LOCLOADA (cfg, ins, n);
- handle_stobj (cfg, bblock, ins, *sp,
ip, ins->klass, FALSE, FALSE);
+ handle_stobj (cfg, bblock, ins, *sp,
ip, ins->klass, FALSE, FALSE, FALSE);
} else
MONO_ADD_INS (bblock, ins);
ip += 4;
@@ -10786,6 +10828,7 @@
register_icall (mono_helper_ldstr, "helper_ldstr", "object ptr int",
FALSE);
register_icall (mono_helper_ldstr_mscorlib, "helper_ldstr_mscorlib",
"object int", FALSE);
register_icall (mono_helper_newobj_mscorlib, "helper_newobj_mscorlib",
"object int", FALSE);
+ register_icall (mono_value_copy, "mono_value_copy", "void ptr ptr ptr",
FALSE);
#endif
#define JIT_RUNTIME_WORKS
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches