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

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions mono/metadata/class-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,17 +755,17 @@ typedef struct {

typedef struct {
guint64 new_object_count;
size_t initialized_class_count;
size_t generic_vtable_count;
gsize initialized_class_count;
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason to prefer glib types to standard C types in internal headers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just working with the code since June and most things I do are based on observation. Personally, I do not not have any preferences (yet). However, I understand that the glib types are preferred wherever possible. (I might be wrong there!)

My thought was that atomic.h uses gint* so it might be nice to use all g* types in racing.h to keep some kind of consistency. And, since racing.h works with gsize AND mono_stats has this guint64 value anyways, I thought that (again talking about consistency) it would be nice to have those affected fields defined as gsize in mono_stats as well.

gsize generic_vtable_count;
size_t used_class_count;
size_t method_count;
size_t class_vtable_size;
size_t class_static_data_size;
size_t generic_instance_count;
size_t generic_class_count;
size_t inflated_method_count;
gsize generic_class_count;
gsize inflated_method_count;
size_t inflated_method_count_2;
size_t inflated_type_count;
gsize inflated_type_count;
size_t generics_metadata_size;
size_t delegate_creations;
size_t imt_tables_size;
Expand Down
15 changes: 8 additions & 7 deletions mono/metadata/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <mono/utils/mono-logger-internals.h>
#include <mono/utils/mono-memory-model.h>
#include <mono/utils/atomic.h>
#include <mono/utils/unlocked.h>
#include <mono/utils/bsearch.h>
#include <mono/utils/checked-build.h>

Expand Down Expand Up @@ -864,7 +865,7 @@ mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type,
}
}

mono_stats.inflated_type_count++;
UnlockedIncrementSize (&mono_stats.inflated_type_count);
return inflated;
}

Expand Down Expand Up @@ -928,7 +929,7 @@ mono_class_inflate_generic_type_no_copy (MonoImage *image, MonoType *type, MonoG
if (!inflated)
return type;

mono_stats.inflated_type_count++;
UnlockedIncrementSize (&mono_stats.inflated_type_count);
return inflated;
}

Expand Down Expand Up @@ -1089,7 +1090,7 @@ mono_class_inflate_generic_method_full_checked (MonoMethod *method, MonoClass *k
return (MonoMethod*)cached;
}

mono_stats.inflated_method_count++;
UnlockedIncrementSize (&mono_stats.inflated_method_count);

inflated_methods_size += sizeof (MonoMethodInflated);

Expand Down Expand Up @@ -3568,7 +3569,7 @@ mono_class_setup_vtable_full (MonoClass *klass, GList *in_setup)
return;
}

mono_stats.generic_vtable_count ++;
UnlockedIncrementSize (&mono_stats.generic_vtable_count);
in_setup = g_list_prepend (in_setup, klass);

if (mono_class_is_ginst (klass)) {
Expand Down Expand Up @@ -4902,7 +4903,7 @@ mono_class_init (MonoClass *klass)
goto leave;
}

mono_stats.initialized_class_count++;
UnlockedIncrementSize (&mono_stats.initialized_class_count);

if (mono_class_is_ginst (klass) && !mono_class_get_generic_class (klass)->is_dynamic) {
MonoClass *gklass = mono_class_get_generic_class (klass)->container_class;
Expand Down Expand Up @@ -5047,10 +5048,10 @@ mono_class_init (MonoClass *klass)
return !mono_class_has_failure (klass);
}

mono_stats.initialized_class_count++;
UnlockedIncrementSize (&mono_stats.initialized_class_count);

if (mono_class_is_ginst (klass) && !mono_class_get_generic_class (klass)->is_dynamic)
mono_stats.generic_class_count++;
UnlockedIncrementSize (&mono_stats.generic_class_count);

if (mono_class_is_ginst (klass) || image_is_dynamic (klass->image) || !klass->type_token || (has_cached_info && !cached_info.has_nested_classes))
klass->nested_classes_inited = TRUE;
Expand Down
3 changes: 2 additions & 1 deletion mono/utils/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ monoutils_sources = \
checked-build.h \
os-event.h \
refcount.h \
w32api.h
w32api.h \
unlocked.h

arch_sources =

Expand Down
12 changes: 9 additions & 3 deletions mono/utils/mono-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,19 @@ typedef SSIZE_T ssize_t;
#define MONO_GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif

/* Used to tell clang's ThreadSanitizer to not report data races that occur within a certain function */
#if defined(__has_feature)
#if __has_feature(thread_sanitizer)
#define MONO_NO_SANITIZE_THREAD __attribute__ ((no_sanitize("thread")))
#define MONO_HAS_CLANG_THREAD_SANITIZER 1
#else
#define MONO_NO_SANITIZE_THREAD
#define MONO_HAS_CLANG_THREAD_SANITIZER 0
#endif
#else
#define MONO_HAS_CLANG_THREAD_SANITIZER 0
#endif

/* Used to tell Clang's ThreadSanitizer to not report data races that occur within a certain function */
#if MONO_HAS_CLANG_THREAD_SANITIZER
#define MONO_NO_SANITIZE_THREAD __attribute__ ((no_sanitize("thread")))
#else
#define MONO_NO_SANITIZE_THREAD
#endif
Expand Down
42 changes: 42 additions & 0 deletions mono/utils/unlocked.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* \file
* Contains inline functions to explicitly mark data races that should not be changed.
* This way, instruments like Clang's ThreadSanitizer can be told to ignore very specific instructions.
*
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/

#ifndef _UNLOCKED_H_
#define _UNLOCKED_H_

#include <glib.h>
#include <mono/utils/mono-compiler.h>

#if MONO_HAS_CLANG_THREAD_SANITIZER
#define MONO_UNLOCKED_ATTRS MONO_NO_SANITIZE_THREAD MONO_NEVER_INLINE static
#else
#define MONO_UNLOCKED_ATTRS MONO_ALWAYS_INLINE static inline
#endif

MONO_UNLOCKED_ATTRS
gint32
UnlockedIncrement (gint32 *val)
{
return ++*val;
}

MONO_UNLOCKED_ATTRS
gint64
UnlockedIncrement64 (gint64 *val)
{
return ++*val;
}

MONO_UNLOCKED_ATTRS
gsize
UnlockedIncrementSize (gsize *val)
{
return ++*val;
}

#endif /* _UNLOCKED_H_ */
1 change: 1 addition & 0 deletions msvc/libmonoutils.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<ClInclude Include="..\mono\utils\strenc.h" />
<ClInclude Include="..\mono\utils\valgrind.h" />
<ClInclude Include="..\mono\utils\atomic.h" />
<ClInclude Include="..\mono\utils\unlocked.h" />
<ClInclude Include="..\mono\utils\mono-hwcap.h" />
<ClInclude Include="..\mono\utils\mono-hwcap-x86.h" />
<ClInclude Include="..\mono\utils\bsearch.h" />
Expand Down
3 changes: 3 additions & 0 deletions msvc/libmonoutils.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@
<ClInclude Include="..\mono\utils\os-event.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\mono\utils\unlocked.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">
Expand Down