private void Compile(object frameObj) { if (Compiled) { return; } lock (this) { if (Compiled) { return; } PerfTrack.NoteEvent(PerfTrack.Categories.Compiler, "Interpreted loop compiled"); InterpretedFrame frame = (InterpretedFrame)frameObj; var compiler = new LoopCompiler(_loop, frame.Interpreter.LabelMapping, frame.Interpreter.Locals, _instructionIndex, _loopEnd); var instructions = frame.Interpreter.Instructions.Instructions; // replace this instruction with an optimized one: instructions[_instructionIndex] = new CompiledLoopInstruction(compiler.CreateDelegate()); // invalidate this instruction, some threads may still hold on it: _loop = null; } }