Span support in VM
authorJan Kotas <jkotas@microsoft.com>
Thu, 16 Jun 2016 16:39:28 +0000 (09:39 -0700)
committerJan Kotas <jkotas@microsoft.com>
Mon, 31 Oct 2016 00:27:16 +0000 (17:27 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/cb17e332f2dc3fc4af31d017f9d09d223c4a57ed

src/coreclr/src/inc/dacvars.h
src/coreclr/src/vm/appdomain.cpp
src/coreclr/src/vm/classnames.h
src/coreclr/src/vm/jitinterface.cpp
src/coreclr/src/vm/methodtablebuilder.cpp
src/coreclr/src/vm/mscorlib.h
src/coreclr/src/vm/vars.cpp
src/coreclr/src/vm/vars.hpp

index c5de02b..0f13cff 100644 (file)
@@ -218,6 +218,10 @@ DEFINE_DACVAR(ULONG, UNKNOWN_POINTER_TYPE, dac__g_pStringClass, ::g_pStringClass
 DEFINE_DACVAR(ULONG, UNKNOWN_POINTER_TYPE, dac__g_pArrayClass, ::g_pArrayClass)
 DEFINE_DACVAR(ULONG, UNKNOWN_POINTER_TYPE, dac__g_pSZArrayHelperClass, ::g_pSZArrayHelperClass)
 DEFINE_DACVAR(ULONG, UNKNOWN_POINTER_TYPE, dac__g_pNullableClass, ::g_pNullableClass)
+#ifdef FEATURE_SPAN_OF_T
+DEFINE_DACVAR(ULONG, UNKNOWN_POINTER_TYPE, dac__g_pSpanClass, ::g_pSpanClass)
+DEFINE_DACVAR(ULONG, UNKNOWN_POINTER_TYPE, dac__g_pReadOnlySpanClass, ::g_pReadOnlySpanClass)
+#endif
 DEFINE_DACVAR(ULONG, UNKNOWN_POINTER_TYPE, dac__g_pExceptionClass, ::g_pExceptionClass)
 DEFINE_DACVAR(ULONG, UNKNOWN_POINTER_TYPE, dac__g_pThreadAbortExceptionClass, ::g_pThreadAbortExceptionClass)
 DEFINE_DACVAR(ULONG, UNKNOWN_POINTER_TYPE, dac__g_pOutOfMemoryExceptionClass, ::g_pOutOfMemoryExceptionClass)
index e8aed79..c8049bc 100644 (file)
@@ -2870,6 +2870,12 @@ void SystemDomain::LoadBaseSystemClasses()
     // the SZArrayHelper class here.
     g_pSZArrayHelperClass = MscorlibBinder::GetClass(CLASS__SZARRAYHELPER);
 
+#ifdef FEATURE_SPAN_OF_T
+    // Load Span class
+    g_pSpanClass = MscorlibBinder::GetClass(CLASS__SPAN);
+    g_pReadOnlySpanClass = MscorlibBinder::GetClass(CLASS__READONLY_SPAN);
+#endif
+
     // Load Nullable class
     g_pNullableClass = MscorlibBinder::GetClass(CLASS__NULLABLE);
 
index 949c6c4..ec5486a 100644 (file)
 #define g_ArrayClassName "System.Array"
 
 #define g_NullableName "Nullable`1"
+#ifdef FEATURE_SPAN_OF_T
+#define g_SpanName "Span`1"
+#define g_ReadOnlySpanName "ReadOnlySpan`1"
+#endif
 
 #define g_CollectionsEnumerableItfName "System.Collections.IEnumerable"
 #define g_CollectionsEnumeratorClassName "System.Collections.IEnumerator"
index 8171eb6..2771cdf 100644 (file)
@@ -2303,11 +2303,22 @@ unsigned CEEInfo::getClassGClayout (CORINFO_CLASS_HANDLE clsHnd, BYTE* gcPtrs)
 
     MethodTable* pMT = VMClsHnd.GetMethodTable();
 
-    if (pMT == g_TypedReferenceMT)
+    if (pMT->IsByRefLike())
     {
-        gcPtrs[0] = TYPE_GC_BYREF;
-        gcPtrs[1] = TYPE_GC_NONE;
-        result = 1;
+        if (pMT == g_TypedReferenceMT 
+#ifdef FEATURE_SPAN_OF_T
+            || pMT->HasSameTypeDefAs(g_pSpanClass) || pMT->HasSameTypeDefAs(g_pReadOnlySpanClass)
+#endif
+            )
+        {
+            gcPtrs[0] = TYPE_GC_BYREF;
+            gcPtrs[1] = TYPE_GC_NONE;
+            result = 1;
+        }
+        else
+        {
+            result = 0;
+        }
     }
     else if (VMClsHnd.IsNativeValueType())
     {
index 0ba9de0..48bfb54 100644 (file)
@@ -10201,15 +10201,36 @@ void MethodTableBuilder::CheckForSystemTypes()
     MethodTable * pMT = GetHalfBakedMethodTable();
     EEClass * pClass = GetHalfBakedClass();
 
-    // We can exit early for generic types - there is just one case to check for.
-    if (g_pNullableClass != NULL && bmtGenerics->HasInstantiation())
+    // We can exit early for generic types - there are just a few cases to check for.
+    if (bmtGenerics->HasInstantiation() && g_pNullableClass != NULL)
     {
+#ifdef FEATURE_SPAN_OF_T
+        _ASSERTE(g_pSpanClass != NULL);
+        _ASSERTE(g_pReadOnlySpanClass != NULL);
+
+        _ASSERTE(g_pSpanClass->IsByRefLike());
+        _ASSERTE(g_pReadOnlySpanClass->IsByRefLike());
+
+        if (GetCl() == g_pSpanClass->GetCl())
+        {
+            pMT->SetIsByRefLike();
+            return;
+        }
+
+        if (GetCl() == g_pReadOnlySpanClass->GetCl())
+        {
+            pMT->SetIsByRefLike();
+            return;
+        }
+#endif
+
         _ASSERTE(g_pNullableClass->IsNullable());
 
         // Pre-compute whether the class is a Nullable<T> so that code:Nullable::IsNullableType is efficient
         // This is useful to the performance of boxing/unboxing a Nullable
         if (GetCl() == g_pNullableClass->GetCl())
             pMT->SetIsNullable();
+
         return;
     }
 
@@ -10257,6 +10278,16 @@ void MethodTableBuilder::CheckForSystemTypes()
         {
             pMT->SetIsNullable();
         }
+#ifdef FEATURE_SPAN_OF_T
+        else if (strcmp(name, g_SpanName) == 0)
+        {
+            pMT->SetIsByRefLike();
+        }
+        else if (strcmp(name, g_ReadOnlySpanName) == 0)
+        {
+            pMT->SetIsByRefLike();
+        }
+#endif
         else if (strcmp(name, g_ArgIteratorName) == 0)
         {
             // Mark the special types that have embeded stack poitners in them
index 9d5fb2f..a51024b 100644 (file)
@@ -1054,6 +1054,11 @@ DEFINE_FIELD(NULL,                  VALUE,          Value)
 
 DEFINE_CLASS(NULLABLE,              System,                 Nullable`1)
 
+#ifdef FEATURE_SPAN_OF_T
+DEFINE_CLASS(SPAN,                  System,                 Span`1)
+DEFINE_CLASS(READONLY_SPAN,         System,                 ReadOnlySpan`1)
+#endif
+
 // Keep this in sync with System.Globalization.NumberFormatInfo
 DEFINE_CLASS_U(Globalization,       NumberFormatInfo,   NumberFormatInfo)
 DEFINE_FIELD_U(numberGroupSizes,       NumberFormatInfo,   cNumberGroup)
index e01ede1..eeef71e 100644 (file)
@@ -69,6 +69,10 @@ GPTR_IMPL(MethodTable,      g_pStringClass);
 GPTR_IMPL(MethodTable,      g_pArrayClass);
 GPTR_IMPL(MethodTable,      g_pSZArrayHelperClass);
 GPTR_IMPL(MethodTable,      g_pNullableClass);
+#ifdef FEATURE_SPAN_OF_T
+GPTR_IMPL(MethodTable,      g_pSpanClass);
+GPTR_IMPL(MethodTable,      g_pReadOnlySpanClass);
+#endif
 GPTR_IMPL(MethodTable,      g_pExceptionClass);
 GPTR_IMPL(MethodTable,      g_pThreadAbortExceptionClass);
 GPTR_IMPL(MethodTable,      g_pOutOfMemoryExceptionClass);
index 859d4c5..4c45a0a 100644 (file)
@@ -402,6 +402,10 @@ GPTR_DECL(MethodTable,      g_pStringClass);
 GPTR_DECL(MethodTable,      g_pArrayClass);
 GPTR_DECL(MethodTable,      g_pSZArrayHelperClass);
 GPTR_DECL(MethodTable,      g_pNullableClass);
+#ifdef FEATURE_SPAN_OF_T
+GPTR_DECL(MethodTable,      g_pSpanClass);
+GPTR_DECL(MethodTable,      g_pReadOnlySpanClass);
+#endif
 GPTR_DECL(MethodTable,      g_pExceptionClass);
 GPTR_DECL(MethodTable,      g_pThreadAbortExceptionClass);
 GPTR_DECL(MethodTable,      g_pOutOfMemoryExceptionClass);