Merge pull request #4938 from kumpera/optimize_ref_queries
[mono.git] / mono / tests / sgen-descriptors.cs
index ae000849cee94158d0779a3cf050a4a4b8d3da84..16f9dd305b98c311ccd3981381f4652df5b8e687 100644 (file)
@@ -1,4 +1,6 @@
 using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
 
 public struct SmallMixed
 {
@@ -47,6 +49,13 @@ public class HugePtrFree {
        public LargeStruct2 c;
 }
 
+[StructLayout (LayoutKind.Sequential)]
+public class Non32bitBitmap {
+       public object o;
+       public long i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, i34, i35;
+       public object o2;
+}
+
 /*
 This is a stress test for descriptors.
 */
@@ -54,10 +63,10 @@ class Driver {
        static char[] FOO = new char[] { 'f', 'o', 'b' };
 
        static void Fill (int cycles) {
-               object[] root = new object [12];
+               object[] root = new object [13];
                object[] current = root;
                for (int i = 0; i < cycles; ++i) {
-                       current [0] = new object [12];
+                       current [0] = new object [13];
                        current [1] = new int [6];
                        current [2] = new int [2,3];
                        current [3] = new string (FOO);
@@ -72,16 +81,34 @@ class Driver {
                                current [10] = new HugePtrFree ();
                        if ((i %  10000) == 0)
                                current [11] = new LargeStruct2 [1];
+
+                       /* Test for 64 bit bitmap descriptors (#14834) */
+                       current [12] = new Non32bitBitmap () { o = new object (), i32 = 1, i33 = 1, i34 = 1, i35 = 1, o2 = new object () };
        
                        current = (object[])current [0];
                }
        }
 
+       static unsafe void FillPtr (int cycles) {
+               var l = new List<Byte*[]> ();
+               for (int i = 0; i < cycles; ++i)
+               {
+                       var a = new Byte* [128];
+                       for (int j = 0; j < a.Length; ++j)
+                               a [j] = (Byte*) new IntPtr (j).ToPointer ();
+                       if (i < 1000)
+                               l.Add (a);
+                       else
+                               l [i % 1000] = a;
+               }
+       }
+
        static void Main () {
                int loops = 3;
                int cycles = 200000;
                for (int i = 0; i < loops; ++i) {
                        Fill (cycles);
+                       FillPtr (cycles);
                }
        }
 }