Example #1
0
        public void TestMultiDimensionaldArray()
        {
            var heap = new Heap();

            var array1 = heap.AllocateArray(new StackValue[] { StackValue.BuildInt(0) });
            var array2 = heap.AllocateArray(new StackValue[] { array1 });
            var array3 = heap.AllocateArray(new StackValue[] { array2 });

            heap.GCMarkAndSweep(new List<StackValue>() {}, testExecutive);

            Assert.IsNull(heap.ToHeapObject<DSArray>(array1));
            Assert.IsNull(heap.ToHeapObject<DSArray>(array2));
            Assert.IsNull(heap.ToHeapObject<DSArray>(array3));
        }
Example #2
0
        public void TestBasic()
        {
            var heap = new Heap();
            var values = new StackValue[]
            {
                StackValue.BuildInt(0),
                StackValue.BuildInt(1),
                StackValue.BuildInt(2)
            };

            var array = heap.AllocateArray(values);
            var str = heap.AllocateString("hello world");

            heap.GCMarkAndSweep(new List<StackValue>(), testExecutive);
            Assert.IsNull(heap.ToHeapObject<DSArray>(array));
            Assert.IsNull(heap.ToHeapObject<DSArray>(str));
        }
Example #3
0
        public void TestBasic()
        {
            var heap = new Heap();
            var values = new StackValue[]
            {
                StackValue.BuildInt(0),
                StackValue.BuildInt(1),
                StackValue.BuildInt(2)
            };

            var array = heap.AllocateArray(values);
            var str = heap.AllocateString("hello world");

            heap.GCMarkAndSweep(new List<StackValue>(), testExecutive);

            HeapElement arrayHeapElement;
            Assert.IsFalse(heap.TryGetHeapElement(array, out arrayHeapElement));

            HeapElement strHeapElement;
            Assert.IsFalse(heap.TryGetHeapElement(str, out strHeapElement));
        }
Example #4
0
        public void TestNonPointers01()
        {
            var heap = new Heap();
            var values = new StackValue[]
            {
                StackValue.BuildInt(0),
                StackValue.BuildInt(1),
                StackValue.BuildInt(2)
            };

            var array1 = heap.AllocateArray(values);

            var allTypes = new List<StackValue>();
            var rawPointer = (int)array1.RawIntValue;
            for (int i = 0; i < (int)AddressType.ArrayKey; ++i)
            {
                var val = new StackValue()
                {
                    optype = (AddressType)i, 
                    opdata = rawPointer
                };

                if (!val.IsReferenceType)
                {
                    allTypes.Add(val);
                }
            }
            var array2 = heap.AllocateArray(allTypes.ToArray());

            heap.GCMarkAndSweep(new List<StackValue>() { array1}, testExecutive);

            HeapElement arrayHeapElement;
            Assert.IsTrue(heap.TryGetHeapElement(array1, out arrayHeapElement));

            heap.Free();
        }
Example #5
0
        public void TestCircularReference()
        {
            var heap = new Heap();
            var array1 = heap.AllocateArray(new StackValue[] { StackValue.Null });
            var array2 = heap.AllocateArray(new StackValue[] { array1 });
            var array1HeapElement = heap.GetHeapElement(array1);
            // self reference
            array1HeapElement.Stack[0] = array2;

            heap.GCMarkAndSweep(new List<StackValue>() { }, testExecutive);

            HeapElement array1Hpe;
            Assert.IsFalse(heap.TryGetHeapElement(array1, out array1Hpe));

            HeapElement array2Hpe;
            Assert.IsFalse(heap.TryGetHeapElement(array2, out array2Hpe));
        }
Example #6
0
        public void TestSelfReference()
        {
            var heap = new Heap();
            var array = heap.AllocateArray(new StackValue[] { StackValue.Null });
            var arrayHeapElement = heap.GetHeapElement(array);
            // self reference
            arrayHeapElement.Stack[0] = array;

            heap.GCMarkAndSweep(new List<StackValue>() {}, testExecutive);

            HeapElement releasedHeapElement;
            Assert.IsFalse(heap.TryGetHeapElement(array, out releasedHeapElement));
        }
Example #7
0
        public void TestDictionary()
        {
            var heap = new Heap();

            var key = heap.AllocateArray(new StackValue[] { StackValue.BuildInt(42) });
            var val = heap.AllocateString("Hello world");
            var dict = new Dictionary<StackValue, StackValue>();
            dict[key] = val;

            var array = heap.AllocateArray(new StackValue[] { }, dict);

            heap.GCMarkAndSweep(new List<StackValue>() {}, testExecutive);

            HeapElement valHeapElement;
            Assert.IsFalse(heap.TryGetHeapElement(val, out valHeapElement));

            HeapElement arrayHeapElement;
            Assert.IsFalse(heap.TryGetHeapElement(array, out arrayHeapElement));
        }
Example #8
0
        public void TestMultiDimensionaldArray()
        {
            var heap = new Heap();

            var array1 = heap.AllocateArray(new StackValue[] { StackValue.BuildInt(0) });
            var array2 = heap.AllocateArray(new StackValue[] { array1 });
            var array3 = heap.AllocateArray(new StackValue[] { array2 });

            heap.GCMarkAndSweep(new List<StackValue>() {}, testExecutive);

            HeapElement array1HeapElement;
            Assert.IsFalse(heap.TryGetHeapElement(array1, out array1HeapElement));

            HeapElement array2HeapElement;
            Assert.IsFalse(heap.TryGetHeapElement(array2, out array2HeapElement));

            HeapElement array3HeapElement;
            Assert.IsFalse(heap.TryGetHeapElement(array3, out array3HeapElement));
        }
Example #9
0
        public void TestNonPointers02()
        {
            var heap = new Heap();
            var values = new StackValue[]
            {
                StackValue.BuildInt(0),
                StackValue.BuildInt(1),
                StackValue.BuildInt(2)
            };

            var array = heap.AllocateArray(values);

            var allTypes = new List<StackValue>();
            var rawPointer = (int)array.RawIntValue;
            for (int i = 0; i < (int)AddressType.ArrayKey; ++i)
            {
                var val = new StackValue()
                {
                    optype = (AddressType)i,
                    opdata = rawPointer
                };

                if (!val.IsReferenceType)
                {
                    allTypes.Add(val);
                }
            }

            // non pointer gc root won't retain memory
            heap.GCMarkAndSweep(allTypes, testExecutive);

            HeapElement arrayHeapElement;
            Assert.IsFalse(heap.TryGetHeapElement(array, out arrayHeapElement));

            heap.Free();
        }
Example #10
0
        public void TestCircularReference()
        {
            var heap = new Heap();
            var svArray1 = heap.AllocateArray(new StackValue[] { StackValue.Null });
            var svArray2 = heap.AllocateArray(new StackValue[] { svArray1 });
            var array1 = heap.ToHeapObject<DSArray>(svArray1);
            // self reference
            array1.SetValueForIndex(0, svArray2, null);

            heap.GCMarkAndSweep(new List<StackValue>() { }, testExecutive);
            Assert.IsNull(heap.ToHeapObject<DSArray>(svArray1));
            Assert.IsNull(heap.ToHeapObject<DSArray>(svArray2));
        }
Example #11
0
        public void TestDictionary()
        {
            var heap = new Heap();

            var key = heap.AllocateArray(new StackValue[] { StackValue.BuildInt(42) });
            var val = heap.AllocateString("Hello world");
            var dict = new Dictionary<StackValue, StackValue>();
            dict[key] = val;

            var array = heap.AllocateArray(new StackValue[] { });

            heap.GCMarkAndSweep(new List<StackValue>() {}, testExecutive);

            Assert.IsNull(heap.ToHeapObject<DSArray>(val));
            Assert.IsNull(heap.ToHeapObject<DSArray>(array));
        }