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:
                instructions[_instructionIndex] = new CompiledLoopInstruction(compiler.CreateDelegate());

                // invalidate this instruction, some threads may still hold on it:
                _loop             = null;
                _variables        = null;
                _closureVariables = null;
            }
        }
 internal EnterLoopInstruction(PowerShellLoopExpression loop, LocalVariables locals, int compilationThreshold, int instructionIndex)
 {
     _loop                 = loop;
     _variables            = locals.CopyLocals();
     _closureVariables     = locals.ClosureVariables;
     _compilationThreshold = compilationThreshold;
     _instructionIndex     = instructionIndex;
 }
Ejemplo n.º 3
0
 internal LoopCompiler(PowerShellLoopExpression loop, HybridReferenceDictionary <LabelTarget, BranchLabel> labelMapping, Dictionary <ParameterExpression, LocalVariable> locals, Dictionary <ParameterExpression, LocalVariable> closureVariables, int loopStartInstructionIndex, int loopEndInstructionIndex)
 {
     this._loop                      = loop;
     this._outerVariables            = locals;
     this._closureVariables          = closureVariables;
     this._frameDataVar              = Expression.Parameter(typeof(object[]));
     this._frameClosureVar           = Expression.Parameter(typeof(StrongBox <object>[]));
     this._frameVar                  = Expression.Parameter(typeof(InterpretedFrame));
     this._loopVariables             = new Dictionary <ParameterExpression, LoopVariable>();
     this._returnLabel               = Expression.Label(typeof(int));
     this._labelMapping              = labelMapping;
     this._loopStartInstructionIndex = loopStartInstructionIndex;
     this._loopEndInstructionIndex   = loopEndInstructionIndex;
 }
Ejemplo n.º 4
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;
             }
         }
     }
 }