From 5f0bb98eca8993d1f72f196d3ea15c1b7d094362 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 28 Mar 2023 11:15:39 -0400 Subject: [PATCH 01/41] Use dn_vector_t instead of GArray in one place in Mono Set up the infrastructure to consume shared container types from src/mono/{metadata,mini}. Replace one use of GArray with dn_vector_t --- src/mono/mono/CMakeLists.txt | 2 ++ src/mono/mono/metadata/CMakeLists.txt | 16 +++++++++++++++- src/mono/mono/metadata/custom-attrs.c | 21 +++++++++++++-------- src/mono/mono/mini/CMakeLists.txt | 2 +- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/mono/mono/CMakeLists.txt b/src/mono/mono/CMakeLists.txt index c59470996f5825..75815d178ee343 100644 --- a/src/mono/mono/CMakeLists.txt +++ b/src/mono/mono/CMakeLists.txt @@ -1,5 +1,7 @@ project(mono) +set(SHARED_CONTAINERS_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/containers/") + set(subdirs eglib utils diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index abddf1a58a5d92..a7a9460304bfd8 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -1,5 +1,19 @@ project(metadata C) +include (${SHARED_CONTAINERS_SOURCE_PATH}containers.cmake) + +set(shared_container_sources "") + +list(APPEND shared_container_sources + ${SHARED_CONTAINER_SOURCES} + ${SHARED_CONTAINER_HEADERS} +) + +addprefix(shared_container_sources ${SHARED_CONTAINERS_SOURCE_PATH} "${shared_container_sources}") + +add_library(shared_container_objects OBJECT ${shared_container_sources}) +target_include_directories(shared_container_objects PUBLIC ${SHARED_CONTAINERS_SOURCE_PATH}) + # # This library contains the icall tables if the runtime was configured with DISABLE_ICALL_TABLES # @@ -203,7 +217,7 @@ target_compile_definitions(metadata_objects PRIVATE ${metadata_compile_definitio target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects) # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm -target_link_libraries(metadata_objects PRIVATE sgen_objects) +target_link_libraries(metadata_objects PRIVATE sgen_objects shared_container_objects) target_compile_definitions(metadata_objects PRIVATE -DMONO_DLL_EXPORT) target_include_directories(metadata_objects PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. diff --git a/src/mono/mono/metadata/custom-attrs.c b/src/mono/mono/metadata/custom-attrs.c index 566c3512202b15..eb27ccd9eb967c 100644 --- a/src/mono/mono/metadata/custom-attrs.c +++ b/src/mono/mono/metadata/custom-attrs.c @@ -13,6 +13,7 @@ * Licensed under the MIT license. See LICENSE file in the project root for full license information. */ #include +#include #include "mono/metadata/assembly.h" #include "mono/metadata/class-init.h" #include "mono/metadata/class-internals.h" @@ -1880,6 +1881,7 @@ mono_custom_attrs_from_index (MonoImage *image, guint32 idx) mono_error_cleanup (error); return result; } + /** * mono_custom_attrs_from_index_checked: * \returns NULL if no attributes are found. On error returns NULL and sets \p error. @@ -1891,7 +1893,7 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig guint32 cols [MONO_CUSTOM_ATTR_SIZE]; MonoTableInfo *ca; MonoCustomAttrInfo *ainfo; - GArray *attr_array; + dn_vector_t *attr_array; const char *data; MonoCustomAttrEntry* attr; @@ -1904,7 +1906,10 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig return NULL; i --; // initial size chosen arbitrarily, but default is 16 which is rather small - attr_array = g_array_sized_new (TRUE, TRUE, sizeof (guint32), 128); + dn_vector_custom_alloc_params_t vec_params = {0,}; + vec_params.capacity = 128; + vec_params.attributes = DN_VECTOR_ATTRIBUTE_MEMORY_INIT; + attr_array = dn_vector_custom_alloc_t (&vec_params, uint32_t); while (!mono_metadata_table_bounds_check (image, MONO_TABLE_CUSTOMATTRIBUTE, i + 1)) { if (mono_metadata_decode_row_col (ca, i, MONO_CUSTOM_ATTR_PARENT) != idx) { if (G_LIKELY (!image->has_updates)) { @@ -1916,19 +1921,19 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig continue; } } - attr_array = g_array_append_val (attr_array, i); + dn_vector_push_back (attr_array, i); ++i; } - len = attr_array->len; + len = dn_vector_size (attr_array); if (!len) { - g_array_free (attr_array, TRUE); + dn_vector_free (attr_array); return NULL; } ainfo = (MonoCustomAttrInfo *)g_malloc0 (MONO_SIZEOF_CUSTOM_ATTR_INFO + sizeof (MonoCustomAttrEntry) * len); ainfo->num_attrs = len; ainfo->image = image; for (i = 0; i < len; ++i) { - mono_metadata_decode_row (ca, g_array_index (attr_array, guint32, i), cols, MONO_CUSTOM_ATTR_SIZE); + mono_metadata_decode_row (ca, *dn_vector_index_t (attr_array, uint32_t, i), cols, MONO_CUSTOM_ATTR_SIZE); mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS; switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) { case MONO_CUSTOM_ATTR_TYPE_METHODDEF: @@ -1949,7 +1954,7 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig mono_error_cleanup (error); error_init (error); } else { - g_array_free (attr_array, TRUE); + dn_vector_free (attr_array); g_free (ainfo); return NULL; } @@ -1959,7 +1964,7 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig attr->data_size = mono_metadata_decode_value (data, &data); attr->data = (guchar*)data; } - g_array_free (attr_array, TRUE); + dn_vector_free (attr_array); return ainfo; } diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 8419317adc58c3..3c14c803db02ae 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -354,7 +354,7 @@ set(monosgen-sources "${icu_shim_sources};${mini_sources};${ZLIB_SOURCES}") add_library(monosgen-objects OBJECT "${monosgen-sources}") target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects) -add_library(monosgen-static STATIC $ $ $ $ $) +add_library(monosgen-static STATIC $ $ $ $ $ $) set_target_properties(monosgen-static PROPERTIES OUTPUT_NAME ${MONO_LIB_NAME}) if(DISABLE_COMPONENTS OR AOT_COMPONENTS) From a9912494f0a5cac7ab911b53cda68046a2beda68 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 28 Mar 2023 12:14:56 -0400 Subject: [PATCH 02/41] include shared containers in mono shared lib, too --- src/mono/mono/mini/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 3c14c803db02ae..843b64f63f6a66 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -353,7 +353,7 @@ endif() set(monosgen-sources "${icu_shim_sources};${mini_sources};${ZLIB_SOURCES}") add_library(monosgen-objects OBJECT "${monosgen-sources}") -target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects) +target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects shared_container_objects) add_library(monosgen-static STATIC $ $ $ $ $ $) set_target_properties(monosgen-static PROPERTIES OUTPUT_NAME ${MONO_LIB_NAME}) @@ -378,7 +378,7 @@ if(NOT DISABLE_SHARED_LIBS) target_link_libraries(monosgen-shared PRIVATE ucontext) endif(CLR_CMAKE_HOST_ALPINE_LINUX AND TARGET_S390X) set_target_properties(monosgen-shared PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME}) - target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects) + target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects shared_container_objects) target_include_directories (monosgen-shared PRIVATE monoapi) if(TARGET_WIN32) # on Windows the import library for the shared mono library will have the same name as the static library, From 87f5d5064e7a2db84a2a9b37425832b807499bce Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 28 Mar 2023 12:29:03 -0400 Subject: [PATCH 03/41] convert mono_seq_point_init_next to use dn_vector_t --- src/mono/mono/metadata/seq-points-data.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mono/mono/metadata/seq-points-data.c b/src/mono/mono/metadata/seq-points-data.c index b5e50eea056852..5680dde50ef38c 100644 --- a/src/mono/mono/metadata/seq-points-data.c +++ b/src/mono/mono/metadata/seq-points-data.c @@ -9,6 +9,7 @@ */ #include "seq-points-data.h" +#include typedef struct { guint8 *data; @@ -274,24 +275,27 @@ mono_seq_point_init_next (MonoSeqPointInfo* info, SeqPoint sp, SeqPoint* next) int i; guint8* ptr; SeqPointIterator it; - GArray* seq_points = g_array_new (FALSE, TRUE, sizeof (SeqPoint)); + dn_vector_t seq_points = {0,}; + + dn_vector_init_t (&seq_points, SeqPoint); + SeqPointInfoInflated info_inflated = seq_point_info_inflate (info); g_assert (info_inflated.has_debug_data); mono_seq_point_iterator_init (&it, info); while (mono_seq_point_iterator_next (&it)) - g_array_append_vals (seq_points, &it.seq_point, 1); + dn_vector_push_back (&seq_points, it.seq_point); ptr = info_inflated.data + sp.next_offset; for (i = 0; i < sp.next_len; i++) { int next_index; next_index = decode_var_int (ptr, &ptr); - g_assert (next_index < seq_points->len); - memcpy (&next[i], seq_points->data + next_index * sizeof (SeqPoint), sizeof (SeqPoint)); + g_assert (next_index < dn_vector_size (&seq_points)); + memcpy (&next[i], dn_vector_index_t (&seq_points, SeqPoint, next_index), sizeof (SeqPoint)); } - g_array_free (seq_points, TRUE); + dn_vector_dispose (&seq_points); } gboolean From e8c7deaae5f697745f9f559fcf9b1b5c43c4267a Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 28 Mar 2023 12:35:11 -0400 Subject: [PATCH 04/41] [custom-attrs] Use init/dispose instead of alloc/free for dn_vector_t Use a stack allocated container (with heap-allocated data) to avoid one extra allocation --- src/mono/mono/metadata/custom-attrs.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/mono/mono/metadata/custom-attrs.c b/src/mono/mono/metadata/custom-attrs.c index eb27ccd9eb967c..78ea4948e86617 100644 --- a/src/mono/mono/metadata/custom-attrs.c +++ b/src/mono/mono/metadata/custom-attrs.c @@ -1893,7 +1893,7 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig guint32 cols [MONO_CUSTOM_ATTR_SIZE]; MonoTableInfo *ca; MonoCustomAttrInfo *ainfo; - dn_vector_t *attr_array; + dn_vector_t attr_array = {0,}; const char *data; MonoCustomAttrEntry* attr; @@ -1908,8 +1908,7 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig // initial size chosen arbitrarily, but default is 16 which is rather small dn_vector_custom_alloc_params_t vec_params = {0,}; vec_params.capacity = 128; - vec_params.attributes = DN_VECTOR_ATTRIBUTE_MEMORY_INIT; - attr_array = dn_vector_custom_alloc_t (&vec_params, uint32_t); + dn_vector_custom_init_t (&attr_array, &vec_params, uint32_t); while (!mono_metadata_table_bounds_check (image, MONO_TABLE_CUSTOMATTRIBUTE, i + 1)) { if (mono_metadata_decode_row_col (ca, i, MONO_CUSTOM_ATTR_PARENT) != idx) { if (G_LIKELY (!image->has_updates)) { @@ -1921,19 +1920,19 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig continue; } } - dn_vector_push_back (attr_array, i); + dn_vector_push_back (&attr_array, i); ++i; } - len = dn_vector_size (attr_array); + len = dn_vector_size (&attr_array); if (!len) { - dn_vector_free (attr_array); + dn_vector_dispose (&attr_array); return NULL; } ainfo = (MonoCustomAttrInfo *)g_malloc0 (MONO_SIZEOF_CUSTOM_ATTR_INFO + sizeof (MonoCustomAttrEntry) * len); ainfo->num_attrs = len; ainfo->image = image; for (i = 0; i < len; ++i) { - mono_metadata_decode_row (ca, *dn_vector_index_t (attr_array, uint32_t, i), cols, MONO_CUSTOM_ATTR_SIZE); + mono_metadata_decode_row (ca, *dn_vector_index_t (&attr_array, uint32_t, i), cols, MONO_CUSTOM_ATTR_SIZE); mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS; switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) { case MONO_CUSTOM_ATTR_TYPE_METHODDEF: @@ -1954,7 +1953,7 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig mono_error_cleanup (error); error_init (error); } else { - dn_vector_free (attr_array); + dn_vector_dispose (&attr_array); g_free (ainfo); return NULL; } @@ -1964,7 +1963,7 @@ mono_custom_attrs_from_index_checked (MonoImage *image, guint32 idx, gboolean ig attr->data_size = mono_metadata_decode_value (data, &data); attr->data = (guchar*)data; } - dn_vector_free (attr_array); + dn_vector_dispose (&attr_array); return ainfo; } From 2c5c00a4c4508c0c877be110e5096f1811537bd4 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 28 Mar 2023 13:02:49 -0400 Subject: [PATCH 05/41] move container logic to toplevel; add deps to runtime components Add a way to specify target_link_libraries for runtime components. Use it to link in the shared containers. Avoids duplicate linking of the container objects in static linking scenarios. --- src/mono/CMakeLists.txt | 19 +++++++++++++++++++ src/mono/mono/CMakeLists.txt | 2 -- src/mono/mono/component/CMakeLists.txt | 14 ++++++++++++-- src/mono/mono/metadata/CMakeLists.txt | 14 -------------- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 7b57776aa007c7..136c2dbc5e3e67 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -929,6 +929,25 @@ if(NOT DISABLE_LIBS) endif() add_subdirectory("${CLR_SRC_NATIVE_DIR}/public" public_apis) +### Paths and Targets for Shared Containers +set(SHARED_CONTAINERS_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/containers/") +include (${SHARED_CONTAINERS_SOURCE_PATH}containers.cmake) + +set(shared_container_sources "") + +list(APPEND shared_container_sources + ${SHARED_CONTAINER_SOURCES} + ${SHARED_CONTAINER_HEADERS} +) + +addprefix(shared_container_sources ${SHARED_CONTAINERS_SOURCE_PATH} "${shared_container_sources}") + +add_library(shared_container_objects OBJECT ${shared_container_sources}) +target_include_directories(shared_container_objects PUBLIC ${SHARED_CONTAINERS_SOURCE_PATH}) + + +### Mono runtime and components + add_subdirectory(mono) if (ENABLE_MSCORDBI AND NOT TARGET_ARCH STREQUAL "arm64" AND NOT CMAKE_CROSSCOMPILING AND NOT TARGET_IOS AND NOT TARGET_ANDROID AND NOT TARGET_BROWSER AND NOT TARGET_WASI AND NOT HOST_MACCAT) add_subdirectory(dlls/mscordbi) diff --git a/src/mono/mono/CMakeLists.txt b/src/mono/mono/CMakeLists.txt index 75815d178ee343..c59470996f5825 100644 --- a/src/mono/mono/CMakeLists.txt +++ b/src/mono/mono/CMakeLists.txt @@ -1,7 +1,5 @@ project(mono) -set(SHARED_CONTAINERS_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/containers/") - set(subdirs eglib utils diff --git a/src/mono/mono/component/CMakeLists.txt b/src/mono/mono/component/CMakeLists.txt index 8a8964efc087e5..fc5388f785382b 100644 --- a/src/mono/mono/component/CMakeLists.txt +++ b/src/mono/mono/component/CMakeLists.txt @@ -1,5 +1,4 @@ set(MONO_COMPONENT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../component") -set(SHARED_CONTAINERS_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/containers/") set(SHARED_EVENTPIPE_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/eventpipe/") set(MONO_EVENTPIPE_SHIM_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../eventpipe/") set(MONO_EVENTPIPE_GEN_INCLUDE_PATH "${CMAKE_CURRENT_BINARY_DIR}/eventpipe") @@ -68,7 +67,6 @@ include_directories( ) set(${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-sources - ${container_sources} ${eventpipe_sources} ${diagnostic_server_sources} ${MONO_COMPONENT_PATH}/event_pipe.c @@ -86,6 +84,9 @@ set(${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-dependencies ${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-gen-sources ) +set(${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-link_libraries + shared_container_objects) + # marshal-ilgen list(APPEND components ${MONO_MARSHAL_ILGEN_COMPONENT_NAME} @@ -155,6 +156,9 @@ foreach(component IN LISTS components) add_library("${component}-objects" OBJECT "${${component}-sources}") target_link_libraries("${component}-objects" PRIVATE component_base) target_link_libraries("${component}-objects" PUBLIC eglib_api) + if(DEFINED "${component}-link_libraries") + target_link_libraries("${component}-objects" PRIVATE "${${component}-link_libraries}") + endif() foreach(dependency IN LISTS "${component}-dependencies") add_dependencies("${component}-objects" "${dependency}") endforeach() @@ -170,9 +174,15 @@ if(NOT DISABLE_COMPONENTS AND NOT STATIC_COMPONENTS) # NOTE: keep library naming pattern in sync with RuntimeComponentManifest.targets if(HOST_WIN32) add_library("mono-component-${component}" SHARED "${${component}-sources}") + if(DEFINED "${component}-link_libraries") + target_link_libraries("mono-component-${component}" PRIVATE "${${component}-link_libraries}") + endif() target_compile_definitions("mono-component-${component}" PRIVATE -DCOMPILING_COMPONENT_DYNAMIC;-DMONO_DLL_IMPORT) else() add_library("mono-component-${component}" SHARED $) + if(DEFINED "${component}-link_libraries") + target_link_libraries("mono-component-${component}" PRIVATE "${${component}-link_libraries}") + endif() target_compile_definitions("${component}-objects" PRIVATE -DCOMPILING_COMPONENT_DYNAMIC;-DMONO_DLL_IMPORT) endif() foreach(dependency IN LISTS "${component}-dependencies") diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index a7a9460304bfd8..8f649a67d4c7ec 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -1,19 +1,5 @@ project(metadata C) -include (${SHARED_CONTAINERS_SOURCE_PATH}containers.cmake) - -set(shared_container_sources "") - -list(APPEND shared_container_sources - ${SHARED_CONTAINER_SOURCES} - ${SHARED_CONTAINER_HEADERS} -) - -addprefix(shared_container_sources ${SHARED_CONTAINERS_SOURCE_PATH} "${shared_container_sources}") - -add_library(shared_container_objects OBJECT ${shared_container_sources}) -target_include_directories(shared_container_objects PUBLIC ${SHARED_CONTAINERS_SOURCE_PATH}) - # # This library contains the icall tables if the runtime was configured with DISABLE_ICALL_TABLES # From 301c2a47997906e395db24a859c5feda66643453 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 28 Mar 2023 14:31:44 -0400 Subject: [PATCH 06/41] fix windows build --- src/mono/mono/metadata/seq-points-data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/seq-points-data.c b/src/mono/mono/metadata/seq-points-data.c index 5680dde50ef38c..2894a88a499553 100644 --- a/src/mono/mono/metadata/seq-points-data.c +++ b/src/mono/mono/metadata/seq-points-data.c @@ -291,7 +291,7 @@ mono_seq_point_init_next (MonoSeqPointInfo* info, SeqPoint sp, SeqPoint* next) for (i = 0; i < sp.next_len; i++) { int next_index; next_index = decode_var_int (ptr, &ptr); - g_assert (next_index < dn_vector_size (&seq_points)); + g_assert (next_index < GUINT_TO_INT (dn_vector_size (&seq_points))); memcpy (&next[i], dn_vector_index_t (&seq_points, SeqPoint, next_index), sizeof (SeqPoint)); } From ec1bf21c86d7eabb57289e9d2bc3559383c927c1 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 28 Mar 2023 16:00:23 -0400 Subject: [PATCH 07/41] fix Darwin frameworks builds --- src/mono/mono/mini/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 843b64f63f6a66..12c4280224062c 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -435,7 +435,7 @@ if(NOT DISABLE_SHARED_LIBS) endif() add_library(${frameworkconfig} SHARED $) target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects) + target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects shared_container_objects) target_link_libraries(${frameworkconfig} PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS} ${Z_LIBS}) if(ICU_LDFLAGS) From 473df840bd310765e7b1696cf5e3f25bf8d43602 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 28 Mar 2023 15:29:06 -0400 Subject: [PATCH 08/41] replace 2 uses of GArray in interp/transform.c --- src/mono/mono/mini/CMakeLists.txt | 2 +- src/mono/mono/mini/interp/transform.c | 32 ++++++++++++++------------- src/mono/mono/mini/interp/transform.h | 3 ++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 12c4280224062c..8f56ea8cbe528b 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -296,7 +296,7 @@ endif() if(ENABLE_INTERP_LIB) add_library(mono-ee-interp STATIC "${interp_sources}") -target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api) +target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api shared_container_objects) target_include_directories(mono-ee-interp PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. ${PROJECT_SOURCE_DIR}/..) diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 895b5cc6bda071..87a93942e71cce 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -9,6 +9,7 @@ #include "config.h" #include +#include #include #include #include @@ -3879,7 +3880,7 @@ get_basic_blocks (TransformData *td, MonoMethodHeader *header, gboolean make_lis } static void -interp_save_debug_info (InterpMethod *rtm, MonoMethodHeader *header, TransformData *td, GArray *line_numbers) +interp_save_debug_info (InterpMethod *rtm, MonoMethodHeader *header, TransformData *td, dn_vector_t *line_numbers) { MonoDebugMethodJitInfo *dinfo; @@ -3899,7 +3900,7 @@ interp_save_debug_info (InterpMethod *rtm, MonoMethodHeader *header, TransformDa dinfo->code_size = GPTRDIFF_TO_UINT32 (td->new_code_end - td->new_code); dinfo->epilogue_begin = 0; dinfo->has_var_info = TRUE; - dinfo->num_line_numbers = line_numbers->len; + dinfo->num_line_numbers = dn_vector_size (line_numbers); dinfo->line_numbers = g_new0 (MonoDebugLineNumberEntry, dinfo->num_line_numbers); for (guint32 i = 0; i < dinfo->num_params; i++) { @@ -3912,7 +3913,7 @@ interp_save_debug_info (InterpMethod *rtm, MonoMethodHeader *header, TransformDa } for (guint32 i = 0; i < dinfo->num_line_numbers; i++) - dinfo->line_numbers [i] = g_array_index (line_numbers, MonoDebugLineNumberEntry, i); + dinfo->line_numbers [i] = *dn_vector_index_t (line_numbers, MonoDebugLineNumberEntry, i); mono_debug_add_method (rtm->method, dinfo, NULL); mono_debug_free_method_jit_info (dinfo); @@ -3939,7 +3940,8 @@ recursively_make_pred_seq_points (TransformData *td, InterpBasicBlock *bb) { SeqPoint ** const MONO_SEQ_SEEN_LOOP = (SeqPoint**)GINT_TO_POINTER(-1); - GArray *predecessors = g_array_new (FALSE, TRUE, sizeof (gpointer)); + dn_vector_t predecessors = {0,}; + dn_vector_init_t (&predecessors, SeqPoint*); GHashTable *seen = g_hash_table_new_full (g_direct_hash, NULL, NULL, NULL); // Insert/remove sentinel into the memoize table to detect loops containing bb @@ -3950,7 +3952,7 @@ recursively_make_pred_seq_points (TransformData *td, InterpBasicBlock *bb) // This bb has the last seq point, append it and continue if (in_bb->last_seq_point != NULL) { - predecessors = g_array_append_val (predecessors, in_bb->last_seq_point); + dn_vector_push_back (&predecessors, in_bb->last_seq_point); continue; } @@ -3970,8 +3972,7 @@ recursively_make_pred_seq_points (TransformData *td, InterpBasicBlock *bb) // Union sequence points with incoming bb's for (guint j = 0; j < in_bb->num_pred_seq_points; j++) { if (!g_hash_table_lookup (seen, in_bb->pred_seq_points [j])) { - g_array_append_val (predecessors, in_bb->pred_seq_points [j]); - g_hash_table_insert (seen, in_bb->pred_seq_points [j], (gpointer)&MONO_SEQ_SEEN_LOOP); + dn_vector_push_back (&predecessors, in_bb->pred_seq_points [j]); } } // predecessors = g_array_append_vals (predecessors, in_bb->pred_seq_points, in_bb->num_pred_seq_points); @@ -3979,16 +3980,17 @@ recursively_make_pred_seq_points (TransformData *td, InterpBasicBlock *bb) g_hash_table_destroy (seen); - if (predecessors->len != 0) { - bb->pred_seq_points = (SeqPoint**)mono_mempool_alloc0 (td->mempool, sizeof (SeqPoint *) * predecessors->len); - bb->num_pred_seq_points = predecessors->len; + if (!dn_vector_empty (&predecessors)) { + uint32_t count = dn_vector_size (&predecessors); + bb->pred_seq_points = (SeqPoint**)mono_mempool_alloc0 (td->mempool, sizeof (SeqPoint *) * count); + bb->num_pred_seq_points = count; for (guint newer = 0; newer < bb->num_pred_seq_points; newer++) { - bb->pred_seq_points [newer] = (SeqPoint*)g_array_index (predecessors, gpointer, newer); + bb->pred_seq_points [newer] = *dn_vector_index_t (&predecessors, SeqPoint*, newer); } } - g_array_free (predecessors, TRUE); + dn_vector_dispose (&predecessors); } static void @@ -8181,7 +8183,7 @@ emit_compacted_instruction (TransformData *td, guint16* start_ip, InterpInst *in MonoDebugLineNumberEntry lne; lne.native_offset = GPTRDIFF_TO_UINT32 ((guint8*)start_ip - (guint8*)td->new_code); lne.il_offset = ins->il_offset; - g_array_append_val (td->line_numbers, lne); + dn_vector_push_back (td->line_numbers, lne); } if (opcode == MINT_NOP || opcode == MINT_DEF || opcode == MINT_DUMMY_USE) @@ -10815,7 +10817,7 @@ generate (MonoMethod *method, MonoMethodHeader *header, InterpMethod *rtm, MonoG td->stack_capacity = header->max_stack + 1; td->sp = td->stack; td->max_stack_height = 0; - td->line_numbers = g_array_new (FALSE, TRUE, sizeof (MonoDebugLineNumberEntry)); + td->line_numbers = dn_vector_alloc_t (MonoDebugLineNumberEntry); td->current_il_offset = -1; generate_code (td, method, header, generic_context, error); @@ -10951,7 +10953,7 @@ generate (MonoMethod *method, MonoMethodHeader *header, InterpMethod *rtm, MonoG #endif g_ptr_array_free (td->seq_points, TRUE); if (td->line_numbers) - g_array_free (td->line_numbers, TRUE); + dn_vector_free (td->line_numbers); g_slist_free (td->imethod_items); mono_mempool_destroy (td->mempool); if (retry_compilation) diff --git a/src/mono/mono/mini/interp/transform.h b/src/mono/mono/mini/interp/transform.h index 7b3e8cf1f2d760..a70442044c1bbc 100644 --- a/src/mono/mono/mini/interp/transform.h +++ b/src/mono/mono/mini/interp/transform.h @@ -1,5 +1,6 @@ #ifndef __MONO_MINI_INTERP_TRANSFORM_H__ #define __MONO_MINI_INTERP_TRANSFORM_H__ +#include #include #include #include "interp-internals.h" @@ -249,7 +250,7 @@ typedef struct GList *basic_blocks; GPtrArray *relocs; gboolean verbose_level; - GArray *line_numbers; + dn_vector_t *line_numbers; gboolean prof_coverage; MonoProfilerCoverageInfo *coverage_info; GList *dont_inline; From 5e4b4534e04beaaa3cf2b1d729a86545e9b40996 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 28 Mar 2023 15:33:30 -0400 Subject: [PATCH 09/41] replace a use of GArray in mini/seq-points.c --- src/mono/mono/mini/seq-points.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/mono/mono/mini/seq-points.c b/src/mono/mono/mini/seq-points.c index b998c6c86d97b6..f378432690b549 100644 --- a/src/mono/mono/mini/seq-points.c +++ b/src/mono/mono/mini/seq-points.c @@ -9,6 +9,8 @@ * Licensed under the MIT license. See LICENSE file in the project root for full license information. */ +#include +#include #include "mini.h" #include "mini-runtime.h" #include "seq-points.h" @@ -33,7 +35,9 @@ recursively_make_pred_seq_points (MonoCompile *cfg, MonoBasicBlock *bb) { const gpointer MONO_SEQ_SEEN_LOOP = GINT_TO_POINTER(-1); - GArray *predecessors = g_array_new (FALSE, TRUE, sizeof (gpointer)); + + dn_vector_t predecessors = {0,}; + dn_vector_init_t (&predecessors, MonoInst*); GHashTable *seen = g_hash_table_new_full (g_direct_hash, NULL, NULL, NULL); // Insert/remove sentinel into the memoize table to detect loops containing bb @@ -44,7 +48,7 @@ recursively_make_pred_seq_points (MonoCompile *cfg, MonoBasicBlock *bb) // This bb has the last seq point, append it and continue if (in_bb->last_seq_point != NULL) { - predecessors = g_array_append_val (predecessors, in_bb->last_seq_point); + dn_vector_push_back (&predecessors, in_bb->last_seq_point); continue; } @@ -64,7 +68,7 @@ recursively_make_pred_seq_points (MonoCompile *cfg, MonoBasicBlock *bb) // Union sequence points with incoming bb's for (guint j = 0; j < in_bb->num_pred_seq_points; j++) { if (!g_hash_table_lookup (seen, in_bb->pred_seq_points [j])) { - g_array_append_val (predecessors, in_bb->pred_seq_points [j]); + dn_vector_push_back (&predecessors, in_bb->pred_seq_points [j]); g_hash_table_insert (seen, in_bb->pred_seq_points [j], (gpointer)&MONO_SEQ_SEEN_LOOP); } } @@ -73,16 +77,17 @@ recursively_make_pred_seq_points (MonoCompile *cfg, MonoBasicBlock *bb) g_hash_table_destroy (seen); - if (predecessors->len != 0) { - bb->pred_seq_points = (MonoInst **)mono_mempool_alloc0 (cfg->mempool, sizeof (MonoInst *) * predecessors->len); - bb->num_pred_seq_points = predecessors->len; + if (!dn_vector_empty (&predecessors)) { + uint32_t count = dn_vector_size (&predecessors); + bb->pred_seq_points = (MonoInst **)mono_mempool_alloc0 (cfg->mempool, sizeof (MonoInst *) * count); + bb->num_pred_seq_points = count; for (guint newer = 0; newer < bb->num_pred_seq_points; newer++) { - bb->pred_seq_points [newer] = g_array_index(predecessors, MonoInst*, newer); + bb->pred_seq_points [newer] = *dn_vector_index_t (&predecessors, MonoInst*, newer); } } - g_array_free (predecessors, TRUE); + dn_vector_dispose (&predecessors); } static void From 6029c3355b82c6b1328b5927a1bc144da237ec25 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 28 Mar 2023 15:41:49 -0400 Subject: [PATCH 10/41] replace use of GArray for debug-mini --- src/mono/mono/mini/debug-mini.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/mono/mono/mini/debug-mini.c b/src/mono/mono/mini/debug-mini.c index f307d08bf7f511..2ad9345880eb29 100644 --- a/src/mono/mono/mini/debug-mini.c +++ b/src/mono/mono/mini/debug-mini.c @@ -12,6 +12,7 @@ #include "mini-runtime.h" #include #include "config.h" +#include #include #include #include @@ -30,7 +31,7 @@ typedef struct { typedef struct { MonoDebugMethodJitInfo *jit; - GArray *line_numbers; + dn_vector_t *line_numbers; guint32 has_line_numbers; guint32 breakpoint_id; } MiniDebugMethodInfo; @@ -43,7 +44,7 @@ record_line_number (MiniDebugMethodInfo *info, guint32 address, guint32 offset) lne.native_offset = address; lne.il_offset = offset; - g_array_append_val (info->line_numbers, lne); + dn_vector_push_back (info->line_numbers, lne); } @@ -78,7 +79,7 @@ mono_debug_open_method (MonoCompile *cfg) g_assert (header); info->jit = jit = g_new0 (MonoDebugMethodJitInfo, 1); - info->line_numbers = g_array_new (FALSE, TRUE, sizeof (MonoDebugLineNumberEntry)); + info->line_numbers = dn_vector_alloc_t (MonoDebugLineNumberEntry); jit->num_locals = header->num_locals; jit->locals = g_new0 (MonoDebugVarInfo, jit->num_locals); } @@ -269,11 +270,11 @@ mono_debug_close_method (MonoCompile *cfg) } } - jit->num_line_numbers = info->line_numbers->len; + jit->num_line_numbers = dn_vector_size (info->line_numbers); jit->line_numbers = g_new0 (MonoDebugLineNumberEntry, jit->num_line_numbers); for (guint32 i = 0; i < jit->num_line_numbers; i++) - jit->line_numbers [i] = g_array_index (info->line_numbers, MonoDebugLineNumberEntry, i); + jit->line_numbers [i] = *dn_vector_index_t (info->line_numbers, MonoDebugLineNumberEntry, i); mono_debug_add_method (cfg->method_to_register, jit, NULL); @@ -291,7 +292,7 @@ mono_debug_free_method (MonoCompile *cfg) info = (MiniDebugMethodInfo *) cfg->debug_info; if (info) { if (info->line_numbers) - g_array_free (info->line_numbers, TRUE); + dn_vector_free (info->line_numbers); g_free (info); cfg->debug_info = NULL; } From 0082829ffb47b670193dc107cf13728a67482a52 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 4 Apr 2023 16:04:42 -0400 Subject: [PATCH 11/41] WIP: start a dn_checkfail helper like g_assertf Will need the same kind of output redirection that mono does for Android and iOS. --- src/native/containers/containers.cmake | 2 ++ src/native/containers/dn-compiler.h | 29 ++++++++++++++++++++++++++ src/native/containers/dn-rt.h | 17 +++++++++++++++ src/native/containers/dn-utils.h | 25 +++++++++++++++------- 4 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 src/native/containers/dn-compiler.h create mode 100644 src/native/containers/dn-rt.h diff --git a/src/native/containers/containers.cmake b/src/native/containers/containers.cmake index dd8829e3bf0426..b1102220939ce3 100644 --- a/src/native/containers/containers.cmake +++ b/src/native/containers/containers.cmake @@ -12,9 +12,11 @@ list(APPEND SHARED_CONTAINER_SOURCES list(APPEND SHARED_CONTAINER_HEADERS dn-allocator.h + dn-compiler.h dn-fwd-list.h dn-list.h dn-queue.h + dn-rt.h dn-sort-frag.inc dn-umap.h dn-umap-t.h diff --git a/src/native/containers/dn-compiler.h b/src/native/containers/dn-compiler.h new file mode 100644 index 00000000000000..cb1867b7e63756 --- /dev/null +++ b/src/native/containers/dn-compiler.h @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef __DN_COMPILER_H__ +#define __DN_COMPILER_H__ + +#if defined(__GNUC__) && (__GNUC__ > 2) +#define DN_LIKELY(expr) (__builtin_expect ((expr) != 0, 1)) +#define DN_UNLIKELY(expr) (__builtin_expect ((expr) != 0, 0)) +#else +#define DN_LIKELY(x) (x) +#define DN_UNLIKELY(x) (x) +#endif + +#if defined(__GNUC__) +#define DN_NORETURN __attribute__((noreturn)) +#elif defined(_MSC_VER) +#define DN_NORETURN __declspec(noreturn) +#else +#define DN_NORETURN /*empty*/ +#endif + +#if defined(__GNUC__) +#define DN_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos) __attribute((__format__(__printf__,fmt_pos,arg_pos))) +#else +#define DN_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos) /*empty*/ +#endif + +#endif /* __DN_COMPILER_H__ */ diff --git a/src/native/containers/dn-rt.h b/src/native/containers/dn-rt.h new file mode 100644 index 00000000000000..797891d1f89d66 --- /dev/null +++ b/src/native/containers/dn-rt.h @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef __DN_RT_H__ +#define __DN_RT_H__ + +#include + +#include + +DN_NORETURN static void +dn_rt_failfast_msgv(const char* fmt, va_list ap); + +DN_NORETURN static void +dn_rt_failfast_msg(const char* file, int line); + +#endif /* __DN_RT_H__ */ diff --git a/src/native/containers/dn-utils.h b/src/native/containers/dn-utils.h index 7c07f5f8df7ecb..ebdbb7e3c50161 100644 --- a/src/native/containers/dn-utils.h +++ b/src/native/containers/dn-utils.h @@ -15,6 +15,8 @@ #include #include +#include + #if defined(_DEBUG) #include #define DN_ASSERT(x) assert(x) @@ -36,14 +38,6 @@ #define DN_CALLBACK_CALLTYPE #endif -#if defined(__GNUC__) && (__GNUC__ > 2) -#define DN_LIKELY(expr) (__builtin_expect ((expr) != 0, 1)) -#define DN_UNLIKELY(expr) (__builtin_expect ((expr) != 0, 0)) -#else -#define DN_LIKELY(x) (x) -#define DN_UNLIKELY(x) (x) -#endif - #define DN_UNREFERENCED_PARAMETER(expr) (void)(expr) // Until C11 support, use typedef expression for static assertion. @@ -76,4 +70,19 @@ dn_safe_uint32_t_add (uint32_t lhs, uint32_t rhs, uint32_t *result) return true; } +DN_NORETURN DN_ATTR_FORMAT_PRINTF(1,2) static inline void +dn_failfast_msg(const char* fmt, ...) +{ + va_list args; + va_start (args, fmt); + dn_rt_failfast_msgv(fmt, args); + va_end (args); +} + +#ifdef DISABLE_ASSERT_MESSAGES +#define dn_checkfail(cond, format, ...) (DN_LIKELY((cond)) ? 1 : (dn_rt_failfast_nomsg (__FILE__, __LINE__), 0)) +#else +#define dn_checkfail(cond,format,...) (DN_LIKELY((cond)) ? 1 : (dn_failfast_msg ("* Assertion at %s:%d, condition `%s' not met, function:%s, " format "\n", __FILE__, __LINE__, #cond, __func__, ##__VA_ARGS__), 0)) +#endif + #endif /* __DN_UTILS_H__ */ From 1cf3d19dca09ffa9cb9234ea8a9fdbdc474cafce Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 5 Apr 2023 11:48:38 -0400 Subject: [PATCH 12/41] remove some unused assignments from eventpipe.cmake fragment We get the shared containers via a dependency on the containers object library now --- src/mono/mono/eventpipe/eventpipe.cmake | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/mono/mono/eventpipe/eventpipe.cmake b/src/mono/mono/eventpipe/eventpipe.cmake index cd0d4a6f123c82..303eeeb61d963c 100644 --- a/src/mono/mono/eventpipe/eventpipe.cmake +++ b/src/mono/mono/eventpipe/eventpipe.cmake @@ -26,17 +26,6 @@ if(ENABLE_PERFTRACING) add_definitions(-DBIGENDIAN) endif (TARGET_S390X) - include (${SHARED_CONTAINERS_SOURCE_PATH}containers.cmake) - - set(container_sources "") - - list(APPEND container_sources - ${SHARED_CONTAINER_SOURCES} - ${SHARED_CONTAINER_HEADERS} - ) - - addprefix(container_sources ${SHARED_CONTAINERS_SOURCE_PATH} "${container_sources}") - include (${SHARED_EVENTPIPE_SOURCE_PATH}eventpipe.cmake) set(MONO_EVENTPIPE_SHIM_SOURCES "") From e5d2108b2112a4015ed05d2c0f496a8929d26faf Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 5 Apr 2023 11:49:26 -0400 Subject: [PATCH 13/41] make containers a normal sub-project for Mono Preliminary step before adding runtime-specific container code --- src/mono/CMakeLists.txt | 4 ---- src/mono/mono/CMakeLists.txt | 1 + src/mono/mono/containers/CMakeLists.txt | 5 +++++ 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 src/mono/mono/containers/CMakeLists.txt diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 136c2dbc5e3e67..658a439edb4144 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -942,10 +942,6 @@ list(APPEND shared_container_sources addprefix(shared_container_sources ${SHARED_CONTAINERS_SOURCE_PATH} "${shared_container_sources}") -add_library(shared_container_objects OBJECT ${shared_container_sources}) -target_include_directories(shared_container_objects PUBLIC ${SHARED_CONTAINERS_SOURCE_PATH}) - - ### Mono runtime and components add_subdirectory(mono) diff --git a/src/mono/mono/CMakeLists.txt b/src/mono/mono/CMakeLists.txt index c59470996f5825..b8ce461272eeff 100644 --- a/src/mono/mono/CMakeLists.txt +++ b/src/mono/mono/CMakeLists.txt @@ -1,6 +1,7 @@ project(mono) set(subdirs + containers eglib utils sgen diff --git a/src/mono/mono/containers/CMakeLists.txt b/src/mono/mono/containers/CMakeLists.txt new file mode 100644 index 00000000000000..6e3877ad77415f --- /dev/null +++ b/src/mono/mono/containers/CMakeLists.txt @@ -0,0 +1,5 @@ +project(containers C) + +add_library(shared_container_objects OBJECT ${shared_container_sources}) +target_include_directories(shared_container_objects PUBLIC ${SHARED_CONTAINERS_SOURCE_PATH}) + From adcb5a671333ed70fa6456ec89ef923003391541 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 5 Apr 2023 14:41:53 -0400 Subject: [PATCH 14/41] Add mono implementation of dn-rt.h --- src/mono/CMakeLists.txt | 13 ------------ src/mono/mono/CMakeLists.txt | 2 +- src/mono/mono/containers/CMakeLists.txt | 25 +++++++++++++++++++++-- src/mono/mono/containers/dn-rt-mono.h | 27 +++++++++++++++++++++++++ src/mono/mono/containers/dn-rt-utils.c | 18 +++++++++++++++++ src/native/containers/dn-rt.h | 11 +++++++++- 6 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 src/mono/mono/containers/dn-rt-mono.h create mode 100644 src/mono/mono/containers/dn-rt-utils.c diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 658a439edb4144..a9efed905158cd 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -929,19 +929,6 @@ if(NOT DISABLE_LIBS) endif() add_subdirectory("${CLR_SRC_NATIVE_DIR}/public" public_apis) -### Paths and Targets for Shared Containers -set(SHARED_CONTAINERS_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/containers/") -include (${SHARED_CONTAINERS_SOURCE_PATH}containers.cmake) - -set(shared_container_sources "") - -list(APPEND shared_container_sources - ${SHARED_CONTAINER_SOURCES} - ${SHARED_CONTAINER_HEADERS} -) - -addprefix(shared_container_sources ${SHARED_CONTAINERS_SOURCE_PATH} "${shared_container_sources}") - ### Mono runtime and components add_subdirectory(mono) diff --git a/src/mono/mono/CMakeLists.txt b/src/mono/mono/CMakeLists.txt index b8ce461272eeff..15321254966934 100644 --- a/src/mono/mono/CMakeLists.txt +++ b/src/mono/mono/CMakeLists.txt @@ -1,8 +1,8 @@ project(mono) set(subdirs - containers eglib + containers utils sgen metadata diff --git a/src/mono/mono/containers/CMakeLists.txt b/src/mono/mono/containers/CMakeLists.txt index 6e3877ad77415f..4b169efcf360b6 100644 --- a/src/mono/mono/containers/CMakeLists.txt +++ b/src/mono/mono/containers/CMakeLists.txt @@ -1,5 +1,26 @@ project(containers C) -add_library(shared_container_objects OBJECT ${shared_container_sources}) -target_include_directories(shared_container_objects PUBLIC ${SHARED_CONTAINERS_SOURCE_PATH}) +### Paths and Targets for Shared Containers +set(SHARED_CONTAINERS_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/containers/") +include (${SHARED_CONTAINERS_SOURCE_PATH}containers.cmake) + +set(shared_container_sources "") + +list(APPEND shared_container_sources + ${SHARED_CONTAINER_SOURCES} + ${SHARED_CONTAINER_HEADERS} +) + +addprefix(shared_container_sources ${SHARED_CONTAINERS_SOURCE_PATH} "${shared_container_sources}") + +set(rt_mono_container_sources + dn-rt-mono.h + dn-rt-utils.c) + +add_library(shared_container_objects OBJECT ${shared_container_sources} ${rt_mono_container_sources}) +target_link_libraries(shared_container_objects PRIVATE eglib_api) +target_include_directories(shared_container_objects PUBLIC ${SHARED_CONTAINERS_SOURCE_PATH} .) +# to pick up config.h +target_include_directories(shared_container_objects PRIVATE + ${PROJECT_BINARY_DIR}/../..) diff --git a/src/mono/mono/containers/dn-rt-mono.h b/src/mono/mono/containers/dn-rt-mono.h new file mode 100644 index 00000000000000..b9cfea00a26b19 --- /dev/null +++ b/src/mono/mono/containers/dn-rt-mono.h @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef __DN_RT_MONO_H__ +#define __DN_RT_MONO_H__ + +#include + +DN_NORETURN void +dn_rt_mono_failfast_msgv (const char* fmt, va_list ap); + +DN_NORETURN void +dn_rt_mono_failfast_nomsg (const char* file, int line); + +DN_NORETURN static inline void +dn_rt_failfast_msgv(const char* fmt, va_list ap) +{ + dn_rt_mono_failfast_msgv (fmt, ap); +} + +DN_NORETURN static inline void +dn_rt_failfast_nomsg(const char* fmt, int line) +{ + dn_rt_mono_failfast_nomsg(fmt, line); +} + +#endif /* __DN_RT_MONO_H__ */ diff --git a/src/mono/mono/containers/dn-rt-utils.c b/src/mono/mono/containers/dn-rt-utils.c new file mode 100644 index 00000000000000..fc0555009c6a89 --- /dev/null +++ b/src/mono/mono/containers/dn-rt-utils.c @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include +#include +#include + +void +dn_rt_mono_failfast_msgv (const char *format, va_list ap) +{ + g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, ap); +} + +void +dn_rt_mono_failfast_nosmg (const char *file, int line) +{ + mono_assertion_message_disabled (file, line); +} diff --git a/src/native/containers/dn-rt.h b/src/native/containers/dn-rt.h index 797891d1f89d66..02eb225425a0b9 100644 --- a/src/native/containers/dn-rt.h +++ b/src/native/containers/dn-rt.h @@ -12,6 +12,15 @@ DN_NORETURN static void dn_rt_failfast_msgv(const char* fmt, va_list ap); DN_NORETURN static void -dn_rt_failfast_msg(const char* file, int line); +dn_rt_failfast_nomsg(const char* file, int line); + +#if defined(FEATUERE_CORECLR) +// TODO: add CoreCLR runtime impl +#elif defined(FEATURE_NATIVEAOT) +// TODO: add NativeAOT runtime impl +#else +// Mono +#include +#endif #endif /* __DN_RT_H__ */ From 0eb1fd51b15281edc6c2698f571a321a09bbcd77 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 5 Apr 2023 14:46:35 -0400 Subject: [PATCH 15/41] check dn_vector_alloc_t result --- src/mono/mono/mini/debug-mini.c | 1 + src/mono/mono/mini/interp/transform.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/mono/mono/mini/debug-mini.c b/src/mono/mono/mini/debug-mini.c index 2ad9345880eb29..77008c70d14db4 100644 --- a/src/mono/mono/mini/debug-mini.c +++ b/src/mono/mono/mini/debug-mini.c @@ -80,6 +80,7 @@ mono_debug_open_method (MonoCompile *cfg) info->jit = jit = g_new0 (MonoDebugMethodJitInfo, 1); info->line_numbers = dn_vector_alloc_t (MonoDebugLineNumberEntry); + dn_checkfail (info->line_numbers != NULL, "Allocation failed"); jit->num_locals = header->num_locals; jit->locals = g_new0 (MonoDebugVarInfo, jit->num_locals); } diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 87a93942e71cce..75994598456c72 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -10818,6 +10818,7 @@ generate (MonoMethod *method, MonoMethodHeader *header, InterpMethod *rtm, MonoG td->sp = td->stack; td->max_stack_height = 0; td->line_numbers = dn_vector_alloc_t (MonoDebugLineNumberEntry); + dn_checkfail (td->line_numbers != NULL, "Allocation failed"); td->current_il_offset = -1; generate_code (td, method, header, generic_context, error); From 15d11fd9ec6a0fe75ee38ccc7a3175fb07a2305f Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 5 Apr 2023 18:21:59 -0400 Subject: [PATCH 16/41] fix coreclr build --- src/native/containers/dn-rt.h | 4 ++-- src/native/containers/dn-utils.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/native/containers/dn-rt.h b/src/native/containers/dn-rt.h index 02eb225425a0b9..ac9f2e9089369e 100644 --- a/src/native/containers/dn-rt.h +++ b/src/native/containers/dn-rt.h @@ -6,7 +6,7 @@ #include -#include +#include "dn-compiler.h" DN_NORETURN static void dn_rt_failfast_msgv(const char* fmt, va_list ap); @@ -20,7 +20,7 @@ dn_rt_failfast_nomsg(const char* file, int line); // TODO: add NativeAOT runtime impl #else // Mono -#include +#include "dn-rt-mono.h" #endif #endif /* __DN_RT_H__ */ diff --git a/src/native/containers/dn-utils.h b/src/native/containers/dn-utils.h index ebdbb7e3c50161..110773d5b2452b 100644 --- a/src/native/containers/dn-utils.h +++ b/src/native/containers/dn-utils.h @@ -15,7 +15,7 @@ #include #include -#include +#include "dn-rt.h" #if defined(_DEBUG) #include From 71fb5c28c8b8ae3100c20682bafafd2c6c058e7f Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 5 Apr 2023 22:15:55 -0400 Subject: [PATCH 17/41] add placeholder dn_rt functions for coreclr and nativeaot --- src/native/containers/dn-rt.h | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/native/containers/dn-rt.h b/src/native/containers/dn-rt.h index ac9f2e9089369e..b181176f25ca55 100644 --- a/src/native/containers/dn-rt.h +++ b/src/native/containers/dn-rt.h @@ -14,10 +14,43 @@ dn_rt_failfast_msgv(const char* fmt, va_list ap); DN_NORETURN static void dn_rt_failfast_nomsg(const char* file, int line); -#if defined(FEATUERE_CORECLR) +#if defined(FEATURE_CORECLR) +#include "pal.h" // TODO: add CoreCLR runtime impl +DN_NORETURN static inline void +dn_rt_failfast_msgv(const char* fmt, va_list ap) +{ + RaiseFailFastException(nullptr, nullptr, 0); +} + +DN_NORETURN static inline void +dn_rt_failfast_nomsg(const char* file, int line) +{ + RaiseFailFastException(nullptr, nullptr, 0); +} + #elif defined(FEATURE_NATIVEAOT) +#include "common.h" +#include "gcenv.h" +#include "CommonTypes.h" +#include "CommonMacros.h" +#include "PalRedhawkCommon.h" +#include "PalRedhawk.h" +#include "rhassert.h" // TODO: add NativeAOT runtime impl +DN_NORETURN static inline void +dn_rt_failfast_msgv(const char* fmt, va_list ap) +{ + RhFailFast(); + UNREACHABLE(); +} + +DN_NORETURN static inline void +dn_rt_failfast_nomsg(const char* file, int line) +{ + RhFailFast(); + UNREACHABLE(); +} #else // Mono #include "dn-rt-mono.h" From fa05fbf73e2b8de530d6253630f16d4837669f8b Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 5 Apr 2023 22:29:28 -0400 Subject: [PATCH 18/41] fix mono build --- src/mono/mono/containers/dn-rt-utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/containers/dn-rt-utils.c b/src/mono/mono/containers/dn-rt-utils.c index fc0555009c6a89..df1bc8dc51d0a1 100644 --- a/src/mono/mono/containers/dn-rt-utils.c +++ b/src/mono/mono/containers/dn-rt-utils.c @@ -9,10 +9,11 @@ void dn_rt_mono_failfast_msgv (const char *format, va_list ap) { g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, ap); + g_assert_not_reached (); } void -dn_rt_mono_failfast_nosmg (const char *file, int line) +dn_rt_mono_failfast_nomsg (const char *file, int line) { mono_assertion_message_disabled (file, line); } From 695575f68db1ec37f5e9df4bdf4bcdc126e47456 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 5 Apr 2023 23:30:04 -0400 Subject: [PATCH 19/41] maybe fix coreclr/nativeaot windows build? --- src/native/containers/dn-rt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/containers/dn-rt.h b/src/native/containers/dn-rt.h index b181176f25ca55..e248db7f998514 100644 --- a/src/native/containers/dn-rt.h +++ b/src/native/containers/dn-rt.h @@ -31,7 +31,7 @@ dn_rt_failfast_nomsg(const char* file, int line) #elif defined(FEATURE_NATIVEAOT) #include "common.h" -#include "gcenv.h" +#include "gcenv.base.h" #include "CommonTypes.h" #include "CommonMacros.h" #include "PalRedhawkCommon.h" From c4a28a5e1bce8a9996fe6694213a8f37e11d2794 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 00:26:12 -0400 Subject: [PATCH 20/41] move nativeaot shims to a separate file fix windows include problems, I guess? --- .../Runtime/eventpipe/CMakeLists.txt | 10 +++++++ .../nativeaot/Runtime/eventpipe/dn-rt-aot.cpp | 27 +++++++++++++++++++ .../nativeaot/Runtime/eventpipe/dn-rt-aot.h | 25 +++++++++++++++++ src/native/containers/dn-rt.h | 22 +-------------- 4 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 src/coreclr/nativeaot/Runtime/eventpipe/dn-rt-aot.cpp create mode 100644 src/coreclr/nativeaot/Runtime/eventpipe/dn-rt-aot.h diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt index d91a084c01a6fc..45a34b274a538d 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt @@ -81,6 +81,14 @@ list(APPEND AOT_EVENTPIPE_MANAGED_TO_NATIVE_SOURCES ${RUNTIME_DIR}/EnabledEventPipeInterface.cpp ) +set(CONTAINER_SHIM_SOURCES + ${AOT_EVENTPIPE_SHIM_DIR}/dn-rt-aot.cpp +) + +set(CONTAINER_SHIM_HEADERS + ${AOT_EVENTPIPE_SHIM_DIR}/dn-rt-aot.h +) + list(APPEND EVENTPIPE_SOURCES ${AOT_EVENTPIPE_SHIM_SOURCES} ${AOT_EVENTPIPE_SHIM_HEADERS} @@ -88,6 +96,8 @@ list(APPEND EVENTPIPE_SOURCES ${SHARED_EVENTPIPE_CONFIG_HEADERS} ${CONTAINER_SOURCES} ${CONTAINER_HEADERS} + ${CONTAINER_SHIM_HEADERS} + ${CONTAINER_SHIM_SOURCES} ) list(APPEND AOT_EVENTPIPE_DISABLED_SOURCES diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dn-rt-aot.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dn-rt-aot.cpp new file mode 100644 index 00000000000000..d3bb67ddedbc75 --- /dev/null +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dn-rt-aot.cpp @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "common.h" +#include "gcenv.base.h" +#include "CommonTypes.h" +#include "CommonMacros.h" +#include "PalRedhawkCommon.h" +#include "PalRedhawk.h" +#include "rhassert.h" + +#include "containers/dn-rt.h" + +DN_NORETURN void +dn_rt_aot_failfast_msgv (const char* fmt, va_list ap) +{ + RhFailFast(); + UNREACHABLE(); +} + +DN_NORETURN void +dn_rt_aot_failfast_nomsg(const char* file, int line) +{ + RhFailFast(); + UNREACHABLE(); +} + diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dn-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/dn-rt-aot.h new file mode 100644 index 00000000000000..d9aec77041aa24 --- /dev/null +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dn-rt-aot.h @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef __DN_RT_AOT_H__ +#define __DN_RT_AOT_H__ + +DN_NORETURN void +dn_rt_aot_failfast_msgv(const char* fmt, va_list ap); + +DN_NORETURN static inline void +dn_rt_failfast_msgv(const char* fmt, va_list ap) +{ + dn_rt_aot_failfast_msgv(fmt, ap); +} + +DN_NORETURN void +dn_rt_aot_failfast_nomsg(const char* file, int line); + +DN_NORETURN static inline void +dn_rt_failfast_nomsg(const char* file, int line) +{ + dn_rt_aot_failfast_nomsg(file, line); +} + +#endif /* __DN_RT_AOT_H__ */ diff --git a/src/native/containers/dn-rt.h b/src/native/containers/dn-rt.h index e248db7f998514..26334590eb25d3 100644 --- a/src/native/containers/dn-rt.h +++ b/src/native/containers/dn-rt.h @@ -30,27 +30,7 @@ dn_rt_failfast_nomsg(const char* file, int line) } #elif defined(FEATURE_NATIVEAOT) -#include "common.h" -#include "gcenv.base.h" -#include "CommonTypes.h" -#include "CommonMacros.h" -#include "PalRedhawkCommon.h" -#include "PalRedhawk.h" -#include "rhassert.h" -// TODO: add NativeAOT runtime impl -DN_NORETURN static inline void -dn_rt_failfast_msgv(const char* fmt, va_list ap) -{ - RhFailFast(); - UNREACHABLE(); -} - -DN_NORETURN static inline void -dn_rt_failfast_nomsg(const char* file, int line) -{ - RhFailFast(); - UNREACHABLE(); -} +#include #else // Mono #include "dn-rt-mono.h" From e0526c1704b38c0a36080c0e08c792532cc6556b Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 00:49:36 -0400 Subject: [PATCH 21/41] fix coreclr windows? --- src/native/containers/dn-rt.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/containers/dn-rt.h b/src/native/containers/dn-rt.h index 26334590eb25d3..a5f276ca67728b 100644 --- a/src/native/containers/dn-rt.h +++ b/src/native/containers/dn-rt.h @@ -15,7 +15,9 @@ DN_NORETURN static void dn_rt_failfast_nomsg(const char* file, int line); #if defined(FEATURE_CORECLR) +#ifdef TARGET_UNIX #include "pal.h" +#endif // TARGET_UNIX // TODO: add CoreCLR runtime impl DN_NORETURN static inline void dn_rt_failfast_msgv(const char* fmt, va_list ap) From 7fc5ecce3bdb69f0c8873874aff7e92468a59e03 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 11:03:21 -0400 Subject: [PATCH 22/41] add typed dn_vector_ptr accessor macros --- src/native/containers/dn-vector-ptr.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/native/containers/dn-vector-ptr.h b/src/native/containers/dn-vector-ptr.h index ca5be73797f398..6df84c61cb7d5b 100644 --- a/src/native/containers/dn-vector-ptr.h +++ b/src/native/containers/dn-vector-ptr.h @@ -24,4 +24,19 @@ DN_DEFINE_VECTOR_T (ptr, void *) } \ } while (0) +#define dn_vector_ptr_index_t(vector, type, index) \ + (type*)dn_vector_ptr_index (vector,index) + +#define dn_vector_ptr_at_t(vector, type, index) \ + (type*)dn_vector_ptr_at (vector, index) + +#define dn_vector_ptr_front_t(vector, type) \ + (type*)dn_vector_ptr_front (vector) + +#define dn_vector_ptr_back_t(vector, type) \ + (type*)dn_vector_ptr_back (vector) + +#define dn_vector_ptr_data_t(vector, type) \ + (type*)dn_vector_btr_data (vector) + #endif /* __DN_VECTOR_PTR_H__ */ From e93efdc79e72c3b13738b97b4dbbe1313f6c32ff Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 11:14:06 -0400 Subject: [PATCH 23/41] Use dn_vector_ptr in a few places instead of dn_vector --- src/mono/mono/mini/interp/transform.c | 17 +++++++++-------- src/mono/mono/mini/seq-points.c | 18 +++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 75994598456c72..44d631efef4746 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -10,6 +10,7 @@ #include "config.h" #include #include +#include #include #include #include @@ -3940,8 +3941,8 @@ recursively_make_pred_seq_points (TransformData *td, InterpBasicBlock *bb) { SeqPoint ** const MONO_SEQ_SEEN_LOOP = (SeqPoint**)GINT_TO_POINTER(-1); - dn_vector_t predecessors = {0,}; - dn_vector_init_t (&predecessors, SeqPoint*); + dn_vector_ptr_t predecessors = {0,}; + dn_vector_ptr_init (&predecessors); GHashTable *seen = g_hash_table_new_full (g_direct_hash, NULL, NULL, NULL); // Insert/remove sentinel into the memoize table to detect loops containing bb @@ -3952,7 +3953,7 @@ recursively_make_pred_seq_points (TransformData *td, InterpBasicBlock *bb) // This bb has the last seq point, append it and continue if (in_bb->last_seq_point != NULL) { - dn_vector_push_back (&predecessors, in_bb->last_seq_point); + dn_vector_ptr_push_back (&predecessors, in_bb->last_seq_point); continue; } @@ -3972,7 +3973,7 @@ recursively_make_pred_seq_points (TransformData *td, InterpBasicBlock *bb) // Union sequence points with incoming bb's for (guint j = 0; j < in_bb->num_pred_seq_points; j++) { if (!g_hash_table_lookup (seen, in_bb->pred_seq_points [j])) { - dn_vector_push_back (&predecessors, in_bb->pred_seq_points [j]); + dn_vector_ptr_push_back (&predecessors, in_bb->pred_seq_points [j]); } } // predecessors = g_array_append_vals (predecessors, in_bb->pred_seq_points, in_bb->num_pred_seq_points); @@ -3980,17 +3981,17 @@ recursively_make_pred_seq_points (TransformData *td, InterpBasicBlock *bb) g_hash_table_destroy (seen); - if (!dn_vector_empty (&predecessors)) { - uint32_t count = dn_vector_size (&predecessors); + if (!dn_vector_ptr_empty (&predecessors)) { + uint32_t count = dn_vector_ptr_size (&predecessors); bb->pred_seq_points = (SeqPoint**)mono_mempool_alloc0 (td->mempool, sizeof (SeqPoint *) * count); bb->num_pred_seq_points = count; for (guint newer = 0; newer < bb->num_pred_seq_points; newer++) { - bb->pred_seq_points [newer] = *dn_vector_index_t (&predecessors, SeqPoint*, newer); + bb->pred_seq_points [newer] = *dn_vector_ptr_index_t (&predecessors, SeqPoint*, newer); } } - dn_vector_dispose (&predecessors); + dn_vector_ptr_dispose (&predecessors); } static void diff --git a/src/mono/mono/mini/seq-points.c b/src/mono/mono/mini/seq-points.c index f378432690b549..38a09494d0f380 100644 --- a/src/mono/mono/mini/seq-points.c +++ b/src/mono/mono/mini/seq-points.c @@ -10,7 +10,7 @@ */ #include -#include +#include #include "mini.h" #include "mini-runtime.h" #include "seq-points.h" @@ -36,8 +36,8 @@ recursively_make_pred_seq_points (MonoCompile *cfg, MonoBasicBlock *bb) const gpointer MONO_SEQ_SEEN_LOOP = GINT_TO_POINTER(-1); - dn_vector_t predecessors = {0,}; - dn_vector_init_t (&predecessors, MonoInst*); + dn_vector_ptr_t predecessors = {0,}; + dn_vector_ptr_init (&predecessors); GHashTable *seen = g_hash_table_new_full (g_direct_hash, NULL, NULL, NULL); // Insert/remove sentinel into the memoize table to detect loops containing bb @@ -48,7 +48,7 @@ recursively_make_pred_seq_points (MonoCompile *cfg, MonoBasicBlock *bb) // This bb has the last seq point, append it and continue if (in_bb->last_seq_point != NULL) { - dn_vector_push_back (&predecessors, in_bb->last_seq_point); + dn_vector_ptr_push_back (&predecessors, in_bb->last_seq_point); continue; } @@ -68,7 +68,7 @@ recursively_make_pred_seq_points (MonoCompile *cfg, MonoBasicBlock *bb) // Union sequence points with incoming bb's for (guint j = 0; j < in_bb->num_pred_seq_points; j++) { if (!g_hash_table_lookup (seen, in_bb->pred_seq_points [j])) { - dn_vector_push_back (&predecessors, in_bb->pred_seq_points [j]); + dn_vector_ptr_push_back (&predecessors, in_bb->pred_seq_points [j]); g_hash_table_insert (seen, in_bb->pred_seq_points [j], (gpointer)&MONO_SEQ_SEEN_LOOP); } } @@ -77,17 +77,17 @@ recursively_make_pred_seq_points (MonoCompile *cfg, MonoBasicBlock *bb) g_hash_table_destroy (seen); - if (!dn_vector_empty (&predecessors)) { - uint32_t count = dn_vector_size (&predecessors); + if (!dn_vector_ptr_empty (&predecessors)) { + uint32_t count = dn_vector_ptr_size (&predecessors); bb->pred_seq_points = (MonoInst **)mono_mempool_alloc0 (cfg->mempool, sizeof (MonoInst *) * count); bb->num_pred_seq_points = count; for (guint newer = 0; newer < bb->num_pred_seq_points; newer++) { - bb->pred_seq_points [newer] = *dn_vector_index_t (&predecessors, MonoInst*, newer); + bb->pred_seq_points [newer] = *dn_vector_ptr_index_t (&predecessors, MonoInst*, newer); } } - dn_vector_dispose (&predecessors); + dn_vector_ptr_dispose (&predecessors); } static void From 80099235fb1b1ad001f22952e1ecc4118e7106b1 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 11:53:06 -0400 Subject: [PATCH 24/41] replace one more GArray by dn_vector_ptr_t --- src/mono/mono/component/CMakeLists.txt | 6 +++++ src/mono/mono/component/debugger-agent.c | 31 ++++++++++++++---------- src/mono/mono/metadata/debug-mono-ppdb.c | 9 ++++--- src/mono/mono/metadata/debug-mono-ppdb.h | 5 +++- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/mono/mono/component/CMakeLists.txt b/src/mono/mono/component/CMakeLists.txt index fc5388f785382b..d3bfe3e6921ee2 100644 --- a/src/mono/mono/component/CMakeLists.txt +++ b/src/mono/mono/component/CMakeLists.txt @@ -41,6 +41,9 @@ set(${MONO_DEBUGGER_COMPONENT_NAME}-stub-sources ${MONO_COMPONENT_PATH}/debugger-stub.c ) +set(${MONO_DEBUGGER_COMPONENT_NAME}-link_libraries + shared_container_objects) + # hot_reload list(APPEND components ${MONO_HOT_RELOAD_COMPONENT_NAME} @@ -54,6 +57,9 @@ set(${MONO_HOT_RELOAD_COMPONENT_NAME}-stub-sources ${MONO_COMPONENT_PATH}/hot_reload-stub.c ) +set(${MONO_HOT_RELOAD_COMPONENT_NAME}-link_libraries + shared_container_objects) + # diagnostics_tracing (event_pipe/diagnostics_server) list(APPEND components ${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME} diff --git a/src/mono/mono/component/debugger-agent.c b/src/mono/mono/component/debugger-agent.c index 3df16f14f3d4a6..7946a8fe4ffdde 100644 --- a/src/mono/mono/component/debugger-agent.c +++ b/src/mono/mono/component/debugger-agent.c @@ -62,6 +62,8 @@ #define SOCKET_ERROR (-1) #endif +#include + #include #include #include @@ -7961,33 +7963,36 @@ assembly_commands (int command, guint8 *p, guint8 *end, Buffer *buf) guint8 *ppdb_data = NULL; int ppdb_size = 0, ppdb_compressed_size = 0; char *ppdb_path; - GArray *pdb_checksum_hash_type = g_array_new (FALSE, TRUE, sizeof (char*)); - GArray *pdb_checksum = g_array_new (FALSE, TRUE, sizeof (guint8*)); - gboolean has_debug_info = mono_get_pe_debug_info_full (ass->image, pe_guid, &pe_age, &pe_timestamp, &ppdb_data, &ppdb_size, &ppdb_compressed_size, &ppdb_path, pdb_checksum_hash_type, pdb_checksum); + dn_vector_ptr_t /* */ pdb_checksum_hash_type = {0,}; + dn_vector_ptr_t /* */ pdb_checksum = {0,}; + dn_vector_ptr_init (&pdb_checksum_hash_type); + dn_vector_ptr_init (&pdb_checksum); + gboolean has_debug_info = mono_get_pe_debug_info_full (ass->image, pe_guid, &pe_age, &pe_timestamp, &ppdb_data, &ppdb_size, &ppdb_compressed_size, &ppdb_path, &pdb_checksum_hash_type, &pdb_checksum); if (!has_debug_info || ppdb_size > 0) { buffer_add_byte (buf, 0); - g_array_free (pdb_checksum_hash_type, TRUE); - g_array_free (pdb_checksum, TRUE); + dn_vector_ptr_dispose (&pdb_checksum_hash_type); + dn_vector_ptr_dispose (&pdb_checksum); return ERR_NONE; } buffer_add_byte (buf, 1); buffer_add_int (buf, pe_age); buffer_add_byte_array (buf, pe_guid, 16); buffer_add_string (buf, ppdb_path); - buffer_add_int (buf, pdb_checksum_hash_type->len); - for (int i = 0 ; i < pdb_checksum_hash_type->len; ++i) { - char* checksum_hash_type = g_array_index (pdb_checksum_hash_type, char*, i); + uint32_t checksum_count = dn_vector_ptr_size (&pdb_checksum_hash_type); + buffer_add_int (buf, checksum_count); + for (int i = 0 ; i < checksum_count; ++i) { + char* checksum_hash_type = *dn_vector_ptr_index_t (&pdb_checksum_hash_type, char*, i); buffer_add_string (buf, checksum_hash_type); if (!strcmp (checksum_hash_type, "SHA256")) - buffer_add_byte_array (buf, g_array_index (pdb_checksum, guint8*, i), 32); + buffer_add_byte_array (buf, *dn_vector_ptr_index_t (&pdb_checksum, guint8*, i), 32); else if (!strcmp (checksum_hash_type, "SHA384")) - buffer_add_byte_array (buf, g_array_index (pdb_checksum, guint8*, i), 48); + buffer_add_byte_array (buf, *dn_vector_ptr_index_t (&pdb_checksum, guint8*, i), 48); else if (!strcmp (checksum_hash_type, "SHA512")) - buffer_add_byte_array (buf, g_array_index (pdb_checksum, guint8*, i), 64); + buffer_add_byte_array (buf, *dn_vector_ptr_index_t (&pdb_checksum, guint8*, i), 64); } - g_array_free (pdb_checksum_hash_type, TRUE); - g_array_free (pdb_checksum, TRUE); + dn_vector_ptr_dispose (&pdb_checksum_hash_type); + dn_vector_ptr_dispose (&pdb_checksum); break; } case MDBGPROT_CMD_ASSEMBLY_HAS_DEBUG_INFO_LOADED: { diff --git a/src/mono/mono/metadata/debug-mono-ppdb.c b/src/mono/mono/metadata/debug-mono-ppdb.c index 9c675af4dc7c8f..f4c4e01c43250e 100644 --- a/src/mono/mono/metadata/debug-mono-ppdb.c +++ b/src/mono/mono/metadata/debug-mono-ppdb.c @@ -16,6 +16,9 @@ #include #include #include + +#include + #include #include #include @@ -62,7 +65,7 @@ enum { gboolean mono_get_pe_debug_info_full (MonoImage *image, guint8 *out_guid, gint32 *out_age, gint32 *out_timestamp, guint8 **ppdb_data, - int *ppdb_uncompressed_size, int *ppdb_compressed_size, char **pdb_path, GArray *pdb_checksum_hash_type, GArray *pdb_checksum) + int *ppdb_uncompressed_size, int *ppdb_compressed_size, char **pdb_path, dn_vector_ptr_t *pdb_checksum_hash_type, dn_vector_ptr_t *pdb_checksum) { MonoPEDirEntry *debug_dir_entry; ImageDebugDirectory debug_dir; @@ -93,8 +96,8 @@ mono_get_pe_debug_info_full (MonoImage *image, guint8 *out_guid, gint32 *out_age data = (guint8 *) (image->raw_data + debug_dir.pointer); char* alg_name = (char*)data; guint8* checksum = (guint8 *) (data + strlen(alg_name)+ 1); - g_array_append_val (pdb_checksum_hash_type, alg_name); - g_array_append_val (pdb_checksum, checksum); + dn_vector_ptr_push_back (pdb_checksum_hash_type, alg_name); + dn_vector_ptr_push_back (pdb_checksum, checksum); } if (debug_dir.type == DEBUG_DIR_ENTRY_CODEVIEW && debug_dir.major_version == 0x100 && debug_dir.minor_version == 0x504d) { diff --git a/src/mono/mono/metadata/debug-mono-ppdb.h b/src/mono/mono/metadata/debug-mono-ppdb.h index 91fea5f249b4a4..68e63926cc7ca8 100644 --- a/src/mono/mono/metadata/debug-mono-ppdb.h +++ b/src/mono/mono/metadata/debug-mono-ppdb.h @@ -14,6 +14,9 @@ #define __MONO_METADATA_DEBUG_MONO_PPDB_H__ #include + +#include + #include #include @@ -76,5 +79,5 @@ mono_create_ppdb_file (MonoImage *ppdb_image, gboolean is_embedded_ppdb); MONO_COMPONENT_API gboolean mono_get_pe_debug_info_full (MonoImage *image, guint8 *out_guid, gint32 *out_age, gint32 *out_timestamp, guint8 **ppdb_data, - int *ppdb_uncompressed_size, int *ppdb_compressed_size, char **pdb_path, GArray *pdb_checksum_hash_type, GArray *pdb_checksum); + int *ppdb_uncompressed_size, int *ppdb_compressed_size, char **pdb_path, dn_vector_ptr_t *pdb_checksum_hash_type, dn_vector_ptr_t *pdb_checksum); #endif From 7a5109d76ffd78f93ea0175292dfccf7696146cc Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 17:04:08 -0400 Subject: [PATCH 25/41] replace GArray by dn_vector_t in hot reload Pass2Skeleton --- src/mono/mono/component/hot_reload.c | 33 +++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/mono/mono/component/hot_reload.c b/src/mono/mono/component/hot_reload.c index 120d227d7ccace..756371ef333457 100644 --- a/src/mono/mono/component/hot_reload.c +++ b/src/mono/mono/component/hot_reload.c @@ -10,6 +10,7 @@ #include "mono/component/hot_reload-internals.h" +#include #include #include #include "mono/metadata/assembly-internals.h" @@ -1801,24 +1802,26 @@ skeleton_add_member (MonoAddedDefSkeleton *sk, uint32_t member_token) } typedef struct Pass2Context { - GArray *skeletons; /* Skeleton for each new added type definition */ - GArray *nested_class_worklist; /* List of tokens in the NestedClass table to re-visit at the end of the pass */ + dn_vector_t /* of MonoAddedDefSkeleton */ *skeletons; /* Skeleton for each new added type definition */ + dn_vector_t /* of uint32_t */ *nested_class_worklist; /* List of tokens in the NestedClass table to re-visit at the end of the pass */ } Pass2Context; static void pass2_context_init (Pass2Context *ctx) { - ctx->skeletons = g_array_new (FALSE, TRUE, sizeof(MonoAddedDefSkeleton)); - ctx->nested_class_worklist = g_array_new (FALSE, TRUE, sizeof(uint32_t)); + ctx->skeletons = dn_vector_alloc_t (MonoAddedDefSkeleton); + dn_checkfail (ctx->skeletons, "Allocation failed"); + ctx->nested_class_worklist = dn_vector_alloc_t (uint32_t); + dn_checkfail (ctx->nested_class_worklist, "Allocation failed"); } static void pass2_context_destroy (Pass2Context *ctx) { if (ctx->skeletons) - g_array_free (ctx->skeletons, TRUE); + dn_vector_free (ctx->skeletons); if (ctx->nested_class_worklist) - g_array_free (ctx->nested_class_worklist, TRUE); + dn_vector_free (ctx->nested_class_worklist); } static void @@ -1827,14 +1830,14 @@ pass2_context_add_skeleton (Pass2Context *ctx, uint32_t typedef_token) MonoAddedDefSkeleton sk = {0, }; g_assert (mono_metadata_token_table (typedef_token) == MONO_TABLE_TYPEDEF); sk.typedef_token = typedef_token; - g_array_append_val (ctx->skeletons, sk); + dn_vector_push_back (ctx->skeletons, sk); } static MonoAddedDefSkeleton* pass2_context_get_skeleton (Pass2Context *ctx, uint32_t typedef_token) { - for (int i = 0 ; i < ctx->skeletons->len; ++i) { - MonoAddedDefSkeleton *sk = &((MonoAddedDefSkeleton*)ctx->skeletons->data)[i]; + for (uint32_t i = 0 ; i < dn_vector_size (ctx->skeletons); ++i) { + MonoAddedDefSkeleton *sk = dn_vector_index_t (ctx->skeletons, MonoAddedDefSkeleton, i); if (sk->typedef_token == typedef_token) return sk; } @@ -1865,9 +1868,9 @@ baseline_info_consume_skeletons (Pass2Context *ctx, MonoImage *base_image, Basel mono_image_lock (base_image); if (!base_info->skeletons) base_info->skeletons = g_array_new (FALSE, TRUE, sizeof(MonoAddedDefSkeleton)); - g_array_append_vals (base_info->skeletons, ctx->skeletons->data, ctx->skeletons->len); + g_array_append_vals (base_info->skeletons, dn_vector_data_t (ctx->skeletons, MonoAddedDefSkeleton), dn_vector_size (ctx->skeletons)); mono_image_unlock (base_image); - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "pass2: Added %d type definition skeletons. Total now %d.", ctx->skeletons->len, base_info->skeletons->len); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "pass2: Added %d type definition skeletons. Total now %d.", dn_vector_size (ctx->skeletons), base_info->skeletons->len); return TRUE; } @@ -1981,7 +1984,7 @@ add_nested_class_to_worklist (Pass2Context *ctx, MonoImage *image_base, uint32_t return; mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "EnC: adding nested class row 0x%08x (enclosing: 0x%08x, nested: 0x%08x) to worklist", log_token, cols[MONO_NESTED_CLASS_ENCLOSING], cols[MONO_NESTED_CLASS_NESTED]); - g_array_append_val (ctx->nested_class_worklist, log_token); + dn_vector_push_back (ctx->nested_class_worklist, log_token); } /** @@ -1996,9 +1999,9 @@ pass2_update_nested_classes (Pass2Context *ctx, MonoImage *image_base, MonoError { if (!ctx->nested_class_worklist) return TRUE; - GArray *arr = ctx->nested_class_worklist; - for (int i = 0; i < arr->len; ++i) { - uint32_t log_token = g_array_index (arr, uint32_t, i); + dn_vector_t *arr = ctx->nested_class_worklist; + for (uint32_t i = 0; i < dn_vector_size (arr); ++i) { + uint32_t log_token = *dn_vector_index_t (arr, uint32_t, i); uint32_t cols[MONO_TABLE_NESTEDCLASS]; mono_metadata_decode_row (&image_base->tables[MONO_TABLE_NESTEDCLASS], mono_metadata_token_index (log_token) - 1, cols, MONO_NESTED_CLASS_SIZE); From 6c2760efc6d494fa42622f59f222427f75986c39 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 17:17:59 -0400 Subject: [PATCH 26/41] one more GArray in hot_reload --- src/mono/mono/component/hot_reload.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/mono/mono/component/hot_reload.c b/src/mono/mono/component/hot_reload.c index 756371ef333457..5f64a3915f699e 100644 --- a/src/mono/mono/component/hot_reload.c +++ b/src/mono/mono/component/hot_reload.c @@ -314,7 +314,7 @@ struct _BaselineInfo { GHashTable *method_params; /* maps methoddef tokens to a MonoClassMetadataUpdateMethodParamInfo* */ /* Skeletons for all newly-added types from every generation. Accessing the array requires the image lock. */ - GArray *skeletons; + dn_vector_t /* of MonoAddedDefSkeleton */ *skeletons; }; @@ -451,7 +451,7 @@ baseline_info_destroy (BaselineInfo *info) } if (info->skeletons) - g_array_free (info->skeletons, TRUE); + dn_vector_free (info->skeletons); if (info->member_parent) g_hash_table_destroy (info->member_parent); @@ -1866,11 +1866,13 @@ static gboolean baseline_info_consume_skeletons (Pass2Context *ctx, MonoImage *base_image, BaselineInfo *base_info, MonoError *error) { mono_image_lock (base_image); - if (!base_info->skeletons) - base_info->skeletons = g_array_new (FALSE, TRUE, sizeof(MonoAddedDefSkeleton)); - g_array_append_vals (base_info->skeletons, dn_vector_data_t (ctx->skeletons, MonoAddedDefSkeleton), dn_vector_size (ctx->skeletons)); + if (!base_info->skeletons) { + base_info->skeletons = dn_vector_alloc_t (MonoAddedDefSkeleton); + dn_checkfail (base_info->skeletons, "Allocation failed"); + } + _dn_vector_append_range (base_info->skeletons, (const uint8_t*)dn_vector_data_t (ctx->skeletons, MonoAddedDefSkeleton), dn_vector_size (ctx->skeletons)); mono_image_unlock (base_image); - mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "pass2: Added %d type definition skeletons. Total now %d.", dn_vector_size (ctx->skeletons), base_info->skeletons->len); + mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "pass2: Added %d type definition skeletons. Total now %d.", dn_vector_size (ctx->skeletons), dn_vector_size (base_info->skeletons)); return TRUE; } @@ -1882,8 +1884,8 @@ hot_reload_get_typedef_skeleton (MonoImage *base_image, uint32_t typedef_token, return FALSE; gboolean found = FALSE; mono_image_lock (base_image); - for (int i = 0; i < info->skeletons->len; ++i) { - MonoAddedDefSkeleton *sk = &((MonoAddedDefSkeleton*)info->skeletons->data)[i]; + for (uint32_t i = 0; i < dn_vector_size (info->skeletons); ++i) { + MonoAddedDefSkeleton *sk = dn_vector_index_t (info->skeletons, MonoAddedDefSkeleton, i); if (sk->typedef_token == typedef_token) { found = TRUE; g_assert (first_method_idx); @@ -1909,8 +1911,8 @@ hot_reload_get_typedef_skeleton_properties (MonoImage *base_image, uint32_t type return FALSE; gboolean found = FALSE; mono_image_lock (base_image); - for (int i = 0; i < info->skeletons->len; ++i) { - MonoAddedDefSkeleton *sk = &((MonoAddedDefSkeleton*)info->skeletons->data)[i]; + for (uint32_t i = 0; i < dn_vector_size (info->skeletons); ++i) { + MonoAddedDefSkeleton *sk = dn_vector_index_t (info->skeletons, MonoAddedDefSkeleton, i); if (sk->typedef_token == typedef_token) { found = TRUE; g_assert (first_prop_idx); @@ -1932,8 +1934,8 @@ hot_reload_get_typedef_skeleton_events (MonoImage *base_image, uint32_t typedef_ return FALSE; gboolean found = FALSE; mono_image_lock (base_image); - for (int i = 0; i < info->skeletons->len; ++i) { - MonoAddedDefSkeleton *sk = &((MonoAddedDefSkeleton*)info->skeletons->data)[i]; + for (uint32_t i = 0; i < dn_vector_size (info->skeletons); ++i) { + MonoAddedDefSkeleton *sk = dn_vector_index_t (info->skeletons, MonoAddedDefSkeleton, i); if (sk->typedef_token == typedef_token) { found = TRUE; g_assert (first_event_idx); From 351a10b1d14765122ad98ad8db282da133ce99a2 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 19:38:38 -0400 Subject: [PATCH 27/41] use dn_vector_ptr_t for coop cookie stack in checked build --- src/mono/mono/utils/CMakeLists.txt | 2 +- src/mono/mono/utils/mono-threads-coop.c | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/mono/mono/utils/CMakeLists.txt b/src/mono/mono/utils/CMakeLists.txt index e26ec96b784f84..9b246273d53529 100644 --- a/src/mono/mono/utils/CMakeLists.txt +++ b/src/mono/mono/utils/CMakeLists.txt @@ -257,7 +257,7 @@ if(ENABLE_DTRACE) endif() add_library(utils_objects OBJECT ${utils_sources}) -target_link_libraries(utils_objects PRIVATE monoapi eglib_api) +target_link_libraries(utils_objects PRIVATE monoapi eglib_api shared_container_objects) target_compile_definitions(utils_objects PRIVATE -DMONO_DLL_EXPORT) target_include_directories(utils_objects PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. diff --git a/src/mono/mono/utils/mono-threads-coop.c b/src/mono/mono/utils/mono-threads-coop.c index 4ed659d66058cc..0bb7b0bcc654c6 100644 --- a/src/mono/mono/utils/mono-threads-coop.c +++ b/src/mono/mono/utils/mono-threads-coop.c @@ -16,6 +16,8 @@ #define _DARWIN_C_SOURCE #endif +#include + #include #include #include @@ -57,32 +59,33 @@ static MonoNativeTlsKey coop_reset_count_stack_key; static void coop_tls_push (gpointer cookie) { - GArray *stack; + dn_vector_ptr_t *stack; - stack = (GArray*)mono_native_tls_get_value (coop_reset_count_stack_key); + stack = (dn_vector_ptr_t*)mono_native_tls_get_value (coop_reset_count_stack_key); if (!stack) { - stack = g_array_new (FALSE, FALSE, sizeof(gpointer)); + stack = dn_vector_ptr_alloc (); + dn_checkfail (stack, "Allocation failed"); mono_native_tls_set_value (coop_reset_count_stack_key, stack); } - g_array_append_val (stack, cookie); + dn_vector_ptr_push_back (stack, cookie); } static void coop_tls_pop (gpointer received_cookie) { - GArray *stack; + dn_vector_ptr_t *stack; gpointer expected_cookie; - stack = (GArray*)mono_native_tls_get_value (coop_reset_count_stack_key); - if (!stack || 0 == stack->len) + stack = (dn_vector_ptr_t*)mono_native_tls_get_value (coop_reset_count_stack_key); + if (!stack || dn_vector_ptr_empty (stack)) mono_fatal_with_history ("Received cookie %p but found no stack at all\n", received_cookie); - expected_cookie = g_array_index (stack, gpointer, stack->len - 1); - stack->len --; + expected_cookie = *dn_vector_ptr_back (stack); + dn_vector_ptr_pop_back (stack); - if (0 == stack->len) { - g_array_free (stack,TRUE); + if (dn_vector_ptr_empty (stack)) { + dn_vector_ptr_free (stack); mono_native_tls_set_value (coop_reset_count_stack_key, NULL); } From 7119af133e1230798e6596b5473ec3e9aad2db7c Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 19:56:38 -0400 Subject: [PATCH 28/41] [mono][eventpipe] fixup DS_EXIT_BLOCKING_PAL_SECTION in checked build The MONO_EXIT_GC_SAFE macro requires a semicolon after it. If we build with -DENABLE_CHECKED_BUILD_GC, MONO_REQ_GC_UNSAFE_MODE expands to something non-empty, and we get a compilation error due to the missing separator semmicolon. --- src/mono/mono/eventpipe/ds-rt-mono.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/eventpipe/ds-rt-mono.h b/src/mono/mono/eventpipe/ds-rt-mono.h index 2bde834f552295..3c2c8e0fed8b9e 100644 --- a/src/mono/mono/eventpipe/ds-rt-mono.h +++ b/src/mono/mono/eventpipe/ds-rt-mono.h @@ -61,7 +61,7 @@ #undef DS_EXIT_BLOCKING_PAL_SECTION #define DS_EXIT_BLOCKING_PAL_SECTION \ MONO_REQ_GC_SAFE_MODE \ - MONO_EXIT_GC_SAFE \ + MONO_EXIT_GC_SAFE; \ MONO_REQ_GC_UNSAFE_MODE bool From 87c6d601edd383ea55f47ab46259569908918fe8 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 20:18:44 -0400 Subject: [PATCH 29/41] replace GArray with dn_vector_t in mini-amd64 --- src/mono/mono/mini/mini-amd64.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/mono/mono/mini/mini-amd64.c b/src/mono/mono/mini/mini-amd64.c index ea2d049b1b75e7..e04bef20028d4e 100644 --- a/src/mono/mono/mini/mini-amd64.c +++ b/src/mono/mono/mini/mini-amd64.c @@ -24,6 +24,8 @@ #include #endif +#include + #include #include #include @@ -346,7 +348,7 @@ typedef struct { * Collect field info from KLASS recursively into FIELDS. */ static void -collect_field_info_nested (MonoClass *klass, GArray *fields_array, int offset, gboolean pinvoke, gboolean unicode) +collect_field_info_nested (MonoClass *klass, dn_vector_t *fields_array, int offset, gboolean pinvoke, gboolean unicode) { MonoMarshalType *info; @@ -369,17 +371,17 @@ collect_field_info_nested (MonoClass *klass, GArray *fields_array, int offset, g /* This can happen with .pack directives eg. 'fixed' arrays */ if (MONO_TYPE_IS_PRIMITIVE (f.type)) { /* Replicate the last field to fill out the remaining place, since the code in add_valuetype () needs type information */ - g_array_append_val (fields_array, f); + dn_vector_push_back (fields_array, f); while (f.size + f.offset < info->native_size) { f.offset += f.size; - g_array_append_val (fields_array, f); + dn_vector_push_back (fields_array, f); } } else { f.size = info->native_size - f.offset; - g_array_append_val (fields_array, f); + dn_vector_push_back (fields_array, f); } } else { - g_array_append_val (fields_array, f); + dn_vector_push_back (fields_array, f); } } } @@ -403,7 +405,7 @@ collect_field_info_nested (MonoClass *klass, GArray *fields_array, int offset, g f.size = mono_type_size (field->type, &align); f.offset = m_field_get_offset (field) - MONO_ABI_SIZEOF (MonoObject) + offset; - g_array_append_val (fields_array, f); + dn_vector_push_back (fields_array, f); } } } @@ -627,7 +629,7 @@ add_valuetype (MonoMethodSignature *sig, ArgInfo *ainfo, MonoType *type, guint32 quadsize [2] = {8, 8}; ArgumentClass args [2]; StructFieldInfo *fields = NULL; - GArray *fields_array; + dn_vector_t fields_array = {0,}; MonoClass *klass; gboolean pass_on_stack = FALSE; int struct_size; @@ -654,10 +656,10 @@ add_valuetype (MonoMethodSignature *sig, ArgInfo *ainfo, MonoType *type, * Collect field information recursively to be able to * handle nested structures. */ - fields_array = g_array_new (FALSE, TRUE, sizeof (StructFieldInfo)); - collect_field_info_nested (klass, fields_array, 0, sig->pinvoke && !sig->marshalling_disabled, m_class_is_unicode (klass)); - fields = (StructFieldInfo*)fields_array->data; - nfields = fields_array->len; + dn_vector_init_t (&fields_array, StructFieldInfo); + collect_field_info_nested (klass, &fields_array, 0, sig->pinvoke && !sig->marshalling_disabled, m_class_is_unicode (klass)); + fields = dn_vector_data_t (&fields_array, StructFieldInfo); + nfields = dn_vector_size (&fields_array); for (i = 0; i < nfields; ++i) { if ((fields [i].offset < 8) && (fields [i].offset + fields [i].size) > 8) { @@ -680,7 +682,7 @@ add_valuetype (MonoMethodSignature *sig, ArgInfo *ainfo, MonoType *type, if (!is_return) ainfo->arg_size = ALIGN_TO (size, 8); - g_array_free (fields_array, TRUE); + dn_vector_dispose (&fields_array); return; } @@ -722,7 +724,7 @@ add_valuetype (MonoMethodSignature *sig, ArgInfo *ainfo, MonoType *type, if (!is_return) ainfo->arg_size = ALIGN_TO (struct_size, 8); - g_array_free (fields_array, TRUE); + dn_vector_dispose (&fields_array); return; } @@ -760,7 +762,7 @@ add_valuetype (MonoMethodSignature *sig, ArgInfo *ainfo, MonoType *type, } } - g_array_free (fields_array, TRUE); + dn_vector_dispose (&fields_array); /* Post merger cleanup */ if ((args [0] == ARG_CLASS_MEMORY) || (args [1] == ARG_CLASS_MEMORY)) From 571be4fea86c7308c087fd1db453d664009c83b6 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 20:55:16 -0400 Subject: [PATCH 30/41] replace GArray by dn_vector_t in debug-mono-ppdb --- src/mono/mono/metadata/debug-mono-ppdb.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/mono/mono/metadata/debug-mono-ppdb.c b/src/mono/mono/metadata/debug-mono-ppdb.c index f4c4e01c43250e..15df0b5dfc8649 100644 --- a/src/mono/mono/metadata/debug-mono-ppdb.c +++ b/src/mono/mono/metadata/debug-mono-ppdb.c @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -491,7 +492,7 @@ mono_ppdb_get_seq_points_internal (MonoImage *image, MonoPPDBFile *ppdb, MonoMet MonoDebugSourceInfo *docinfo; int i, size, docidx, iloffset, delta_il, delta_lines, delta_cols, start_line, start_col, adv_line, adv_col; gboolean first = TRUE, first_non_hidden = TRUE; - GArray *sps; + dn_vector_t sps = {0,}; MonoSymSeqPoint sp; GPtrArray *sfiles = NULL; GPtrArray *sindexes = NULL; @@ -533,7 +534,7 @@ mono_ppdb_get_seq_points_internal (MonoImage *image, MonoPPDBFile *ppdb, MonoMet size = mono_metadata_decode_blob_size (ptr, &ptr); end = ptr + size; - sps = g_array_new (FALSE, TRUE, sizeof (MonoSymSeqPoint)); + dn_vector_init_t (&sps, MonoSymSeqPoint); /* Header */ /* LocalSignature */ @@ -593,26 +594,26 @@ mono_ppdb_get_seq_points_internal (MonoImage *image, MonoPPDBFile *ppdb, MonoMet sp.end_line = start_line + delta_lines; sp.end_column = start_col + delta_cols; - g_array_append_val (sps, sp); + dn_vector_push_back (&sps, sp); if (source_files) g_ptr_array_add (sindexes, GUINT_TO_POINTER (sfiles->len - 1)); } if (n_seq_points) { - *n_seq_points = sps->len; + *n_seq_points = dn_vector_size (&sps); g_assert (seq_points); - *seq_points = g_new (MonoSymSeqPoint, sps->len); - memcpy (*seq_points, sps->data, sps->len * sizeof (MonoSymSeqPoint)); + *seq_points = g_new (MonoSymSeqPoint, dn_vector_size (&sps)); + memcpy (*seq_points, dn_vector_data_t (&sps, MonoSymSeqPoint), dn_vector_size (&sps) * sizeof (MonoSymSeqPoint)); } if (source_files) { - *source_files = g_new (int, sps->len); - for (i = 0; i < sps->len; ++i) + *source_files = g_new (int, dn_vector_size (&sps)); + for (i = 0; i < dn_vector_size (&sps); ++i) (*source_files)[i] = GPOINTER_TO_INT (g_ptr_array_index (sindexes, i)); g_ptr_array_free (sindexes, TRUE); } - int n_seqs = sps->len; - g_array_free (sps, TRUE); + int n_seqs = dn_vector_size (&sps); + dn_vector_dispose (&sps); return n_seqs; } From e595b68a08d0ac8f87edd67fa11436ff4d60fa32 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 20:55:39 -0400 Subject: [PATCH 31/41] replace GArray by dn_vector_t in log and aot profilers --- src/mono/mono/profiler/CMakeLists.txt | 6 +++--- src/mono/mono/profiler/aot.c | 26 +++++++++++++++----------- src/mono/mono/profiler/log.c | 22 ++++++++++++---------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/mono/mono/profiler/CMakeLists.txt b/src/mono/mono/profiler/CMakeLists.txt index 6bca00983686fc..b56c64460a659c 100644 --- a/src/mono/mono/profiler/CMakeLists.txt +++ b/src/mono/mono/profiler/CMakeLists.txt @@ -14,14 +14,14 @@ if(NOT DISABLE_LIBS) # Build the logging profiler only for certain platforms add_library(mono-profiler-log SHARED helper.c log.c log-args.c ${ZLIB_SOURCES}) target_compile_definitions(mono-profiler-log PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects) + target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects shared_container_objects) if(HOST_ANDROID) target_link_libraries(mono-profiler-log PRIVATE log) endif() install(TARGETS mono-profiler-log LIBRARY) add_library(mono-profiler-log-static STATIC helper.c log.c log-args.c) - target_link_libraries(mono-profiler-log-static PRIVATE monoapi) + target_link_libraries(mono-profiler-log-static PRIVATE monoapi shared_container_objects) set_target_properties(mono-profiler-log-static PROPERTIES OUTPUT_NAME mono-profiler-log) install(TARGETS mono-profiler-log-static LIBRARY) @@ -32,7 +32,7 @@ if(NOT DISABLE_LIBS) if(NOT HOST_WASI) add_library(mono-profiler-aot-static STATIC aot.c helper.c) - target_link_libraries(mono-profiler-aot-static PRIVATE monoapi) + target_link_libraries(mono-profiler-aot-static PRIVATE monoapi shared_container_objects) set_target_properties(mono-profiler-aot-static PROPERTIES OUTPUT_NAME mono-profiler-aot) install(TARGETS mono-profiler-aot-static LIBRARY) endif() diff --git a/src/mono/mono/profiler/aot.c b/src/mono/mono/profiler/aot.c index 44d157e2b3d182..b68e70dbea17d6 100644 --- a/src/mono/mono/profiler/aot.c +++ b/src/mono/mono/profiler/aot.c @@ -11,6 +11,8 @@ #include "aot.h" #include "helper.h" +#include + #include #include #include @@ -231,7 +233,9 @@ helper_thread (void *arg) if (aot_profiler.duration >= 0) { sleep (aot_profiler.duration); } else if (aot_profiler.command_port >= 0) { - GArray *command_sockets = g_array_new (FALSE, FALSE, sizeof (int)); + dn_vector_t command_sockets = {0,}; + + dn_vector_init_t (&command_sockets, int); while (1) { fd_set rfds; @@ -242,8 +246,8 @@ helper_thread (void *arg) mono_profhelper_add_to_fd_set (&rfds, aot_profiler.server_socket, &max_fd); - for (gint i = 0; i < command_sockets->len; i++) - mono_profhelper_add_to_fd_set (&rfds, g_array_index (command_sockets, int, i), &max_fd); + for (uint32_t i = 0; i < dn_vector_size (&command_sockets); i++) + mono_profhelper_add_to_fd_set (&rfds, *dn_vector_index_t (&command_sockets, int, i), &max_fd); struct timeval tv = { .tv_sec = 1, .tv_usec = 0 }; @@ -256,8 +260,8 @@ helper_thread (void *arg) exit (1); } - for (gint i = 0; i < command_sockets->len; i++) { - int fd = g_array_index (command_sockets, int, i); + for (uint32_t i = 0; i < dn_vector_size (&command_sockets); i++) { + int fd = *dn_vector_index_t (&command_sockets, int, i); if (!FD_ISSET (fd, &rfds)) continue; @@ -270,7 +274,7 @@ helper_thread (void *arg) if (!len) { // The other end disconnected. - g_array_remove_index (command_sockets, i); + dn_vector_erase (dn_vector_it_next_n (dn_vector_begin (&command_sockets), i)); i--; mono_profhelper_close_socket_fd (fd); @@ -288,7 +292,7 @@ helper_thread (void *arg) mono_profiler_printf_err ("aot profiler data saved to the socket"); - g_array_remove_index (command_sockets, i); + dn_vector_erase (dn_vector_it_next_n (dn_vector_begin (&command_sockets), i)); i--; continue; @@ -307,15 +311,15 @@ helper_thread (void *arg) if (fd >= FD_SETSIZE) mono_profhelper_close_socket_fd (fd); else - g_array_append_val (command_sockets, fd); + dn_vector_push_back (&command_sockets, fd); } } } - for (gint i = 0; i < command_sockets->len; i++) - mono_profhelper_close_socket_fd (g_array_index (command_sockets, int, i)); + for (gint i = 0; i < dn_vector_size (&command_sockets); i++) + mono_profhelper_close_socket_fd (*dn_vector_index_t (&command_sockets, int, i)); - g_array_free (command_sockets, TRUE); + dn_vector_dispose (&command_sockets); } prof_shutdown (&aot_profiler); diff --git a/src/mono/mono/profiler/log.c b/src/mono/mono/profiler/log.c index 110253833a97bb..8b2e7db3ee67cf 100644 --- a/src/mono/mono/profiler/log.c +++ b/src/mono/mono/profiler/log.c @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -2781,7 +2782,8 @@ helper_thread (void *arg) { MonoProfilerThread *thread = profiler_thread_begin ("Profiler Helper", TRUE); - GArray *command_sockets = g_array_new (FALSE, FALSE, sizeof (int)); + dn_vector_t command_sockets = {0,}; + dn_vector_init_t (&command_sockets, int); while (1) { fd_set rfds; @@ -2795,8 +2797,8 @@ helper_thread (void *arg) mono_profhelper_add_to_fd_set (&rfds, log_profiler.pipes [0], &max_fd); #endif - for (gint i = 0; i < command_sockets->len; i++) - mono_profhelper_add_to_fd_set (&rfds, g_array_index (command_sockets, int, i), &max_fd); + for (gint i = 0; i < dn_vector_size (&command_sockets); i++) + mono_profhelper_add_to_fd_set (&rfds, *dn_vector_index_t (&command_sockets, int, i), &max_fd); struct timeval tv = { .tv_sec = 1, .tv_usec = 0 }; @@ -2835,8 +2837,8 @@ helper_thread (void *arg) } #endif - for (gint i = 0; i < command_sockets->len; i++) { - int fd = g_array_index (command_sockets, int, i); + for (gint i = 0; i < dn_vector_size (&command_sockets); i++) { + int fd = *dn_vector_index_t (&command_sockets, int, i); if (!FD_ISSET (fd, &rfds)) continue; @@ -2852,7 +2854,7 @@ helper_thread (void *arg) if (!len) { // The other end disconnected. - g_array_remove_index (command_sockets, i); + dn_vector_erase (dn_vector_it_next_n (dn_vector_begin (&command_sockets), i)); mono_profhelper_close_socket_fd (fd); continue; @@ -2873,17 +2875,17 @@ helper_thread (void *arg) mono_profhelper_close_socket_fd (fd); else #endif - g_array_append_val (command_sockets, fd); + dn_vector_push_back (&command_sockets, fd); } } profiler_thread_check_detach (thread); } - for (gint i = 0; i < command_sockets->len; i++) - mono_profhelper_close_socket_fd (g_array_index (command_sockets, int, i)); + for (gint i = 0; i < dn_vector_size (&command_sockets); i++) + mono_profhelper_close_socket_fd (*dn_vector_intex_t (&command_sockets, int, i)); - g_array_free (command_sockets, TRUE); + dn_vector_dispose (&command_sockets); profiler_thread_end (thread, &log_profiler.helper_thread_exited, TRUE); From bc81bd6e389940c6d5559f9238e5fb13b09f5eb4 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 21:07:09 -0400 Subject: [PATCH 32/41] Add G_CONTAINER_DEPRECATED macro. Mark GArray creation funcs deprecated --- src/mono/mono/eglib/glib.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mono/mono/eglib/glib.h b/src/mono/mono/eglib/glib.h index e438c00298ec72..8d33e6da52d871 100644 --- a/src/mono/mono/eglib/glib.h +++ b/src/mono/mono/eglib/glib.h @@ -104,6 +104,13 @@ struct g_cast #define G_MAY_ALIAS /* nothing */ #endif +#if defined (__GNUC__) +#define G_CONTAINER_DEPRECATED(gcontainer,dncontainer) __attribute__((deprecated("Do not use " #gcontainer ", use " #dncontainer " from src/native/containers"))) +#elif defined (_MSC_VER) +#define G_CONTAINER_DEPRECATED(gcontainer,dncontainer) __declspec(deprecated("Do not use " #gcontainer ", use " #dncontainer " from src\\native\\containers")) +#endif + + #ifdef __cplusplus // Provide for bit operations on enums, but not all integer operations. @@ -663,7 +670,9 @@ struct _GArray { gint len; }; +G_CONTAINER_DEPRECATED(GArray,dn_vector_t) GArray *g_array_new (gboolean zero_terminated, gboolean clear_, guint element_size); +G_CONTAINER_DEPRECATED(GArray,dn_vector_t) GArray *g_array_sized_new (gboolean zero_terminated, gboolean clear_, guint element_size, guint reserved_size); gchar* g_array_free (GArray *array, gboolean free_segment); GArray *g_array_append_vals (GArray *array, gconstpointer data, guint len); From c1fcf96d5237cebaf09167e4e14410169f2349c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 21:17:29 -0400 Subject: [PATCH 33/41] replace GArray with dn_vector_t in hazard-pointer --- src/mono/mono/utils/hazard-pointer.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/mono/mono/utils/hazard-pointer.c b/src/mono/mono/utils/hazard-pointer.c index 9769c4b38ad026..18b8923ecc8608 100644 --- a/src/mono/mono/utils/hazard-pointer.c +++ b/src/mono/mono/utils/hazard-pointer.c @@ -10,6 +10,8 @@ #include +#include + #include #include #include @@ -359,17 +361,23 @@ mono_hazard_pointer_install_free_queue_size_callback (MonoHazardFreeQueueSizeCal static void try_free_delayed_free_items (guint32 limit) { - GArray *hazardous = NULL; + + dn_vector_t hazardous = {0,}; + gboolean hazardous_inited = FALSE; DelayedFreeItem item; guint32 freed = 0; // Free all the items we can and re-add the ones we can't to the queue. while (mono_lock_free_array_queue_pop (&delayed_free_queue, &item)) { if (is_pointer_hazardous (item.p)) { - if (!hazardous) - hazardous = g_array_sized_new (FALSE, FALSE, sizeof (DelayedFreeItem), delayed_free_queue.num_used_entries); - - g_array_append_val (hazardous, item); + if (!hazardous_inited) { + dn_vector_custom_init_params_t init_params = {0,}; + init_params.capacity = delayed_free_queue.num_used_entries; + dn_vector_custom_init_t (&hazardous, &init_params, DelayedFreeItem); + hazardous_inited = TRUE; + } + + dn_vector_push_back (&hazardous, item); continue; } @@ -380,11 +388,11 @@ try_free_delayed_free_items (guint32 limit) break; } - if (hazardous) { - for (gint i = 0; i < hazardous->len; i++) - mono_lock_free_array_queue_push (&delayed_free_queue, &g_array_index (hazardous, DelayedFreeItem, i)); + if (hazardous_inited) { + for (gint i = 0; i < dn_vector_size (&hazardous); i++) + mono_lock_free_array_queue_push (&delayed_free_queue, dn_vector_index_t (&hazardous, DelayedFreeItem, i)); - g_array_free (hazardous, TRUE); + dn_vector_dispose (&hazardous); } } From 15b08d89894295febab7feb937304849902f2d16 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Thu, 6 Apr 2023 21:31:19 -0400 Subject: [PATCH 34/41] replace GArray with dn_vector_t in ep-rt-mono --- src/mono/mono/eventpipe/ep-rt-mono.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/mono/mono/eventpipe/ep-rt-mono.c b/src/mono/mono/eventpipe/ep-rt-mono.c index b68a71af08bdcb..526adb5616b7c2 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.c +++ b/src/mono/mono/eventpipe/ep-rt-mono.c @@ -7,6 +7,8 @@ #include #include +#include + #include #include #include @@ -61,7 +63,7 @@ struct _EventPipeThreadData { }; // Sample profiler. -static GArray * _ep_rt_mono_sampled_thread_callstacks = NULL; +static dn_vector_t * _ep_rt_mono_sampled_thread_callstacks = NULL; static uint32_t _ep_rt_mono_max_sampled_thread_count = 32; // Mono profilers. @@ -2076,7 +2078,7 @@ void ep_rt_mono_fini (void) { if (_ep_rt_mono_sampled_thread_callstacks) - g_array_free (_ep_rt_mono_sampled_thread_callstacks, TRUE); + dn_vector_free (_ep_rt_mono_sampled_thread_callstacks); if (_ep_rt_mono_initialized) mono_rand_close (_ep_rt_mono_rand_provider); @@ -2766,13 +2768,17 @@ ep_rt_mono_sample_profiler_write_sampling_event_for_threads ( // TODO: Investigate alternatives on platforms supporting Signals/SuspendThread (see Mono profiler) or CPU PMU's (see ETW/perf_event_open). // Sample profiler only runs on one thread, no need to synchorinize. - if (!_ep_rt_mono_sampled_thread_callstacks) - _ep_rt_mono_sampled_thread_callstacks = g_array_sized_new (FALSE, FALSE, sizeof (EventPipeSampleProfileStackWalkData), _ep_rt_mono_max_sampled_thread_count); + if (!_ep_rt_mono_sampled_thread_callstacks) { + dn_vector_custom_alloc_params_t alloc_params = {0,}; + alloc_params.capacity = _ep_rt_mono_max_sampled_thread_count; + alloc_params.attributes = DN_VECTOR_ATTRIBUTE_MEMORY_INIT; + _ep_rt_mono_sampled_thread_callstacks = dn_vector_custom_alloc_t (&alloc_params, EventPipeSampleProfileStackWalkData); + } // Make sure there is room based on previous max number of sampled threads. // NOTE, there is a chance there are more threads than max, if that's the case we will // miss those threads in this sample, but will be included in next when max has been adjusted. - g_array_set_size (_ep_rt_mono_sampled_thread_callstacks, _ep_rt_mono_max_sampled_thread_count); + dn_vector_reserve (_ep_rt_mono_sampled_thread_callstacks, _ep_rt_mono_max_sampled_thread_count); uint32_t filtered_thread_count = 0; uint32_t sampled_thread_count = 0; @@ -2791,7 +2797,7 @@ ep_rt_mono_sample_profiler_write_sampling_event_for_threads ( MonoThreadUnwindState *thread_state = mono_thread_info_get_suspend_state (thread_info); if (thread_state->valid) { if (sampled_thread_count < _ep_rt_mono_max_sampled_thread_count) { - EventPipeSampleProfileStackWalkData *data = &g_array_index (_ep_rt_mono_sampled_thread_callstacks, EventPipeSampleProfileStackWalkData, sampled_thread_count); + EventPipeSampleProfileStackWalkData *data = dn_vector_index_t (_ep_rt_mono_sampled_thread_callstacks, EventPipeSampleProfileStackWalkData, sampled_thread_count); data->thread_id = ep_rt_thread_id_t_to_uint64_t (mono_thread_info_get_tid (thread_info)); data->thread_ip = (uintptr_t)MONO_CONTEXT_GET_IP (&thread_state->ctx); data->payload_data = EP_SAMPLE_PROFILER_SAMPLE_TYPE_ERROR; @@ -2835,7 +2841,7 @@ ep_rt_mono_sample_profiler_write_sampling_event_for_threads ( // adapter instance and only set recorded tid as parameter inside adapter. THREAD_INFO_TYPE adapter = { { 0 } }; for (uint32_t thread_count = 0; thread_count < sampled_thread_count; ++thread_count) { - EventPipeSampleProfileStackWalkData *data = &g_array_index (_ep_rt_mono_sampled_thread_callstacks, EventPipeSampleProfileStackWalkData, thread_count); + EventPipeSampleProfileStackWalkData *data = dn_vector_index_t (_ep_rt_mono_sampled_thread_callstacks, EventPipeSampleProfileStackWalkData, thread_count); if ((data->stack_walk_data.top_frame && data->payload_data == EP_SAMPLE_PROFILER_SAMPLE_TYPE_EXTERNAL) || (data->payload_data != EP_SAMPLE_PROFILER_SAMPLE_TYPE_ERROR && ep_stack_contents_get_length (&data->stack_contents) > 0)) { // Check if we have an async frame, if so we will need to make sure all frames are registered in regular jit info table. // TODO: An async frame can contain wrapper methods (no way to check during stackwalk), we could skip writing profile event From ba3fc387e78f83df5e7dadc49af02272ef294c56 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 7 Apr 2023 11:06:52 -0400 Subject: [PATCH 35/41] Add a shared_container_api cmake interface library For dependencies that only need to see the container headers but not the code (e.g. to describe the interface for the runtime component stubs) --- src/mono/mono/component/CMakeLists.txt | 8 ++++++-- src/mono/mono/containers/CMakeLists.txt | 14 ++++++++++++-- src/mono/mono/metadata/CMakeLists.txt | 2 +- src/mono/mono/mini/CMakeLists.txt | 2 +- src/mono/mono/profiler/CMakeLists.txt | 2 +- src/mono/mono/sgen/CMakeLists.txt | 2 +- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/mono/mono/component/CMakeLists.txt b/src/mono/mono/component/CMakeLists.txt index d3bfe3e6921ee2..ceb47adaadb019 100644 --- a/src/mono/mono/component/CMakeLists.txt +++ b/src/mono/mono/component/CMakeLists.txt @@ -106,6 +106,10 @@ set(${MONO_MARSHAL_ILGEN_COMPONENT_NAME}-sources ${MONO_COMPONENT_PATH}/marshal-ilgen.h ) +set(${MONO_MARSHAL_ILGEN_COMPONENT_NAME}-link_libraries + shared_container_objects +) + # For every component not build into the AOT compiler, build the stub instead set(stubs_for_aot "") foreach (component IN LISTS components) @@ -161,7 +165,7 @@ foreach(component IN LISTS components) if(NOT DISABLE_COMPONENT_OBJECTS) add_library("${component}-objects" OBJECT "${${component}-sources}") target_link_libraries("${component}-objects" PRIVATE component_base) - target_link_libraries("${component}-objects" PUBLIC eglib_api) + target_link_libraries("${component}-objects" PUBLIC eglib_api shared_container_api) if(DEFINED "${component}-link_libraries") target_link_libraries("${component}-objects" PRIVATE "${${component}-link_libraries}") endif() @@ -171,7 +175,7 @@ foreach(component IN LISTS components) endif() add_library("${component}-stub-objects" OBJECT "${${component}-stub-sources}") target_link_libraries("${component}-stub-objects" PRIVATE component_base) - target_link_libraries("${component}-stub-objects" PUBLIC eglib_api) + target_link_libraries("${component}-stub-objects" PUBLIC eglib_api shared_container_api) endforeach() if(NOT DISABLE_COMPONENTS AND NOT STATIC_COMPONENTS) diff --git a/src/mono/mono/containers/CMakeLists.txt b/src/mono/mono/containers/CMakeLists.txt index 4b169efcf360b6..4815076f555279 100644 --- a/src/mono/mono/containers/CMakeLists.txt +++ b/src/mono/mono/containers/CMakeLists.txt @@ -11,14 +11,24 @@ list(APPEND shared_container_sources ${SHARED_CONTAINER_HEADERS} ) +addprefix(shared_container_api_sources ${SHARED_CONTAINERS_SOURCE_PATH} "${SHARED_CONTAINER_HEADERS}") + addprefix(shared_container_sources ${SHARED_CONTAINERS_SOURCE_PATH} "${shared_container_sources}") +set(rt_mono_container_api_sources + dn-rt-mono.h) + set(rt_mono_container_sources - dn-rt-mono.h + ${rn_mono_container_api_sources} dn-rt-utils.c) + +add_library(shared_container_api INTERFACE) +target_sources(shared_container_api INTERFACE ${shared_container_api_sources} ${rt_mono_container_api_sources}) +target_include_directories(shared_container_api INTERFACE ${SHARED_CONTAINERS_SOURCE_PATH} .) + add_library(shared_container_objects OBJECT ${shared_container_sources} ${rt_mono_container_sources}) -target_link_libraries(shared_container_objects PRIVATE eglib_api) +target_link_libraries(shared_container_objects PRIVATE eglib_api shared_container_api) target_include_directories(shared_container_objects PUBLIC ${SHARED_CONTAINERS_SOURCE_PATH} .) # to pick up config.h target_include_directories(shared_container_objects PRIVATE diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index 8f649a67d4c7ec..cf1859658dbc88 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -5,7 +5,7 @@ project(metadata C) # if(DISABLE_ICALL_TABLES) add_library(mono-icall-table STATIC "icall-table.c") -target_link_libraries(mono-icall-table PRIVATE monoapi eglib_api) +target_link_libraries(mono-icall-table PRIVATE monoapi eglib_api shared_container_api) target_include_directories(mono-icall-table PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. ${PROJECT_SOURCE_DIR}/..) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 8f56ea8cbe528b..77d8669230924f 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -540,7 +540,7 @@ if(NOT DISABLE_EXECUTABLES) if(MONO_CROSS_COMPILE_EXECUTABLE_NAME) set_target_properties(mono-sgen PROPERTIES OUTPUT_NAME mono-aot-cross) endif() - target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS} ${Z_LIBS}) + target_link_libraries(mono-sgen PRIVATE monoapi eglib_api shared_container_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS} ${Z_LIBS}) # Alpine Linux implements ucontext in a different library if(CLR_CMAKE_HOST_ALPINE_LINUX AND TARGET_S390X) target_link_libraries(mono-sgen PRIVATE ucontext) diff --git a/src/mono/mono/profiler/CMakeLists.txt b/src/mono/mono/profiler/CMakeLists.txt index b56c64460a659c..9477c316cad6d5 100644 --- a/src/mono/mono/profiler/CMakeLists.txt +++ b/src/mono/mono/profiler/CMakeLists.txt @@ -39,7 +39,7 @@ if(NOT DISABLE_LIBS) if(HOST_BROWSER) add_library(mono-profiler-browser-static STATIC browser.c) - target_link_libraries(mono-profiler-browser-static PRIVATE monoapi) + target_link_libraries(mono-profiler-browser-static PRIVATE monoapi shared_container_api) set_target_properties(mono-profiler-browser-static PROPERTIES OUTPUT_NAME mono-profiler-browser) install(TARGETS mono-profiler-browser-static LIBRARY) endif() diff --git a/src/mono/mono/sgen/CMakeLists.txt b/src/mono/mono/sgen/CMakeLists.txt index 8297a877fbb136..a40cc437735302 100644 --- a/src/mono/mono/sgen/CMakeLists.txt +++ b/src/mono/mono/sgen/CMakeLists.txt @@ -60,7 +60,7 @@ set(sgen_sources_base set(sgen_sources "${sgen_sources_base}") add_library(sgen_objects ${sgen_sources}) -target_link_libraries(sgen_objects PRIVATE monoapi eglib_api utils_objects) +target_link_libraries(sgen_objects PRIVATE monoapi eglib_api shared_container_api utils_objects) target_compile_definitions(sgen_objects PRIVATE -DMONO_DLL_EXPORT -DHAVE_SGEN_GC) target_include_directories(sgen_objects PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. From bfb27a9d7f6debb789691a66490101f7c68327fe Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 7 Apr 2023 11:08:01 -0400 Subject: [PATCH 36/41] [icall] Don't use bareword bool in icall signature macros If `` gets included, the preprocessor will replace it with `bool` with `_Bool` and mess up the ICALL_SIGS macro machinery Use `boolean` in icall signature macros instead --- src/mono/mono/metadata/icall-signatures.h | 8 ++++---- src/mono/mono/metadata/icall.c | 5 ++--- src/mono/mono/mini/aot-compiler.c | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/mono/mono/metadata/icall-signatures.h b/src/mono/mono/metadata/icall-signatures.h index 16b35efa530ce9..72bf477c50add1 100644 --- a/src/mono/mono/metadata/icall-signatures.h +++ b/src/mono/mono/metadata/icall-signatures.h @@ -57,7 +57,7 @@ // mono_icall_sig_void_int32 // mono_icall_sig_void_object // mono_icall_sig_void_ptr -// mono_icall_sig_bool_ptr_ptrref +// mono_icall_sig_boolean_ptr_ptrref // mono_icall_sig_double_double_double // mono_icall_sig_float_float_float // mono_icall_sig_int_obj_ptr @@ -94,7 +94,7 @@ // mono_icall_sig_void_ptr_ptr // mono_icall_sig_void_ptr_ptrref // mono_icall_sig_void_uint32_ptrref -// mono_icall_sig_bool_ptr_int32_ptrref +// mono_icall_sig_boolean_ptr_int32_ptrref // mono_icall_sig_int32_int32_ptr_ptrref // mono_icall_sig_int32_ptr_int32_ptr // mono_icall_sig_int32_ptr_int32_ptrref @@ -182,7 +182,7 @@ ICALL_SIG (2, (void, int)) \ ICALL_SIG (2, (void, int32)) \ ICALL_SIG (2, (void, object)) \ ICALL_SIG (2, (void, ptr)) \ -ICALL_SIG (3, (bool, ptr, ptrref)) \ +ICALL_SIG (3, (boolean, ptr, ptrref)) \ ICALL_SIG (3, (double, double, double)) \ ICALL_SIG (3, (float, float, float)) \ ICALL_SIG (3, (int, obj, ptr)) \ @@ -221,7 +221,7 @@ ICALL_SIG (3, (void, ptr, object)) \ ICALL_SIG (3, (void, ptr, ptr)) \ ICALL_SIG (3, (void, ptr, ptrref)) \ ICALL_SIG (3, (void, uint32, ptrref)) \ -ICALL_SIG (4, (bool, ptr, int32, ptrref)) \ +ICALL_SIG (4, (boolean, ptr, int32, ptrref)) \ ICALL_SIG (4, (int32, int32, ptr, ptrref)) \ ICALL_SIG (4, (int32, ptr, int32, ptr)) \ ICALL_SIG (4, (int32, ptr, int32, ptrref)) \ diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index 63a83b091ee51d..c15544317ffd0a 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -7123,8 +7123,7 @@ mono_lookup_icall_symbol (MonoMethod *m) // // mono_create_icall_signatures depends on this order. Handle with care. typedef enum ICallSigType { - ICALL_SIG_TYPE_bool = 0x00, - ICALL_SIG_TYPE_boolean = ICALL_SIG_TYPE_bool, + ICALL_SIG_TYPE_boolean = 0x00, ICALL_SIG_TYPE_double = 0x01, ICALL_SIG_TYPE_float = 0x02, ICALL_SIG_TYPE_int = 0x03, @@ -7202,7 +7201,7 @@ mono_create_icall_signatures (void) typedef gsize G_MAY_ALIAS gsize_a; MonoType * const lookup [ ] = { - m_class_get_byval_arg (mono_defaults.boolean_class), // ICALL_SIG_TYPE_bool + m_class_get_byval_arg (mono_defaults.boolean_class), // ICALL_SIG_TYPE_boolean m_class_get_byval_arg (mono_defaults.double_class), // ICALL_SIG_TYPE_double m_class_get_byval_arg (mono_defaults.single_class), // ICALL_SIG_TYPE_float m_class_get_byval_arg (mono_defaults.int32_class), // ICALL_SIG_TYPE_int diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index 611a75b07b805d..7da7ba0aad9c39 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -14300,8 +14300,8 @@ add_preinit_got_slots (MonoAotCompile *acfg) #ifndef MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE static MonoMethodSignature * const * const interp_in_static_sigs [] = { - &mono_icall_sig_bool_ptr_int32_ptrref, - &mono_icall_sig_bool_ptr_ptrref, + &mono_icall_sig_boolean_ptr_int32_ptrref, + &mono_icall_sig_boolean_ptr_ptrref, &mono_icall_sig_int32_int32_ptrref, &mono_icall_sig_int32_int32_ptr_ptrref, &mono_icall_sig_int32_ptr_int32_ptr, From b7399242e09062337fc95d7ec13c9aa0f2f36994 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 7 Apr 2023 11:09:31 -0400 Subject: [PATCH 37/41] replace GByteArray by dn_vector_t in mono-threads --- src/mono/mono/utils/mono-threads-coop.c | 4 ++-- src/mono/mono/utils/mono-threads.c | 5 +++-- src/mono/mono/utils/mono-threads.h | 6 ++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/mono/mono/utils/mono-threads-coop.c b/src/mono/mono/utils/mono-threads-coop.c index 0bb7b0bcc654c6..294af45f2dc215 100644 --- a/src/mono/mono/utils/mono-threads-coop.c +++ b/src/mono/mono/utils/mono-threads-coop.c @@ -191,8 +191,8 @@ copy_stack_data_internal (MonoThreadInfo *info, MonoStackData *stackdata_begin, if (stackdata_size <= 0) g_error ("%s stackdata_size = %d, but must be > 0, stackdata_begin = %p, stackdata_end = %p", mono_stackdata_get_function_name (stackdata_begin), stackdata_size, stackdata_begin, stackdata_end); - g_byte_array_set_size (info->stackdata, stackdata_size); - state->gc_stackdata = info->stackdata->data; + dn_checkfail (dn_vector_resize (info->stackdata, stackdata_size), "Allocation failed"); + state->gc_stackdata = dn_vector_data (info->stackdata); memcpy (state->gc_stackdata, stackdata_end, stackdata_size); state->gc_stackdata_size = stackdata_size; diff --git a/src/mono/mono/utils/mono-threads.c b/src/mono/mono/utils/mono-threads.c index 026c290fb3224d..637b8d40652f24 100644 --- a/src/mono/mono/utils/mono-threads.c +++ b/src/mono/mono/utils/mono-threads.c @@ -519,7 +519,8 @@ register_thread (MonoThreadInfo *info) g_assert (stsize); info->stack_start_limit = staddr; info->stack_end = staddr + stsize; - info->stackdata = g_byte_array_new (); + info->stackdata = dn_vector_alloc_t (uint8_t); + dn_checkfail (info->stackdata, "Allocation failed"); info->internal_thread_gchandle = NULL; @@ -641,7 +642,7 @@ unregister_thread (void *arg) mono_thread_info_suspend_unlock (); - g_byte_array_free (info->stackdata, /*free_segment=*/TRUE); + dn_vector_free (info->stackdata); /*now it's safe to free the thread info.*/ mono_thread_hazardous_try_free (info, free_thread_info); diff --git a/src/mono/mono/utils/mono-threads.h b/src/mono/mono/utils/mono-threads.h index 6a548b1838c342..cfb7c865b9bbb1 100644 --- a/src/mono/mono/utils/mono-threads.h +++ b/src/mono/mono/utils/mono-threads.h @@ -25,6 +25,8 @@ #include #include +#include + #include #include #ifdef HOST_WIN32 @@ -236,8 +238,8 @@ typedef struct _MonoThreadInfo { gboolean suspend_can_continue; - /* This memory pool is used by coop GC to save stack data roots between GC unsafe regions */ - GByteArray *stackdata; + /* This memory block is used by coop GC to save stack data roots between GC unsafe regions */ + dn_vector_t *stackdata; /*In theory, only the posix backend needs this, but having it on mach/win32 simplifies things a lot.*/ MonoThreadUnwindState thread_saved_state [2]; //0 is self suspend, 1 is async suspend. From b5799cc7c67a7539c240b958a7cfcb30fa49d656 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 7 Apr 2023 11:14:57 -0400 Subject: [PATCH 38/41] Add a way to bypass glib container deprecation warning For example when one container is implemented in terms of another --- src/mono/mono/eglib/gbytearray.c | 1 + src/mono/mono/eglib/glib.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/mono/mono/eglib/gbytearray.c b/src/mono/mono/eglib/gbytearray.c index 6bb3b74f2c61bf..c068d2b8f38b15 100644 --- a/src/mono/mono/eglib/gbytearray.c +++ b/src/mono/mono/eglib/gbytearray.c @@ -27,6 +27,7 @@ */ #include "config.h" #include +#define G_ALLOW_DEPRECATED_CONTAINER #include GByteArray * diff --git a/src/mono/mono/eglib/glib.h b/src/mono/mono/eglib/glib.h index 8d33e6da52d871..d0d31b4c079361 100644 --- a/src/mono/mono/eglib/glib.h +++ b/src/mono/mono/eglib/glib.h @@ -104,11 +104,15 @@ struct g_cast #define G_MAY_ALIAS /* nothing */ #endif +#ifndef G_ALLOW_DEPRECATED_CONTAINER #if defined (__GNUC__) #define G_CONTAINER_DEPRECATED(gcontainer,dncontainer) __attribute__((deprecated("Do not use " #gcontainer ", use " #dncontainer " from src/native/containers"))) #elif defined (_MSC_VER) #define G_CONTAINER_DEPRECATED(gcontainer,dncontainer) __declspec(deprecated("Do not use " #gcontainer ", use " #dncontainer " from src\\native\\containers")) #endif +#else +#define G_CONTAINER_DEPRECATED(gcontainer,dncontainer) /* empty */ +#endif #ifdef __cplusplus From 4a118ee5e46e799f14434ac939965d30fac12307 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 7 Apr 2023 11:44:56 -0400 Subject: [PATCH 39/41] add containers dir to offsets tool include paths --- src/mono/mono/tools/offsets-tool/offsets-tool.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mono/mono/tools/offsets-tool/offsets-tool.py b/src/mono/mono/tools/offsets-tool/offsets-tool.py index 5f52ab268adc49..c06d40e60de034 100644 --- a/src/mono/mono/tools/offsets-tool/offsets-tool.py +++ b/src/mono/mono/tools/offsets-tool/offsets-tool.py @@ -229,8 +229,10 @@ def run_clang(self): args.mono_path, args.mono_path + "/mono", args.mono_path + "/mono/eglib", + args.mono_path + "/mono/containers", args.native_path, args.native_path + "/public", + args.native_path + "/containers", args.target_path, args.target_path + "/mono/eglib" ] From 9fd9e91627146c892e996691deff5ae76ac327ef Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 7 Apr 2023 11:45:40 -0400 Subject: [PATCH 40/41] use dn_vector_t instead of GByteArray for seq-points-data --- src/mono/mono/metadata/seq-points-data.c | 14 +++++++------- src/mono/mono/metadata/seq-points-data.h | 4 +++- src/mono/mono/mini/interp/transform.c | 10 +++++----- src/mono/mono/mini/seq-points.c | 11 ++++++----- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/mono/mono/metadata/seq-points-data.c b/src/mono/mono/metadata/seq-points-data.c index 2894a88a499553..11a91fecb86c3d 100644 --- a/src/mono/mono/metadata/seq-points-data.c +++ b/src/mono/mono/metadata/seq-points-data.c @@ -170,7 +170,7 @@ seq_point_read (SeqPoint* seq_point, guint8* ptr, guint8* buffer_ptr, gboolean h } gboolean -mono_seq_point_info_add_seq_point (GByteArray* array, SeqPoint *sp, SeqPoint *last_seq_point, GSList *next, gboolean has_debug_data) +mono_seq_point_info_add_seq_point (dn_vector_t* array, SeqPoint *sp, SeqPoint *last_seq_point, GSList *next, gboolean has_debug_data) { int il_delta, native_delta; GSList *l; @@ -193,25 +193,25 @@ mono_seq_point_info_add_seq_point (GByteArray* array, SeqPoint *sp, SeqPoint *la } len = encode_var_int (buffer, NULL, encode_zig_zag (il_delta)); - g_byte_array_append (array, buffer, len); + _dn_vector_append_range (array, buffer, len); len = encode_var_int (buffer, NULL, encode_zig_zag (native_delta)); - g_byte_array_append (array, buffer, len); + _dn_vector_append_range (array, buffer, len); if (has_debug_data) { - sp->next_offset = array->len; + sp->next_offset = dn_vector_size (array); sp->next_len = g_slist_length (next); len = encode_var_int (buffer, NULL, flags); - g_byte_array_append (array, buffer, len); + _dn_vector_append_range (array, buffer, len); len = encode_var_int (buffer, NULL, sp->next_len); - g_byte_array_append (array, buffer, len); + _dn_vector_append_range (array, buffer, len); for (l = next; l; l = l->next) { int next_index = GPOINTER_TO_UINT (l->data); len = encode_var_int (buffer, NULL, next_index); - g_byte_array_append (array, buffer, len); + _dn_vector_append_range (array, buffer, len); } } diff --git a/src/mono/mono/metadata/seq-points-data.h b/src/mono/mono/metadata/seq-points-data.h index 575e0f815fdc9d..c48d8bc9fad92d 100644 --- a/src/mono/mono/metadata/seq-points-data.h +++ b/src/mono/mono/metadata/seq-points-data.h @@ -7,6 +7,8 @@ #ifndef __MONO_SEQ_POINTS_DATA_H__ #define __MONO_SEQ_POINTS_DATA_H__ +#include + #include #include "mono/utils/mono-compiler.h" @@ -65,7 +67,7 @@ int mono_seq_point_info_get_write_size (MonoSeqPointInfo* info); gboolean -mono_seq_point_info_add_seq_point (GByteArray* array, SeqPoint *sp, SeqPoint *last_seq_point, GSList *next, gboolean has_debug_data); +mono_seq_point_info_add_seq_point (dn_vector_t* array, SeqPoint *sp, SeqPoint *last_seq_point, GSList *next, gboolean has_debug_data); MonoSeqPointInfo* mono_seq_point_info_new (int len, gboolean alloc_data, guint8 *data, gboolean has_debug_data, int *out_size); diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 44d631efef4746..1849dd1a4eecf5 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -4010,7 +4010,7 @@ collect_pred_seq_points (TransformData *td, InterpBasicBlock *bb, SeqPoint *seqp static void save_seq_points (TransformData *td, MonoJitInfo *jinfo) { - GByteArray *array; + dn_vector_t array = {0,}; int seq_info_size; MonoSeqPointInfo *info; GSList **next = NULL; @@ -4055,14 +4055,14 @@ save_seq_points (TransformData *td, MonoJitInfo *jinfo) } /* Serialize the seq points into a byte array */ - array = g_byte_array_new (); + dn_vector_init_t (&array, uint8_t); SeqPoint zero_seq_point = {0}; SeqPoint* last_seq_point = &zero_seq_point; for (guint i = 0; i < td->seq_points->len; ++i) { SeqPoint *sp = (SeqPoint*)g_ptr_array_index (td->seq_points, i); sp->next_offset = 0; - if (mono_seq_point_info_add_seq_point (array, sp, last_seq_point, next [i], TRUE)) + if (mono_seq_point_info_add_seq_point (&array, sp, last_seq_point, next [i], TRUE)) last_seq_point = sp; } @@ -4085,10 +4085,10 @@ save_seq_points (TransformData *td, MonoJitInfo *jinfo) } } - info = mono_seq_point_info_new (array->len, TRUE, array->data, TRUE, &seq_info_size); + info = mono_seq_point_info_new (dn_vector_size (&array), TRUE, dn_vector_data (&array), TRUE, &seq_info_size); mono_atomic_fetch_add_i32 (&mono_jit_stats.allocated_seq_points_size, seq_info_size); - g_byte_array_free (array, TRUE); + dn_vector_dispose (&array); jinfo->seq_points = info; } diff --git a/src/mono/mono/mini/seq-points.c b/src/mono/mono/mini/seq-points.c index 38a09494d0f380..7a75df00833f1e 100644 --- a/src/mono/mono/mini/seq-points.c +++ b/src/mono/mono/mini/seq-points.c @@ -10,6 +10,7 @@ */ #include +#include #include #include "mini.h" #include "mini-runtime.h" @@ -112,7 +113,7 @@ mono_save_seq_point_info (MonoCompile *cfg, MonoJitInfo *jinfo) int seq_info_size; GSList **next = NULL; SeqPoint* seq_points; - GByteArray* array; + dn_vector_t array = {0,}; gboolean has_debug_data = cfg->gen_sdb_seq_points; if (!cfg->seq_points) @@ -206,7 +207,7 @@ mono_save_seq_point_info (MonoCompile *cfg, MonoJitInfo *jinfo) } } - array = g_byte_array_new (); + dn_vector_init_t (&array, uint8_t); { /* Add sequence points to seq_point_info */ SeqPoint zero_seq_point = {0}; @@ -219,7 +220,7 @@ mono_save_seq_point_info (MonoCompile *cfg, MonoJitInfo *jinfo) if (has_debug_data) next_list = next[i]; - if (mono_seq_point_info_add_seq_point (array, sp, last_seq_point, next_list, has_debug_data)) + if (mono_seq_point_info_add_seq_point (&array, sp, last_seq_point, next_list, has_debug_data)) last_seq_point = sp; if (has_debug_data) @@ -232,10 +233,10 @@ mono_save_seq_point_info (MonoCompile *cfg, MonoJitInfo *jinfo) if (has_debug_data) g_free (next); - cfg->seq_point_info = mono_seq_point_info_new (array->len, TRUE, array->data, has_debug_data, &seq_info_size); + cfg->seq_point_info = mono_seq_point_info_new (dn_vector_size (&array), TRUE, dn_vector_data (&array), has_debug_data, &seq_info_size); mono_atomic_fetch_add_i32 (&mono_jit_stats.allocated_seq_points_size, seq_info_size); - g_byte_array_free (array, TRUE); + dn_vector_dispose (&array); // FIXME: dynamic methods if (!cfg->compile_aot) { From 02155b3fa21ba43e75eb47b51a2b5d80fb88c106 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 7 Apr 2023 12:53:19 -0400 Subject: [PATCH 41/41] replace GArray by dn_vector_t in mini-llvm --- src/mono/mono/mini/mini-llvm.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/mono/mono/mini/mini-llvm.c b/src/mono/mono/mini/mini-llvm.c index 1d78c8dd81d825..ee5dd36a6961c1 100644 --- a/src/mono/mono/mini/mini-llvm.c +++ b/src/mono/mono/mini/mini-llvm.c @@ -9,6 +9,8 @@ #include "config.h" +#include + #include #include #include @@ -13662,13 +13664,16 @@ mono_llvm_nonnull_state_update (EmitContext *ctx, LLVMValueRef lcall, MonoMethod g_assert (num_params <= num_passed); g_assert (ctx->module->method_to_call_info); - GArray *call_site_union = (GArray *) g_hash_table_lookup (ctx->module->method_to_call_info, call_method); + dn_vector_t *call_site_union = (dn_vector_t *) g_hash_table_lookup (ctx->module->method_to_call_info, call_method); if (!call_site_union) { - call_site_union = g_array_sized_new (FALSE, TRUE, sizeof (gint32), num_params); + dn_vector_custom_alloc_params_t alloc_params = {0,}; + alloc_params.capacity = num_params; + call_site_union = dn_vector_custom_alloc_t (&alloc_params, int32_t); + dn_checkfail(call_site_union, "Allocation failed"); int zero = 0; for (guint i = 0; i < num_params; i++) - g_array_insert_val (call_site_union, i, zero); + dn_vector_push_back (call_site_union, zero); } for (guint i = 0; i < num_params; i++) { @@ -13676,7 +13681,7 @@ mono_llvm_nonnull_state_update (EmitContext *ctx, LLVMValueRef lcall, MonoMethod g_assert (i < LLVMGetNumArgOperands (lcall)); mono_llvm_set_call_nonnull_arg (lcall, i); } else { - gint32 *nullable_count = &g_array_index (call_site_union, gint32, i); + gint32 *nullable_count = dn_vector_index_t (call_site_union, int32_t, i); *nullable_count = *nullable_count + 1; } } @@ -13702,15 +13707,15 @@ mono_llvm_propagate_nonnull_final (GHashTable *all_specializable, MonoLLVMModule MonoMethod *method; g_hash_table_iter_init (&iter, all_specializable); while (g_hash_table_iter_next (&iter, (void**)&lmethod, (void**)&method)) { - GArray *call_site_union = (GArray *) g_hash_table_lookup (module->method_to_call_info, method); + dn_vector_t *call_site_union = (dn_vector_t *) g_hash_table_lookup (module->method_to_call_info, method); // Basic sanity checking if (call_site_union) - g_assert (call_site_union->len == LLVMCountParams (lmethod)); + g_assert (dn_vector_size (call_site_union) == LLVMCountParams (lmethod)); // Add root to work queue - for (int i = 0; call_site_union && i < call_site_union->len; i++) { - if (g_array_index (call_site_union, gint32, i) == 0) { + for (int i = 0; call_site_union && i < dn_vector_size (call_site_union); i++) { + if (*dn_vector_index_t (call_site_union, int32_t, i) == 0) { NonnullPropWorkItem *item = g_malloc (sizeof (NonnullPropWorkItem)); item->lmethod = lmethod; item->argument = i; @@ -13762,7 +13767,7 @@ mono_llvm_propagate_nonnull_final (GHashTable *all_specializable, MonoLLVMModule continue; // Decrement number of nullable refs at that func's arg offset - GArray *call_site_union = (GArray *) g_hash_table_lookup (module->method_to_call_info, callee_method); + dn_vector_t *call_site_union = (dn_vector_t *) g_hash_table_lookup (module->method_to_call_info, callee_method); // It has module-local callers and is specializable, should have seen this call site // and inited this @@ -13770,7 +13775,7 @@ mono_llvm_propagate_nonnull_final (GHashTable *all_specializable, MonoLLVMModule // The function *definition* parameter arity should always be consistent int max_params = LLVMCountParams (callee_lmethod); - if (call_site_union->len != max_params) { + if (dn_vector_size (call_site_union) != max_params) { mono_llvm_dump_value (callee_lmethod); g_assert_not_reached (); } @@ -13782,7 +13787,7 @@ mono_llvm_propagate_nonnull_final (GHashTable *all_specializable, MonoLLVMModule // Every time we used the newly-non-nullable argument, decrement the nullable // refcount for that function. if (caller_argument == operands [call_argument]) { - gint32 *nullable_count = &g_array_index (call_site_union, gint32, call_argument); + gint32 *nullable_count = dn_vector_index_t (call_site_union, int32_t, call_argument); g_assert (*nullable_count > 0); *nullable_count = *nullable_count - 1;