Skip to content

Commit

Permalink
Readding type size retrieval to regain lost perf.
Browse files Browse the repository at this point in the history
  • Loading branch information
UnityAlex committed Sep 12, 2024
1 parent edb575d commit 7773bd0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/dlls/mscoree/mscorwks_ntdef.src
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ EXPORTS

; mono
coreclr_image_get_custom_attribute_data
coreclr_unity_array_element_size
coreclr_unity_class_array_element_size
coreclr_unity_profiler_register
coreclr_unity_profiler_get_managed_assembly_load_context
coreclr_unity_gc_concurrent_mode
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/dlls/mscoree/mscorwks_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ MetaDataGetDispenser

; mono
coreclr_image_get_custom_attribute_data
coreclr_unity_array_element_size
coreclr_unity_class_array_element_size
coreclr_unity_profiler_register
coreclr_unity_profiler_get_managed_assembly_load_context
coreclr_unity_gc_concurrent_mode
Expand Down
26 changes: 26 additions & 0 deletions src/coreclr/vm/mono/mono_coreclr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,32 @@ extern "C" EXPORT_API MonoClass* EXPORT_CC mono_class_from_mono_type(MonoType *i
return (MonoClass*)klass;
}

extern "C" EXPORT_API int EXPORT_CC coreclr_unity_array_element_size(MonoClass* classOfArray)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
PRECONDITION(classOfArray != NULL);
}
CONTRACTL_END;

return reinterpret_cast<MonoClass_clr*>(classOfArray)->GetArrayElementTypeHandle().GetSize();
}

extern "C" EXPORT_API gint32 EXPORT_CC coreclr_unity_class_array_element_size(MonoClass *ac)
{
CONTRACTL{
STANDARD_VM_CHECK;
PRECONDITION(ac != nullptr);
} CONTRACTL_END;
auto ac_clr = (MonoClass_clr*)ac;

// TODO: Is it really the method to use?
DWORD s = ac_clr->IsValueType() ? ac_clr->GetNumInstanceFieldBytes() : sizeof(void*);// ac_clr->GetBaseSize();
return s;
}

// remove once usages in this file are removed
static MonoClass* mono_class_get_element_class(MonoClass *klass)
{
Expand Down

0 comments on commit 7773bd0

Please sign in to comment.