+/**
+ * Generates a memory barrier to be used after volatile writes. It can be
+ * patched out later if the field turns out not to be volatile.
+ */
+void codegen_emit_patchable_barrier(instruction *iptr, codegendata *cd, patchref_t *pr, fieldinfo *fi)
+{
+ if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
+ /* Align on word boundary */
+ if ((((intptr_t) cd->mcodeptr) & 3) >= 2)
+ emit_nop(cd, 4 - (((intptr_t) cd->mcodeptr) & 3));
+ /* Displacement for patching out MFENCE */
+ pr->disp_mb = (cd->mcodeptr - cd->mcodebase - pr->mpc);
+ }
+ if (INSTRUCTION_IS_UNRESOLVED(iptr) || fi->flags & ACC_VOLATILE)
+ M_MFENCE;
+}