Fix incorrect behavior noted while compiling large aspnet application with debug...
authorDavid Wrighton <davidwr@microsoft.com>
Sun, 12 Apr 2020 10:20:01 +0000 (03:20 -0700)
committerGitHub <noreply@github.com>
Sun, 12 Apr 2020 10:20:01 +0000 (12:20 +0200)
- Multi-thread handling of UnboxingMethodDesc was incorrect. It would result in incorrect caching of fixups to unboxing methods
- ldtoken of a static method on a valuetype should not refer to an unboxing stub

src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs
src/coreclr/src/tools/Common/JitInterface/UnboxingMethodDesc.cs
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs

index 77b3743..064327a 100644 (file)
@@ -109,7 +109,7 @@ namespace Internal.JitInterface
         [DllImport(JitSupportLibrary)]
         private extern static char* GetExceptionMessage(IntPtr obj);
 
-        private readonly UnboxingMethodDescFactory _unboxingThunkFactory;
+        private static readonly UnboxingMethodDescFactory _unboxingThunkFactory = new UnboxingMethodDescFactory();
 
         public static void Startup()
         {
@@ -125,8 +125,6 @@ namespace Internal.JitInterface
             }
 
             _unmanagedCallbacks = GetUnmanagedCallbacks(out _keepAlive);
-
-            _unboxingThunkFactory = new UnboxingMethodDescFactory();
         }
 
         public TextWriter Log
index 2710f16..b21a721 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 using System;
+using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.Diagnostics;
 using Internal.TypeSystem;
@@ -79,17 +80,22 @@ namespace Internal.JitInterface
 #endif
     }
 
-    internal class UnboxingMethodDescFactory : Dictionary<MethodDesc, UnboxingMethodDesc>
+    internal class UnboxingMethodDescFactory : ConcurrentDictionary<MethodDesc, UnboxingMethodDesc>
     {
-        public UnboxingMethodDesc GetUnboxingMethod(MethodDesc method)
+        private Func<MethodDesc, UnboxingMethodDesc> _factoryDelegate;
+        private UnboxingMethodDesc CreateUnboxingMethod(MethodDesc method)
         {
-            if (!TryGetValue(method, out UnboxingMethodDesc result))
-            {
-                result = new UnboxingMethodDesc(method, this);
-                Add(method, result);
-            }
+            return new UnboxingMethodDesc(method, this);
+        }
 
-            return result;
+        public UnboxingMethodDescFactory()
+        {
+            _factoryDelegate = CreateUnboxingMethod;
+        }
+
+        public UnboxingMethodDesc GetUnboxingMethod(MethodDesc method)
+        {
+            return GetOrAdd(method, _factoryDelegate);
         }
     }
 
index c33280e..50a9dbb 100644 (file)
@@ -1882,7 +1882,7 @@ namespace Internal.JitInterface
                             MethodDesc md = HandleToObject(pResolvedToken.hMethod);
                             TypeDesc td = HandleToObject(pResolvedToken.hClass);
 
-                            if (td.IsValueType)
+                            if ((td.IsValueType) && !md.Signature.IsStatic)
                             {
                                 md = _unboxingThunkFactory.GetUnboxingMethod(md);
                             }