Skip to content

Commit 417aa90

Browse files
authored
[mono] More domain cleanups. (#48291)
* Remove the MonoClassRuntimeInfo structure, store the runtime vtable directly in MonoClass. * Remove the 'domain' argument from mono_class_vtable_checked (). * Remove the 'domain' argument from the object allocation functions. * Remove the 'domain' argument from the m_.._alloc methods. * Revert accidental changes. * Remove more unused 'domain' parameters. * Remove more remoting code. * Remove shared code support. * Remove the 'domain' argument from the IMT builder functions. * Remove the 'domain' argument from the m_method_ functions. * Remove more domain usage from the JIT backends. * Remove the MONO_ARCH_HAVE_PATCH_CODE_NEW ifdef, all architectures support it now. * Remove 'domain' argument from mini_jit_info_table_find (). * Remove 'domain' argument from mono_arch_unwind_frame (). * Remove unused/unfinished AOT cache code. * Remove the 'domain' argument from mono_resolve_patch_target (). * Remove domains from the stack walk/exception handling code. * Remove domains from mono-debug.c. The memory in mono-debug.c is now owned by a MonoMemoryManager instead of by a domain. * Remove unused mono-mlist.{h,c}. * Fix the coverage profiler build. * Fix the build.
1 parent ed2e749 commit 417aa90

File tree

112 files changed

+1078
-2406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1078
-2406
lines changed

src/mono/mono/metadata/appdomain.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ create_domain_objects (MonoDomain *domain)
201201
* Initialize String.Empty. This enables the removal of
202202
* the static cctor of the String class.
203203
*/
204-
string_vt = mono_class_vtable_checked (domain, mono_defaults.string_class, error);
204+
string_vt = mono_class_vtable_checked (mono_defaults.string_class, error);
205205
mono_error_assert_ok (error);
206206
string_empty_fld = mono_class_get_field_from_name_full (mono_defaults.string_class, "Empty", NULL);
207207
g_assert (string_empty_fld);
208-
MonoStringHandle empty_str = mono_string_new_handle (domain, "", error);
208+
MonoStringHandle empty_str = mono_string_new_handle ("", error);
209209
mono_error_assert_ok (error);
210210
empty_str = mono_string_intern_checked (empty_str, error);
211211
mono_error_assert_ok (error);
@@ -215,7 +215,7 @@ create_domain_objects (MonoDomain *domain)
215215
/*
216216
* Create an instance early since we can't do it when there is no memory.
217217
*/
218-
arg = mono_string_new_handle (domain, "Out of memory", error);
218+
arg = mono_string_new_handle ("Out of memory", error);
219219
mono_error_assert_ok (error);
220220
domain->out_of_memory_ex = MONO_HANDLE_RAW (mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "OutOfMemoryException", arg, NULL_HANDLE_STRING, error));
221221
mono_error_assert_ok (error);
@@ -224,17 +224,17 @@ create_domain_objects (MonoDomain *domain)
224224
* These two are needed because the signal handlers might be executing on
225225
* an alternate stack, and Boehm GC can't handle that.
226226
*/
227-
arg = mono_string_new_handle (domain, "A null value was found where an object instance was required", error);
227+
arg = mono_string_new_handle ("A null value was found where an object instance was required", error);
228228
mono_error_assert_ok (error);
229229
domain->null_reference_ex = MONO_HANDLE_RAW (mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "NullReferenceException", arg, NULL_HANDLE_STRING, error));
230230
mono_error_assert_ok (error);
231-
arg = mono_string_new_handle (domain, "The requested operation caused a stack overflow.", error);
231+
arg = mono_string_new_handle ("The requested operation caused a stack overflow.", error);
232232
mono_error_assert_ok (error);
233233
domain->stack_overflow_ex = MONO_HANDLE_RAW (mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "StackOverflowException", arg, NULL_HANDLE_STRING, error));
234234
mono_error_assert_ok (error);
235235

236236
/*The ephemeron tombstone i*/
237-
domain->ephemeron_tombstone = MONO_HANDLE_RAW (mono_object_new_handle (domain, mono_defaults.object_class, error));
237+
domain->ephemeron_tombstone = MONO_HANDLE_RAW (mono_object_new_handle (mono_defaults.object_class, error));
238238
mono_error_assert_ok (error);
239239

240240
if (domain != old_domain)
@@ -297,7 +297,7 @@ mono_runtime_init_checked (MonoDomain *domain, MonoThreadStartCB start_cb, MonoT
297297

298298
klass = mono_class_get_appdomain_class ();
299299

300-
ad = MONO_HANDLE_CAST (MonoAppDomain, mono_object_new_pinned_handle (domain, klass, error));
300+
ad = MONO_HANDLE_CAST (MonoAppDomain, mono_object_new_pinned_handle (klass, error));
301301
goto_if_nok (error, exit);
302302

303303
domain->domain = MONO_HANDLE_RAW (ad);
@@ -449,7 +449,7 @@ mono_context_init_checked (MonoDomain *domain, MonoError *error)
449449
goto exit;
450450

451451
klass = mono_class_load_from_name (mono_defaults.corlib, "System.Runtime.Remoting.Contexts", "Context");
452-
context = MONO_HANDLE_CAST (MonoAppContext, mono_object_new_pinned_handle (domain, klass, error));
452+
context = MONO_HANDLE_CAST (MonoAppContext, mono_object_new_pinned_handle (klass, error));
453453
goto_if_nok (error, exit);
454454

455455
MONO_HANDLE_SETVAL (context, domain_id, gint32, domain->domain_id);
@@ -582,7 +582,7 @@ mono_domain_try_type_resolve (MonoDomain *domain, char *name, MonoObject *typebu
582582

583583
// This will not work correctly on netcore
584584
if (name) {
585-
MonoStringHandle name_handle = mono_string_new_handle (mono_domain_get (), name, error);
585+
MonoStringHandle name_handle = mono_string_new_handle (name, error);
586586
goto_if_nok (error, exit);
587587
ret = mono_domain_try_type_resolve_name (domain, NULL, name_handle, error);
588588
} else {
@@ -691,7 +691,7 @@ get_assembly_array_from_domain (MonoDomain *domain, MonoError *error)
691691

692692
assemblies = mono_domain_get_assemblies (domain);
693693

694-
MonoArrayHandle res = mono_array_new_handle (domain, mono_class_get_assembly_class (), assemblies->len, error);
694+
MonoArrayHandle res = mono_array_new_handle (mono_class_get_assembly_class (), assemblies->len, error);
695695
goto_if_nok (error, leave);
696696
for (i = 0; i < assemblies->len; ++i) {
697697
if (!add_assembly_to_array (domain, res, i, (MonoAssembly *)g_ptr_array_index (assemblies, i), error))
@@ -716,7 +716,7 @@ mono_try_assembly_resolve (MonoAssemblyLoadContext *alc, const char *fname_raw,
716716
HANDLE_FUNCTION_ENTER ();
717717
error_init (error);
718718
MonoAssembly *result = NULL;
719-
MonoStringHandle fname = mono_string_new_handle (mono_alc_domain (alc), fname_raw, error);
719+
MonoStringHandle fname = mono_string_new_handle (fname_raw, error);
720720
goto_if_nok (error, leave);
721721
result = mono_try_assembly_resolve_handle (alc, fname, requesting, error);
722722
leave:

src/mono/mono/metadata/assembly-load-context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ invoke_resolve_method (MonoMethod *resolve_method, MonoAssemblyLoadContext *alc,
285285

286286
aname_str = mono_stringify_assembly_name (aname);
287287

288-
MonoStringHandle aname_obj = mono_string_new_handle (mono_alc_domain (alc), aname_str, error);
288+
MonoStringHandle aname_obj = mono_string_new_handle (aname_str, error);
289289
goto_if_nok (error, leave);
290290

291291
MonoReflectionAssemblyHandle assm;

src/mono/mono/metadata/class-getters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ MONO_CLASS_GETTER(m_class_get_methods, MonoMethod **, , MonoClass, methods)
6969
MONO_CLASS_GETTER(m_class_get_this_arg, MonoType*, &, MonoClass, this_arg)
7070
MONO_CLASS_GETTER(m_class_get_byval_arg, MonoType*, &, MonoClass, _byval_arg)
7171
MONO_CLASS_GETTER(m_class_get_gc_descr, MonoGCDescriptor, , MonoClass, gc_descr)
72-
MONO_CLASS_GETTER(m_class_get_runtime_info, MonoClassRuntimeInfo *, , MonoClass, runtime_info)
72+
MONO_CLASS_GETTER(m_class_get_runtime_vtable, MonoVTable*, , MonoClass, runtime_vtable)
7373
MONO_CLASS_GETTER(m_class_get_vtable, MonoMethod **, , MonoClass, vtable)
7474
MONO_CLASS_GETTER(m_class_get_infrequent_data, MonoPropertyBag*, &, MonoClass, infrequent_data)
7575

src/mono/mono/metadata/class-init.c

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,52 +3958,6 @@ mono_class_setup_nested_types (MonoClass *klass)
39583958
mono_loader_unlock ();
39593959
}
39603960

3961-
/**
3962-
* mono_class_setup_runtime_info:
3963-
* \param klass the class to setup
3964-
* \param domain the domain of the \p vtable
3965-
* \param vtable
3966-
*
3967-
* Store \p vtable in \c klass->runtime_info.
3968-
*
3969-
* Sets the following field in MonoClass:
3970-
* - runtime_info
3971-
*
3972-
* LOCKING: domain lock and loaderlock must be held.
3973-
*/
3974-
void
3975-
mono_class_setup_runtime_info (MonoClass *klass, MonoDomain *domain, MonoVTable *vtable)
3976-
{
3977-
MonoClassRuntimeInfo *old_info = m_class_get_runtime_info (klass);
3978-
if (old_info && old_info->max_domain >= domain->domain_id) {
3979-
/* someone already created a large enough runtime info */
3980-
old_info->domain_vtables [domain->domain_id] = vtable;
3981-
} else {
3982-
int new_size = domain->domain_id;
3983-
if (old_info)
3984-
new_size = MAX (new_size, old_info->max_domain);
3985-
new_size++;
3986-
/* make the new size a power of two */
3987-
int i = 2;
3988-
while (new_size > i)
3989-
i <<= 1;
3990-
new_size = i;
3991-
/* this is a bounded memory retention issue: may want to
3992-
* handle it differently when we'll have a rcu-like system.
3993-
*/
3994-
MonoClassRuntimeInfo *runtime_info = (MonoClassRuntimeInfo *)mono_image_alloc0 (m_class_get_image (klass), MONO_SIZEOF_CLASS_RUNTIME_INFO + new_size * sizeof (gpointer));
3995-
runtime_info->max_domain = new_size - 1;
3996-
/* copy the stuff from the older info */
3997-
if (old_info) {
3998-
memcpy (runtime_info->domain_vtables, old_info->domain_vtables, (old_info->max_domain + 1) * sizeof (gpointer));
3999-
}
4000-
runtime_info->domain_vtables [domain->domain_id] = vtable;
4001-
/* keep this last*/
4002-
mono_memory_barrier ();
4003-
klass->runtime_info = runtime_info;
4004-
}
4005-
}
4006-
40073961
/**
40083962
* mono_class_create_array_fill_type:
40093963
*
@@ -4025,6 +3979,12 @@ mono_class_create_array_fill_type (void)
40253979
return &aklass.klass;
40263980
}
40273981

3982+
void
3983+
mono_class_set_runtime_vtable (MonoClass *klass, MonoVTable *vtable)
3984+
{
3985+
klass->runtime_vtable = vtable;
3986+
}
3987+
40283988
/**
40293989
* mono_classes_init:
40303990
*

src/mono/mono/metadata/class-init.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ mono_class_setup_has_finalizer (MonoClass *klass);
8282
void
8383
mono_class_setup_nested_types (MonoClass *klass);
8484

85-
void
86-
mono_class_setup_runtime_info (MonoClass *klass, MonoDomain *domain, MonoVTable *vtable);
87-
8885
MonoClass *
8986
mono_class_create_array_fill_type (void);
9087

88+
void
89+
mono_class_set_runtime_vtable (MonoClass *klass, MonoVTable *vtable);
90+
9191
#endif

src/mono/mono/metadata/class-internals.h

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,6 @@ typedef enum {
223223
/* add other exception type */
224224
} MonoExceptionType;
225225

226-
/* This struct collects the info needed for the runtime use of a class,
227-
* like the vtables for a domain, the GC descriptor, etc.
228-
*/
229-
typedef struct {
230-
guint16 max_domain;
231-
/* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
232-
MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
233-
} MonoClassRuntimeInfo;
234-
235-
#define MONO_SIZEOF_CLASS_RUNTIME_INFO (sizeof (MonoClassRuntimeInfo) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
236-
237226
typedef struct {
238227
MonoPropertyBagItem head;
239228

@@ -1237,7 +1226,7 @@ MonoClassField*
12371226
mono_class_get_field_from_name_full (MonoClass *klass, const char *name, MonoType *type);
12381227

12391228
MonoVTable*
1240-
mono_class_vtable_checked (MonoDomain *domain, MonoClass *klass, MonoError *error);
1229+
mono_class_vtable_checked (MonoClass *klass, MonoError *error);
12411230

12421231
void
12431232
mono_class_is_assignable_from_checked (MonoClass *klass, MonoClass *oklass, gboolean *result, MonoError *error);
@@ -1544,48 +1533,71 @@ m_field_get_offset (MonoClassField *field)
15441533
}
15451534

15461535
/*
1547-
* Memory allocation for classes/methods
1536+
* Memory allocation for images/classes/methods
15481537
*
15491538
* These should be used to allocate memory whose lifetime is equal to
1550-
* the lifetime of the domain+class/method pair.
1539+
* the lifetime of the image/class/method.
15511540
*/
15521541

15531542
static inline MonoMemoryManager*
1554-
m_class_get_mem_manager (MonoDomain *domain, MonoClass *klass)
1543+
m_image_get_mem_manager (MonoImage *image)
15551544
{
1556-
// FIXME:
1557-
return mono_domain_memory_manager (domain);
1545+
return (MonoMemoryManager*)mono_image_get_alc (image)->memory_manager;
1546+
}
1547+
1548+
static inline void *
1549+
m_image_alloc (MonoImage *image, guint size)
1550+
{
1551+
return mono_mem_manager_alloc (m_image_get_mem_manager (image), size);
1552+
}
1553+
1554+
static inline void *
1555+
m_image_alloc0 (MonoImage *image, guint size)
1556+
{
1557+
return mono_mem_manager_alloc0 (m_image_get_mem_manager (image), size);
1558+
}
1559+
1560+
static inline MonoMemoryManager*
1561+
m_class_get_mem_manager (MonoClass *klass)
1562+
{
1563+
// FIXME: Generics
1564+
MonoAssemblyLoadContext *alc = mono_image_get_alc (m_class_get_image (klass));
1565+
if (alc)
1566+
return (MonoMemoryManager*)alc->memory_manager;
1567+
else
1568+
/* Dynamic assemblies */
1569+
return mono_domain_ambient_memory_manager (mono_get_root_domain ());
15581570
}
15591571

15601572
static inline void *
1561-
m_class_alloc (MonoDomain *domain, MonoClass *klass, guint size)
1573+
m_class_alloc (MonoClass *klass, guint size)
15621574
{
1563-
return mono_mem_manager_alloc (m_class_get_mem_manager (domain, klass), size);
1575+
return mono_mem_manager_alloc (m_class_get_mem_manager (klass), size);
15641576
}
15651577

15661578
static inline void *
1567-
m_class_alloc0 (MonoDomain *domain, MonoClass *klass, guint size)
1579+
m_class_alloc0 (MonoClass *klass, guint size)
15681580
{
1569-
return mono_mem_manager_alloc0 (m_class_get_mem_manager (domain, klass), size);
1581+
return mono_mem_manager_alloc0 (m_class_get_mem_manager (klass), size);
15701582
}
15711583

15721584
static inline MonoMemoryManager*
1573-
m_method_get_mem_manager (MonoDomain *domain, MonoMethod *method)
1585+
m_method_get_mem_manager (MonoMethod *method)
15741586
{
15751587
// FIXME:
1576-
return mono_domain_memory_manager (domain);
1588+
return mono_domain_memory_manager (mono_get_root_domain ());
15771589
}
15781590

15791591
static inline void *
1580-
m_method_alloc (MonoDomain *domain, MonoMethod *method, guint size)
1592+
m_method_alloc (MonoMethod *method, guint size)
15811593
{
1582-
return mono_mem_manager_alloc (m_method_get_mem_manager (domain, method), size);
1594+
return mono_mem_manager_alloc (m_method_get_mem_manager (method), size);
15831595
}
15841596

15851597
static inline void *
1586-
m_method_alloc0 (MonoDomain *domain, MonoMethod *method, guint size)
1598+
m_method_alloc0 (MonoMethod *method, guint size)
15871599
{
1588-
return mono_mem_manager_alloc0 (m_method_get_mem_manager (domain, method), size);
1600+
return mono_mem_manager_alloc0 (m_method_get_mem_manager (method), size);
15891601
}
15901602

15911603
// Enum and static storage for JIT icalls.

src/mono/mono/metadata/class-private-definition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct _MonoClass {
117117

118118
MonoGCDescriptor gc_descr;
119119

120-
MonoClassRuntimeInfo *runtime_info;
120+
MonoVTable *runtime_vtable;
121121

122122
/* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
123123
MonoMethod **vtable;

src/mono/mono/metadata/class.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,27 +1606,18 @@ mono_error_set_for_class_failure (MonoError *oerror, const MonoClass *klass)
16061606
/*
16071607
* mono_class_alloc:
16081608
*
1609-
* Allocate memory for some data belonging to CLASS, either from its image's mempool,
1610-
* or from the heap.
1609+
* Allocate memory for data belonging to CLASS.
16111610
*/
16121611
gpointer
16131612
mono_class_alloc (MonoClass *klass, int size)
16141613
{
1615-
MonoGenericClass *gklass = mono_class_try_get_generic_class (klass);
1616-
if (gklass)
1617-
return mono_image_set_alloc (gklass->owner, size);
1618-
else
1619-
return mono_image_alloc (m_class_get_image (klass), size);
1614+
return m_class_alloc (klass, size);
16201615
}
16211616

16221617
gpointer
16231618
(mono_class_alloc0) (MonoClass *klass, int size)
16241619
{
1625-
gpointer res;
1626-
1627-
res = mono_class_alloc (klass, size);
1628-
memset (res, 0, size);
1629-
return res;
1620+
return m_class_alloc0 (klass, size);
16301621
}
16311622

16321623
#define mono_class_new0(klass,struct_type, n_structs) \

src/mono/mono/metadata/cominterop.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ ves_icall_System_ComObject_CreateRCW (MonoReflectionTypeHandle ref_type, MonoErr
17951795
* is called by the corresponding real proxy to create the real RCW.
17961796
* Constructor does not need to be called. Will be called later.
17971797
*/
1798-
MonoVTable *vtable = mono_class_vtable_checked (domain, klass, error);
1798+
MonoVTable *vtable = mono_class_vtable_checked (klass, error);
17991799
return_val_if_nok (error, NULL_HANDLE);
18001800
return mono_object_new_alloc_by_vtable (vtable, error);
18011801
}
@@ -3218,21 +3218,21 @@ mono_string_from_bstr_checked (mono_bstr_const bstr, MonoError *error)
32183218
return NULL_HANDLE_STRING;
32193219
#ifdef HOST_WIN32
32203220
#if HAVE_API_SUPPORT_WIN32_BSTR
3221-
return mono_string_new_utf16_handle (mono_domain_get (), bstr, SysStringLen ((BSTR)bstr), error);
3221+
return mono_string_new_utf16_handle (bstr, SysStringLen ((BSTR)bstr), error);
32223222
#else
3223-
return mono_string_new_utf16_handle (mono_domain_get (), bstr, *((guint32 *)bstr - 1) / sizeof (gunichar2), error);
3223+
return mono_string_new_utf16_handle (bstr, *((guint32 *)bstr - 1) / sizeof (gunichar2), error);
32243224
#endif /* HAVE_API_SUPPORT_WIN32_BSTR */
32253225
#else
32263226
#ifndef DISABLE_COM
32273227
if (com_provider == MONO_COM_DEFAULT)
32283228
#endif
3229-
return mono_string_new_utf16_handle (mono_domain_get (), bstr, *((guint32 *)bstr - 1) / sizeof (gunichar2), error);
3229+
return mono_string_new_utf16_handle (bstr, *((guint32 *)bstr - 1) / sizeof (gunichar2), error);
32303230
#ifndef DISABLE_COM
32313231
else if (com_provider == MONO_COM_MS && init_com_provider_ms ()) {
32323232
glong written = 0;
32333233
// FIXME mono_string_new_utf32_handle to combine g_ucs4_to_utf16 and mono_string_new_utf16_handle.
32343234
gunichar2* utf16 = g_ucs4_to_utf16 ((const gunichar *)bstr, sys_string_len_ms (bstr), NULL, &written, NULL);
3235-
MonoStringHandle res = mono_string_new_utf16_handle (mono_domain_get (), utf16, written, error);
3235+
MonoStringHandle res = mono_string_new_utf16_handle (utf16, written, error);
32363236
g_free (utf16);
32373237
return res;
32383238
} else {

0 commit comments

Comments
 (0)