Exemplo n.º 1
0
 public override MockHeap CollectGarbage(MockHeap h)
 {
     Heap = h;
     Mark();
     FreeMarked();
     Compact();
     return Heap;
 }
 public override MockHeap CollectGarbage(MockHeap h)
 {
     MockHeap Heap = h;
     for (int i = 0; i < Heap.Length; i++)
         for (int j = 0; j < Heap.Length; j++)
             if (Heap.Storage[i, j] != null)
                 if (Heap.IsDead(i, j))
                     Heap.Dispose(i, j);
     return Heap;
 }
Exemplo n.º 3
0
        public override MockHeap CollectGarbage(MockHeap h)
        {
            this.Heap = h;
            Mark();
            FreeMarked();
            Console.WriteLine("HEAP TO BE RETURNED");
            PrintToConsole();

            return Heap;
        }
Exemplo n.º 4
0
        public static void Do(MockHeap heap)
        {
            Console.WriteLine("MUTATOR IN WORK");
            for (int i = 0; i < heap.Length; i++)
                for (int j = 0; j < heap.Length; j++) { 
                    if (heap.Storage[i, j] != null && !heap.Storage[i, j].IsDead())
                        heap.Storage[i, j].ActiveReferences--;

                    /*
                    if (heap.Storage[i, j] != null && heap.Storage[i, j].IsDead())
                    {
                        heap.Storage[i, j] = null;
                    }
                    */
                }
        }
Exemplo n.º 5
0
        public void Compact()
        {
            MockHeap mh = new MockHeap(Heap.Length);

            Stack<MockObject> mockObjectStack = new Stack<MockObject>();
            for (int i = 0; i < Heap.Length; i++)
                for (int j = 0; j < Heap.Length; j++)
                    if (Heap.Storage[i, j] != null)
                        mockObjectStack.Push(Heap.Storage[i, j]);
            Heap = new MockHeap(Heap.Length);
            while (mockObjectStack.Count > 0)
            {
                MockObject mockObject = mockObjectStack.Pop();
                Heap.Add(mockObject);
            }
        }
Exemplo n.º 6
0
 public virtual MockHeap CollectGarbage(MockHeap h)
 {
     Heap = h;
     return Heap;
 }
Exemplo n.º 7
0
        public void MakeSimulation()
        {
            Stopwatch mutatorStopwatch = new Stopwatch();
            TimeSpan mutatorTime = new TimeSpan(0, 0, 0);
            Stopwatch collectorStopwatch = new Stopwatch();
            TimeSpan collectorTime = new TimeSpan(0, 0, 0);
            TimeSpan totalTime = new TimeSpan(0, 0, 0);

            int m = 0;
            int s = 0;
            int ms = 0;

            collectorTime = new TimeSpan(0, 0, m, s, ms);

            collectorWorkTime.Text = String.Format("{0}:{1}:{2}",
                collectorTime.Minutes, collectorTime.Seconds, collectorTime.Milliseconds);

            GarbageCollector collector = new GarbageCollector();

            if (radioButton.IsChecked == true)
                collector = new MarkSweepCollector();
            if (radioButton1.IsChecked == true)
                collector = new CopyingCollector();
            if (radioButton2.IsChecked == true)
                collector = new ReferenceCountingCollector();

            heap = new MockHeap(dimension);

            int objsCount = objectsAmount;

            // mutator stopwatch
            mutatorStopwatch.Start();

            MockObject mo = null;
            MarkSweepCollector msc = new MarkSweepCollector();
            do
            {
                if (objsCount != 0)
                {
                    int i = 0;
                    while (i < 5)
                    {
                        mo = new MockObject(objsCount);
                        objsCount--;
                        heap = AllocateObject(mo, heap);
                        i++;
                        Thread.Sleep(50);
                        ReDraw();
                        objectsInMemory.Text = "" + heap.ObjectsInMemory();
                        PrintToConsole();
                    }
                }
                heap = MutateHeap(heap);
                PrintToConsole();

                // mutaotr time stop
                mutatorStopwatch.Stop();
                m = mutatorStopwatch.Elapsed.Minutes + mutatorTime.Minutes;
                s = mutatorStopwatch.Elapsed.Seconds + mutatorTime.Seconds;
                ms = mutatorStopwatch.Elapsed.Milliseconds + mutatorTime.Milliseconds;

                mutatorTime = new TimeSpan(0, 0, m, s, ms);

                mutatorWorkTime.Text = String.Format("{0}:{1}:{2}", m, s, ms);
                // total time stop
                m = totalTime.Minutes + mutatorStopwatch.Elapsed.Minutes;
                s = totalTime.Seconds + mutatorStopwatch.Elapsed.Seconds;
                ms = totalTime.Milliseconds + mutatorStopwatch.Elapsed.Milliseconds;

                totalTime = new TimeSpan(0, 0, m, s, ms);

                totalWorkTime.Text = String.Format("{0}:{1}:{2}", m, s, ms);

                collectorStopwatch.Start();
                heap = collector.CollectGarbage(heap);

                // collector time stop
                collectorStopwatch.Stop();
                m = collectorStopwatch.Elapsed.Minutes + collectorTime.Minutes;
                s = collectorStopwatch.Elapsed.Seconds + collectorTime.Seconds;
                ms = collectorStopwatch.Elapsed.Milliseconds + collectorTime.Milliseconds;

                collectorTime = new TimeSpan(0, 0, m, s, ms);

                collectorWorkTime.Text = String.Format("{0}:{1}:{2}",
                    collectorTime.Minutes, collectorTime.Seconds, collectorTime.Milliseconds);

                // total time stop
                m = totalTime.Minutes + collectorStopwatch.Elapsed.Minutes;
                s = totalTime.Seconds + collectorStopwatch.Elapsed.Seconds;
                ms = totalTime.Milliseconds + collectorStopwatch.Elapsed.Milliseconds;

                totalTime = new TimeSpan(0, 0, m, s, ms);

                totalWorkTime.Text = String.Format("{0}:{1}:{2}", m, s, ms);


                PrintToConsole();
                ReDraw();
                objectsInMemory.Text = "" + heap.ObjectsInMemory();

            } while (!heap.IsEmpty());

            collctorSimulationTime = collectorTime;
        }
Exemplo n.º 8
0
 public MockHeap MutateHeap(MockHeap h)
 {
     if (!h.IsEmpty())
         Mutator.Do(h);
     return h;
 }
Exemplo n.º 9
0
 public MockHeap AllocateObject(MockObject o, MockHeap h)
 {
     h.Allocate(o);
     return h;
 }