Ejemplo n.º 1
0
        public static uint StartContext(string name, System.Threading.ParameterizedThreadStart entry, Context_Type type, object param)
        {
            Context context = new Context();

            context.type       = type;
            context.tid        = m_NextCID++;
            context.name       = name;
            context.stacktop   = GCImplementation.AllocNewObject(4096);
            context.esp        = (uint)SetupStack((uint *)(context.stacktop + 4000));
            context.state      = Thread_State.ALIVE;
            context.paramentry = entry;
            context.param      = param;
            if (type == Context_Type.PROCESS)
            {
                context.parent = 0;
            }
            else
            {
                context.parent = m_CurrentContext.tid;
            }
            Context ctx = m_ContextList;

            while (ctx.next != null)
            {
                ctx = ctx.next;
            }
            ctx.next = context;
            return(context.tid);
        }
Ejemplo n.º 2
0
 public static unsafe uint InternalAllocLike(uint* aDelegate)
 {
     uint xNeededSize = 1024; // 24 is needed fields for Multicast Delegate
     xNeededSize += 12;
     uint xResultAddr = GCImplementation.AllocNewObject(xNeededSize);
     byte* xResult = (byte*) xResultAddr;
     byte* xDelegateAsByte = (byte*) aDelegate;
     for (int i = 0; i < 1024; i++)
     {
         xResult[i] = xDelegateAsByte[i];
     }
     return xResultAddr;
 }
Ejemplo n.º 3
0
 public override void UpdateApp()
 {
     Kernel.canvas.DrawString("Available RAM                = " + GCImplementation.GetAvailableRAM() + "MB", Kernel.font, Kernel.BlackPen, (int)x, (int)y);
     Kernel.canvas.DrawString("Used RAM                     = " + GCImplementation.GetUsedRAM() + "B", Kernel.font, Kernel.BlackPen, (int)x, (int)(y + Kernel.font.Height));
     Kernel.canvas.DrawString("Small Allocated Object Count = " + HeapSmall.GetAllocatedObjectCount(), Kernel.font, Kernel.BlackPen, (int)x, (int)(y + 2 * Kernel.font.Height));
     Kernel.canvas.DrawString("Small Page Count             = " + RAT.GetPageCount(RAT.PageType.HeapSmall), Kernel.font, Kernel.BlackPen, (int)x, (int)(y + 3 * Kernel.font.Height));
     Kernel.canvas.DrawString("Medium Page Count            = " + RAT.GetPageCount(RAT.PageType.HeapMedium), Kernel.font, Kernel.BlackPen, (int)x, (int)(y + 4 * Kernel.font.Height));
     Kernel.canvas.DrawString("Large Page Count             = " + RAT.GetPageCount(RAT.PageType.HeapLarge), Kernel.font, Kernel.BlackPen, (int)x, (int)(y + 5 * Kernel.font.Height));
     Kernel.canvas.DrawString("RAT Page Count               = " + RAT.GetPageCount(RAT.PageType.RAT), Kernel.font, Kernel.BlackPen, (int)x, (int)(y + 6 * Kernel.font.Height));
     Kernel.canvas.DrawString("SMT Page Count               = " + RAT.GetPageCount(RAT.PageType.SMT), Kernel.font, Kernel.BlackPen, (int)x, (int)(y + 7 * Kernel.font.Height));
     Kernel.canvas.DrawString("GC Managed Page Count        = " + RAT.GetPageCount(RAT.PageType.SMT), Kernel.font, Kernel.BlackPen, (int)x, (int)(y + 8 * Kernel.font.Height));
     Kernel.canvas.DrawString("Free Count                   = " + Kernel.FreeCount, Kernel.font, Kernel.BlackPen, (int)x, (int)(y + 9 * Kernel.font.Height));
 }
Ejemplo n.º 4
0
        public static unsafe ulong MemberwiseClone([ObjectPointerAccess] uint aThis)
        {
            var xThisPointer = (uint *)aThis;
            var xSize        = ObjectUtils.FieldDataOffset + xThisPointer[2];

            var xResult = GCImplementation.AllocNewObject(xSize);

            var xThisPointerByte = (byte *)xThisPointer;
            var xThatPointerByte = (byte *)xResult;

            for (int i = 0; i < xSize; i++)
            {
                xThatPointerByte[i] = xThisPointerByte[i];
            }

            ulong xReturn = ((ulong)xResult) << (sizeof(ulong) / 2 * 8);

            return(xReturn);
        }
Ejemplo n.º 5
0
        public static unsafe ulong MemberwiseClone([ObjectPointerAccess] uint aThis)
        {
            var xThisPointer = (uint *)aThis;

            var xSize = xThisPointer[1];

            var xResult = GCImplementation.AllocNewObject(xSize);

            var xThatPointer       = (uint *)xResult;
            var xThatPointerByte   = (byte *)xThatPointer[0];
            var xThisSimplePointer = (uint *)aThis;
            var xThisPointerByte   = (byte *)xThisSimplePointer[0];

            for (int i = 0; i < xSize; i++)
            {
                xThatPointerByte[i] = xThisPointerByte[i];
            }
            return(xResult);
        }
Ejemplo n.º 6
0
        private unsafe void TestGarbageCollectorMethods()
        {
            // allocating + freeing works on gc side
            int    allocated    = HeapSmall.GetAllocatedObjectCount();
            object c            = new object();
            int    nowAllocated = HeapSmall.GetAllocatedObjectCount();

            GCImplementation.Free(c);
            int afterFree = HeapSmall.GetAllocatedObjectCount();

            Assert.AreEqual(allocated + 1, nowAllocated, "NewObj causes one object to be allocated");
            Assert.AreEqual(allocated, afterFree, "Free causes one object to be freed again");

            var testString = "asd";

            Assert.AreEqual(RAT.PageType.Empty, RAT.GetPageType(GCImplementation.GetPointer(testString)), "String is created statically and not managed by GC");

            Assert.IsTrue(Heap.Collect() >= 0, "Running GC Collect first time does not crash and returns non-negative value");
        }
Ejemplo n.º 7
0
        private void TestVTablesImpl()
        {
            object obj = new object();

            Assert.AreEqual(GCImplementation.GetType(obj), ((CosmosRuntimeType)obj.GetType()).mTypeId, "Both methods to get type id return the same value for object");

            string s = "a";

            Assert.AreEqual(GCImplementation.GetType(s), ((CosmosRuntimeType)s.GetType()).mTypeId, "Both methods to get type id return the same value for string");

            Assert.AreEqual(GCImplementation.GetType(s), ((CosmosRuntimeType)typeof(string)).mTypeId, "Methods and constato get type id return the same value for string");
            List <int> x = new List <int>();

            Assert.AreEqual(GCImplementation.GetType(x), ((CosmosRuntimeType)typeof(List <int>)).mTypeId, "Methods and constant get type id return the same value for List<int>");

            TestType tObj = new TestType();

            Assert.AreEqual(GCImplementation.GetType(tObj), ((CosmosRuntimeType)typeof(TestType)).mTypeId, "Methods and constant get type id return the same value for TestType");

            Assert.AreEqual(4, VTablesImpl.GetGCFieldCount(GCImplementation.GetType(tObj)), "TestType has 4 fields tracked by GC");

            var types = VTablesImpl.GetGCFieldTypes(GCImplementation.GetType(tObj));

            Assert.AreEqual(4, types.Length, "GetGCFieldTypes returns correct number of values");
            Assert.AreEqual(((CosmosRuntimeType)typeof(object)).mTypeId, types[0], "GetGCFieldTypes returns object at offset 0");
            Assert.AreEqual(((CosmosRuntimeType)typeof(List <int>)).mTypeId, types[1], "GetGCFieldTypes returns List<int> at offset 1");
            Assert.AreEqual(((CosmosRuntimeType)typeof(string)).mTypeId, types[2], "GetGCFieldTypes returns string at offset 2");
            Assert.AreEqual(((CosmosRuntimeType)typeof(object)).mTypeId, types[3], "GetGCFieldTypes returns object at offset 3");

            Assert.AreEqual(4, VTablesImpl.GetGCFieldOffsets(GCImplementation.GetType(tObj)).Length, "GetGCFieldOffsets returned the correct number of values");

            Assert.AreEqual(new uint[] { 12, 20, 28, 36 }, VTablesImpl.GetGCFieldOffsets(GCImplementation.GetType(tObj)), "GetGCFieldOffsets returns the correct values");

            ClassWithStruct classWithStruct = new ClassWithStruct();

            Assert.AreEqual(3, VTablesImpl.GetGCFieldCount(GCImplementation.GetType(classWithStruct)), "ClassWithStruct has 3 fields tracked by GC");
            types = VTablesImpl.GetGCFieldTypes(GCImplementation.GetType(classWithStruct));
            Assert.AreEqual(((CosmosRuntimeType)typeof(object)).mTypeId, types[0], "GetGCFieldTypes returns object at offset 0");
            Assert.AreEqual(((CosmosRuntimeType)typeof(TestStruct)).mTypeId, types[1], "GetGCFieldTypes returns TestStruct at offset 1");
            Assert.AreEqual(((CosmosRuntimeType)typeof(object)).mTypeId, types[2], "GetGCFieldTypes returns object at offset 2");
        }