#include <mono/metadata/profiler-private.h>
#include <mono/metadata/profiler.h>
#include <mono/utils/mono-compiler.h>
+#include <mono/utils/mono-memory-model.h>
#include <mono/metadata/mono-basic-block.h>
#include "mini.h"
return ins;
}
+static MonoInst*
+emit_memory_barrier (MonoCompile *cfg, int kind)
+{
+ MonoInst *ins = NULL;
+ MONO_INST_NEW (cfg, ins, OP_MEMORY_BARRIER);
+ MONO_ADD_INS (cfg->cbb, ins);
+ ins->backend.memory_barrier_kind = kind;
+
+ return ins;
+}
+
static MonoInst*
mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
{
MONO_ADD_INS (cfg->cbb, ins);
return ins;
} else if (strcmp (cmethod->name, "MemoryBarrier") == 0) {
- MONO_INST_NEW (cfg, ins, OP_MEMORY_BARRIER);
- MONO_ADD_INS (cfg->cbb, ins);
- return ins;
+ return emit_memory_barrier (cfg, FullBarrier);
}
} else if (cmethod->klass == mono_defaults.monitor_class) {
MONO_ADD_INS (bblock, ins);
*sp++ = ins;
if (ins->flags & MONO_INST_VOLATILE) {
- MonoInst *barrier;
-
/* Volatile loads have acquire semantics, see 12.6.7 in Ecma 335 */
- MONO_INST_NEW (cfg, barrier, OP_MEMORY_BARRIER);
- MONO_ADD_INS (cfg->cbb, barrier);
+ /* FIXME it's questionable if acquire semantics require full barrier or just LoadLoad*/
+ emit_memory_barrier (cfg, FullBarrier);
}
++ip;
break;
ins_flag = 0;
if (ins->flags & MONO_INST_VOLATILE) {
- MonoInst *barrier;
-
/* Volatile stores have release semantics, see 12.6.7 in Ecma 335 */
- MONO_INST_NEW (cfg, barrier, OP_MEMORY_BARRIER);
- MONO_ADD_INS (cfg->cbb, barrier);
+ /* FIXME it's questionable if acquire semantics require full barrier or just LoadLoad*/
+ emit_memory_barrier (cfg, FullBarrier);
}
MONO_ADD_INS (bblock, ins);
#define _MONO_UTILS_MONO_MEMMODEL_H_
#include <config.h>
-#include "utils/mono-membar.h"
+#include <mono/utils/mono-membar.h>
/*
In order to allow for fast concurrent code, we must use fencing to properly order
We assume 3 kinds of barriers are available: load, store and memory (load+store).
TODO: Add support for weaker forms of CAS such as present on ARM.
-TODO: replace all explicit uses of memory barriers with macros from this section. This will make
-a nicer read of lazy init code.
-TODO: if we find places where a data depencency could replace barriers, add macros here to help with it
+TODO: replace all explicit uses of memory barriers with macros from this section. This will make a nicer read of lazy init code.
+TODO: if we find places where a data depencency could replace barriers, add macros here to help with it
+TODO: some arch with strong consistency, such as x86, support weaker access. We might need to expose more kinds of barriers once we exploit this.
*/
#define MEMORY_BARRIER mono_memory_barrier