From f143f7d007996039b72519551354d3e2f2636052 Mon Sep 17 00:00:00 2001 From: Ryan Lucia Date: Tue, 19 Jan 2021 12:31:54 -0500 Subject: [PATCH] [mono] Remove MonoListItem from Corelib --- src/mono/mono/metadata/CMakeLists.txt | 2 -- src/mono/mono/metadata/object-internals.h | 7 ++++ src/mono/mono/metadata/object.c | 14 +++----- src/mono/mono/mini/mini-exceptions.c | 36 ++++++++++++++++++- .../System.Private.CoreLib.csproj | 1 - .../src/ILLink/ILLink.Descriptors.xml | 3 -- .../src/Mono/MonoListItem.cs | 12 ------- .../src/System/Exception.Mono.cs | 2 +- 8 files changed, 48 insertions(+), 29 deletions(-) delete mode 100644 src/mono/netcore/System.Private.CoreLib/src/Mono/MonoListItem.cs diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index 232729b8014c29..b974a9733afed1 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -145,8 +145,6 @@ set(metadata_common_sources mono-hash.h mono-conc-hash.c mono-conc-hash.h - mono-mlist.c - mono-mlist.h mono-perfcounters.c mono-perfcounters.h mono-perfcounters-def.h diff --git a/src/mono/mono/metadata/object-internals.h b/src/mono/mono/metadata/object-internals.h index af9514d2ccb714..08b27521589410 100644 --- a/src/mono/mono/metadata/object-internals.h +++ b/src/mono/mono/metadata/object-internals.h @@ -358,7 +358,11 @@ struct _MonoException { MonoString *remote_stack_trace; gint32 remote_stack_index; /* Dynamic methods referenced by the stack trace */ +#ifdef ENABLE_NETCORE + MonoArray *dynamic_methods; +#else MonoObject *dynamic_methods; +#endif gint32 hresult; MonoString *source; MonoObject *serialization_manager; @@ -1776,6 +1780,9 @@ mono_array_clone_checked (MonoArray *array, MonoError *error); void mono_array_full_copy (MonoArray *src, MonoArray *dest); +void +mono_array_full_copy_unchecked_size (MonoArray *src, MonoArray *dest, MonoClass *klass, uintptr_t size); + gboolean mono_array_calc_byte_len (MonoClass *klass, uintptr_t len, uintptr_t *res); diff --git a/src/mono/mono/metadata/object.c b/src/mono/mono/metadata/object.c index d70e3df2909935..b1147753dd9480 100644 --- a/src/mono/mono/metadata/object.c +++ b/src/mono/mono/metadata/object.c @@ -88,9 +88,6 @@ mono_string_to_utf8_internal (MonoMemPool *mp, MonoImage *image, MonoString *s, static char * mono_string_to_utf8_mp (MonoMemPool *mp, MonoString *s, MonoError *error); -static void -array_full_copy_unchecked_size (MonoArray *src, MonoArray *dest, MonoClass *klass, uintptr_t size); - /* Class lazy loading functions */ static GENERATE_GET_CLASS_WITH_CACHE (pointer, "System.Reflection", "Pointer") static GENERATE_GET_CLASS_WITH_CACHE (remoting_services, "System.Runtime.Remoting", "RemotingServices") @@ -6338,11 +6335,11 @@ mono_array_full_copy (MonoArray *src, MonoArray *dest) g_assert (size == mono_array_length_internal (dest)); size *= mono_array_element_size (klass); - array_full_copy_unchecked_size (src, dest, klass, size); + mono_array_full_copy_unchecked_size (src, dest, klass, size); } -static void -array_full_copy_unchecked_size (MonoArray *src, MonoArray *dest, MonoClass *klass, uintptr_t size) +void +mono_array_full_copy_unchecked_size (MonoArray *src, MonoArray *dest, MonoClass *klass, uintptr_t size) { if (mono_gc_is_moving ()) { MonoClass *element_class = m_class_get_element_class (klass); @@ -6352,8 +6349,7 @@ array_full_copy_unchecked_size (MonoArray *src, MonoArray *dest, MonoClass *klas else mono_gc_memmove_atomic (&dest->vector, &src->vector, size); } else { - mono_array_memcpy_refs_internal - (dest, 0, src, 0, mono_array_length_internal (src)); + mono_array_memcpy_refs_internal (dest, 0, src, 0, mono_array_length_internal (src)); } } else { mono_gc_memmove_atomic (&dest->vector, &src->vector, size); @@ -6405,7 +6401,7 @@ mono_array_clone_in_domain (MonoDomain *domain, MonoArrayHandle array_handle, Mo MonoGCHandle dst_handle; dst_handle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, o), TRUE); - array_full_copy_unchecked_size (MONO_HANDLE_RAW (array_handle), MONO_HANDLE_RAW (o), klass, size); + mono_array_full_copy_unchecked_size (MONO_HANDLE_RAW (array_handle), MONO_HANDLE_RAW (o), klass, size); mono_gchandle_free_internal (dst_handle); MONO_HANDLE_ASSIGN (result, o); diff --git a/src/mono/mono/mini/mini-exceptions.c b/src/mono/mono/mini/mini-exceptions.c index b26c6334224809..b920dc87d4c832 100644 --- a/src/mono/mono/mini/mini-exceptions.c +++ b/src/mono/mono/mini/mini-exceptions.c @@ -2184,12 +2184,45 @@ setup_stack_trace (MonoException *mono_ex, GSList **dynamic_methods, GList *trac mono_error_assert_ok (error); if (*dynamic_methods) { /* These methods could go away anytime, so save a reference to them in the exception object */ + MonoDomain *domain = mono_domain_get (); +#ifdef ENABLE_NETCORE + int methods_len = g_slist_length (*dynamic_methods); + MonoArray *old_methods = mono_ex->dynamic_methods; + int old_methods_len = 0; + + if (old_methods) { + old_methods_len = mono_array_length_internal (old_methods); + methods_len += old_methods_len; + } + + MonoArray *all_methods = mono_array_new_checked (domain, mono_defaults.object_class, methods_len, error); + mono_error_assert_ok (error); + + if (old_methods) + mono_array_full_copy_unchecked_size (old_methods, all_methods, mono_defaults.object_class, old_methods_len); + int index = old_methods_len; + + for (GSList *l = *dynamic_methods; l; l = l->next) { + g_assert (domain->method_to_dyn_method); + + mono_domain_lock (domain); + MonoGCHandle dis_link = (MonoGCHandle)g_hash_table_lookup (domain->method_to_dyn_method, l->data); + mono_domain_unlock (domain); + + if (dis_link) { + MonoObject *o = mono_gchandle_get_target_internal (dis_link); + mono_array_set_internal (all_methods, MonoObject *, index, o); + index++; + } + } + + MONO_OBJECT_SETREF_INTERNAL (mono_ex, dynamic_methods, all_methods); +#else GSList *l; MonoMList *list = (MonoMList*)mono_ex->dynamic_methods; for (l = *dynamic_methods; l; l = l->next) { MonoGCHandle dis_link; - MonoDomain *domain = mono_domain_get (); if (domain->method_to_dyn_method) { mono_domain_lock (domain); @@ -2206,6 +2239,7 @@ setup_stack_trace (MonoException *mono_ex, GSList **dynamic_methods, GList *trac } MONO_OBJECT_SETREF_INTERNAL (mono_ex, dynamic_methods, list); +#endif g_slist_free (*dynamic_methods); *dynamic_methods = NULL; diff --git a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj index 123281934d2ce5..bdb5b7dd26d546 100644 --- a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -142,7 +142,6 @@ - diff --git a/src/mono/netcore/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.xml b/src/mono/netcore/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.xml index a7123b5c756b19..a80a66e4a682a1 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.xml +++ b/src/mono/netcore/System.Private.CoreLib/src/ILLink/ILLink.Descriptors.xml @@ -230,9 +230,6 @@ - - - diff --git a/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoListItem.cs b/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoListItem.cs deleted file mode 100644 index ca52ef0326e66c..00000000000000 --- a/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoListItem.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Mono -{ - // Internal type used by Mono runtime only - internal sealed class MonoListItem - { - public MonoListItem? next; - public object? data; - } -} diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Exception.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Exception.Mono.cs index 8bd7cd6d5bb55b..5e369825827b90 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Exception.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Exception.Mono.cs @@ -32,7 +32,7 @@ public DispatchState(MonoStackFrame[]? stackFrames) private string? _stackTraceString; private string? _remoteStackTraceString; private int _unused4; - private object? _dynamicMethods; // Dynamic methods referenced by the stack trace + private object[]? _dynamicMethods; // Dynamic methods referenced by the stack trace private int _HResult; private string? _source; private object? _unused6;