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
4 changes: 2 additions & 2 deletions mono/metadata/boehm-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ on_gc_notification (GC_EventType event)
if (mono_perfcounters)
mono_perfcounters->gc_collections0++;
#endif
gc_stats.major_gc_count ++;
InterlockedIncrement (&gc_stats.major_gc_count);
gc_start_time = mono_100ns_ticks ();
break;

Expand All @@ -482,7 +482,7 @@ on_gc_notification (GC_EventType event)
mono_perfcounters->gc_gen0size = heap_size;
}
#endif
gc_stats.major_gc_time += mono_100ns_ticks () - gc_start_time;
InterlockedAdd64 (&gc_stats.major_gc_time, mono_100ns_ticks () - gc_start_time);
mono_trace_message (MONO_TRACE_GC, "gc took %" G_GINT64_FORMAT " usecs", (mono_100ns_ticks () - gc_start_time) / 10);
break;
default:
Expand Down
58 changes: 25 additions & 33 deletions mono/metadata/class-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,39 +756,31 @@ typedef struct {
#define MONO_SIZEOF_REMOTE_CLASS (sizeof (MonoRemoteClass) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)

typedef struct {
guint64 new_object_count;
gsize initialized_class_count;
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;
gsize generic_class_count;
gsize inflated_method_count;
size_t inflated_method_count_2;
gsize inflated_type_count;
size_t generics_metadata_size;
size_t delegate_creations;
size_t imt_tables_size;
size_t imt_number_of_tables;
size_t imt_number_of_methods;
size_t imt_used_slots;
size_t imt_slots_with_collisions;
size_t imt_max_collisions_in_slot;
size_t imt_method_count_when_max_collisions;
size_t imt_trampolines_size;
size_t jit_info_table_insert_count;
size_t jit_info_table_remove_count;
size_t jit_info_table_lookup_count;
size_t generics_sharable_methods;
size_t generics_unsharable_methods;
size_t generics_shared_methods;
size_t gsharedvt_methods;
size_t minor_gc_count;
size_t major_gc_count;
size_t minor_gc_time_usecs;
size_t major_gc_time_usecs;
gint32 initialized_class_count;
gint32 generic_vtable_count;
gint32 used_class_count;
gint32 method_count;
gint32 class_vtable_size;
gint32 class_static_data_size;
gint32 generic_class_count;
gint32 inflated_method_count;
gint32 inflated_type_count;
gint32 delegate_creations;
gint32 imt_tables_size;
gint32 imt_number_of_tables;
gint32 imt_number_of_methods;
gint32 imt_used_slots;
gint32 imt_slots_with_collisions;
gint32 imt_max_collisions_in_slot;
gint32 imt_method_count_when_max_collisions;
gint32 imt_trampolines_size;
gint32 jit_info_table_insert_count;
gint32 jit_info_table_remove_count;
gint32 jit_info_table_lookup_count;
gint32 generics_sharable_methods;
gint32 generics_unsharable_methods;
gint32 generics_shared_methods;
gint32 gsharedvt_methods;
gboolean enabled;
} MonoStats;

Expand Down
14 changes: 7 additions & 7 deletions mono/metadata/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type,
}
}

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

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

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

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

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

inflated_methods_size += sizeof (MonoMethodInflated);

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

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

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

UnlockedIncrementSize (&mono_stats.initialized_class_count);
UnlockedIncrement (&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 @@ -5048,10 +5048,10 @@ mono_class_init (MonoClass *klass)
return !mono_class_has_failure (klass);
}

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

if (mono_class_is_ginst (klass) && !mono_class_get_generic_class (klass)->is_dynamic)
UnlockedIncrementSize (&mono_stats.generic_class_count);
UnlockedIncrement (&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
8 changes: 4 additions & 4 deletions mono/metadata/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,11 +933,11 @@ mono_gc_init (void)
mono_coop_mutex_init_recursive (&finalizer_mutex);
mono_coop_mutex_init_recursive (&reference_queue_mutex);

mono_counters_register ("Minor GC collections", MONO_COUNTER_GC | MONO_COUNTER_UINT, &gc_stats.minor_gc_count);
mono_counters_register ("Major GC collections", MONO_COUNTER_GC | MONO_COUNTER_UINT, &gc_stats.major_gc_count);
mono_counters_register ("Minor GC collections", MONO_COUNTER_GC | MONO_COUNTER_INT, &gc_stats.minor_gc_count);
mono_counters_register ("Major GC collections", MONO_COUNTER_GC | MONO_COUNTER_INT, &gc_stats.major_gc_count);
mono_counters_register ("Minor GC time", MONO_COUNTER_GC | MONO_COUNTER_ULONG | MONO_COUNTER_TIME, &gc_stats.minor_gc_time);
mono_counters_register ("Major GC time", MONO_COUNTER_GC | MONO_COUNTER_ULONG | MONO_COUNTER_TIME, &gc_stats.major_gc_time);
mono_counters_register ("Major GC time concurrent", MONO_COUNTER_GC | MONO_COUNTER_ULONG | MONO_COUNTER_TIME, &gc_stats.major_gc_time_concurrent);
mono_counters_register ("Major GC time", MONO_COUNTER_GC | MONO_COUNTER_LONG | MONO_COUNTER_TIME, &gc_stats.major_gc_time);
mono_counters_register ("Major GC time concurrent", MONO_COUNTER_GC | MONO_COUNTER_LONG | MONO_COUNTER_TIME, &gc_stats.major_gc_time_concurrent);

mono_gc_base_init ();

Expand Down
7 changes: 4 additions & 3 deletions mono/metadata/jit-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <mono/utils/mono-tls.h>
#include <mono/utils/mono-mmap.h>
#include <mono/utils/mono-threads.h>
#include <mono/utils/unlocked.h>
#include <mono/metadata/object.h>
#include <mono/metadata/object-internals.h>
#include <mono/metadata/domain-internals.h>
Expand Down Expand Up @@ -263,7 +264,7 @@ mono_jit_info_table_find_internal (MonoDomain *domain, char *addr, gboolean try_
MonoJitInfo *ji, *module_ji;
MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();

++mono_stats.jit_info_table_lookup_count;
UnlockedIncrement (&mono_stats.jit_info_table_lookup_count);

/* First we have to get the domain's jit_info_table. This is
complicated by the fact that a writer might substitute a
Expand Down Expand Up @@ -654,7 +655,7 @@ mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji)

mono_domain_lock (domain);

++mono_stats.jit_info_table_insert_count;
UnlockedIncrement (&mono_stats.jit_info_table_insert_count);

jit_info_table_add (domain, &domain->jit_info_table, ji);

Expand Down Expand Up @@ -738,7 +739,7 @@ mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji)
mono_domain_lock (domain);
table = domain->jit_info_table;

++mono_stats.jit_info_table_remove_count;
UnlockedIncrement (&mono_stats.jit_info_table_remove_count);

jit_info_table_remove (table, ji);

Expand Down
2 changes: 1 addition & 1 deletion mono/metadata/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ mono_get_method_from_token (MonoImage *image, guint32 token, MonoClass *klass,
methods_size += sizeof (MonoMethod);
}

mono_stats.method_count ++;
InterlockedIncrement (&mono_stats.method_count);

result->slot = -1;
result->klass = klass;
Expand Down
31 changes: 16 additions & 15 deletions mono/metadata/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <mono/utils/mono-threads-coop.h>
#include "cominterop.h"
#include <mono/utils/w32api.h>
#include <mono/utils/unlocked.h>

static void
get_default_field_value (MonoDomain* domain, MonoClassField *field, void *value, MonoError *error);
Expand Down Expand Up @@ -1217,12 +1218,12 @@ add_imt_builder_entry (MonoImtBuilderEntry **imt_builder, MonoMethod *method, gu
if (imt_builder [imt_slot] != NULL) {
entry->children = imt_builder [imt_slot]->children + 1;
if (entry->children == 1) {
mono_stats.imt_slots_with_collisions++;
UnlockedIncrement (&mono_stats.imt_slots_with_collisions);
*imt_collisions_bitmap |= (1 << imt_slot);
}
} else {
entry->children = 0;
mono_stats.imt_used_slots++;
UnlockedIncrement (&mono_stats.imt_used_slots);
}
imt_builder [imt_slot] = entry;
#if DEBUG_IMT
Expand Down Expand Up @@ -1477,17 +1478,17 @@ build_imt_slots (MonoClass *klass, MonoVTable *vt, MonoDomain *domain, gpointer*

if (imt_builder [i] != NULL) {
int methods_in_slot = imt_builder [i]->children + 1;
if (methods_in_slot > mono_stats.imt_max_collisions_in_slot) {
mono_stats.imt_max_collisions_in_slot = methods_in_slot;
if (methods_in_slot > UnlockedRead (&mono_stats.imt_max_collisions_in_slot)) {
UnlockedWrite (&mono_stats.imt_max_collisions_in_slot, methods_in_slot);
record_method_count_for_max_collisions = TRUE;
}
method_count += methods_in_slot;
}
}

mono_stats.imt_number_of_methods += method_count;
UnlockedAdd (&mono_stats.imt_number_of_methods, method_count);
if (record_method_count_for_max_collisions) {
mono_stats.imt_method_count_when_max_collisions = method_count;
UnlockedWrite (&mono_stats.imt_method_count_when_max_collisions, method_count);
}

for (i = 0; i < MONO_IMT_SIZE; i++) {
Expand Down Expand Up @@ -1900,16 +1901,16 @@ mono_class_create_runtime_vtable (MonoDomain *domain, MonoClass *klass, MonoErro

if (klass->interface_offsets_count) {
imt_table_bytes = sizeof (gpointer) * (MONO_IMT_SIZE);
mono_stats.imt_number_of_tables++;
mono_stats.imt_tables_size += imt_table_bytes;
UnlockedIncrement (&mono_stats.imt_number_of_tables);
UnlockedAdd (&mono_stats.imt_tables_size, imt_table_bytes);
} else {
imt_table_bytes = 0;
}

vtable_size = imt_table_bytes + MONO_SIZEOF_VTABLE + vtable_slots * sizeof (gpointer);

mono_stats.used_class_count++;
mono_stats.class_vtable_size += vtable_size;
UnlockedIncrement (&mono_stats.used_class_count);
UnlockedAdd (&mono_stats.class_vtable_size, vtable_size);

interface_offsets = alloc_vtable (domain, vtable_size, imt_table_bytes);
vt = (MonoVTable*) ((char*)interface_offsets + imt_table_bytes);
Expand Down Expand Up @@ -1961,7 +1962,7 @@ mono_class_create_runtime_vtable (MonoDomain *domain, MonoClass *klass, MonoErro
vt->vtable [klass->vtable_size] = mono_domain_alloc0 (domain, class_size);
}
vt->has_static_fields = TRUE;
mono_stats.class_static_data_size += class_size;
UnlockedAdd (&mono_stats.class_static_data_size, class_size);
}

iter = NULL;
Expand Down Expand Up @@ -2248,12 +2249,12 @@ mono_class_proxy_vtable (MonoDomain *domain, MonoRemoteClass *remote_class, Mono
}

imt_table_bytes = sizeof (gpointer) * MONO_IMT_SIZE;
mono_stats.imt_number_of_tables++;
mono_stats.imt_tables_size += imt_table_bytes;
UnlockedIncrement (&mono_stats.imt_number_of_tables);
UnlockedAdd (&mono_stats.imt_tables_size, imt_table_bytes);

vtsize = imt_table_bytes + MONO_SIZEOF_VTABLE + klass->vtable_size * sizeof (gpointer);

mono_stats.class_vtable_size += vtsize + extra_interface_vtsize;
UnlockedAdd (&mono_stats.class_vtable_size, vtsize + extra_interface_vtsize);

interface_offsets = alloc_vtable (domain, vtsize + extra_interface_vtsize, imt_table_bytes);
pvt = (MonoVTable*) ((char*)interface_offsets + imt_table_bytes);
Expand Down Expand Up @@ -7866,7 +7867,7 @@ mono_delegate_ctor_with_method (MonoObjectHandle this_obj, MonoObjectHandle targ
if (method)
MONO_HANDLE_SETVAL (delegate, method, MonoMethod*, method);

mono_stats.delegate_creations++;
UnlockedIncrement (&mono_stats.delegate_creations);

#ifndef DISABLE_REMOTING
if (!MONO_HANDLE_IS_NULL (target) && mono_class_is_transparent_proxy (mono_handle_class (target))) {
Expand Down
17 changes: 9 additions & 8 deletions mono/metadata/sgen-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -2799,18 +2799,19 @@ mono_gc_add_memory_pressure (gint64 value)
*/

void
sgen_client_degraded_allocation (size_t size)
sgen_client_degraded_allocation (void)
Copy link
Member

Choose a reason for hiding this comment

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

@BrzVlad is the size arg of sgen_client_degraded_allocation not useful?

Copy link
Contributor

Choose a reason for hiding this comment

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

Anything starting with sgen_client_ is part of the SGen API, so this is a breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

@alexrp I don't think these are meant to be an official API and they were changed in the past. Are there other runtimes out there that actually use sgen in the first place ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess @schani would know. He did the whole SGen separation effort for a use case I can't remember.

Copy link
Contributor

Choose a reason for hiding this comment

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

Changing this is fine.

{
static int last_major_gc_warned = -1;
static int num_degraded = 0;
static gint32 last_major_gc_warned = -1;
static gint32 num_degraded = 0;

if (last_major_gc_warned < (int)gc_stats.major_gc_count) {
++num_degraded;
if (num_degraded == 1 || num_degraded == 3)
gint32 major_gc_count = InterlockedRead (&gc_stats.major_gc_count);
if (InterlockedRead (&last_major_gc_warned) < major_gc_count) {
gint32 num = InterlockedIncrement (&num_degraded);
if (num == 1 || num == 3)
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_GC, "Warning: Degraded allocation. Consider increasing nursery-size if the warning persists.");
else if (num_degraded == 10)
else if (num == 10)
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_GC, "Warning: Repeated degraded allocation. Consider increasing nursery-size.");
last_major_gc_warned = gc_stats.major_gc_count;
InterlockedWrite (&last_major_gc_warned, major_gc_count);
}
}

Expand Down
4 changes: 2 additions & 2 deletions mono/mini/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ mono_jit_parse_options (int argc, char * argv[])
opt->break_on_exc = TRUE;
} else if (strcmp (argv [i], "--stats") == 0) {
mono_counters_enable (-1);
mono_stats.enabled = TRUE;
InterlockedWriteBool (&mono_stats.enabled, TRUE);
mono_jit_stats.enabled = TRUE;
} else if (strcmp (argv [i], "--break") == 0) {
if (i+1 >= argc){
Expand Down Expand Up @@ -1767,7 +1767,7 @@ mono_main (int argc, char* argv[])
mono_print_vtable = TRUE;
} else if (strcmp (argv [i], "--stats") == 0) {
mono_counters_enable (-1);
mono_stats.enabled = TRUE;
InterlockedWriteBool (&mono_stats.enabled, TRUE);
mono_jit_stats.enabled = TRUE;
#ifndef DISABLE_AOT
} else if (strcmp (argv [i], "--aot") == 0) {
Expand Down
3 changes: 2 additions & 1 deletion mono/mini/mini-amd64.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <mono/utils/mono-tls.h>
#include <mono/utils/mono-hwcap.h>
#include <mono/utils/mono-threads.h>
#include <mono/utils/unlocked.h>

#include "trace.h"
#include "ir-emit.h"
Expand Down Expand Up @@ -8011,7 +8012,7 @@ mono_arch_build_imt_trampoline (MonoVTable *vtable, MonoDomain *domain, MonoIMTC
}

if (!fail_tramp)
mono_stats.imt_trampolines_size += code - start;
UnlockedAdd (&mono_stats.imt_trampolines_size, code - start);
g_assert (code - start <= size);
g_assert_checked (mono_arch_unwindinfo_validate_size (unwind_ops, MONO_TRAMPOLINE_UNWINDINFO_SIZE(0)));

Expand Down
3 changes: 2 additions & 1 deletion mono/mini/mini-arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <mono/utils/mono-hwcap.h>
#include <mono/utils/mono-memory-model.h>
#include <mono/utils/mono-threads-coop.h>
#include <mono/utils/unlocked.h>

#include "mini-arm.h"
#include "cpu-arm.h"
Expand Down Expand Up @@ -7046,7 +7047,7 @@ mono_arch_build_imt_trampoline (MonoVTable *vtable, MonoDomain *domain, MonoIMTC

mono_arch_flush_icache ((guint8*)start, size);
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE, NULL));
mono_stats.imt_trampolines_size += code - start;
UnlockedAdd (&mono_stats.imt_trampolines_size, code - start);

g_assert (DISTANCE (start, code) <= size);

Expand Down
Loading