From 60c277cb4eec4bac9b4149cc345155f3b810e7da Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Wed, 31 Jul 2019 14:08:50 -0400 Subject: [PATCH] [runtime] Convert more icalls to use handles. (#15862) * [runtime] Convert Volatile to use the same approach as the netcore version, get rid of most Volatile icalls. * [runtime] Reduce the number of handles used by construct_culture (). * [runtime] Convert some icalls to handles. * Fix signature of FAMNextEvent. * [aot] Avoid aoting the gsharedvt versions of Volatile:Read/Write. * Bump API snapshot submodule * Convert Marshal:UnsafeAddrOfPinnedArrayElement to use coop handles. --- external/api-snapshot | 2 +- mcs/class/corlib/System.Threading/Volatile.cs | 358 +++++++++++++++----------- mono/metadata/filewatcher.c | 24 +- mono/metadata/filewatcher.h | 5 - mono/metadata/icall-decl.h | 1 - mono/metadata/icall-def.h | 55 ++-- mono/metadata/icall-table.h | 5 +- mono/metadata/icall.c | 15 +- mono/metadata/locales.c | 4 +- mono/metadata/marshal.c | 7 +- mono/metadata/marshal.h | 4 - mono/metadata/threads-types.h | 36 --- mono/metadata/threads.c | 80 ------ mono/mini/aot-compiler.c | 25 +- 14 files changed, 249 insertions(+), 372 deletions(-) rewrite mcs/class/corlib/System.Threading/Volatile.cs (63%) diff --git a/external/api-snapshot b/external/api-snapshot index f605f3d983b..8ffa0632f52 160000 --- a/external/api-snapshot +++ b/external/api-snapshot @@ -1 +1 @@ -Subproject commit f605f3d983b225bcff429dee166cb1375d8d4869 +Subproject commit 8ffa0632f5209c92298d718fe9a1fd8a172f3090 diff --git a/mcs/class/corlib/System.Threading/Volatile.cs b/mcs/class/corlib/System.Threading/Volatile.cs dissimilarity index 63% index 5c80d7a16c9..4049533fad4 100644 --- a/mcs/class/corlib/System.Threading/Volatile.cs +++ b/mcs/class/corlib/System.Threading/Volatile.cs @@ -1,157 +1,201 @@ -// -// Volatile.cs -// -// Authors: -// Marek Safar (marek.safar@gmail.com) -// -// Copyright 2011 Xamarin, Inc (http://www.xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System.Runtime.ConstrainedExecution; -using System.Runtime.CompilerServices; - -namespace System.Threading -{ - public - static class Volatile - { - [MethodImplAttribute (MethodImplOptions.InternalCall)] - [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] - public extern static bool Read (ref bool location); - - [MethodImplAttribute (MethodImplOptions.InternalCall)] - [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] - public extern static byte Read (ref byte location); - - [MethodImplAttribute (MethodImplOptions.InternalCall)] - [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] - [CLSCompliant (false)] - public extern static sbyte Read (ref sbyte location); - - [MethodImplAttribute (MethodImplOptions.InternalCall)] - [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] - public extern static short Read (ref short location); - - [MethodImplAttribute (MethodImplOptions.InternalCall)] - [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] - [CLSCompliant (false)] - public extern static ushort Read (ref ushort location); - - [MethodImplAttribute (MethodImplOptions.InternalCall)] - [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] - public extern static int Read (ref int location); - - [MethodImplAttribute (MethodImplOptions.InternalCall)] - [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] - [CLSCompliant (false)] - public extern static uint Read (ref uint location); - - [MethodImplAttribute (MethodImplOptions.InternalCall)] - [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] - public extern static long Read (ref long location); - - [MethodImplAttribute (MethodImplOptions.InternalCall)] - [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] - [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 (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); - - [MethodImplAttribute (MethodImplOptions.InternalCall)] - [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] - [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(ref T location, T value) where T : class; - } -} +// +// Volatile.cs +// +// Authors: +// Marek Safar (marek.safar@gmail.com) +// +// Copyright 2011 Xamarin, Inc (http://www.xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System.Runtime.ConstrainedExecution; +using System.Runtime.CompilerServices; + +namespace System.Threading +{ + public + static class Volatile + { + #region Boolean + private struct VolatileBoolean { public volatile bool Value; } + + [Intrinsic] + public static bool Read(ref bool location) => + Unsafe.As(ref location).Value; + + [Intrinsic] + public static void Write(ref bool location, bool value) => + Unsafe.As(ref location).Value = value; + #endregion + + #region Byte + private struct VolatileByte { public volatile byte Value; } + + [Intrinsic] + public static byte Read(ref byte location) => + Unsafe.As(ref location).Value; + + [Intrinsic] + public static void Write(ref byte location, byte value) => + Unsafe.As(ref location).Value = value; + #endregion + + #region Int16 + private struct VolatileInt16 { public volatile short Value; } + + [Intrinsic] + public static short Read(ref short location) => + Unsafe.As(ref location).Value; + + [Intrinsic] + public static void Write(ref short location, short value) => + Unsafe.As(ref location).Value = value; + #endregion + + #region Int32 + private struct VolatileInt32 { public volatile int Value; } + + [Intrinsic] + public static int Read(ref int location) => + Unsafe.As(ref location).Value; + + [Intrinsic] + public static void Write(ref int location, int value) => + Unsafe.As(ref location).Value = value; + #endregion + + #region IntPtr + private struct VolatileIntPtr { public volatile IntPtr Value; } + + [Intrinsic] + public static IntPtr Read(ref IntPtr location) => + Unsafe.As(ref location).Value; + + [Intrinsic] + public static void Write(ref IntPtr location, IntPtr value) => + Unsafe.As(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(ref location).Value; + + [CLSCompliant(false)] + [Intrinsic] + public static void Write(ref sbyte location, sbyte value) => + Unsafe.As(ref location).Value = value; + #endregion + + #region Single + private struct VolatileSingle { public volatile float Value; } + + [Intrinsic] + public static float Read(ref float location) => + Unsafe.As(ref location).Value; + + [Intrinsic] + public static void Write(ref float location, float value) => + Unsafe.As(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(ref location).Value; + + [CLSCompliant(false)] + [Intrinsic] + public static void Write(ref ushort location, ushort value) => + Unsafe.As(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(ref location).Value; + + [CLSCompliant(false)] + [Intrinsic] + public static void Write(ref uint location, uint value) => + Unsafe.As(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(ref location).Value; + + [CLSCompliant(false)] + [Intrinsic] + public static void Write(ref UIntPtr location, UIntPtr value) => + Unsafe.As(ref location).Value = value; + #endregion + + #region T + private struct VolatileObject { public volatile object Value; } + + [Intrinsic] + public static T Read(ref T location) where T : class => + Unsafe.As(Unsafe.As(ref location).Value); + + [Intrinsic] + public static void Write(ref T location, T value) where T : class => + Unsafe.As(ref location).Value = value; + #endregion + + [MethodImplAttribute (MethodImplOptions.InternalCall)] + [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] + public extern static long Read (ref long location); + + [MethodImplAttribute (MethodImplOptions.InternalCall)] + [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] + [CLSCompliant (false)] + public extern static ulong Read (ref ulong 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 void Write (ref long location, long value); + + [MethodImplAttribute (MethodImplOptions.InternalCall)] + [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)] + [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 double location, double value); + } +} diff --git a/mono/metadata/filewatcher.c b/mono/metadata/filewatcher.c index a49b7e1aff9..69ab3a89fb0 100644 --- a/mono/metadata/filewatcher.c +++ b/mono/metadata/filewatcher.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -43,11 +44,11 @@ ves_icall_System_IO_FSW_SupportsFSW (void) return 1; } -gboolean +int ves_icall_System_IO_FAMW_InternalFAMNextEvent (gpointer conn, - MonoString **filename, - gint *code, - gint *reqnum) + MonoStringHandleOut filename, + int *code, + int *reqnum, MonoError *error) { return FALSE; } @@ -113,21 +114,20 @@ typedef struct FAMEvent { gint code; } FAMEvent; -gboolean +int ves_icall_System_IO_FAMW_InternalFAMNextEvent (gpointer conn, - MonoString **filename, - gint *code, - gint *reqnum) + MonoStringHandleOut filename, + int *code, + int *reqnum, + MonoError *error) { - ERROR_DECL (error); FAMEvent ev; if (FAMNextEvent (conn, &ev) == 1) { - *filename = mono_string_new_checked (mono_domain_get (), ev.filename, error); + MONO_HANDLE_ASSIGN_RAW (filename, mono_string_new_checked (mono_domain_get (), ev.filename, error)); + return_val_if_nok (error, FALSE); *code = ev.code; *reqnum = ev.fr.reqnum; - if (mono_error_set_pending_exception (error)) - return FALSE; return TRUE; } diff --git a/mono/metadata/filewatcher.h b/mono/metadata/filewatcher.h index 8a224852337..3d484b92f61 100644 --- a/mono/metadata/filewatcher.h +++ b/mono/metadata/filewatcher.h @@ -26,11 +26,6 @@ ICALL_EXPORT gint ves_icall_System_IO_FSW_SupportsFSW (void); ICALL_EXPORT -gboolean ves_icall_System_IO_FAMW_InternalFAMNextEvent (gpointer conn, - MonoString **filename, - gint *code, - gint *reqnum); -ICALL_EXPORT int ves_icall_System_IO_KqueueMonitor_kevent_notimeout (int *kq, gpointer changelist, int nchanges, gpointer eventlist, int nevents); #endif diff --git a/mono/metadata/icall-decl.h b/mono/metadata/icall-decl.h index 8cabf40019e..c697877abd6 100644 --- a/mono/metadata/icall-decl.h +++ b/mono/metadata/icall-decl.h @@ -88,7 +88,6 @@ ICALL_EXPORT MonoObject* ves_icall_InternalInvoke (MonoReflectionMethod*, MonoOb ICALL_EXPORT MonoObject* ves_icall_RuntimeFieldInfo_GetRawConstantValue (MonoReflectionField* rfield); ICALL_EXPORT MonoObject* ves_icall_RuntimeFieldInfo_GetValueInternal (MonoReflectionField* field, MonoObject* obj); ICALL_EXPORT MonoObject* ves_icall_property_info_get_default_value (MonoReflectionProperty*); -ICALL_EXPORT MonoReflectionType* ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy*); ICALL_EXPORT void ves_icall_System_ArgIterator_Setup (MonoArgIterator*, char*, char*); ICALL_EXPORT MonoType* ves_icall_System_ArgIterator_IntGetNextArgType (MonoArgIterator*); ICALL_EXPORT void ves_icall_System_ArgIterator_IntGetNextArg (MonoArgIterator*, MonoTypedRef*); diff --git a/mono/metadata/icall-def.h b/mono/metadata/icall-def.h index 045b9cb7523..69875fe7736 100644 --- a/mono/metadata/icall-def.h +++ b/mono/metadata/icall-def.h @@ -287,15 +287,15 @@ HANDLES(PERFCTRCAT_8, "InstanceExistsInternal_icall", mono_perfcounter_instance_ ICALL_TYPE(PROCESS, "System.Diagnostics.Process", PROCESS_1) HANDLES(PROCESS_1, "CreateProcess_internal", ves_icall_System_Diagnostics_Process_CreateProcess_internal, MonoBoolean, 5, (MonoW32ProcessStartInfo, gpointer, gpointer, gpointer, MonoW32ProcessInfo_ref)) -HANDLES(PROCESS_4, "GetModules_icall", ves_icall_System_Diagnostics_Process_GetModules_internal, MonoArray, 2, (MonoObject, HANDLE)) +HANDLES(PROCESS_4, "GetModules_icall", ves_icall_System_Diagnostics_Process_GetModules_internal, MonoArray, 2, (MonoObject, PROCESS_HANDLE)) NOHANDLES(ICALL(PROCESS_5H, "GetProcessData", ves_icall_System_Diagnostics_Process_GetProcessData)) HANDLES(PROCESS_6, "GetProcess_internal", ves_icall_System_Diagnostics_Process_GetProcess_internal, gpointer, 1, (guint32)) HANDLES(PROCESS_7, "GetProcesses_internal", ves_icall_System_Diagnostics_Process_GetProcesses_internal, MonoArray, 0, ()) -HANDLES(PROCESS_10, "ProcessName_icall", ves_icall_System_Diagnostics_Process_ProcessName_internal, MonoString, 1, (HANDLE)) +HANDLES(PROCESS_10, "ProcessName_icall", ves_icall_System_Diagnostics_Process_ProcessName_internal, MonoString, 1, (PROCESS_HANDLE)) HANDLES(PROCESS_13, "ShellExecuteEx_internal", ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal, MonoBoolean, 2, (MonoW32ProcessStartInfo, MonoW32ProcessInfo_ref)) ICALL_TYPE(STOPWATCH, "System.Diagnostics.Stopwatch", STOPWATCH_1) -ICALL(STOPWATCH_1, "GetTimestamp", ves_icall_System_Diagnostics_Stopwatch_GetTimestamp) +NOHANDLES(ICALL(STOPWATCH_1, "GetTimestamp", ves_icall_System_Diagnostics_Stopwatch_GetTimestamp)) ICALL_TYPE(ENUM, "System.Enum", ENUM_1) HANDLES(ENUM_1, "GetEnumValuesAndNames", ves_icall_System_Enum_GetEnumValuesAndNames, MonoBoolean, 3, (MonoReflectionType, MonoArrayOut, MonoArrayOut)) @@ -365,7 +365,6 @@ HANDLES(CULINF_5, "construct_internal_locale_from_lcid", ves_icall_System_Global HANDLES(CULINF_6, "construct_internal_locale_from_name", ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name, MonoBoolean, 2, (MonoCultureInfo, MonoString)) HANDLES(CULINF_7, "get_current_locale_name", ves_icall_System_Globalization_CultureInfo_get_current_locale_name, MonoString, 0, ()) HANDLES(CULINF_9, "internal_get_cultures", ves_icall_System_Globalization_CultureInfo_internal_get_cultures, MonoArray, 3, (MonoBoolean, MonoBoolean, MonoBoolean)) -//ICALL(CULINF_10, "internal_is_lcid_neutral", ves_icall_System_Globalization_CultureInfo_internal_is_lcid_neutral) ICALL_TYPE(REGINF, "System.Globalization.RegionInfo", REGINF_2) HANDLES(REGINF_2, "construct_internal_region_from_name", ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_name, MonoBoolean, 2, (MonoRegionInfo, MonoString)) @@ -387,13 +386,13 @@ HANDLES(IODRIVEINFO_3, "GetDriveTypeInternal", ves_icall_System_IO_DriveInfo_Get #endif ICALL_TYPE(FAMW, "System.IO.FAMWatcher", FAMW_1) -ICALL(FAMW_1, "InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent) +HANDLES(FAMW_1, "InternalFAMNextEvent", ves_icall_System_IO_FAMW_InternalFAMNextEvent, int, 4, (gpointer, MonoStringOut, int_ref, int_ref)) ICALL_TYPE(FILEW, "System.IO.FileSystemWatcher", FILEW_4) -ICALL(FILEW_4, "InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW) +NOHANDLES(ICALL(FILEW_4, "InternalSupportsFSW", ves_icall_System_IO_FSW_SupportsFSW)) ICALL_TYPE(KQUEM, "System.IO.KqueueMonitor", KQUEM_1) -ICALL(KQUEM_1, "kevent_notimeout", ves_icall_System_IO_KqueueMonitor_kevent_notimeout) +NOHANDLES(ICALL(KQUEM_1, "kevent_notimeout", ves_icall_System_IO_KqueueMonitor_kevent_notimeout)) ICALL_TYPE(LOGCATEXTWRITER, "System.IO.LogcatTextWriter", LOGCATEXTWRITER_1) NOHANDLES(ICALL(LOGCATEXTWRITER_1, "Log", ves_icall_System_IO_LogcatTextWriter_Log)) @@ -578,7 +577,7 @@ NOHANDLES(ICALL(SOCKEX_1, "WSAGetLastError_internal", ves_icall_System_Net_Socke #endif /* !DISABLE_SOCKETS */ ICALL_TYPE(NUMBER_FORMATTER, "System.NumberFormatter", NUMBER_FORMATTER_1) -ICALL(NUMBER_FORMATTER_1, "GetFormatterTables", ves_icall_System_NumberFormatter_GetFormatterTables) +NOHANDLES(ICALL(NUMBER_FORMATTER_1, "GetFormatterTables", ves_icall_System_NumberFormatter_GetFormatterTables)) ICALL_TYPE(OBJ, "System.Object", OBJ_1) HANDLES(OBJ_1, "GetType", ves_icall_System_Object_GetType, MonoReflectionType, 1, (MonoObject)) @@ -811,7 +810,7 @@ HANDLES(MARSHAL_31, "SizeOfHelper", ves_icall_System_Runtime_InteropServices_Mar HANDLES(MARSHAL_32, "StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi, char_ptr, 2, (const_gunichar2_ptr, int)) HANDLES(MARSHAL_33, "StringToHGlobalUni", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni, gunichar2_ptr, 2, (const_gunichar2_ptr, int)) HANDLES(MARSHAL_34, "StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr, void, 3, (MonoObject, gpointer, MonoBoolean)) -ICALL(MARSHAL_35, "UnsafeAddrOfPinnedArrayElement", ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement) +HANDLES(MARSHAL_35, "UnsafeAddrOfPinnedArrayElement", ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement, gpointer, 2, (MonoArray, int)) HANDLES(MARSHAL_41, "copy_from_unmanaged_fixed", ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged, void, 5, (gconstpointer, gint32, MonoArray, gint32, gpointer)) HANDLES(MARSHAL_42, "copy_to_unmanaged_fixed", ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged, void, 5, (MonoArray, gint32, gpointer, gint32, gconstpointer)) @@ -842,7 +841,7 @@ ICALL(ARES_1, "Invoke", ves_icall_System_Runtime_Remoting_Messaging_AsyncResult_ #ifndef DISABLE_REMOTING ICALL_TYPE(REALP, "System.Runtime.Remoting.Proxies.RealProxy", REALP_1) -ICALL(REALP_1, "InternalGetProxyType", ves_icall_Remoting_RealProxy_InternalGetProxyType) +HANDLES(REALP_1, "InternalGetProxyType", ves_icall_Remoting_RealProxy_InternalGetProxyType, MonoReflectionType, 1, (MonoTransparentProxy)) HANDLES(REALP_2, "InternalGetTransparentProxy", ves_icall_Remoting_RealProxy_GetTransparentProxy, MonoObject, 2, (MonoObject, MonoString)) ICALL_TYPE(REMSER, "System.Runtime.Remoting.RemotingServices", REMSER_0) @@ -1101,35 +1100,13 @@ HANDLES(THREADP_14, "SetMinThreadsNative", ves_icall_System_Threading_ThreadPool ICALL_TYPE(TTIMER, "System.Threading.Timer", TTIMER_1) NOHANDLES(ICALL(TTIMER_1, "GetTimeMonotonic", ves_icall_System_Threading_Timer_GetTimeMonotonic)) -ICALL_TYPE(VOLATILE, "System.Threading.Volatile", VOLATILE_28) -ICALL(VOLATILE_28, "Read(T&)", ves_icall_System_Threading_Volatile_Read_T) -NOHANDLES(ICALL(VOLATILE_1, "Read(bool&)", ves_icall_System_Threading_Volatile_Read1)) -NOHANDLES(ICALL(VOLATILE_2, "Read(byte&)", ves_icall_System_Threading_Volatile_Read1)) -NOHANDLES(ICALL(VOLATILE_3, "Read(double&)", ves_icall_System_Threading_Volatile_ReadDouble)) -NOHANDLES(ICALL(VOLATILE_4, "Read(int&)", ves_icall_System_Threading_Volatile_Read4)) -NOHANDLES(ICALL(VOLATILE_5, "Read(int16&)", ves_icall_System_Threading_Volatile_Read2)) -NOHANDLES(ICALL(VOLATILE_6, "Read(intptr&)", ves_icall_System_Threading_Volatile_ReadIntPtr)) -NOHANDLES(ICALL(VOLATILE_7, "Read(long&)", ves_icall_System_Threading_Volatile_Read8)) -NOHANDLES(ICALL(VOLATILE_8, "Read(sbyte&)", ves_icall_System_Threading_Volatile_Read1)) -NOHANDLES(ICALL(VOLATILE_9, "Read(single&)", ves_icall_System_Threading_Volatile_ReadFloat)) -NOHANDLES(ICALL(VOLATILE_10, "Read(uint&)", ves_icall_System_Threading_Volatile_Read4)) -NOHANDLES(ICALL(VOLATILE_11, "Read(uint16&)", ves_icall_System_Threading_Volatile_Read2)) -NOHANDLES(ICALL(VOLATILE_12, "Read(uintptr&)", ves_icall_System_Threading_Volatile_ReadIntPtr)) -NOHANDLES(ICALL(VOLATILE_13, "Read(ulong&)", ves_icall_System_Threading_Volatile_ReadU8)) -ICALL(VOLATILE_27, "Write(T&,T)", ves_icall_System_Threading_Volatile_Write_T) -NOHANDLES(ICALL(VOLATILE_14, "Write(bool&,bool)", ves_icall_System_Threading_Volatile_Write1)) -NOHANDLES(ICALL(VOLATILE_15, "Write(byte&,byte)", ves_icall_System_Threading_Volatile_Write1)) -NOHANDLES(ICALL(VOLATILE_16, "Write(double&,double)", ves_icall_System_Threading_Volatile_WriteDouble)) -NOHANDLES(ICALL(VOLATILE_17, "Write(int&,int)", ves_icall_System_Threading_Volatile_Write4)) -NOHANDLES(ICALL(VOLATILE_18, "Write(int16&,int16)", ves_icall_System_Threading_Volatile_Write2)) -NOHANDLES(ICALL(VOLATILE_19, "Write(intptr&,intptr)", ves_icall_System_Threading_Volatile_WriteIntPtr)) -NOHANDLES(ICALL(VOLATILE_20, "Write(long&,long)", ves_icall_System_Threading_Volatile_Write8)) -NOHANDLES(ICALL(VOLATILE_21, "Write(sbyte&,sbyte)", ves_icall_System_Threading_Volatile_Write1)) -NOHANDLES(ICALL(VOLATILE_22, "Write(single&,single)", ves_icall_System_Threading_Volatile_WriteFloat)) -NOHANDLES(ICALL(VOLATILE_23, "Write(uint&,uint)", ves_icall_System_Threading_Volatile_Write4)) -NOHANDLES(ICALL(VOLATILE_24, "Write(uint16&,uint16)", ves_icall_System_Threading_Volatile_Write2)) -NOHANDLES(ICALL(VOLATILE_25, "Write(uintptr&,uintptr)", ves_icall_System_Threading_Volatile_WriteIntPtr)) -NOHANDLES(ICALL(VOLATILE_26, "Write(ulong&,ulong)", ves_icall_System_Threading_Volatile_WriteU8)) +ICALL_TYPE(VOLATILE, "System.Threading.Volatile", VOLATILE_1) +NOHANDLES(ICALL(VOLATILE_1, "Read(double&)", ves_icall_System_Threading_Volatile_ReadDouble)) +NOHANDLES(ICALL(VOLATILE_2, "Read(long&)", ves_icall_System_Threading_Volatile_Read8)) +NOHANDLES(ICALL(VOLATILE_3, "Read(ulong&)", ves_icall_System_Threading_Volatile_ReadU8)) +NOHANDLES(ICALL(VOLATILE_4, "Write(double&,double)", ves_icall_System_Threading_Volatile_WriteDouble)) +NOHANDLES(ICALL(VOLATILE_5, "Write(long&,long)", ves_icall_System_Threading_Volatile_Write8)) +NOHANDLES(ICALL(VOLATILE_6, "Write(ulong&,ulong)", ves_icall_System_Threading_Volatile_WriteU8)) ICALL_TYPE(WAITH, "System.Threading.WaitHandle", WAITH_1) HANDLES(WAITH_1, "SignalAndWait_Internal", ves_icall_System_Threading_WaitHandle_SignalAndWait_Internal, gint32, 3, (gpointer, gpointer, gint32)) diff --git a/mono/metadata/icall-table.h b/mono/metadata/icall-table.h index 350a8c37998..e8cb6c85231 100644 --- a/mono/metadata/icall-table.h +++ b/mono/metadata/icall-table.h @@ -47,7 +47,7 @@ typedef int *int_ptr; typedef int **int_ptr_ref; typedef guint8 **guint8_ptr_ref; typedef GPtrArray *GPtrArray_ptr; -typedef void *HANDLE; +typedef gpointer PROCESS_HANDLE; typedef MonoAssemblyName *MonoAssemblyName_ptr; typedef MonoBoolean *MonoBoolean_ptr; typedef MonoClass *MonoClass_ptr; @@ -182,7 +182,7 @@ typedef MonoReflectionModuleHandle MonoReflectionModuleOutHandle; #define MONO_HANDLE_TYPE_WRAP_MonoStackCrawlMark_ptr ICALL_HANDLES_WRAP_NONE #define MONO_HANDLE_TYPE_WRAP_gint32_ptr ICALL_HANDLES_WRAP_NONE #define MONO_HANDLE_TYPE_WRAP_gpointer_ptr ICALL_HANDLES_WRAP_NONE -#define MONO_HANDLE_TYPE_WRAP_HANDLE ICALL_HANDLES_WRAP_NONE +#define MONO_HANDLE_TYPE_WRAP_PROCESS_HANDLE ICALL_HANDLES_WRAP_NONE // Please keep this sorted (grep ICALL_HANDLES_WRAP_OBJ$ | sort) #define MONO_HANDLE_TYPE_WRAP_MonoAppContext ICALL_HANDLES_WRAP_OBJ @@ -220,6 +220,7 @@ typedef MonoReflectionModuleHandle MonoReflectionModuleOutHandle; #define MONO_HANDLE_TYPE_WRAP_MonoString ICALL_HANDLES_WRAP_OBJ #define MONO_HANDLE_TYPE_WRAP_MonoStringBuilder ICALL_HANDLES_WRAP_OBJ #define MONO_HANDLE_TYPE_WRAP_MonoThreadObject ICALL_HANDLES_WRAP_OBJ +#define MONO_HANDLE_TYPE_WRAP_MonoTransparentProxy ICALL_HANDLES_WRAP_OBJ #define MONO_HANDLE_TYPE_WRAP_MonoW32ProcessStartInfo ICALL_HANDLES_WRAP_OBJ #define MONO_HANDLE_TYPE_WRAP_MonoObjectOut ICALL_HANDLES_WRAP_OBJ_OUT diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index 89471991147..18ad5013012 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -7218,16 +7218,15 @@ ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObjectHandle this_obj, Mon return res; } -MonoReflectionType * -ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxy *tp) +MonoReflectionTypeHandle +ves_icall_Remoting_RealProxy_InternalGetProxyType (MonoTransparentProxyHandle tp, MonoError *error) { - ERROR_DECL (error); - g_assert (tp != NULL && mono_object_class (tp) == mono_defaults.transparent_proxy_class); - g_assert (tp->remote_class != NULL && tp->remote_class->proxy_class != NULL); - MonoReflectionType *ret = mono_type_get_object_checked (mono_object_domain (tp), m_class_get_byval_arg (tp->remote_class->proxy_class), error); - mono_error_set_pending_exception (error); + MonoRemoteClass *remote_class; - return ret; + g_assert (mono_handle_class (tp) == mono_defaults.transparent_proxy_class); + remote_class = MONO_HANDLE_RAW (tp)->remote_class; + g_assert (remote_class != NULL && remote_class->proxy_class != NULL); + return mono_type_get_object_handle (mono_handle_domain (tp), m_class_get_byval_arg (remote_class->proxy_class), error); } #endif diff --git a/mono/metadata/locales.c b/mono/metadata/locales.c index a8efefc3170..89dbb245081 100644 --- a/mono/metadata/locales.c +++ b/mono/metadata/locales.c @@ -308,9 +308,9 @@ construct_culture (MonoCultureInfoHandle this_obj, const CultureInfoEntry *ci, M mono_handle_setval (this_obj, lcid, ci->lcid); #define SET_STR_FIELD(obj,field,domain,expr,error) do { \ - MonoStringHandle _str = mono_string_new_handle ((domain), (expr), (error)); \ + MonoString *_str = mono_string_new_checked ((domain), (expr), (error)); \ return_val_if_nok (error, FALSE); \ - MONO_HANDLE_SET ((obj), field, _str); \ + MONO_HANDLE_SETRAW ((obj), field, _str); \ } while (0) SET_STR_FIELD (this_obj, name, domain, idx2string (ci->name), error); diff --git a/mono/metadata/marshal.c b/mono/metadata/marshal.c index 0e7d358eaaf..5b3fdfd02b4 100644 --- a/mono/metadata/marshal.c +++ b/mono/metadata/marshal.c @@ -5538,10 +5538,11 @@ ves_icall_System_Runtime_InteropServices_Marshal_ReAllocCoTaskMem (gpointer ptr, return res; } -void* -ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement (MonoArray *arrayobj, int index) +gpointer +ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement (MonoArrayHandle arrayobj, int index, MonoError *error) { - return mono_array_addr_with_size_fast (arrayobj, mono_array_element_size (arrayobj->obj.vtable->klass), index); + int esize = mono_array_element_size (mono_handle_class (arrayobj)); + return mono_array_addr_with_size_fast (MONO_HANDLE_RAW (arrayobj), esize, index); } MonoDelegateHandle diff --git a/mono/metadata/marshal.h b/mono/metadata/marshal.h index 89697d245cf..dbfc07d17c1 100644 --- a/mono/metadata/marshal.h +++ b/mono/metadata/marshal.h @@ -600,10 +600,6 @@ void ves_icall_System_Runtime_InteropServices_Marshal_FreeBSTR (mono_bstr_const ptr); ICALL_EXPORT -void* -ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement (MonoArray *arrayobj, int index); - -ICALL_EXPORT int ves_icall_System_Runtime_InteropServices_Marshal_AddRefInternal (MonoIUnknown *pUnk); diff --git a/mono/metadata/threads-types.h b/mono/metadata/threads-types.h index ea9e7c56446..172c48d37ae 100644 --- a/mono/metadata/threads-types.h +++ b/mono/metadata/threads-types.h @@ -267,60 +267,24 @@ ICALL_EXPORT void ves_icall_System_Threading_Thread_VolatileWriteDouble (void *ptr, double); ICALL_EXPORT -gint8 ves_icall_System_Threading_Volatile_Read1 (void *ptr); - -ICALL_EXPORT -gint16 ves_icall_System_Threading_Volatile_Read2 (void *ptr); - -ICALL_EXPORT -gint32 ves_icall_System_Threading_Volatile_Read4 (void *ptr); - -ICALL_EXPORT gint64 ves_icall_System_Threading_Volatile_Read8 (void *ptr); ICALL_EXPORT guint64 ves_icall_System_Threading_Volatile_ReadU8 (void *ptr); ICALL_EXPORT -void * ves_icall_System_Threading_Volatile_ReadIntPtr (void *ptr); - -ICALL_EXPORT double ves_icall_System_Threading_Volatile_ReadDouble (void *ptr); ICALL_EXPORT -float ves_icall_System_Threading_Volatile_ReadFloat (void *ptr); - -ICALL_EXPORT -MonoObject* ves_icall_System_Threading_Volatile_Read_T (void *ptr); - -ICALL_EXPORT -void ves_icall_System_Threading_Volatile_Write1 (void *ptr, gint8); - -ICALL_EXPORT -void ves_icall_System_Threading_Volatile_Write2 (void *ptr, gint16); - -ICALL_EXPORT -void ves_icall_System_Threading_Volatile_Write4 (void *ptr, gint32); - -ICALL_EXPORT void ves_icall_System_Threading_Volatile_Write8 (void *ptr, gint64); ICALL_EXPORT void ves_icall_System_Threading_Volatile_WriteU8 (void *ptr, guint64); ICALL_EXPORT -void ves_icall_System_Threading_Volatile_WriteIntPtr (void *ptr, void *); - -ICALL_EXPORT -void ves_icall_System_Threading_Volatile_WriteFloat (void *ptr, float); - -ICALL_EXPORT void ves_icall_System_Threading_Volatile_WriteDouble (void *ptr, double); ICALL_EXPORT -void ves_icall_System_Threading_Volatile_Write_T (void *ptr, MonoObject *value); - -ICALL_EXPORT void ves_icall_System_Threading_Thread_MemoryBarrier (void); void diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index f17c0568a55..398b7e5daa3 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -2994,24 +2994,6 @@ ves_icall_System_Threading_Thread_VolatileReadFloat (void *ptr) return tmp; } -gint8 -ves_icall_System_Threading_Volatile_Read1 (void *ptr) -{ - return mono_atomic_load_i8 ((volatile gint8 *)ptr); -} - -gint16 -ves_icall_System_Threading_Volatile_Read2 (void *ptr) -{ - return mono_atomic_load_i16 ((volatile gint16 *)ptr); -} - -gint32 -ves_icall_System_Threading_Volatile_Read4 (void *ptr) -{ - return mono_atomic_load_i32 ((volatile gint32 *)ptr); -} - gint64 ves_icall_System_Threading_Volatile_Read8 (void *ptr) { @@ -3042,12 +3024,6 @@ ves_icall_System_Threading_Volatile_ReadU8 (void *ptr) return (guint64)mono_atomic_load_i64 ((volatile gint64 *)ptr); } -void * -ves_icall_System_Threading_Volatile_ReadIntPtr (void *ptr) -{ - return mono_atomic_load_ptr ((volatile gpointer *)ptr); -} - double ves_icall_System_Threading_Volatile_ReadDouble (void *ptr) { @@ -3068,22 +3044,6 @@ ves_icall_System_Threading_Volatile_ReadDouble (void *ptr) return u.fval; } -float -ves_icall_System_Threading_Volatile_ReadFloat (void *ptr) -{ - IntFloatUnion u; - - u.ival = mono_atomic_load_i32 ((volatile gint32 *)ptr); - - return u.fval; -} - -MonoObject* -ves_icall_System_Threading_Volatile_Read_T (void *ptr) -{ - return (MonoObject *)mono_atomic_load_ptr ((volatile gpointer *)ptr); -} - void ves_icall_System_Threading_Thread_VolatileWrite1 (void *ptr, gint8 value) { @@ -3141,24 +3101,6 @@ ves_icall_System_Threading_Thread_VolatileWriteFloat (void *ptr, float value) } void -ves_icall_System_Threading_Volatile_Write1 (void *ptr, gint8 value) -{ - mono_atomic_store_i8 ((volatile gint8 *)ptr, value); -} - -void -ves_icall_System_Threading_Volatile_Write2 (void *ptr, gint16 value) -{ - mono_atomic_store_i16 ((volatile gint16 *)ptr, value); -} - -void -ves_icall_System_Threading_Volatile_Write4 (void *ptr, gint32 value) -{ - mono_atomic_store_i32 ((volatile gint32 *)ptr, value); -} - -void ves_icall_System_Threading_Volatile_Write8 (void *ptr, gint64 value) { #if SIZEOF_VOID_P == 4 @@ -3189,12 +3131,6 @@ ves_icall_System_Threading_Volatile_WriteU8 (void *ptr, guint64 value) } void -ves_icall_System_Threading_Volatile_WriteIntPtr (void *ptr, void *value) -{ - mono_atomic_store_ptr ((volatile gpointer *)ptr, value); -} - -void ves_icall_System_Threading_Volatile_WriteDouble (void *ptr, double value) { LongDoubleUnion u; @@ -3213,22 +3149,6 @@ ves_icall_System_Threading_Volatile_WriteDouble (void *ptr, double value) mono_atomic_store_i64 ((volatile gint64 *)ptr, u.ival); } -void -ves_icall_System_Threading_Volatile_WriteFloat (void *ptr, float value) -{ - IntFloatUnion u; - - u.fval = value; - - mono_atomic_store_i32 ((volatile gint32 *)ptr, u.ival); -} - -void -ves_icall_System_Threading_Volatile_Write_T (void *ptr, MonoObject *value) -{ - mono_gc_wbarrier_generic_store_atomic_internal (ptr, value); -} - static void free_context (void *user_data) { diff --git a/mono/mini/aot-compiler.c b/mono/mini/aot-compiler.c index eebc663dd43..aaba8b08d8c 100644 --- a/mono/mini/aot-compiler.c +++ b/mono/mini/aot-compiler.c @@ -5669,28 +5669,6 @@ add_generic_instances (MonoAotCompile *acfg) } } - /* Same for Volatile.Read/Write */ - { - MonoGenericContext ctx; - MonoType *args [16]; - MonoMethod *m; - MonoClass *volatile_klass = mono_class_try_load_from_name (mono_defaults.corlib, "System.Threading", "Volatile"); - gpointer iter = NULL; - - if (volatile_klass) { - while ((m = mono_class_get_methods (volatile_klass, &iter))) { - if ((!strcmp (m->name, "Read") || !strcmp (m->name, "Write")) && m->is_generic) { - ERROR_DECL (error); - memset (&ctx, 0, sizeof (ctx)); - args [0] = object_type; - ctx.method_inst = mono_metadata_get_generic_inst (1, args); - add_extra_method (acfg, mono_marshal_get_native_wrapper (mono_class_inflate_generic_method_checked (m, &ctx, error), TRUE, TRUE)); - g_assert (mono_error_ok (error)); /* FIXME don't swallow the error */ - } - } - } - } - /* object[] accessor wrappers. */ for (i = 1; i < 4; ++i) { MonoClass *obj_array_class = mono_class_create_array (mono_defaults.object_class, i); @@ -11697,6 +11675,9 @@ should_emit_gsharedvt_method (MonoAotCompile *acfg, MonoMethod *method) /* The SIMD fallback code in Vector is very large, and not likely to be used */ return FALSE; #endif + if (acfg->image == mono_get_corlib () && !strcmp (m_class_get_name (method->klass), "Volatile")) + /* Read/Write are not needed and cause JIT failures */ + return FALSE; return TRUE; } -- 2.11.4.GIT