Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mono/dis/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "get.h"
#include "dis-cil.h"
#include "declsec.h"
#include <mono/metadata/class-init.h>
#include <mono/metadata/class-internals.h>
#include <mono/metadata/object-internals.h>
#include <mono/metadata/loader.h>
Expand Down Expand Up @@ -1546,7 +1547,7 @@ dis_data (MonoImage *m)
mono_error_cleanup (error);
continue;
}
mono_class_init (mono_class_from_mono_type (type));
mono_class_init_ready (mono_class_from_mono_type (type), MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
size = mono_type_size (type, &align);

if (rva) {
Expand Down
4 changes: 2 additions & 2 deletions mono/metadata/appdomain.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ create_domain_objects (MonoDomain *domain)
* This class is used during exception handling, so initialize it here, to prevent
* stack overflows while handling stack overflows.
*/
mono_class_init (mono_class_create_array (mono_defaults.int_class, 1));
mono_class_init_ready (mono_class_create_array (mono_defaults.int_class, 1), MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
}

/**
Expand Down Expand Up @@ -344,7 +344,7 @@ mono_get_corlib_version (void)
MonoObject *value;

klass = mono_class_load_from_name (mono_defaults.corlib, "System", "Environment");
mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
field = mono_class_get_field_from_name (klass, "mono_corlib_version");
if (!field)
return -1;
Expand Down
39 changes: 28 additions & 11 deletions mono/metadata/class-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ mono_class_setup_fields (MonoClass *klass)
instance_size = 0;
if (klass->parent) {
/* For generic instances, klass->parent might not have been initialized */
mono_class_init (klass->parent);
mono_class_init_ready (klass->parent, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
mono_class_setup_fields (klass->parent);
if (mono_class_set_type_load_failure_causedby_class (klass, klass->parent, "Could not set up parent class"))
return;
Expand Down Expand Up @@ -888,7 +888,7 @@ mono_class_create_bounded_array (MonoClass *eclass, guint32 rank, gboolean bound

parent = mono_defaults.array_class;
if (!parent->inited)
mono_class_init (parent);
mono_class_init_ready (parent, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

klass = image_set ? (MonoClass *)mono_image_set_alloc0 (image_set, sizeof (MonoClassArray)) : (MonoClass *)mono_image_alloc0 (image, sizeof (MonoClassArray));

Expand Down Expand Up @@ -934,7 +934,7 @@ mono_class_create_bounded_array (MonoClass *eclass, guint32 rank, gboolean bound
mono_class_setup_supertypes (klass);

if (mono_class_is_ginst (eclass))
mono_class_init (eclass);
mono_class_init_ready (eclass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
if (!eclass->size_inited)
mono_class_setup_fields (eclass);
mono_class_set_type_load_failure_causedby_class (klass, eclass, "Could not load array element type");
Expand Down Expand Up @@ -1688,7 +1688,7 @@ setup_interface_offsets (MonoClass *klass, int cur_slot, gboolean overwrite)

/* A gparam does not have any interface_id set. */
if (! mono_class_is_gparam (ic))
mono_class_init (ic);
mono_class_init_ready (ic, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

if (max_iid < ic->interface_id)
max_iid = ic->interface_id;
Expand Down Expand Up @@ -2720,7 +2720,7 @@ mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int o
}

if (klass->parent) {
mono_class_init (klass->parent);
mono_class_init_ready (klass->parent, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
mono_class_setup_vtable_full (klass->parent, in_setup);

if (mono_class_set_type_load_failure_causedby_class (klass, klass->parent, "Parent class failed to load"))
Expand Down Expand Up @@ -3159,7 +3159,7 @@ mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int o
if (mono_class_is_ginst (klass)) {
MonoClass *gklass = mono_class_get_generic_class (klass)->container_class;

mono_class_init (gklass);
mono_class_init_ready (gklass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

klass->vtable_size = MAX (gklass->vtable_size, cur_slot);
} else {
Expand Down Expand Up @@ -4096,6 +4096,12 @@ mono_get_unique_iid (MonoClass *klass)
*/
gboolean
mono_class_init (MonoClass *klass)
{
return mono_class_init_ready (klass, MONO_CLASS_READY_MAX);
}

gboolean
mono_class_init_ready (MonoClass *klass, MonoClassReady readiness)
{
int i, vtable_size = 0, array_method_count = 0;
MonoCachedClassInfo cached_info;
Expand All @@ -4107,6 +4113,17 @@ mono_class_init (MonoClass *klass)

g_assert (klass);

g_assert (readiness >= MONO_CLASS_READY_MIN && readiness <= MONO_CLASS_READY_MAX);

switch (readiness) {
case MONO_CLASS_READY_BAREBONES:
return !mono_class_has_failure (klass);
case MONO_CLASS_READY_INSTANTIATE:
break; /* continue with initialization */
default:
g_assert_not_reached ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a g_error with the value passed would help debugging.

}

/* Double-checking locking pattern */
if (klass->inited || mono_class_has_failure (klass))
return !mono_class_has_failure (klass);
Expand Down Expand Up @@ -4137,7 +4154,7 @@ mono_class_init (MonoClass *klass)
if (klass->byval_arg.type == MONO_TYPE_ARRAY || klass->byval_arg.type == MONO_TYPE_SZARRAY) {
MonoClass *element_class = klass->element_class;
if (!element_class->inited)
mono_class_init (element_class);
mono_class_init_ready (element_class, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
if (mono_class_set_type_load_failure_causedby_class (klass, element_class, "Could not load array element class"))
goto leave;
}
Expand All @@ -4147,7 +4164,7 @@ mono_class_init (MonoClass *klass)
if (mono_class_is_ginst (klass) && !mono_class_get_generic_class (klass)->is_dynamic) {
MonoClass *gklass = mono_class_get_generic_class (klass)->container_class;

mono_class_init (gklass);
mono_class_init_ready (gklass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
if (mono_class_set_type_load_failure_causedby_class (klass, gklass, "Generic Type Definition failed to init"))
goto leave;

Expand All @@ -4156,7 +4173,7 @@ mono_class_init (MonoClass *klass)
}

if (klass->parent && !klass->parent->inited)
mono_class_init (klass->parent);
mono_class_init_ready (klass->parent, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

has_cached_info = mono_class_get_cached_class_info (klass, &cached_info);

Expand Down Expand Up @@ -4647,7 +4664,7 @@ mono_class_setup_methods (MonoClass *klass)
ERROR_DECL (error);
MonoClass *gklass = mono_class_get_generic_class (klass)->container_class;

mono_class_init (gklass);
mono_class_init_ready (gklass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
if (!mono_class_has_failure (gklass))
mono_class_setup_methods (gklass);
if (mono_class_set_type_load_failure_causedby_class (klass, gklass, "Generic type definition failed to load"))
Expand Down Expand Up @@ -4828,7 +4845,7 @@ mono_class_setup_properties (MonoClass *klass)
if (mono_class_is_ginst (klass)) {
MonoClass *gklass = mono_class_get_generic_class (klass)->container_class;

mono_class_init (gklass);
mono_class_init_ready (gklass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
mono_class_setup_properties (gklass);
if (mono_class_set_type_load_failure_causedby_class (klass, gklass, "Generic type definition failed to load"))
return;
Expand Down
12 changes: 12 additions & 0 deletions mono/metadata/class-init.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ mono_class_create_ptr (MonoType *type);
MonoClass *
mono_class_create_fnptr (MonoMethodSignature *sig);

typedef enum _MonoClassReady {
/* Barebones readiness: just allocate a MonoClass and set its image, name and name space. */
MONO_CLASS_READY_BAREBONES = 0,
/* Instantiate readiness: metadata vtable is initialized, ready to create runtime vtables. */
MONO_CLASS_READY_INSTANTIATE = 0xff,
MONO_CLASS_READY_MIN = MONO_CLASS_READY_BAREBONES,
MONO_CLASS_READY_MAX = MONO_CLASS_READY_INSTANTIATE,
} MonoClassReady;

gboolean
mono_class_init_ready (MonoClass *klass, MonoClassReady readiness);

void
mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum, GList *in_setup);

Expand Down
28 changes: 14 additions & 14 deletions mono/metadata/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ collect_implemented_interfaces_aux (MonoClass *klass, GPtrArray **res, GHashTabl
continue;
g_ptr_array_add (*res, ic);
g_hash_table_insert (*ifaces, ic, ic);
mono_class_init (ic);
mono_class_init_ready (ic, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
if (mono_class_has_failure (ic)) {
mono_error_set_type_load_class (error, ic, "Error Loading class");
return;
Expand Down Expand Up @@ -1962,7 +1962,7 @@ gint32
mono_class_instance_size (MonoClass *klass)
{
if (!m_class_is_size_inited (klass))
mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

return m_class_get_instance_size (klass);
}
Expand All @@ -1979,7 +1979,7 @@ gint32
mono_class_min_align (MonoClass *klass)
{
if (!m_class_is_size_inited (klass))
mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

return m_class_get_min_align (klass);
}
Expand Down Expand Up @@ -2021,7 +2021,7 @@ gint32
mono_class_data_size (MonoClass *klass)
{
if (!m_class_is_inited (klass))
mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
/* This can happen with dynamically created types */
if (!m_class_is_fields_inited (klass))
mono_class_setup_fields (klass);
Expand Down Expand Up @@ -3189,8 +3189,8 @@ mono_class_is_subclass_of (MonoClass *klass, MonoClass *klassc,
gboolean check_interfaces)
{
/* FIXME test for interfaces with variant generic arguments */
mono_class_init (klass);
mono_class_init (klassc);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
mono_class_init_ready (klassc, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

if (check_interfaces && MONO_CLASS_IS_INTERFACE (klassc) && !MONO_CLASS_IS_INTERFACE (klass)) {
if (MONO_CLASS_IMPLEMENTS_INTERFACE (klass, m_class_get_interface_id (klassc)))
Expand Down Expand Up @@ -3434,10 +3434,10 @@ mono_class_is_assignable_from (MonoClass *klass, MonoClass *oklass)
ERROR_DECL (error);
/*FIXME this will cause a lot of irrelevant stuff to be loaded.*/
if (!m_class_is_inited (klass))
mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

if (!m_class_is_inited (oklass))
mono_class_init (oklass);
mono_class_init_ready (oklass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

if (mono_class_has_failure (klass) || mono_class_has_failure (oklass))
return FALSE;
Expand Down Expand Up @@ -3771,7 +3771,7 @@ mono_class_get_cctor (MonoClass *klass)
return mono_class_get_method_from_name_flags (klass, ".cctor", -1, METHOD_ATTRIBUTE_SPECIAL_NAME);
}

mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

if (!m_class_has_cctor (klass))
return NULL;
Expand Down Expand Up @@ -3806,7 +3806,7 @@ mono_class_get_finalizer (MonoClass *klass)
MonoCachedClassInfo cached_info;

if (!m_class_is_inited (klass))
mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
if (!mono_class_has_finalizer (klass))
return NULL;

Expand Down Expand Up @@ -3967,7 +3967,7 @@ mono_ldtoken_checked (MonoImage *image, guint32 token, MonoClass **handle_class,
if (!type)
return NULL;

mono_class_init (mono_class_from_mono_type (type));
mono_class_init_ready (mono_class_from_mono_type (type), MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
/* We return a MonoType* as handle */
return type;
}
Expand All @@ -3984,7 +3984,7 @@ mono_ldtoken_checked (MonoImage *image, guint32 token, MonoClass **handle_class,
if (!klass)
return NULL;

mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
return mono_class_get_field (klass, token);
}
case MONO_TOKEN_METHOD_DEF:
Expand Down Expand Up @@ -4480,7 +4480,7 @@ mono_class_get_interfaces (MonoClass* klass, gpointer *iter)
return NULL;
if (!*iter) {
if (!m_class_is_inited (klass))
mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
if (!m_class_is_interfaces_inited (klass)) {
mono_class_setup_interfaces (klass, error);
if (!mono_error_ok (error)) {
Expand Down Expand Up @@ -4941,7 +4941,7 @@ mono_class_get_method_from_name_checked (MonoClass *klass, const char *name,
MonoMethod *res = NULL;
int i;

mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

if (mono_class_is_ginst (klass) && !m_class_get_methods (klass)) {
res = mono_class_get_method_from_name_checked (mono_class_get_generic_class (klass)->container_class, name, param_count, flags, error);
Expand Down
1 change: 1 addition & 0 deletions mono/metadata/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ MONO_RT_EXTERNAL_ONLY
MONO_API MonoClass *
mono_class_get_full (MonoImage *image, uint32_t type_token, MonoGenericContext *context);

MONO_RT_EXTERNAL_ONLY
MONO_API mono_bool
mono_class_init (MonoClass *klass);

Expand Down
6 changes: 3 additions & 3 deletions mono/metadata/cominterop.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ cominterop_type_from_handle (MonoType *handle)
MonoDomain *domain = mono_domain_get ();
MonoClass *klass = mono_class_from_mono_type (handle);

mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

ret = mono_type_get_object_checked (domain, handle, error);
mono_error_set_pending_exception (error);
Expand Down Expand Up @@ -1685,7 +1685,7 @@ ves_icall_System_Runtime_InteropServices_Marshal_GetCCW (MonoObject* object, Mon
g_assert (type->type);
klass = mono_type_get_class (type->type);
g_assert (klass);
if (!mono_class_init (klass)) {
if (!mono_class_init_ready (klass, MONO_CLASS_READY_MAX)) { /* FIXME lower readiness if possible */
mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
return NULL;
}
Expand Down Expand Up @@ -1855,7 +1855,7 @@ ves_icall_System_ComObject_GetInterfaceInternal (MonoComObject* obj, MonoReflect
#ifndef DISABLE_COM
ERROR_DECL (error);
MonoClass *klass = mono_type_get_class (type->type);
if (!mono_class_init (klass)) {
if (!mono_class_init_ready (klass, MONO_CLASS_READY_MAX)) { /* FIXME lower readiness if possible */
mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
return NULL;
}
Expand Down
6 changes: 3 additions & 3 deletions mono/metadata/custom-attrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ create_custom_attr (MonoImage *image, MonoMethod *method, const guchar *data, gu

error_init (error);

mono_class_init (method->klass);
mono_class_init_ready (method->klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

if (!mono_verifier_verify_cattr_content (image, method, data, len, NULL)) {
set_custom_attr_fmt_error (error);
Expand Down Expand Up @@ -988,7 +988,7 @@ mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *meth
return;
}

mono_class_init (method->klass);
mono_class_init_ready (method->klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

domain = mono_domain_get ();

Expand Down Expand Up @@ -1141,7 +1141,7 @@ reflection_resolve_custom_attribute_data (MonoReflectionMethod *ref_method, Mono
method = ref_method->method;
domain = mono_object_domain (ref_method);

if (!mono_class_init (method->klass)) {
if (!mono_class_init_ready (method->klass, MONO_CLASS_READY_MAX)) { /* FIXME lower readiness if possible */
mono_error_set_for_class_failure (error, method->klass);
goto leave;
}
Expand Down
2 changes: 1 addition & 1 deletion mono/metadata/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ mono_init_internal (const char *filename, const char *exe_filename, const char *
mono_defaults.customattribute_data_class = mono_class_load_from_name (
mono_defaults.corlib, "System.Reflection", "CustomAttributeData");

mono_class_init (mono_defaults.array_class);
mono_class_init_ready (mono_defaults.array_class, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */
mono_defaults.generic_nullable_class = mono_class_load_from_name (
mono_defaults.corlib, "System", "Nullable`1");
mono_defaults.generic_ilist_class = mono_class_load_from_name (
Expand Down
5 changes: 3 additions & 2 deletions mono/metadata/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <glib.h>
#include <config.h>
#include <mono/metadata/class-init.h>
#include <mono/metadata/environment.h>
#include <mono/metadata/exception.h>
#include <mono/metadata/exception-internals.h>
Expand Down Expand Up @@ -811,7 +812,7 @@ mono_get_exception_type_initialization_checked (const gchar *type_name, MonoExce

klass = mono_class_load_from_name (mono_get_corlib (), "System", "TypeInitializationException");

mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

iter = NULL;
while ((method = mono_class_get_methods (klass, &iter))) {
Expand Down Expand Up @@ -1000,7 +1001,7 @@ mono_get_exception_reflection_type_load_checked (MonoArrayHandle types, MonoArra

klass = mono_class_load_from_name (mono_get_corlib (), "System.Reflection", "ReflectionTypeLoadException");

mono_class_init (klass);
mono_class_init_ready (klass, MONO_CLASS_READY_MAX); /* FIXME lower readiness if possible */

/* Find the Type[], Exception[] ctor */
iter = NULL;
Expand Down
Loading