public ProgramCounter(ZingMethod method)
        {
            string name = method.MethodName;
            object o = methodNameTable[name];
            Hashtable blockTable = null;
            if (o == null)
            {
                methodNameTable[name] = ++methodCounter;
                blockTable = new Hashtable();
                methodBlockTable[name] = blockTable;
                methodNumberTable[methodCounter] = name;
                methodNumber = methodCounter;
            }
            else
            {
                blockTable = (Hashtable)methodBlockTable[name];
                methodNumber = (ushort)o;
            }

            nextBlock = method.NextBlock;
            blockTable[nextBlock] = method.ProgramCounter;
        }
Esempio n. 2
0
 public UndoPop(Process p, ZingMethod theFrame)
     : base(p)
 {
     savedStackFrame = theFrame;
 }
Esempio n. 3
0
        private void rollbackStackFrames(Stack sules)
        {
            StackULE ule;

            Debug.Assert(stackULEs != null);
            Debug.Assert(stackULEs.Count == 0);

            if (sules == null)
            {
                savedTopOfStack = topOfStack;
                return;
            }
            while (sules.Count > 0)
            {
                ule = (StackULE)sules.Pop();
                ule.Undo();
            }
            savedTopOfStack = topOfStack;
        }
Esempio n. 4
0
 private void doPush(ZingMethod method)
 {
     method.Caller = topOfStack;
     topOfStack = method;
     if (stackULEs == null)
         return;
     stackULEs.Push(new UndoPush(this));
 }
Esempio n. 5
0
 private ZingMethod doPop()
 {
     if (stackULEs != null)
     {
         if (stackULEs.Count > 0 && stackULEs.Peek() is UndoPush)
             stackULEs.Pop();
         else
         {
             Debug.Assert(topOfStack == savedTopOfStack);
             stackULEs.Push(new UndoPop(this, topOfStack));
             savedTopOfStack = topOfStack.Caller;
         }
     }
     ZingMethod oldTop = topOfStack;
     topOfStack = topOfStack.Caller;
     return oldTop;
 }
Esempio n. 6
0
        private Stack checkInStackFrames()
        {
            // this is the first time we checked in
            if (stackULEs == null)
            {
                stackULEs = new Stack();
                for (savedTopOfStack = topOfStack;
                     savedTopOfStack != null;
                     savedTopOfStack = savedTopOfStack.Caller)
                    savedTopOfStack.DoCheckIn();

                savedTopOfStack = topOfStack;
                return null;
            }

            object zmULE = null;

            if (savedTopOfStack != null)
                zmULE = savedTopOfStack.DoCheckIn();

            // small optimization when no changes was made in the
            // current transition
            if (stackULEs.Count == 0 && zmULE == null)
            {
                Debug.Assert(savedTopOfStack == topOfStack);
                return null;
            }

            // the result
            Stack resStack = stackULEs;

            stackULEs = new Stack();

            ZingMethod stackFrame = topOfStack;

            // move newly pushed frames away from the result, save
            // them temporarily in stackULEs; while doing that, we
            // checkIn every newly pushed node
            while (resStack.Count > 0 && resStack.Peek() is UndoPush)
            {
                //object sfULE =
                // this would be the first time we check in these
                // freshly pushed nodes. so we discard their undo log
                // entries
                stackFrame.DoCheckIn();
                stackULEs.Push(resStack.Pop());
                stackFrame = stackFrame.Caller;
            }

            // everything below should be UndoPop's or UndoResetLastFunctionCompleted,
            // and if anything is to be saved, it should be right there at stackFrame
            Debug.Assert(resStack.Count == 0 || resStack.Peek() is UndoPop
                         || resStack.Peek() is UndoResetLastFunctionCompleted);
            Debug.Assert(savedTopOfStack == stackFrame);

            // insert zmULE between UndoPop objects and UndoPush
            // objects
            if (zmULE != null)
                resStack.Push(new UndoUpdate(this, zmULE));

            // move undoPush objects back into the result
            while (stackULEs.Count > 0)
                resStack.Push(stackULEs.Pop());

            savedTopOfStack = topOfStack;
            return resStack;
        }
Esempio n. 7
0
 //the following is used during application of effects
 public void UpdateDirectLastFunctionCompleted(ZingMethod method)
 {
     lastFunctionCompleted = method;
 }
Esempio n. 8
0
 internal OutputVars(ZingMethod zm)
 {
     stackFrame = zm;
 }
Esempio n. 9
0
        public void RaiseZingException(int exception)
        {
            this.lastFunctionCompleted = null;

            doPop();

            while (topOfStack != null)
            {
                this.atomicityLevel = this.topOfStack.SavedAtomicityLevel;
                // If we find a handler, we're done
                if (this.topOfStack.RaiseZingException(exception))
                    return;

                doPop();
            }

            throw new ZingUnhandledExceptionException(exception);
        }
Esempio n. 10
0
        public void DoCheckout(object currentUle)
        {
            ProcessULE pULE = (ProcessULE)currentUle;

            // cloned components
            atomicityLevel = pULE.atomicityLevel;
            middleOfTransition = pULE.middleOfTransition;
            choicePending = pULE.choicePending;
            lastFunctionCompleted = pULE.lastFunctionCompleted;

            // undoable ones -- do nothing
        }
Esempio n. 11
0
        /*
        public static ZingAttribute PredicateContext
        {
            get { return predicateContext; }
            set { predicateContext = value; }
        }
        */
        public bool CallPredicateMethod(ZingMethod predicateMethod)
        {
            if (runningPredicateMethod[MyThreadId])
            {
                Debugger.Break();
                throw new Exception("Predicate !");
            }

            Process dummyProc = new Process(this.StateImpl, predicateMethod, string.Empty, 0);

            Exception savedException = this.StateImpl.Exception;
            this.StateImpl.Exception = null;

            while (dummyProc.TopOfStack != null)
            {
                runningPredicateMethod[MyThreadId] = true;
                this.StateImpl.RunBlocks(dummyProc);
                runningPredicateMethod[MyThreadId] = false;

                if (this.StateImpl.Exception != null)
                {
                    if (savedException == null)
                    {
                        this.StateImpl.Exception = new Exception("Predicate");
                        throw this.StateImpl.Exception;
                    }
                    else
                    {
                        // If we already have a pending exception on the state, just
                        // return false and restore the original exception.
                        this.StateImpl.Exception = savedException;
                        return false;
                    }
                }

                if (dummyProc.choicePending)
                    throw new Exception("Predicate");
            }
            this.StateImpl.Exception = savedException;
            return predicateMethod.BooleanReturnValue;
        }
Esempio n. 12
0
 public void Call(ZingMethod method)
 {
     // method.StateImpl = this.StateImpl;
     method.SavedAtomicityLevel = this.atomicityLevel;
     doPush(method);
 }
Esempio n. 13
0
 public Process(StateImpl stateObj, ZingMethod entryPoint, string name, uint id, int threadID)
     : this(stateObj, entryPoint, name, id)
 {
     this.MyThreadId = threadID;
 }
Esempio n. 14
0
        // <summary>
        // Constructor
        // </summary>
        // <param name="entryPoint"></param>
        // <param name="name"></param>
        // <param name="id"></param>
        public Process(StateImpl stateObj, ZingMethod entryPoint, string name, uint id)
        {
            this.StateImpl = stateObj;
            this.entryPoint = entryPoint;
            this.name = name;
            this.id = id;

            this.Call(entryPoint);
        }
Esempio n. 15
0
 internal LocalVars(ZingMethod zm)
 {
     stackFrame = zm;
 }
Esempio n. 16
0
 protected override void doUndo()
 {
     savedStackFrame.Caller = process.topOfStack;
     process.topOfStack = process.savedTopOfStack = savedStackFrame;
     savedStackFrame = null;
     process.topOfStack.DoRevert();
 }
Esempio n. 17
0
 public UndoResetLastFunctionCompleted(Process p, ZingMethod l)
     : base(p)
 {
     savedLastFunctionCompleted = l;
 }
Esempio n. 18
0
        public void Return(ZingSourceContext context, ZingAttribute contextAttribute)
        {
            ZingMethod returningMethod = doPop();

            this.atomicityLevel = returningMethod.SavedAtomicityLevel;

            // Keep a ref to the completed function so the caller can access
            // the return value and output parameters.

            if (topOfStack != null)
                lastFunctionCompleted = returningMethod;
            else
            {
                lastFunctionCompleted = null;
                middleOfTransition = false;
            }

            if (this.topOfStack == null && ZingerConfiguration.ExecuteTraceStatements && (this.name != null && this.name.Length != 0))
            {
                if (ZingerConfiguration.DegreeOfParallelism == 1)
                {
                    this.StateImpl.ReportEvent(new TerminateProcessEvent(context, contextAttribute));
                }
                else
                {
                    this.StateImpl.ReportEvent(new TerminateProcessEvent(context, contextAttribute, this.MyThreadId));
                }
            }
        }