Skip to content

Commit

Permalink
[MonoVM] Improve thread state debugging and make it usable on Android (
Browse files Browse the repository at this point in the history
…#108401)

* [MonoVM] Improve thread state debugging and make it usable on Android

* Do not disable logging on Debug builds

---------

Co-authored-by: Aleksey Kliger (λgeek) <alklig@microsoft.com>
  • Loading branch information
filipnavara and lambdageek authored Nov 2, 2024
1 parent 275ea58 commit a9ca413
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@ JS_ENGINES = [NODE_JS]
<_MonoCMakeArgs Condition="'$(Platform)' == 'arm'" Include="-DANDROID_ABI=armeabi-v7a" />
<_MonoCMakeArgs Condition="'$(Platform)' == 'x86'" Include="-DANDROID_ABI=x86" />
<_MonoCMakeArgs Condition="'$(Platform)' == 'x64'" Include="-DANDROID_ABI=x86_64" />
<_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,logging" />
<_MonoCMakeArgs Condition="'$(Configuration)' != 'Debug'" Include="-DENABLE_MINIMAL=ssa,logging" />
<_MonoCMakeArgs Condition="'$(Configuration)' == 'Debug'" Include="-DENABLE_MINIMAL=ssa" />

<_MonoCFLAGS Condition="'$(Platform)' == 'arm'" Include="-march=armv7-a" />
<_MonoCFLAGS Condition="'$(Platform)' == 'arm'" Include="-mtune=cortex-a8" />
Expand Down
9 changes: 9 additions & 0 deletions src/mono/mono/utils/mono-threads-debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@

#include <config.h>
#include <glib.h>
#if defined (HOST_ANDROID)
#include <android/log.h>
#endif

/* Logging - enable them below if you need specific logging for the category you need */
#define MOSTLY_ASYNC_SAFE_FPRINTF(handle, ...) do { \
g_async_safe_fprintf (handle, __VA_ARGS__); \
} while (0)

#if defined (HOST_ANDROID)
#define MOSTLY_ASYNC_SAFE_PRINTF(...) do { \
__android_log_print (ANDROID_LOG_ERROR, "THREAD", __VA_ARGS__); \
} while (0)
#else
#define MOSTLY_ASYNC_SAFE_PRINTF(...) MOSTLY_ASYNC_SAFE_FPRINTF(1, __VA_ARGS__);
#endif

#if 1
#define THREADS_DEBUG(...)
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/utils/mono-threads-state-machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,15 +737,15 @@ mono_threads_transition_do_blocking (MonoThreadInfo* info, const char *func)
mono_fatal_with_history ("no_safepoints = TRUE, but should be FALSE in state RUNNING with DO_BLOCKING");
if (thread_state_cas (&info->thread_state, build_thread_state (STATE_BLOCKING, suspend_count, no_safepoints), raw_state) != raw_state)
goto retry_state_change;
trace_state_change ("DO_BLOCKING", info, raw_state, STATE_BLOCKING, no_safepoints, 0);
trace_state_change_with_func ("DO_BLOCKING", info, raw_state, STATE_BLOCKING, no_safepoints, 0, func);
return DoBlockingContinue;

case STATE_ASYNC_SUSPEND_REQUESTED:
if (!(suspend_count > 0))
mono_fatal_with_history ("suspend_count = %d, but should be > 0", suspend_count);
if (no_safepoints)
mono_fatal_with_history ("no_safepoints = TRUE, but should be FALSE in state ASYNC_SUSPEND_REQUESTED with DO_BLOCKING");
trace_state_change ("DO_BLOCKING", info, raw_state, cur_state, no_safepoints, 0);
trace_state_change_with_func ("DO_BLOCKING", info, raw_state, cur_state, no_safepoints, 0, func);
return DoBlockingPollAndRetry;
/*
STATE_ASYNC_SUSPENDED
Expand Down

0 comments on commit a9ca413

Please sign in to comment.