Reorder fields to improve object layout since the runtime can't do it for corlib...
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 23 May 2011 04:11:44 +0000 (01:11 -0300)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 23 May 2011 04:13:09 +0000 (01:13 -0300)
17 files changed:
mcs/class/corlib/Mono.Globalization.Unicode/SimpleCollator.cs
mcs/class/corlib/Mono.Globalization.Unicode/SortKey.cs
mcs/class/corlib/Mono.Globalization.Unicode/SortKeyBuffer.cs
mcs/class/corlib/System.Collections.Generic/Dictionary.cs
mcs/class/corlib/System.Collections/ArrayList.cs
mcs/class/corlib/System.Collections/Hashtable.cs
mcs/class/corlib/System.Collections/SortedList.cs
mcs/class/corlib/System.IO/BinaryWriter.cs
mcs/class/corlib/System.IO/FileStream.cs
mcs/class/corlib/System.IO/StreamReader.cs
mcs/class/corlib/System.IO/StreamWriter.cs
mcs/class/corlib/System.Text/Encoding.cs
mcs/class/corlib/System.Threading/ReaderWriterLock.cs
mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs
mcs/class/corlib/System/ActivationContext.cs
mcs/class/corlib/System/Lazy.cs
mcs/class/corlib/System/NumberFormatter.cs

index 7bbb0d30b8af89a2e34d7ae4eaac3d588661c828..65228b4da62be90dd0846843c52cd90bd3cac62d 100644 (file)
@@ -139,20 +139,21 @@ namespace Mono.Globalization.Unicode
                        new SimpleCollator (CultureInfo.InvariantCulture);
 
                readonly TextInfo textInfo; // for ToLower().
-               readonly bool frenchSort;
-               unsafe readonly byte* cjkCatTable;
-               unsafe readonly byte* cjkLv1Table;
                readonly CodePointIndexer cjkIndexer;
-               unsafe readonly byte* cjkLv2Table;
-               readonly CodePointIndexer cjkLv2Indexer;
-               readonly int lcid;
                readonly Contraction [] contractions;
                readonly Level2Map [] level2Maps;
-
                // This flag marks characters as "unsafe", where the character
                // could be used as part of a contraction (whose length > 1).
                readonly byte [] unsafeFlags;
 
+               unsafe readonly byte* cjkCatTable;
+               unsafe readonly byte* cjkLv1Table;
+               unsafe readonly byte* cjkLv2Table;
+               readonly CodePointIndexer cjkLv2Indexer;
+               readonly int lcid;
+               readonly bool frenchSort;
+
+
                const int UnsafeFlagLength = 0x300 / 8;
 
 //             readonly byte [] contractionFlags = new byte [16];
index dfabbf98af58a4ffa8a37bf9c7ef07bf262e99d5..0fd90684af3a941d861be2f185b8a0438152e6af 100644 (file)
@@ -65,8 +65,8 @@ namespace System.Globalization
                #endregion
 
                readonly string source;
-               readonly CompareOptions options;
                readonly byte [] key;
+               readonly CompareOptions options;
                readonly int lcid;
 
                // for legacy unmanaged one
index 258e6bd348aa1db1b343079e86c20da002566899..61e909aa1d97f15ca49ce1134e0f70ad909265b9 100644 (file)
@@ -37,16 +37,16 @@ namespace Mono.Globalization.Unicode
        {
                // l4s = small kana sensitivity, l4t = mark type,
                // l4k = katakana flag, l4w = kana width sensitivity
-               int l1, l2, l3, l4s, l4t, l4k, l4w, l5;
                byte [] l1b, l2b, l3b, l4sb, l4tb, l4kb, l4wb, l5b;
 //             int level5LastPos;
 
                string source;
+               int l1, l2, l3, l4s, l4t, l4k, l4w, l5;
+               int lcid;
+               CompareOptions options;
                bool processLevel2;
                bool frenchSort;
                bool frenchSorted;
-               int lcid;
-               CompareOptions options;
 
                public SortKeyBuffer (int lcid)
                {
index 65d88dbde3731eb7fb3943b8ab443a97d3562399..4290ba12a6c14a7eeb6c246ded207c80b1d43573 100644 (file)
@@ -100,6 +100,10 @@ namespace System.Collections.Generic {
                TKey [] keySlots;
                TValue [] valueSlots;
 
+               //Leave those 2 fields here to improve heap layout.
+               IEqualityComparer<TKey> hcp;
+               SerializationInfo serialization_info;
+
                // The number of slots in "linkSlots" and "keySlots"/"valueSlots" that
                // are in use (i.e. filled with data) or have been used and marked as
                // "empty" later on.
@@ -118,9 +122,6 @@ namespace System.Collections.Generic {
                // resizing the hash table and the slots arrays.
                int threshold;
 
-               IEqualityComparer<TKey> hcp;
-               SerializationInfo serialization_info;
-
                // The number of changes made to this dictionary. Used by enumerators
                // to detect changes and invalidate themselves.
                int generation;
index edffa3a4de553fe268b6d790ec70ad93bb18d4ad..0a67c6a2c830e103b621716de866a21453f744e7 100644 (file)
@@ -44,11 +44,11 @@ namespace System.Collections
                private sealed class ArrayListEnumerator
                        : IEnumerator, ICloneable 
                {                       
+                       private object m_Current;
+                       private ArrayList m_List;
                        private int m_Pos;
                        private int m_Index;
                        private int m_Count;
-                       private object m_Current;
-                       private ArrayList m_List;
                        private int m_ExpectedStateChanges;
 
                        public ArrayListEnumerator(ArrayList list)
@@ -112,9 +112,9 @@ namespace System.Collections
                sealed class SimpleEnumerator : IEnumerator, ICloneable
                {
                        ArrayList list;
+                       object currentElement;
                        int index;
                        int version;
-                       object currentElement;
                        static object endFlag = new object ();
                                                        
                        public SimpleEnumerator (ArrayList list)
@@ -2494,17 +2494,17 @@ namespace System.Collections
                #region Fields
 
                private const int DefaultInitialCapacity = 4;
-               
-               /// <summary>
-               /// Number of items in the list.
-               /// </summary>
-               private int _size;
 
                /// <summary>
                /// Array to store the items.
                /// </summary>
                private object[] _items;
-               
+                               
+               /// <summary>
+               /// Number of items in the list.
+               /// </summary>
+               private int _size;
+
                /// <summary>
                /// Total number of state changes.
                /// </summary>
index 9e297fef6d12d84cc922b85c56f4871cf3c603fd..ddb8d3fc9d0ddf1724a35e68ee47a33fc8f3ca21 100644 (file)
@@ -78,25 +78,22 @@ namespace System.Collections {
                const int CHAIN_MARKER  = ~Int32.MaxValue;
 
 
-               private int inUse;
-               private int modificationCount;
-               private float loadFactor;
                private Slot [] table;
                // Hashcodes of the corresponding entries in the slot table. Kept separate to
                // help the GC
                private int [] hashes;
-
-               private int threshold;
-       
                private HashKeys hashKeys;
                private HashValues hashValues;
-
                private IHashCodeProvider hcpRef;
                private IComparer comparerRef;
                private SerializationInfo serializationInfo;
-
                private IEqualityComparer equalityComparer;
 
+               private int inUse;
+               private int modificationCount;
+               private float loadFactor;
+               private int threshold;
+
                private static readonly int [] primeTbl = {
                        11,
                        19,
@@ -859,14 +856,14 @@ namespace System.Collections {
                private sealed class Enumerator : IDictionaryEnumerator, IEnumerator {
 
                        private Hashtable host;
+                       private Object currentKey;
+                       private Object currentValue;
+
                        private int stamp;
                        private int pos;
                        private int size;
                        private EnumeratorMode mode;
 
-                       private Object currentKey;
-                       private Object currentValue;
-
                        private readonly static string xstr = "Hashtable.Enumerator: snapshot out of sync.";
 
                        public Enumerator (Hashtable host, EnumeratorMode mode) {
index 2eff3c5604688d6299935c36ece0e8303e87ec94..d39f7de044375ef60cd05e6a10f947cde6aa202a 100644 (file)
@@ -59,10 +59,10 @@ namespace System.Collections {
 
                private enum EnumeratorMode : int { KEY_MODE = 0, VALUE_MODE, ENTRY_MODE }
 
-               private int inUse;
-               private int modificationCount;
                private Slot[] table;
                private IComparer comparer;
+               private int inUse;
+               private int modificationCount;
                private int defaultCapacity;
 
                //
@@ -611,14 +611,14 @@ namespace System.Collections {
                private sealed class Enumerator : ICloneable, IDictionaryEnumerator, IEnumerator {
 
                        private SortedList host;
+                       private object currentKey;
+                       private object currentValue;
+
                        private int stamp;
                        private int pos;
                        private int size;
                        private EnumeratorMode mode;
 
-                       private object currentKey;
-                       private object currentValue;
-
                        bool invalid = false;
 
                        private readonly static string xstr = "SortedList.Enumerator: snapshot out of sync.";
index 00a49e6a16f891d3b94f07ee06bf409c9cdbc567..e7c92a626b169445f122a0cab8b129e88c89088b 100644 (file)
@@ -45,6 +45,8 @@ namespace System.IO {
                protected Stream OutStream;
                private Encoding m_encoding;
                private byte [] buffer;
+               byte [] stringBuffer;
+               int maxCharsPerRound;
                private bool disposed = false;
 
                protected BinaryWriter() : this (Stream.Null, Encoding.UTF8UnmarkedUnsafe) {
@@ -271,9 +273,6 @@ namespace System.IO {
 
                        OutStream.Write(BitConverterLE.GetBytes(value), 0, 4);
                }
-
-               byte [] stringBuffer;
-               int maxCharsPerRound;
                
                public virtual void Write(string value) {
 
index 86d5d59e95083cdcd507196dfcd1f0dfe64b55b9..710602814fcfa2170e69cdfd179cd3f909f250f7 100644 (file)
@@ -1129,23 +1129,25 @@ namespace System.IO
                static byte[] buf_recycle;
                static readonly object buf_recycle_lock = new object ();
 
+               private byte [] buf;                    // the buffer
+               private string name = "[Unknown]";      // name of file.
+
+               SafeFileHandle safeHandle;              // set only when using one of the
+                                                       // constructors taking SafeFileHandle
+
+               private long append_startpos;
+               IntPtr handle;                          // handle to underlying file
+
                private FileAccess access;
                private bool owner;
                private bool async;
                private bool canseek;
-               private long append_startpos;
                private bool anonymous;
+               private bool buf_dirty;                 // true if buffer has been written to
 
-               private byte [] buf;                    // the buffer
                private int buf_size;                   // capacity in bytes
                private int buf_length;                 // number of valid bytes in buffer
                private int buf_offset;                 // position of next byte
-               private bool buf_dirty;                 // true if buffer has been written to
                private long buf_start;                 // location of buffer in file
-               private string name = "[Unknown]";      // name of file.
-
-               IntPtr handle;                          // handle to underlying file
-               SafeFileHandle safeHandle;              // set only when using one of the
-                                                       // constructors taking SafeFileHandle
        }
 }
index 279922b43edb9c6eea0923df3a38070fdaf1864b..08a1e32ee3676523d0991f6e059656221755bd7e 100644 (file)
@@ -61,6 +61,11 @@ namespace System.IO {
                char [] decoded_buffer;
                static char[] decoded_buffer_recycle;
 
+               Encoding encoding;
+               Decoder decoder;
+               StringBuilder line_builder;
+               Stream base_stream;
+
                //
                // Decoded bytes in decoded_buffer.
                //
@@ -78,12 +83,7 @@ namespace System.IO {
 
                int do_checks;
                
-               Encoding encoding;
-               Decoder decoder;
-
-               Stream base_stream;
                bool mayBlock;
-               StringBuilder line_builder;
 
                private class NullStreamReader : StreamReader {
                        public override int Peek ()
index 5f25a0cf1b49157939508044eb4eaa3f896db77b..755a553f6a3fe7690a35a2c5372d38e3691781a5 100644 (file)
@@ -46,17 +46,16 @@ namespace System.IO {
 \r
                private Stream internalStream;\r
 \r
-               private bool iflush;\r
-               \r
                private const int DefaultBufferSize = 1024;\r
                private const int DefaultFileBufferSize = 4096;\r
                private const int MinimumBufferSize = 256;\r
 \r
                private byte[] byte_buf;\r
-               private int byte_pos;\r
                private char[] decode_buf;\r
+               private int byte_pos;\r
                private int decode_pos;\r
 \r
+               private bool iflush;\r
                private bool DisposedAlready;\r
                private bool preamble_done;\r
 \r
index 1034f957fb3d9c750f126ba8ed3265fc7358dbdc..346f0a25fd84f650742717e0b3c5763bd49c932f 100644 (file)
@@ -713,13 +713,13 @@ public abstract class Encoding : ICloneable
 
 #if !ECMA_COMPAT
 
-       internal string body_name;
-       internal string encoding_name;
-       internal string header_name;
        internal bool is_mail_news_display;
        internal bool is_mail_news_save;
        internal bool is_browser_save = false;
        internal bool is_browser_display = false;
+       internal string body_name;
+       internal string encoding_name;
+       internal string header_name;
        internal string web_name;
 
        // Get the mail body name for this encoding.
index ebb718cce02f0cc338a6dc47051d2ee874f8688b..2103cb89717aad1a9aa082b42d73ebc97090fdc4 100644 (file)
@@ -46,9 +46,9 @@ namespace System.Threading
                private int seq_num = 1;
                private int state;
                private int readers;
+               private int writer_lock_owner;
                private LockQueue writer_queue;
                private Hashtable reader_locks;
-               private int writer_lock_owner;
 
                public ReaderWriterLock()
                {
index 0293f44fc6327962e92c3c54a87b48089dff4431..522c78c9e4b0f86cfade4c5ec4c1d05632c79ee7 100644 (file)
@@ -43,12 +43,12 @@ namespace System.Threading
        {
                WaitHandle _waitObject;
                WaitOrTimerCallback _callback;
-               TimeSpan _timeout;
                object _state;
-               bool _executeOnlyOnce;
                WaitHandle _finalEvent;
                ManualResetEvent _cancelEvent;
+               TimeSpan _timeout;
                int _callsInProcess;
+               bool _executeOnlyOnce;
                bool _unregistered;
 
                internal RegisteredWaitHandle (WaitHandle waitObject, WaitOrTimerCallback callback, object state, TimeSpan timeout, bool executeOnlyOnce)
index 69fe1f9b1c72bbd5b78271c8a5bbea7bafb326ec..49b2aff0c2ef6408801984e06a82a7c5718b6ef2 100644 (file)
@@ -40,11 +40,12 @@ namespace System {
                        StoreBounded
                }
 
+               private ApplicationIdentity _appid;
+
                // FIXME:
         #pragma warning disable 649
                private ContextForm _form;
         #pragma warning restore 649
-               private ApplicationIdentity _appid;
                private bool _disposed;
 
                private ActivationContext (ApplicationIdentity identity)
index b7c41f996634c626e485cfbd77c172817fbe56cf..a98b7d95a6c60da53136c9d9b9ea07b6080aaf7a 100644 (file)
@@ -45,11 +45,11 @@ namespace System
        public class Lazy<T> 
        {
                T value;
-               bool inited;
-               LazyThreadSafetyMode mode;
                Func<T> factory;
                object monitor;
                Exception exception;
+               LazyThreadSafetyMode mode;
+               bool inited;
 
                public Lazy ()
                        : this (LazyThreadSafetyMode.ExecutionAndPublication)
index d4b92460394a9d1ad89c65557fa90d54f71d94ec..3188f7ec1c9189e2f40fb1072914d95ce9cb2856 100644 (file)
@@ -108,6 +108,9 @@ namespace System
 
                private NumberFormatInfo _nfi;
 
+               //part of the private stringbuffer
+               private char[] _cbuf;
+
                private bool _NaN;
                private bool _infinity;
                private bool _isCustomFormat;
@@ -542,7 +545,7 @@ namespace System
 
                #region Inner String Buffer
 
-               private char[] _cbuf;
+               //_cbuf moved to before other fields to improve layout
                private int _ind;
 
                private void ResetCharBuf (int size)