Skip to content

Commit

Permalink
[wasm] Trim down size of dotnet.wasm (mono#20139)
Browse files Browse the repository at this point in the history
This disables several debugging features in sgen, helps the compiler remove some unused code related to concurrent collector and disables more assertion messages, but also some other logs. We might have to reenable some of them if this is problematic.

Saves about 60k on wasm

Co-authored-by: BrzVlad <BrzVlad@users.noreply.github.com>
  • Loading branch information
monojenkins and BrzVlad authored Jul 18, 2020
1 parent 2058deb commit 0372a38
Show file tree
Hide file tree
Showing 17 changed files with 275 additions and 13 deletions.
14 changes: 11 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1783,9 +1783,7 @@ fi
AM_CONDITIONAL(ENABLE_STATIC_GCC_LIBS, test "x$enable_static_gcc_libs" = "xyes")

AC_ARG_ENABLE(minimal, [ --enable-minimal=LIST drop support for LIST subsystems.
LIST is a comma-separated list from: aot, profiler, decimal, pinvoke, debug, appdomains, verifier, dllmap,
reflection_emit, reflection_emit_save, large_code, logging, com, ssa, generics, attach, jit, interpreter, simd, soft_debug, perfcounters, normalization, desktop_loader, shared_perfcounters, remoting,
security, lldb, mdb, assert_messages, config, cfgdir_config, cleanup, sgen_marksweep_conc, sgen_split_nursery, sgen_gc_bridge, sgen_debug_helpers, sockets, gac, threads, processes, eventpipe.],
LIST is a comma-separated list from: aot, profiler, decimal, pinvoke, debug, appdomains, verifier, dllmap, reflection_emit, reflection_emit_save, large_code, logging, com, ssa, generics, attach, jit, interpreter, simd, soft_debug, perfcounters, normalization, desktop_loader, shared_perfcounters, remoting, security, lldb, mdb, assert_messages, config, cfgdir_config, cleanup, sgen_marksweep_conc, sgen_split_nursery, sgen_gc_bridge, sgen_toggleref, sgen_debug_helpers, sgen_binary_protocol, sockets, gac, threads, processes, eventpipe.],
[
for feature in `echo "$enable_minimal" | sed -e "s/,/ /g"`; do
eval "mono_feature_disable_$feature='yes'"
Expand Down Expand Up @@ -1991,11 +1989,21 @@ if test "x$mono_feature_disable_sgen_gc_bridge" = "xyes"; then
AC_MSG_NOTICE([Disabled gc bridge support in SGEN.])
fi

if test "x$mono_feature_disable_sgen_toggleref" = "xyes"; then
AC_DEFINE(DISABLE_SGEN_TOGGLEREF, 1, [Disable toggleref support in SGEN.])
AC_MSG_NOTICE([Disabled toggleref support in SGEN.])
fi

if test "x$mono_feature_disable_sgen_debug_helpers" = "xyes"; then
AC_DEFINE(DISABLE_SGEN_DEBUG_HELPERS, 1, [Disable debug helpers in SGEN.])
AC_MSG_NOTICE([Disabled debug helpers in SGEN.])
fi

if test "x$mono_feature_disable_sgen_binary_protocol" = "xyes"; then
AC_DEFINE(DISABLE_SGEN_BINARY_PROTOCOL, 1, [Disable binary protocol logging in SGEN.])
AC_MSG_NOTICE([Disabled binary protocol logging in SGEN.])
fi

if test "x$mono_feature_disable_sockets" = "xyes"; then
AC_DEFINE(DISABLE_SOCKETS, 1, [Disable sockets])
AC_MSG_NOTICE([Disabled sockets])
Expand Down
9 changes: 9 additions & 0 deletions mono/eglib/glib.h
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,15 @@ GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain, GLogLevelFlags f
void g_logv (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args);
G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
void g_log (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...);
void g_log_disabled (const gchar *log_domain, GLogLevelFlags log_level, const char *file, int line);
G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
void g_assertion_message (const gchar *format, ...) G_GNUC_NORETURN;
void mono_assertion_message_disabled (const char *file, int line) G_GNUC_NORETURN;
void mono_assertion_message (const char *file, int line, const char *condition) G_GNUC_NORETURN;
void mono_assertion_message_unreachable (const char *file, int line) G_GNUC_NORETURN;
const char * g_get_assertion_message (void);

#ifndef DISABLE_ASSERT_MESSAGES
#ifdef HAVE_C99_SUPPORT
/* The for (;;) tells gc thats g_error () doesn't return, avoiding warnings */
#define g_error(format, ...) do { g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, __VA_ARGS__); for (;;); } while (0)
Expand All @@ -800,6 +802,13 @@ const char * g_get_assertion_message (void);
#define g_message(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
#define g_debug(...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__)
#endif /* ndef HAVE_C99_SUPPORT */
#else
#define g_error(...) do { g_log_disabled (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, __FILE__, __LINE__); for (;;); } while (0)
#define g_critical(...) g_log_disabled (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __FILE__, __LINE__)
#define g_warning(...) g_log_disabled (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __FILE__, __LINE__)
#define g_message(...) g_log_disabled (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __FILE__, __LINE__)
#define g_debug(...) g_log_disabled (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __FILE__, __LINE__)
#endif

typedef void (*GLogFunc) (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data);
typedef void (*GPrintFunc) (const gchar *string);
Expand Down
6 changes: 6 additions & 0 deletions mono/eglib/goutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ g_log (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, .
va_end (args);
}

void
g_log_disabled (const gchar *log_domain, GLogLevelFlags log_level, const char *file, int line)
{
g_log (log_domain, log_level, "%s:%d <disabled>", file, line);
}

static char *failure_assertion = NULL;

const char *
Expand Down
15 changes: 15 additions & 0 deletions mono/metadata/sgen-toggleref.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "sgen-toggleref.h"
#include "sgen/sgen-client.h"

#ifndef DISABLE_SGEN_TOGGLEREF

/*only one of the two can be non null at a given time*/
typedef struct {
Expand Down Expand Up @@ -234,4 +235,18 @@ sgen_register_test_toggleref_callback (void)
toggleref_callback = test_toggleref_callback;
}

#else

void
mono_gc_toggleref_register_callback (MonoToggleRefStatus (*proccess_toggleref) (MonoObject *obj))
{
}

void
mono_gc_toggleref_add (MonoObject *object, mono_bool strong_ref)
{
}

#endif

#endif
7 changes: 7 additions & 0 deletions mono/sgen/sgen-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,19 @@ void sgen_client_bridge_processing_finish (int generation);
gboolean sgen_client_bridge_is_bridge_object (GCObject *obj);
void sgen_client_bridge_register_finalized_object (GCObject *object);

#ifndef DISABLE_SGEN_TOGGLEREF
/*
* No action is necessary.
*/
void sgen_client_mark_togglerefs (char *start, char *end, ScanCopyContext ctx);
void sgen_client_clear_togglerefs (char *start, char *end, ScanCopyContext ctx);
void sgen_foreach_toggleref_root (void (*callback)(MonoObject*, gpointer), gpointer data);
#else
static inline void sgen_client_mark_togglerefs (char *start, char *end, ScanCopyContext ctx) { }
static inline void sgen_client_clear_togglerefs (char *start, char *end, ScanCopyContext ctx) { }
static inline void sgen_foreach_toggleref_root (void (*callback)(MonoObject*, gpointer), gpointer data) { }
#endif


/*
* Called to handle `MONO_GC_PARAMS` and `MONO_GC_DEBUG` options. The `handle` functions
Expand Down
5 changes: 5 additions & 0 deletions mono/sgen/sgen-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ typedef target_mword SgenDescriptor;
* Making this a constant enables us to put logging in a lot of places and
* not pay its cost on release builds.
*/
#ifndef DISABLE_SGEN_DEBUG_HELPERS
#define SGEN_MAX_DEBUG_LEVEL 2
#else
/* No logging support */
#define SGEN_MAX_DEBUG_LEVEL (-1)
#endif

/*
* Maximum level of asserts to enable on this build.
Expand Down
17 changes: 17 additions & 0 deletions mono/sgen/sgen-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ static gboolean disable_minor_collections = FALSE;
static gboolean disable_major_collections = FALSE;
static gboolean do_verify_nursery = FALSE;
static gboolean do_dump_nursery_content = FALSE;

#ifndef DISABLE_SGEN_DEBUG_HELPERS
static gboolean enable_nursery_canaries = FALSE;
#else
static const gboolean enable_nursery_canaries = FALSE;
#endif

static gboolean precleaning_enabled = TRUE;
static gboolean dynamic_nursery = FALSE;
Expand Down Expand Up @@ -378,7 +383,9 @@ static volatile mword highest_heap_address = 0;
MonoCoopMutex sgen_interruption_mutex;

int sgen_current_collection_generation = -1;
#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
volatile gboolean sgen_concurrent_collection_in_progress = FALSE;
#endif

/* objects that are ready to be finalized */
static SgenPointerQueue fin_ready_queue = SGEN_POINTER_QUEUE_INIT (INTERNAL_MEM_FINALIZE_READY);
Expand Down Expand Up @@ -1359,6 +1366,7 @@ sgen_set_pinned_from_failed_allocation (mword objsize)
bytes_pinned_from_failed_allocation += objsize;
}

#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
gboolean
sgen_collection_is_concurrent (void)
{
Expand All @@ -1378,6 +1386,7 @@ sgen_get_concurrent_collection_in_progress (void)
{
return sgen_concurrent_collection_in_progress;
}
#endif

typedef struct {
SgenThreadPoolJob job;
Expand Down Expand Up @@ -2176,10 +2185,12 @@ major_start_collection (SgenGrayQueue *gc_thread_gray_queue, const char *reason,
{
SgenObjectOperations *object_ops_nopar, *object_ops_par = NULL;

#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
if (concurrent) {
g_assert (sgen_major_collector.is_concurrent);
sgen_concurrent_collection_in_progress = TRUE;
}
#endif

sgen_binary_protocol_collection_begin (mono_atomic_load_i32 (&mono_gc_stats.major_gc_count), GENERATION_OLD);

Expand Down Expand Up @@ -2366,8 +2377,10 @@ major_finish_collection (SgenGrayQueue *gc_thread_gray_queue, const char *reason

sgen_binary_protocol_collection_end (mono_atomic_load_i32 (&mono_gc_stats.major_gc_count) - 1, GENERATION_OLD, counts.num_scanned_objects, counts.num_unique_scanned_objects);

#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
if (sgen_concurrent_collection_in_progress)
sgen_concurrent_collection_in_progress = FALSE;
#endif
}

static gboolean
Expand Down Expand Up @@ -3729,7 +3742,11 @@ sgen_gc_init (void)
sgen_binary_protocol_init (filename, (gint64)limit);
} else if (!strcmp (opt, "nursery-canaries")) {
do_verify_nursery = TRUE;
#ifndef DISABLE_SGEN_DEBUG_HELPERS
enable_nursery_canaries = TRUE;
#else
g_error ("Sgen was built with canaries disabled");
#endif
/* If aot code is used, allocation from there won't expect the layout with canaries enabled */
sgen_set_use_managed_allocator (FALSE);
} else if (!sgen_client_handle_gc_debug (opt)) {
Expand Down
27 changes: 27 additions & 0 deletions mono/sgen/sgen-gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,20 +476,37 @@ void sgen_free_internal (void *addr, int type);
void* sgen_alloc_internal_dynamic (size_t size, int type, gboolean assert_on_failure);
void sgen_free_internal_dynamic (void *addr, size_t size, int type);

#ifndef DISABLE_SGEN_DEBUG_HELPERS
void sgen_pin_stats_enable (void);
void sgen_pin_stats_register_object (GCObject *obj, int generation);
void sgen_pin_stats_register_global_remset (GCObject *obj);
void sgen_pin_stats_report (void);
#else
static inline void sgen_pin_stats_enable (void) { }
static inline void sgen_pin_stats_register_object (GCObject *obj, int generation) { }
static inline void sgen_pin_stats_register_global_remset (GCObject *obj) { }
static inline void sgen_pin_stats_report (void) { }
#endif

#ifndef DISABLE_SGEN_DEBUG_HELPERS
void sgen_gchandle_stats_enable (void);
void sgen_gchandle_stats_report (void);
#else
static inline void sgen_gchandle_stats_enable (void) { }
static inline void sgen_gchandle_stats_report (void) { }
#endif

void sgen_sort_addresses (void **array, size_t size);
void sgen_add_to_global_remset (gpointer ptr, GCObject *obj);

int sgen_get_current_collection_generation (void);
#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
gboolean sgen_collection_is_concurrent (void);
gboolean sgen_get_concurrent_collection_in_progress (void);
#else
#define sgen_collection_is_concurrent() FALSE
#define sgen_get_concurrent_collection_in_progress() FALSE
#endif

void sgen_set_bytes_allocated_attached (guint64 bytes);
void sgen_increment_bytes_allocated_detached (guint64 bytes);
Expand Down Expand Up @@ -837,8 +854,14 @@ void sgen_register_obj_with_weak_fields (GCObject *obj);
void sgen_mark_togglerefs (char *start, char *end, ScanCopyContext ctx);
void sgen_clear_togglerefs (char *start, char *end, ScanCopyContext ctx);

#ifndef DISABLE_SGEN_TOGGLEREF
void sgen_process_togglerefs (void);
void sgen_register_test_toggleref_callback (void);
#else
static inline void sgen_process_togglerefs (void) { }
static inline void sgen_register_test_toggleref_callback (void) { }
#endif


void sgen_mark_bridge_object (GCObject *obj)
MONO_PERMIT (need (sgen_gc_locked));
Expand Down Expand Up @@ -1074,7 +1097,11 @@ extern mword sgen_total_promoted_size;
extern mword sgen_total_allocated_major;
extern volatile gboolean sgen_suspend_finalizers;
extern MonoCoopMutex sgen_gc_mutex;
#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
extern volatile gboolean sgen_concurrent_collection_in_progress;
#else
static const gboolean sgen_concurrent_collection_in_progress = FALSE;
#endif

/* Nursery helpers. */

Expand Down
2 changes: 2 additions & 0 deletions mono/sgen/sgen-gchandles.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ sgen_register_obj_with_weak_fields (GCObject *obj)
alloc_handle (gc_handles_for_type (HANDLE_WEAK_FIELDS), obj, FALSE);
}

#ifndef DISABLE_SGEN_DEBUG_HELPERS
void
sgen_gchandle_stats_enable (void)
{
Expand Down Expand Up @@ -596,6 +597,7 @@ sgen_gchandle_stats_report (void)
mono_gc_printf (sgen_gc_debug_file, "\n");
} SGEN_HASH_TABLE_FOREACH_END;
}
#endif

void
sgen_init_gchandles (void)
Expand Down
17 changes: 17 additions & 0 deletions mono/sgen/sgen-marksweep.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ typedef enum {
static volatile int sweep_state = SWEEP_STATE_SWEPT;

static gboolean concurrent_mark;
#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
static gboolean concurrent_sweep = DEFAULT_SWEEP_MODE;
#else
static const gboolean concurrent_sweep = SGEN_SWEEP_SERIAL;
#endif

static int sweep_pool_context = -1;

Expand Down Expand Up @@ -908,6 +912,9 @@ static SgenThreadPoolJob * volatile sweep_blocks_job;
static void
major_finish_sweep_checking (void)
{
if (!concurrent_sweep)
return;

guint32 block_index;
SgenThreadPoolJob *job;

Expand Down Expand Up @@ -2399,10 +2406,16 @@ major_handle_gc_param (const char *opt)
lazy_sweep = FALSE;
return TRUE;
} else if (!strcmp (opt, "concurrent-sweep")) {
#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
concurrent_sweep = TRUE;
#else
g_error ("Sgen was built with concurrent collector disabled");
#endif
return TRUE;
} else if (!strcmp (opt, "no-concurrent-sweep")) {
#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
concurrent_sweep = FALSE;
#endif
return TRUE;
}

Expand Down Expand Up @@ -2884,7 +2897,9 @@ sgen_marksweep_init_internal (SgenMajorCollector *collector, gboolean is_concurr
collector->alloc_degraded = major_alloc_degraded;

collector->alloc_object = major_alloc_object;
#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
collector->alloc_object_par = major_alloc_object_par;
#endif
collector->free_pinned_object = free_pinned_object;
collector->iterate_objects = major_iterate_objects;
collector->free_non_pinned_object = major_free_non_pinned_object;
Expand Down Expand Up @@ -2921,7 +2936,9 @@ sgen_marksweep_init_internal (SgenMajorCollector *collector, gboolean is_concurr
collector->post_param_init = post_param_init;
collector->is_valid_object = major_is_valid_object;
collector->describe_pointer = major_describe_pointer;
#ifndef DISABLE_SGEN_BINARY_PROTOCOL
collector->count_cards = major_count_cards;
#endif
collector->init_block_free_lists = sgen_init_block_free_lists;

collector->major_ops_serial.copy_or_mark_object = major_copy_or_mark_object_canonical;
Expand Down
4 changes: 4 additions & 0 deletions mono/sgen/sgen-pinning-stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "config.h"
#ifdef HAVE_SGEN_GC

#ifndef DISABLE_SGEN_DEBUG_HELPERS

#include <string.h>

#include "mono/sgen/sgen-gc.h"
Expand Down Expand Up @@ -247,4 +249,6 @@ sgen_pin_stats_get_object_list (void)
return &pinned_objects;
}

#endif

#endif /* HAVE_SGEN_GC */
7 changes: 7 additions & 0 deletions mono/sgen/sgen-pinning.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ void sgen_pin_objects_in_section (GCMemSection *section, ScanCopyContext ctx);

/* Pinning stats */

#ifndef DISABLE_SGEN_DEBUG_HELPERS
void sgen_pin_stats_register_address (char *addr, int pin_type);
size_t sgen_pin_stats_get_pinned_byte_count (int pin_type);
SgenPointerQueue *sgen_pin_stats_get_object_list (void);
void sgen_pin_stats_reset (void);
#else
static inline void sgen_pin_stats_register_address (char *addr, int pin_type) { }
static inline size_t sgen_pin_stats_get_pinned_byte_count (int pin_type) { return 0; }
static inline SgenPointerQueue *sgen_pin_stats_get_object_list (void) { return NULL; }
static inline void sgen_pin_stats_reset (void) { }
#endif

/* Perpetual pinning, aka cementing */

Expand Down
Loading

0 comments on commit 0372a38

Please sign in to comment.