The Labs \ Source Viewer \ SSCLI \ System \ Internal

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*============================================================
  16. **
  17. ** This file exists to contain miscellaneous module-level attributes
  18. ** and other miscellaneous stuff.
  19. **
  20. **
  21. **
  22. ===========================================================*/
  23. using System.Runtime.InteropServices;
  24. using System.Runtime.CompilerServices;
  25. using System.Collections.Generic;
  26. using System.Reflection;
  27. [assembly: DefaultDependencyAttribute(LoadHint.Always)]
  28. // mscorlib would like to have its literal strings frozen if possible
  29. [assembly: System.Runtime.CompilerServices.StringFreezingAttribute()]
  30. namespace System
  31. {
  32.     static class Internal
  33.     {
  34.         // This method is purely an aid for NGen to statically deduce which
  35.         // instantiations to save in the ngen image.
  36.         // Otherwise, the JIT-compiler gets used, which is bad for working-set.
  37.         // Note that IBC can provide this information too.
  38.         // However, this helps in keeping the JIT-compiler out even for
  39.         // test scenarios which do not use IBC.
  40.         // This can be removed after V2, when we implement other schemes
  41.         // of keeping the JIT-compiler out for generic instantiations.
  42.        
  43.         static void CommonlyUsedGenericInstantiations_HACK()
  44.         {
  45.             // Make absolutely sure we include some of the most common
  46.             // instantiations here in mscorlib's ngen image.
  47.             // Note that reference type instantiations are already included
  48.             // automatically for us.
  49.            
  50.             new ArraySegment<byte>(new byte[1], 0, 0);
  51.            
  52.             new Dictionary<char, object>();
  53.             new Dictionary<Int16, IntPtr>();
  54.             new Dictionary<Int32, byte>();
  55.             new Dictionary<Int32, Int32>();
  56.             new Dictionary<Int32, object>();
  57.             new Dictionary<IntPtr, Int16>();
  58.             new Dictionary<object, char>();
  59.             new Dictionary<object, Guid>();
  60.             new Dictionary<object, Int32>();
  61.            
  62.             NullableHelper_HACK<bool>();
  63.             NullableHelper_HACK<byte>();
  64.             NullableHelper_HACK<char>();
  65.             NullableHelper_HACK<DateTime>();
  66.             NullableHelper_HACK<decimal>();
  67.             NullableHelper_HACK<double>();
  68.             NullableHelper_HACK<Guid>();
  69.             NullableHelper_HACK<Int16>();
  70.             NullableHelper_HACK<Int32>();
  71.             NullableHelper_HACK<Int64>();
  72.             NullableHelper_HACK<float>();
  73.             NullableHelper_HACK<TimeSpan>();
  74.            
  75.             new List<bool>();
  76.             new List<byte>();
  77.             new List<DateTime>();
  78.             new List<decimal>();
  79.             new List<double>();
  80.             new List<Guid>();
  81.             new List<Int16>();
  82.             new List<Int32>();
  83.             new List<Int64>();
  84.             new List<TimeSpan>();
  85.             new List<sbyte>();
  86.             new List<float>();
  87.             new List<UInt16>();
  88.             new List<UInt32>();
  89.             new List<UInt64>();
  90.             new List<KeyValuePair<object, object>>();
  91.            
  92.             RuntimeType.RuntimeTypeCache.Prejitinit_HACK();
  93.            
  94.             new CerArrayList<RuntimeMethodInfo>(0);
  95.             new CerArrayList<RuntimeConstructorInfo>(0);
  96.             new CerArrayList<RuntimePropertyInfo>(0);
  97.             new CerArrayList<RuntimeEventInfo>(0);
  98.             new CerArrayList<RuntimeFieldInfo>(0);
  99.             new CerArrayList<RuntimeType>(0);
  100.            
  101.             new KeyValuePair<char, UInt16>('\0', UInt16.MinValue);
  102.             new KeyValuePair<UInt16, double>(UInt16.MinValue, Double.MinValue);
  103.            
  104.            
  105.             SZArrayHelper_HACK<bool>(null);
  106.             SZArrayHelper_HACK<byte>(null);
  107.             SZArrayHelper_HACK<DateTime>(null);
  108.             SZArrayHelper_HACK<decimal>(null);
  109.             SZArrayHelper_HACK<double>(null);
  110.             SZArrayHelper_HACK<Guid>(null);
  111.             SZArrayHelper_HACK<Int16>(null);
  112.             SZArrayHelper_HACK<Int32>(null);
  113.             SZArrayHelper_HACK<Int64>(null);
  114.             SZArrayHelper_HACK<TimeSpan>(null);
  115.             SZArrayHelper_HACK<sbyte>(null);
  116.             SZArrayHelper_HACK<float>(null);
  117.             SZArrayHelper_HACK<UInt16>(null);
  118.             SZArrayHelper_HACK<UInt32>(null);
  119.             SZArrayHelper_HACK<UInt64>(null);
  120.            
  121.             SZArrayHelper_HACK<CustomAttributeTypedArgument>(null);
  122.             SZArrayHelper_HACK<CustomAttributeNamedArgument>(null);
  123.         }
  124.        
  125.         static T NullableHelper_HACK<T>() where T : struct
  126.         {
  127.             Nullable.Compare<T>(null, null);
  128.             Nullable.Equals<T>(null, null);
  129.             Nullable<T> nullable = new Nullable<T>();
  130.             return nullable.GetValueOrDefault();
  131.         }
  132.        
  133.         static void SZArrayHelper_HACK<T>(SZArrayHelper oSZArrayHelper)
  134.         {
  135.             // Instantiate common methods for IList implementation on Array
  136.             oSZArrayHelper.get_Count<T>();
  137.             oSZArrayHelper.get_Item<T>(0);
  138.             oSZArrayHelper.GetEnumerator<T>();
  139.         }
  140.     }
  141. }

Developer Fusion