Example #1
0
 private void Compile(object frameObj)
 {
     if (!this.Compiled)
     {
         lock (this)
         {
             if (!this.Compiled)
             {
                 InterpretedFrame frame = (InterpretedFrame) frameObj;
                 LoopCompiler compiler = new LoopCompiler(this._loop, frame.Interpreter.LabelMapping, this._variables, this._closureVariables, this._instructionIndex, this._loopEnd);
                 frame.Interpreter.Instructions.Instructions[this._instructionIndex] = new CompiledLoopInstruction(compiler.CreateDelegate());
                 this._loop = null;
                 this._variables = null;
                 this._closureVariables = null;
             }
         }
     }
 }
Example #2
0
        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, _variables, _closureVariables, _instructionIndex, _loopEnd);
                var instructions = frame.Interpreter.Instructions.Instructions;

                // replace this instruction with an optimized one:
                Interlocked.Exchange(ref instructions[_instructionIndex], new CompiledLoopInstruction(compiler.CreateDelegate()));

                // invalidate this instruction, some threads may still hold on it:
                _loop = null;
                _variables = null;
                _closureVariables = null;
            }
        }