Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mono] Use dn_vector_t instead of GArray in a few places #84027

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5f0bb98
Use dn_vector_t instead of GArray in one place in Mono
lambdageek Mar 28, 2023
a991249
include shared containers in mono shared lib, too
lambdageek Mar 28, 2023
87f5d50
convert mono_seq_point_init_next to use dn_vector_t
lambdageek Mar 28, 2023
e8c7dea
[custom-attrs] Use init/dispose instead of alloc/free for dn_vector_t
lambdageek Mar 28, 2023
2c5c00a
move container logic to toplevel; add deps to runtime components
lambdageek Mar 28, 2023
301c2a4
fix windows build
lambdageek Mar 28, 2023
ec1bf21
fix Darwin frameworks builds
lambdageek Mar 28, 2023
473df84
replace 2 uses of GArray in interp/transform.c
lambdageek Mar 28, 2023
5e4b453
replace a use of GArray in mini/seq-points.c
lambdageek Mar 28, 2023
6029c33
replace use of GArray for debug-mini
lambdageek Mar 28, 2023
0082829
WIP: start a dn_checkfail helper like g_assertf
lambdageek Apr 4, 2023
1cf3d19
remove some unused assignments from eventpipe.cmake fragment
lambdageek Apr 5, 2023
e5d2108
make containers a normal sub-project for Mono
lambdageek Apr 5, 2023
adcb5a6
Add mono implementation of dn-rt.h
lambdageek Apr 5, 2023
0eb1fd5
check dn_vector_alloc_t result
lambdageek Apr 5, 2023
15d11fd
fix coreclr build
lambdageek Apr 5, 2023
71fb5c2
add placeholder dn_rt functions for coreclr and nativeaot
lambdageek Apr 6, 2023
fa05fbf
fix mono build
lambdageek Apr 6, 2023
695575f
maybe fix coreclr/nativeaot windows build?
lambdageek Apr 6, 2023
c4a28a5
move nativeaot shims to a separate file
lambdageek Apr 6, 2023
e0526c1
fix coreclr windows?
lambdageek Apr 6, 2023
7fc5ecc
add typed dn_vector_ptr accessor macros
lambdageek Apr 6, 2023
e93efdc
Use dn_vector_ptr in a few places instead of dn_vector
lambdageek Apr 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,23 @@ 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}
${AOT_EVENTPIPE_MANAGED_TO_NATIVE_SOURCES}
${SHARED_EVENTPIPE_CONFIG_HEADERS}
${CONTAINER_SOURCES}
${CONTAINER_HEADERS}
${CONTAINER_SHIM_HEADERS}
${CONTAINER_SHIM_SOURCES}
)

list(APPEND AOT_EVENTPIPE_DISABLED_SOURCES
Expand Down
27 changes: 27 additions & 0 deletions src/coreclr/nativeaot/Runtime/eventpipe/dn-rt-aot.cpp
Original file line number Diff line number Diff line change
@@ -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();
}

25 changes: 25 additions & 0 deletions src/coreclr/nativeaot/Runtime/eventpipe/dn-rt-aot.h
Original file line number Diff line number Diff line change
@@ -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__ */
2 changes: 2 additions & 0 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ project(mono)

set(subdirs
eglib
containers
utils
sgen
metadata
Expand Down
14 changes: 12 additions & 2 deletions src/mono/mono/component/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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()
Expand All @@ -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 $<TARGET_OBJECTS:${component}-objects>)
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")
Expand Down
26 changes: 26 additions & 0 deletions src/mono/mono/containers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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_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}/../..)

27 changes: 27 additions & 0 deletions src/mono/mono/containers/dn-rt-mono.h
Original file line number Diff line number Diff line change
@@ -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-rt.h>

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__ */
19 changes: 19 additions & 0 deletions src/mono/mono/containers/dn-rt-utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the naming of this file follow the naming of the header, dn-rt-mono.c?

// The .NET Foundation licenses this file to you under the MIT license.

#include <config.h>
#include <glib.h>
#include <dn-rt-mono.h>

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);
}
11 changes: 0 additions & 11 deletions src/mono/mono/eventpipe/eventpipe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}/../..
Expand Down
20 changes: 12 additions & 8 deletions src/mono/mono/metadata/custom-attrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
#include <config.h>
#include <dn-vector.h>
#include "mono/metadata/assembly.h"
#include "mono/metadata/class-init.h"
#include "mono/metadata/class-internals.h"
Expand Down Expand Up @@ -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.
Expand All @@ -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;

Expand All @@ -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)) {
Expand All @@ -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:
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
14 changes: 9 additions & 5 deletions src/mono/mono/metadata/seq-points-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include "seq-points-data.h"
#include <dn-vector.h>

typedef struct {
guint8 *data;
Expand Down Expand Up @@ -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,};
Copy link
Member

Choose a reason for hiding this comment

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

No need to init the dn_vector_t, it will be memset by dn_vector_init_t.


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
Expand Down
Loading