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/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 7b57776aa007c7..a9efed905158cd 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -929,6 +929,8 @@ if(NOT DISABLE_LIBS) endif() add_subdirectory("${CLR_SRC_NATIVE_DIR}/public" public_apis) +### 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 c59470996f5825..15321254966934 100644 --- a/src/mono/mono/CMakeLists.txt +++ b/src/mono/mono/CMakeLists.txt @@ -2,6 +2,7 @@ project(mono) set(subdirs eglib + containers utils sgen metadata diff --git a/src/mono/mono/component/CMakeLists.txt b/src/mono/mono/component/CMakeLists.txt index 8a8964efc087e5..ceb47adaadb019 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") @@ -42,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} @@ -55,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} @@ -68,7 +73,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 +90,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} @@ -99,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) @@ -154,14 +165,17 @@ 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() foreach(dependency IN LISTS "${component}-dependencies") add_dependencies("${component}-objects" "${dependency}") endforeach() 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) @@ -170,9 +184,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/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/component/hot_reload.c b/src/mono/mono/component/hot_reload.c index 120d227d7ccace..5f64a3915f699e 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" @@ -313,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; }; @@ -450,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); @@ -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; } @@ -1863,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, ctx->skeletons->data, ctx->skeletons->len); + 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.", 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), dn_vector_size (base_info->skeletons)); return TRUE; } @@ -1879,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); @@ -1906,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); @@ -1929,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); @@ -1981,7 +1986,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 +2001,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); diff --git a/src/mono/mono/containers/CMakeLists.txt b/src/mono/mono/containers/CMakeLists.txt new file mode 100644 index 00000000000000..4815076f555279 --- /dev/null +++ b/src/mono/mono/containers/CMakeLists.txt @@ -0,0 +1,36 @@ +project(containers C) + +### 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_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 + ${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 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 + ${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..df1bc8dc51d0a1 --- /dev/null +++ b/src/mono/mono/containers/dn-rt-utils.c @@ -0,0 +1,19 @@ +// 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); + g_assert_not_reached (); +} + +void +dn_rt_mono_failfast_nomsg (const char *file, int line) +{ + mono_assertion_message_disabled (file, line); +} 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 e438c00298ec72..d0d31b4c079361 100644 --- a/src/mono/mono/eglib/glib.h +++ b/src/mono/mono/eglib/glib.h @@ -104,6 +104,17 @@ 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 // Provide for bit operations on enums, but not all integer operations. @@ -663,7 +674,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); 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 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 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 "") diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index abddf1a58a5d92..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}/..) @@ -203,7 +203,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..78ea4948e86617 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 = {0,}; const char *data; MonoCustomAttrEntry* attr; @@ -1904,7 +1906,9 @@ 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; + 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)) { @@ -1916,19 +1920,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_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, 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 +1953,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_dispose (&attr_array); g_free (ainfo); return NULL; } @@ -1959,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; } - g_array_free (attr_array, TRUE); + dn_vector_dispose (&attr_array); return ainfo; } diff --git a/src/mono/mono/metadata/debug-mono-ppdb.c b/src/mono/mono/metadata/debug-mono-ppdb.c index 9c675af4dc7c8f..15df0b5dfc8649 100644 --- a/src/mono/mono/metadata/debug-mono-ppdb.c +++ b/src/mono/mono/metadata/debug-mono-ppdb.c @@ -16,6 +16,10 @@ #include #include #include + +#include +#include + #include #include #include @@ -62,7 +66,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 +97,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) { @@ -488,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; @@ -530,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 */ @@ -590,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; } 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 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/metadata/seq-points-data.c b/src/mono/mono/metadata/seq-points-data.c index b5e50eea056852..11a91fecb86c3d 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; @@ -169,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; @@ -192,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); } } @@ -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 < GUINT_TO_INT (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 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/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 8419317adc58c3..77d8669230924f 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}/..) @@ -353,8 +353,8 @@ 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) -add_library(monosgen-static STATIC $ $ $ $ $) +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}) if(DISABLE_COMPONENTS OR AOT_COMPONENTS) @@ -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, @@ -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) @@ -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/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, diff --git a/src/mono/mono/mini/debug-mini.c b/src/mono/mono/mini/debug-mini.c index f307d08bf7f511..77008c70d14db4 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,8 @@ 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); + dn_checkfail (info->line_numbers != NULL, "Allocation failed"); jit->num_locals = header->num_locals; jit->locals = g_new0 (MonoDebugVarInfo, jit->num_locals); } @@ -269,11 +271,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 +293,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; } diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 895b5cc6bda071..1849dd1a4eecf5 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -9,6 +9,8 @@ #include "config.h" #include +#include +#include #include #include #include @@ -3879,7 +3881,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 +3901,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 +3914,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 +3941,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_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 @@ -3950,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) { - predecessors = g_array_append_val (predecessors, in_bb->last_seq_point); + dn_vector_ptr_push_back (&predecessors, in_bb->last_seq_point); continue; } @@ -3970,8 +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])) { - 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_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); @@ -3979,16 +3981,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_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] = (SeqPoint*)g_array_index (predecessors, gpointer, newer); + bb->pred_seq_points [newer] = *dn_vector_ptr_index_t (&predecessors, SeqPoint*, newer); } } - g_array_free (predecessors, TRUE); + dn_vector_ptr_dispose (&predecessors); } static void @@ -4007,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; @@ -4052,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; } @@ -4082,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; } @@ -8181,7 +8184,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 +10818,8 @@ 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); + dn_checkfail (td->line_numbers != NULL, "Allocation failed"); td->current_il_offset = -1; generate_code (td, method, header, generic_context, error); @@ -10951,7 +10955,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; 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)) 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; diff --git a/src/mono/mono/mini/seq-points.c b/src/mono/mono/mini/seq-points.c index b998c6c86d97b6..7a75df00833f1e 100644 --- a/src/mono/mono/mini/seq-points.c +++ b/src/mono/mono/mini/seq-points.c @@ -9,6 +9,9 @@ * Licensed under the MIT license. See LICENSE file in the project root for full license information. */ +#include +#include +#include #include "mini.h" #include "mini-runtime.h" #include "seq-points.h" @@ -33,7 +36,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_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 @@ -44,7 +49,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_ptr_push_back (&predecessors, in_bb->last_seq_point); continue; } @@ -64,7 +69,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_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); } } @@ -73,16 +78,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_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] = g_array_index(predecessors, MonoInst*, newer); + bb->pred_seq_points [newer] = *dn_vector_ptr_index_t (&predecessors, MonoInst*, newer); } } - g_array_free (predecessors, TRUE); + dn_vector_ptr_dispose (&predecessors); } static void @@ -107,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) @@ -201,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}; @@ -214,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) @@ -227,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) { diff --git a/src/mono/mono/profiler/CMakeLists.txt b/src/mono/mono/profiler/CMakeLists.txt index 6bca00983686fc..9477c316cad6d5 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,14 +32,14 @@ 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() 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/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); 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}/../.. 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" ] 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/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); } } diff --git a/src/mono/mono/utils/mono-threads-coop.c b/src/mono/mono/utils/mono-threads-coop.c index 4ed659d66058cc..294af45f2dc215 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); } @@ -188,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. 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..a5f276ca67728b --- /dev/null +++ b/src/native/containers/dn-rt.h @@ -0,0 +1,41 @@ +// 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-compiler.h" + +DN_NORETURN static void +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(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) +{ + 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 +#else +// Mono +#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 7c07f5f8df7ecb..110773d5b2452b 100644 --- a/src/native/containers/dn-utils.h +++ b/src/native/containers/dn-utils.h @@ -15,6 +15,8 @@ #include #include +#include "dn-rt.h" + #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__ */ 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__ */