[Ikvm-commit] ikvm/runtime DynamicTypeWrapper.cs, 1.258, 1.259 atomic.cs, 1.21, 1.22
Brought to you by:
jfrijters
|
From: Jeroen F. <jfr...@us...> - 2014-11-18 11:33:38
|
Update of /cvsroot/ikvm/ikvm/runtime In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv22811 Modified Files: DynamicTypeWrapper.cs atomic.cs Log Message: Added cache for methodinfos of interlocked methods. Index: atomic.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/runtime/atomic.cs,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** atomic.cs 5 Jul 2012 09:57:09 -0000 1.21 --- atomic.cs 18 Nov 2014 11:33:36 -0000 1.22 *************** *** 96,109 **** internal static MethodInfo MakeCompareExchange(Type type) { ! MethodInfo interlockedCompareExchange = null; ! foreach (MethodInfo m in JVM.Import(typeof(System.Threading.Interlocked)).GetMethods()) ! { ! if (m.Name == "CompareExchange" && m.IsGenericMethodDefinition) ! { ! interlockedCompareExchange = m; ! break; ! } ! } ! return interlockedCompareExchange.MakeGenericMethod(type); } --- 96,100 ---- internal static MethodInfo MakeCompareExchange(Type type) { ! return InterlockedMethods.CompareExchangeOfT.MakeGenericMethod(type); } *************** *** 134,135 **** --- 125,158 ---- } } + + static class InterlockedMethods + { + internal static readonly MethodInfo AddInt32; + internal static readonly MethodInfo CompareExchangeInt32; + internal static readonly MethodInfo CompareExchangeInt64; + internal static readonly MethodInfo CompareExchangeOfT; + internal static readonly MethodInfo ExchangeOfT; + + static InterlockedMethods() + { + Type type = JVM.Import(typeof(System.Threading.Interlocked)); + AddInt32 = type.GetMethod("Add", new Type[] { Types.Int32.MakeByRefType(), Types.Int32 }); + CompareExchangeInt32 = type.GetMethod("CompareExchange", new Type[] { Types.Int32.MakeByRefType(), Types.Int32, Types.Int32 }); + CompareExchangeInt64 = type.GetMethod("CompareExchange", new Type[] { Types.Int64.MakeByRefType(), Types.Int64, Types.Int64 }); + foreach (MethodInfo m in type.GetMethods()) + { + if (m.IsGenericMethodDefinition) + { + switch (m.Name) + { + case "CompareExchange": + CompareExchangeOfT = m; + break; + case "Exchange": + ExchangeOfT = m; + break; + } + } + } + } + } Index: DynamicTypeWrapper.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/runtime/DynamicTypeWrapper.cs,v retrieving revision 1.258 retrieving revision 1.259 diff -C2 -d -r1.258 -r1.259 *** DynamicTypeWrapper.cs 11 Nov 2014 15:37:09 -0000 1.258 --- DynamicTypeWrapper.cs 18 Nov 2014 11:33:36 -0000 1.259 *************** *** 4924,4932 **** if (fieldType == PrimitiveTypeWrapper.LONG) { ! ilGenerator.Emit(OpCodes.Call, JVM.Import(typeof(System.Threading.Interlocked)).GetMethod("CompareExchange", new Type[] { Types.Int64.MakeByRefType(), Types.Int64, Types.Int64 })); } else if (fieldType == PrimitiveTypeWrapper.INT) { ! ilGenerator.Emit(OpCodes.Call, JVM.Import(typeof(System.Threading.Interlocked)).GetMethod("CompareExchange", new Type[] { Types.Int32.MakeByRefType(), Types.Int32, Types.Int32 })); } else --- 4924,4932 ---- if (fieldType == PrimitiveTypeWrapper.LONG) { ! ilGenerator.Emit(OpCodes.Call, InterlockedMethods.CompareExchangeInt64); } else if (fieldType == PrimitiveTypeWrapper.INT) { ! ilGenerator.Emit(OpCodes.Call, InterlockedMethods.CompareExchangeInt32); } else |