[Ikvm-commit] ikvm/runtime/openjdk sun.misc.cs,1.9,1.10
Brought to you by:
jfrijters
|
From: Jeroen F. <jfr...@us...> - 2014-11-17 11:21:22
|
Update of /cvsroot/ikvm/ikvm/runtime/openjdk In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv16821 Modified Files: sun.misc.cs Log Message: Added (conditionally compiled) statistics for some Unsafe operations (that aren't intrinsified). Index: sun.misc.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/runtime/openjdk/sun.misc.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** sun.misc.cs 17 Nov 2014 09:24:15 -0000 1.9 --- sun.misc.cs 17 Nov 2014 11:21:20 -0000 1.10 *************** *** 307,310 **** --- 307,311 ---- public static short ReadInt16(object obj, long offset) { + Stats.Log("ReadInt16"); CheckArrayBounds(obj, offset, 2); GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Pinned); *************** *** 317,320 **** --- 318,322 ---- public static int ReadInt32(object obj, long offset) { + Stats.Log("ReadInt32"); CheckArrayBounds(obj, offset, 4); GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Pinned); *************** *** 327,330 **** --- 329,333 ---- public static long ReadInt64(object obj, long offset) { + Stats.Log("ReadInt64"); CheckArrayBounds(obj, offset, 8); GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Pinned); *************** *** 337,340 **** --- 340,344 ---- public static void WriteInt16(object obj, long offset, short value) { + Stats.Log("WriteInt16"); CheckArrayBounds(obj, offset, 2); GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Pinned); *************** *** 346,349 **** --- 350,354 ---- public static void WriteInt32(object obj, long offset, int value) { + Stats.Log("WriteInt32"); CheckArrayBounds(obj, offset, 4); GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Pinned); *************** *** 355,358 **** --- 360,364 ---- public static void WriteInt64(object obj, long offset, long value) { + Stats.Log("WriteInt64"); CheckArrayBounds(obj, offset, 8); GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Pinned); *************** *** 449,456 **** --- 455,464 ---- if (array != null && (offset & 3) == 0) { + Stats.Log("compareAndSwapInt.array"); return Interlocked.CompareExchange(ref array[offset / 4], update, expect) == expect; } else if (obj is Array) { + Stats.Log("compareAndSwapInt.unaligned"); // unaligned or not the right array type, so we can't be atomic lock (thisUnsafe) *************** *** 471,474 **** --- 479,483 ---- cacheCompareExchangeInt32[offset] = (CompareExchangeInt32)CreateCompareExchange(offset); } + Stats.Log("compareAndSwapInt.", offset); return cacheCompareExchangeInt32[offset](obj, update, expect) == expect; } *************** *** 484,491 **** --- 493,502 ---- if (array != null && (offset & 7) == 0) { + Stats.Log("compareAndSwapLong.array"); return Interlocked.CompareExchange(ref array[offset / 8], update, expect) == expect; } else if (obj is Array) { + Stats.Log("compareAndSwapLong.unaligned"); // unaligned or not the right array type, so we can't be atomic lock (thisUnsafe) *************** *** 506,509 **** --- 517,521 ---- cacheCompareExchangeInt64[offset] = (CompareExchangeInt64)CreateCompareExchange(offset); } + Stats.Log("compareAndSwapLong.", offset); return cacheCompareExchangeInt64[offset](obj, update, expect) == expect; } *************** *** 562,569 **** --- 574,583 ---- if (array != null) { + Stats.Log("compareAndSwapObject.array"); return Atomic.CompareExchange(array, (int)offset, update, expect) == expect; } else { + Stats.Log("compareAndSwapObject.", offset); FieldInfo field = FieldWrapper.FromField(sun.misc.Unsafe.getField(offset)).GetField(); return Atomic.CompareExchange(obj, new FieldInfo[] { field }, update, expect) == expect; *************** *** 619,622 **** --- 633,684 ---- } } + + static class Stats + { + #if !FIRST_PASS && UNSAFE_STATISTICS + private static readonly Dictionary<string, int> dict = new Dictionary<string, int>(); + + static Stats() + { + java.lang.Runtime.getRuntime().addShutdownHook(new DumpStats()); + } + + sealed class DumpStats : java.lang.Thread + { + public override void run() + { + List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>(dict); + list.Sort(delegate(KeyValuePair<string, int> kv1, KeyValuePair<string, int> kv2) { return kv1.Value.CompareTo(kv2.Value); }); + foreach (KeyValuePair<string, int> kv in list) + { + Console.WriteLine("{0,10}: {1}", kv.Value, kv.Key); + } + } + } + #endif + + [Conditional("UNSAFE_STATISTICS")] + internal static void Log(string key) + { + #if !FIRST_PASS && UNSAFE_STATISTICS + lock (dict) + { + int count; + dict.TryGetValue(key, out count); + dict[key] = count + 1; + } + #endif + } + + [Conditional("UNSAFE_STATISTICS")] + internal static void Log(string key, long offset) + { + #if !FIRST_PASS && UNSAFE_STATISTICS + FieldWrapper field = FieldWrapper.FromField(sun.misc.Unsafe.getField(offset)); + key += field.DeclaringType.Name + "::" + field.Name; + Log(key); + #endif + } + } } |