Imported Upstream version 6.6.0.89

Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-09-24 08:53:40 +00:00
parent cf815e07e0
commit 95fdb59ea6
2556 changed files with 138145 additions and 47453 deletions

View File

@@ -364,6 +364,9 @@
<!-- domain.c: mono_defaults.methodhandle_class -->
<type fullname="System.RuntimeMethodHandle" preserve="fields" />
<!-- domain.c: mono_defaults.runtimetype_class -->
<type fullname="System.RuntimeType" preserve="fields" />
<!-- domain.c: mono_defaults.typehandle_class -->
<type fullname="System.RuntimeTypeHandle" preserve="fields" />

View File

@@ -193,6 +193,18 @@ namespace Mono {
return new Tuple<String, ulong, ulong> (payload_str, portable_hash, unportable_hash);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern void RegisterReportingForNativeLib_internal (IntPtr modulePathSuffix, IntPtr moduleName);
static void RegisterReportingForNativeLib (string modulePathSuffix_str, string moduleName_str)
{
using (var modulePathSuffix_chars = RuntimeMarshal.MarshalString (modulePathSuffix_str))
using (var moduleName_chars = RuntimeMarshal.MarshalString (moduleName_str))
{
RegisterReportingForNativeLib_internal (modulePathSuffix_chars.Value, moduleName_chars.Value);
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern void EnableCrashReportLog_internal (IntPtr directory);

View File

@@ -33,20 +33,20 @@ namespace System
return length;
}
public static byte GetByte (Array array, int index)
public static unsafe byte GetByte (Array array, int index)
{
if (index < 0 || index >= ByteLength (array))
throw new ArgumentOutOfRangeException ("index");
return _GetByte (array, index);
return *(byte*)(Unsafe.AsPointer<byte> (ref Unsafe.Add<byte> (ref array.GetRawSzArrayData (), index)));
}
public static void SetByte (Array array, int index, byte value)
public static unsafe void SetByte (Array array, int index, byte value)
{
if (index < 0 || index >= ByteLength (array))
throw new ArgumentOutOfRangeException ("index");
_SetByte (array, index, value);
*(byte*)(Unsafe.AsPointer<byte> (ref Unsafe.Add<byte> (ref array.GetRawSzArrayData (), index))) = value;
}
public static void BlockCopy (Array src, int srcOffset, Array dst, int dstOffset, int count)

View File

@@ -14,19 +14,18 @@ namespace System.Globalization
using System.Threading;
using System.Diagnostics.Contracts;
internal static partial class EncodingTable
{
internal static partial class EncodingTable
{
static int GetNumEncodingItems ()
{
return encodingDataPtr.Length;
}
return encodingDataPtr.Length;
}
#region "from coreclr/src/classlibnative/nls/encodingdata.cpp"
// as of d921298
static InternalEncodingDataItem ENC (string name, ushort cp) { return new InternalEncodingDataItem () { webName = name, codePage = cp }; }
static InternalEncodingDataItem ENC (string name, ushort cp) { return new InternalEncodingDataItem () { webName = name, codePage = cp }; }
internal static InternalEncodingDataItem [] encodingDataPtr = new InternalEncodingDataItem [] {
#if FEATURE_CORECLR
// encoding name, codepage.
@@ -498,18 +497,18 @@ ENC ("x-x-big5", 950),
#endif // FEATURE_CORECLR
};
};
// Working set optimization:
// 1. code page, family code page stored as unsigned short
// 2. if web/header/body names are the same, only web name is stored; otherwise, we store "|webname|headername|bodyname"
// 3. Move flags before names to fill gap on 64-bit platforms
static InternalCodePageDataItem MapCodePageDataItem (UInt16 cp, UInt16 fcp, string names, uint flags) { return new InternalCodePageDataItem () { codePage = cp, uiFamilyCodePage = fcp, flags = flags, Names = names }; }
static InternalCodePageDataItem MapCodePageDataItem (UInt16 cp, UInt16 fcp, string names, uint flags) { return new InternalCodePageDataItem () { codePage = cp, uiFamilyCodePage = fcp, flags = flags, Names = names }; }
//
// Information about codepages.
//
internal static InternalCodePageDataItem [] codePageDataPtr = new InternalCodePageDataItem [] {
internal static InternalCodePageDataItem [] codePageDataPtr = new InternalCodePageDataItem [] {
#if FEATURE_CORECLR
// Total Items:
@@ -695,7 +694,7 @@ ENC ("x-x-big5", 950),
#region "from coreclr/src/pal/inc/rt/palrt.h"
// modified
const int
const int
//typedef
//enum tagMIMECONTF {
MIMECONTF_MAILNEWS = 0x1,
@@ -747,14 +746,15 @@ ENC ("x-x-big5", 950),
[SecurityCritical]
unsafe internal static InternalCodePageDataItem* codePageDataPtr = GetCodePageData();
*/
//
// This caches the mapping of an encoding name to a code page.
//
private static Hashtable hashByName = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase));
private static Dictionary<string, int> hashByName = new Dictionary<string, int> (StringComparer.OrdinalIgnoreCase);
//
// THe caches the data item which is indexed by the code page value.
//
private static Hashtable hashByCodePage = Hashtable.Synchronized(new Hashtable());
private static Dictionary<int, CodePageDataItem> hashByCodePage = new Dictionary<int, CodePageDataItem> ();
[System.Security.SecuritySafeCritical] // static constructors should be safe to call
static EncodingTable()
@@ -845,25 +845,25 @@ ENC ("x-x-big5", 950),
}
Contract.EndContractBlock();
Object codePageObj;
//
// The name is case-insensitive, but ToLower isn't free. Check for
// the code page in the given capitalization first.
//
codePageObj = hashByName[name];
ICollection ic = hashByName;
lock (ic.SyncRoot) {
int codePage;
if (codePageObj!=null) {
return ((int)codePageObj);
if (hashByName.TryGetValue (name, out codePage))
return codePage;
//Okay, we didn't find it in the hash table, try looking it up in the
//unmanaged data.
codePage = internalGetCodePageFromName(name);
hashByName[name] = codePage;
return codePage;
}
//Okay, we didn't find it in the hash table, try looking it up in the
//unmanaged data.
int codePage = internalGetCodePageFromName(name);
hashByName[name] = codePage;
return codePage;
}
[System.Security.SecuritySafeCritical] // auto-generated
@@ -876,29 +876,27 @@ ENC ("x-x-big5", 950),
// other than that.
//Look up the item in the hashtable.
dataItem = (CodePageDataItem)hashByCodePage[codepage];
//If we found it, return it.
if (dataItem!=null) {
return dataItem;
}
ICollection ic = hashByCodePage;
lock (ic.SyncRoot) {
if (hashByCodePage.TryGetValue (codepage, out dataItem))
return dataItem;
//If we didn't find it, try looking it up now.
//If we find it, add it to the hashtable.
//This is a linear search, but we probably won't be doing it very often.
//
int i = 0;
int data;
while ((data = codePageDataPtr[i].codePage) != 0) {
if (data == codepage) {
dataItem = new CodePageDataItem(i);
hashByCodePage[codepage] = dataItem;
return (dataItem);
//If we didn't find it, try looking it up now.
//If we find it, add it to the hashtable.
//This is a linear search, but we probably won't be doing it very often.
//
int i = 0;
int data;
while ((data = codePageDataPtr[i].codePage) != 0) {
if (data == codepage) {
dataItem = new CodePageDataItem(i);
hashByCodePage[codepage] = dataItem;
return (dataItem);
}
i++;
}
i++;
}
//Nope, we didn't find it.
return null;
}

View File

@@ -433,6 +433,21 @@ namespace System.IO
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static bool Cancel_internal (IntPtr handle, out MonoIOError error);
internal static bool Cancel (SafeHandle safeHandle, out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return Cancel_internal (safeHandle.DangerousGetHandle (), out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static bool Close (IntPtr handle,
out MonoIOError error);

View File

@@ -75,8 +75,8 @@ namespace System.IO
ERROR_SHARING_BUFFER_EXCEEDED = 36,
ERROR_HANDLE_EOF = 38,
*/ ERROR_HANDLE_DISK_FULL = 39,
/* ERROR_NOT_SUPPORTED = 50,
ERROR_REM_NOT_LIST = 51,
ERROR_NOT_SUPPORTED = 50,
/* ERROR_REM_NOT_LIST = 51,
ERROR_DUP_NAME = 52,
ERROR_BAD_NETPATH = 53,
ERROR_NETWORK_BUSY = 54,

View File

@@ -30,6 +30,10 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if FULL_AOT_INTERP && DISABLE_COM
#define FULL_AOT_RUNTIME
#endif
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
@@ -62,7 +66,7 @@ namespace System.Runtime.InteropServices
{
#if !MOBILE || WINAOT
if (pUnk == IntPtr.Zero)
throw new ArgumentException ("Value cannot be null.", "pUnk");
throw new ArgumentNullException ("pUnk");
return AddRefInternal (pUnk);
#else
throw new NotImplementedException ();
@@ -935,7 +939,7 @@ namespace System.Runtime.InteropServices
{
#if !MOBILE || WINAOT
if (pUnk == IntPtr.Zero)
throw new ArgumentException ("Value cannot be null.", "pUnk");
throw new ArgumentNullException ("pUnk");
return QueryInterfaceInternal (pUnk, ref iid, out ppv);
#else
throw new NotImplementedException ();
@@ -1108,7 +1112,7 @@ namespace System.Runtime.InteropServices
{
#if !MOBILE || WINAOT
if (pUnk == IntPtr.Zero)
throw new ArgumentException ("Value cannot be null.", "pUnk");
throw new ArgumentNullException ("pUnk");
return ReleaseInternal (pUnk);
#else

View File

@@ -53,7 +53,6 @@ namespace System.Threading {
// stores a thread handle
IntPtr handle;
IntPtr native_handle; // used only on Win32
IntPtr unused3;
/* accessed only from unmanaged code */
private IntPtr name;
private int name_len;
@@ -83,7 +82,6 @@ namespace System.Threading {
internal int managed_id;
private int small_id;
private IntPtr manage_callback;
private IntPtr unused4;
private IntPtr flags;
private IntPtr thread_pinning_ref;
private IntPtr abort_protected_block_count;
@@ -91,12 +89,12 @@ namespace System.Threading {
private IntPtr owned_mutex;
private IntPtr suspended_event;
private int self_suspended;
/*
* These fields are used to avoid having to increment corlib versions
* when a new field is added to the unmanaged MonoThread structure.
*/
private IntPtr unused1;
private IntPtr unused2;
private IntPtr thread_state;
// Unused fields to have same size as netcore.
private IntPtr netcore0;
private IntPtr netcore1;
private IntPtr netcore2;
/* This is used only to check that we are in sync between the representation
* of MonoInternalThread in native and InternalThread in managed

View File

@@ -32,36 +32,145 @@ namespace System.Threading
public
static class Volatile
{
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static bool Read (ref bool location);
#region Boolean
private struct VolatileBoolean { public volatile bool Value; }
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static byte Read (ref byte location);
[Intrinsic]
public static bool Read(ref bool location) =>
Unsafe.As<bool, VolatileBoolean>(ref location).Value;
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
[CLSCompliant (false)]
public extern static sbyte Read (ref sbyte location);
[Intrinsic]
public static void Write(ref bool location, bool value) =>
Unsafe.As<bool, VolatileBoolean>(ref location).Value = value;
#endregion
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static short Read (ref short location);
#region Byte
private struct VolatileByte { public volatile byte Value; }
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
[CLSCompliant (false)]
public extern static ushort Read (ref ushort location);
[Intrinsic]
public static byte Read(ref byte location) =>
Unsafe.As<byte, VolatileByte>(ref location).Value;
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static int Read (ref int location);
[Intrinsic]
public static void Write(ref byte location, byte value) =>
Unsafe.As<byte, VolatileByte>(ref location).Value = value;
#endregion
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
[CLSCompliant (false)]
public extern static uint Read (ref uint location);
#region Int16
private struct VolatileInt16 { public volatile short Value; }
[Intrinsic]
public static short Read(ref short location) =>
Unsafe.As<short, VolatileInt16>(ref location).Value;
[Intrinsic]
public static void Write(ref short location, short value) =>
Unsafe.As<short, VolatileInt16>(ref location).Value = value;
#endregion
#region Int32
private struct VolatileInt32 { public volatile int Value; }
[Intrinsic]
public static int Read(ref int location) =>
Unsafe.As<int, VolatileInt32>(ref location).Value;
[Intrinsic]
public static void Write(ref int location, int value) =>
Unsafe.As<int, VolatileInt32>(ref location).Value = value;
#endregion
#region IntPtr
private struct VolatileIntPtr { public volatile IntPtr Value; }
[Intrinsic]
public static IntPtr Read(ref IntPtr location) =>
Unsafe.As<IntPtr, VolatileIntPtr>(ref location).Value;
[Intrinsic]
public static void Write(ref IntPtr location, IntPtr value) =>
Unsafe.As<IntPtr, VolatileIntPtr>(ref location).Value = value;
#endregion
#region SByte
private struct VolatileSByte { public volatile sbyte Value; }
[CLSCompliant(false)]
[Intrinsic]
public static sbyte Read(ref sbyte location) =>
Unsafe.As<sbyte, VolatileSByte>(ref location).Value;
[CLSCompliant(false)]
[Intrinsic]
public static void Write(ref sbyte location, sbyte value) =>
Unsafe.As<sbyte, VolatileSByte>(ref location).Value = value;
#endregion
#region Single
private struct VolatileSingle { public volatile float Value; }
[Intrinsic]
public static float Read(ref float location) =>
Unsafe.As<float, VolatileSingle>(ref location).Value;
[Intrinsic]
public static void Write(ref float location, float value) =>
Unsafe.As<float, VolatileSingle>(ref location).Value = value;
#endregion
#region UInt16
private struct VolatileUInt16 { public volatile ushort Value; }
[CLSCompliant(false)]
[Intrinsic]
public static ushort Read(ref ushort location) =>
Unsafe.As<ushort, VolatileUInt16>(ref location).Value;
[CLSCompliant(false)]
[Intrinsic]
public static void Write(ref ushort location, ushort value) =>
Unsafe.As<ushort, VolatileUInt16>(ref location).Value = value;
#endregion
#region UInt32
private struct VolatileUInt32 { public volatile uint Value; }
[CLSCompliant(false)]
[Intrinsic]
public static uint Read(ref uint location) =>
Unsafe.As<uint, VolatileUInt32>(ref location).Value;
[CLSCompliant(false)]
[Intrinsic]
public static void Write(ref uint location, uint value) =>
Unsafe.As<uint, VolatileUInt32>(ref location).Value = value;
#endregion
#region UIntPtr
private struct VolatileUIntPtr { public volatile UIntPtr Value; }
[CLSCompliant(false)]
[Intrinsic]
public static UIntPtr Read(ref UIntPtr location) =>
Unsafe.As<UIntPtr, VolatileUIntPtr>(ref location).Value;
[CLSCompliant(false)]
[Intrinsic]
public static void Write(ref UIntPtr location, UIntPtr value) =>
Unsafe.As<UIntPtr, VolatileUIntPtr>(ref location).Value = value;
#endregion
#region T
private struct VolatileObject { public volatile object Value; }
[Intrinsic]
public static T Read<T>(ref T location) where T : class =>
Unsafe.As<T>(Unsafe.As<T, VolatileObject>(ref location).Value);
[Intrinsic]
public static void Write<T>(ref T location, T value) where T : class =>
Unsafe.As<T, VolatileObject>(ref location).Value = value;
#endregion
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
@@ -72,58 +181,10 @@ namespace System.Threading
[CLSCompliant (false)]
public extern static ulong Read (ref ulong location);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static IntPtr Read (ref IntPtr location);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
[CLSCompliant (false)]
public extern static UIntPtr Read (ref UIntPtr location);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static double Read (ref double location);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static float Read (ref float location);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static T Read<T> (ref T location) where T : class;
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static void Write (ref bool location, bool value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static void Write (ref byte location, byte value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
[CLSCompliant (false)]
public extern static void Write (ref sbyte location, sbyte value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static void Write (ref short location, short value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
[CLSCompliant (false)]
public extern static void Write (ref ushort location, ushort value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static void Write (ref int location, int value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
[CLSCompliant (false)]
public extern static void Write (ref uint location, uint value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static void Write (ref long location, long value);
@@ -133,25 +194,8 @@ namespace System.Threading
[CLSCompliant (false)]
public extern static void Write (ref ulong location, ulong value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static void Write (ref IntPtr location, IntPtr value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
[CLSCompliant (false)]
public extern static void Write (ref UIntPtr location, UIntPtr value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static void Write (ref double location, double value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static void Write (ref float location, float value);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
public extern static void Write<T>(ref T location, T value) where T : class;
}
}

View File

@@ -920,22 +920,23 @@ namespace System {
[SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode=true)]
public static void FailFast (string message)
{
throw new NotImplementedException ();
FailFast (message, null, null);
}
internal static void FailFast (String message, uint exitCode)
{
throw new NotImplementedException ();
FailFast (message, null, null);
}
[SecurityCritical]
public static void FailFast (string message, Exception exception)
{
#pragma warning disable 618
throw new ExecutionEngineException (message, exception);
#pragma warning restore
FailFast (message, exception, null);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern static void FailFast (string message, Exception exception, string errorSource);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
extern static bool GetIs64BitOperatingSystem ();

View File

@@ -629,7 +629,7 @@ namespace System
return bmethod.GetParameters ()[parinfo.Position];
}
}
/**
/*
* ParameterInfo -> null
* Assembly -> null
* RuntimeEventInfo -> null

View File

@@ -38,6 +38,7 @@ namespace Mono
MONO_NATIVE_PLATFORM_TYPE_AIX = 4,
MONO_NATIVE_PLATFORM_TYPE_ANDROID = 5,
MONO_NATIVE_PLATFORM_TYPE_FREEBSD = 6,
MONO_NATIVE_PLATFORM_TYPE_HAIKU = 7,
MONO_NATIVE_PLATFORM_TYPE_IPHONE = 0x100,
MONO_NATIVE_PLATFORM_TYPE_TV = 0x200,

View File

@@ -29,9 +29,11 @@
using System;
using System.Threading;
using NUnit.Framework;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Collections.Generic;
namespace MonoTests.System.Threading
{
@@ -496,33 +498,102 @@ namespace MonoTests.System.Threading
}
}
[Test] // https://github.com/mono/mono/issues/12421
public void EnsurePostIsNotCalled ()
[Test] // https://github.com/mono/mono/issues/16759
[Category("NotWasm")]
public void EnsureCanceledContinuationsAreOnSameThread ()
{
SynchronizationContext mainContext = SynchronizationContext.Current;
var asc = new AssertSyncContext ();
SynchronizationContext.SetSynchronizationContext (asc);
var ct = new CancellationTokenSource ();
var tcs = new TaskCompletionSource<bool> ();
ct.Token.Register (() => tcs.TrySetCanceled ());
AsyncPump.Run(async delegate {
var _tcs = new TaskCompletionSource<bool>();
var _cts = new CancellationTokenSource();
bool taskIsCancelled = false;
Action awaitAction = async () => {
try { await tcs.Task; }
catch (OperationCanceledException) {
taskIsCancelled = true;
}
};
awaitAction ();
ct.Cancel (); // should not trigger SynchronizationContext.Post
Assert.IsTrue (taskIsCancelled);
SynchronizationContext.SetSynchronizationContext (mainContext);
var curThreadId = Thread.CurrentThread.ManagedThreadId;
var taskThreadId = 0;
var taskIsCancelled = false;
var task = Task.Run(() =>
{
taskThreadId = Thread.CurrentThread.ManagedThreadId;
_cts.Cancel();
});
_cts.Token.Register(() => _tcs.TrySetCanceled());
try
{
await _tcs.Task;
}
catch (OperationCanceledException)
{
// Continuation should run on the same thread before the task started.
Assert.AreEqual(curThreadId, Thread.CurrentThread.ManagedThreadId, "#1");
taskIsCancelled = true;
}
Assert.IsTrue (taskIsCancelled, "#2");
Assert.AreNotEqual(taskThreadId, curThreadId, "#3");
});
}
class AssertSyncContext : SynchronizationContext
public static class AsyncPump
{
public override void Post (SendOrPostCallback d, object state) =>
throw new InvalidOperationException ("SynchronizationContext.Post was not expected.");
/// <summary>Runs the specified asynchronous function.</summary>
/// <param name="func">The asynchronous function to execute.</param>
public static void Run(Func<Task> func)
{
if (func == null) throw new ArgumentNullException("func");
var prevCtx = SynchronizationContext.Current;
try
{
// Establish the new context
var syncCtx = new SingleThreadSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(syncCtx);
// Invoke the function and alert the context to when it completes
var t = func();
if (t == null) throw new InvalidOperationException("No task provided.");
t.ContinueWith(delegate { syncCtx.Complete(); }, TaskScheduler.Default);
// Pump continuations and propagate any exceptions
syncCtx.RunOnCurrentThread();
t.GetAwaiter().GetResult();
}
finally { SynchronizationContext.SetSynchronizationContext(prevCtx); }
}
/// <summary>Provides a SynchronizationContext that's single-threaded.</summary>
private sealed class SingleThreadSynchronizationContext : SynchronizationContext
{
/// <summary>The queue of work items.</summary>
private readonly BlockingCollection<KeyValuePair<SendOrPostCallback, object>> m_queue =
new BlockingCollection<KeyValuePair<SendOrPostCallback, object>>();
/// <summary>The processing thread.</summary>
private readonly Thread m_thread = Thread.CurrentThread;
/// <summary>Dispatches an asynchronous message to the synchronization context.</summary>
/// <param name="d">The System.Threading.SendOrPostCallback delegate to call.</param>
/// <param name="state">The object passed to the delegate.</param>
public override void Post(SendOrPostCallback d, object state)
{
if (d == null) throw new ArgumentNullException("d");
m_queue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state));
}
/// <summary>Not supported.</summary>
public override void Send(SendOrPostCallback d, object state)
{
throw new NotSupportedException("Synchronously sending is not supported.");
}
/// <summary>Runs an loop to process all queued work items.</summary>
public void RunOnCurrentThread()
{
foreach (var workItem in m_queue.GetConsumingEnumerable())
workItem.Key(workItem.Value);
}
/// <summary>Notifies the context that no more work will arrive.</summary>
public void Complete() { m_queue.CompleteAdding(); }
}
}
}
}

View File

@@ -34,6 +34,60 @@ using NUnit.Framework;
namespace MonoTests.System {
public interface SizedObject
{
long ExpectedSize();
}
public class NoPointer : SizedObject
{
public long ExpectedSize()
{
return 2 * IntPtr.Size;
}
}
public class TwoPointer : SizedObject
{
public object field1;
public object field2;
public long ExpectedSize()
{
return 4*IntPtr.Size;
}
}
public class FourPointer : SizedObject
{
public object field1;
public object field2;
public object field3;
public object field4;
public long ExpectedSize()
{
return 6*IntPtr.Size;
}
}
public class EightPointer : SizedObject
{
public object field1;
public object field2;
public object fiedl3;
public object field4;
public object field5;
public object field6;
public object field7;
public object field8;
public long ExpectedSize()
{
return (long)(10*IntPtr.Size);
}
}
[TestFixture]
public class GCTest {
class MyFinalizeObject
@@ -71,5 +125,45 @@ namespace MonoTests.System {
Assert.IsTrue (t.Wait (5000));
}
}
[Test]
public static void TestGetBytesAllocatedForCurrentThread()
{
Func<SizedObject>[] objectAllocators = {
() => new NoPointer(),
() => new TwoPointer(),
() => new FourPointer(),
() => new EightPointer()
};
Random r = new Random();
// Methods trigger allocation when first run.
// So this code warms up allocation before measuring.
for (int i = 0; i < objectAllocators.Length; i++)
{
Console.WriteLine(objectAllocators[i]().ExpectedSize());
}
Console.WriteLine(r.Next(1, 10));
Assert.AreEqual(1L, 1L);
// End warmup
long expectedSize = 0;
long bytesBeforeAlloc = GC.GetAllocatedBytesForCurrentThread();
for (int i = 0; i < 10000000; i++)
{
expectedSize += objectAllocators[r.Next(0, objectAllocators.Length) ]().ExpectedSize();
}
long bytesAfterAlloc = GC.GetAllocatedBytesForCurrentThread();
Assert.AreEqual(expectedSize, bytesAfterAlloc - bytesBeforeAlloc);
}
}
}

View File

@@ -1 +1 @@
4764f928a33575be51d28de55b54259c83148390
cfe087d7016cf448a122fee6dfccd92e7bae902c

View File

@@ -3,7 +3,7 @@ using System.Reflection;
namespace System {
partial class Type {
public static Type GetTypeFromCLSID (Guid clsid, string server, bool throwOnError) => RuntimeType.GetTypeFromCLSIDImpl (clsid, server, throwOnError);
public static Type GetTypeFromProgID (string progID, string server, bool throwOnError) => RuntimeType.GetTypeFromProgID (progID, server, throwOnError);
public static Type GetTypeFromProgID (string progID, string server, bool throwOnError) => RuntimeType.GetTypeFromProgIDImpl (progID, server, throwOnError);
internal const string DefaultTypeNameWhenMissingMetadata = "UnknownType";

View File

@@ -0,0 +1,2 @@
#include winaot_corlib.dll.exclude.sources
#include testing_aot_common_corlib.dll.exclude.sources

View File

@@ -0,0 +1,2 @@
#include winaot_corlib.dll.sources
#include testing_aot_common_corlib.dll.sources

View File

@@ -0,0 +1,3 @@
#include winaot_corlib_test.dll.exclude.sources
System.Reflection.Emit/AssemblyBuilderTest.cs

View File

@@ -0,0 +1 @@
#include winaot_corlib_test.dll.sources