From: Vlad Brezae Date: Thu, 12 Sep 2019 09:45:35 +0000 (+0300) Subject: [interp] Fix COUNT_OPS X-Git-Tag: submit/tizen/20210909.063632~10331^2~5^2~515 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72c5bb12fb34c5891a3b61d708d4214128538aeb;p=platform%2Fupstream%2Fdotnet%2Fruntime.git [interp] Fix COUNT_OPS And make it print the sorted opcode counts when runtime is shutting down Commit migrated from https://github.com/mono/mono/commit/54a7e61115ba556fbef59c0849ded109baa67cde --- diff --git a/src/mono/mono/mini/ee.h b/src/mono/mono/mini/ee.h index ca9b34a..2bd5da5 100644 --- a/src/mono/mono/mini/ee.h +++ b/src/mono/mono/mini/ee.h @@ -57,6 +57,7 @@ typedef gpointer MonoInterpFrameHandle; MONO_EE_CALLBACK (MonoInterpFrameHandle, frame_get_parent, (MonoInterpFrameHandle frame)) \ MONO_EE_CALLBACK (void, start_single_stepping, (void)) \ MONO_EE_CALLBACK (void, stop_single_stepping, (void)) \ + MONO_EE_CALLBACK (void, cleanup, (void)) \ typedef struct _MonoEECallbacks { diff --git a/src/mono/mono/mini/interp-stubs.c b/src/mono/mono/mini/interp-stubs.c index 2b10d4c..a77e85c 100644 --- a/src/mono/mono/mini/interp-stubs.c +++ b/src/mono/mono/mini/interp-stubs.c @@ -82,6 +82,11 @@ stub_stop_single_stepping (void) } static void +stub_cleanup (void) +{ +} + +static void stub_set_resume_state (MonoJitTlsData *jit_tls, MonoException *ex, MonoJitExceptionInfo *ei, MonoInterpFrameHandle interp_frame, gpointer handler_ip) { g_assert_not_reached (); diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index f9884bf..0638453 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -207,25 +207,26 @@ int mono_interp_traceopt = 0; #endif -#if defined(__GNUC__) && !defined(TARGET_WASM) +#if defined(__GNUC__) && !defined(TARGET_WASM) && !COUNT_OPS #define USE_COMPUTED_GOTO 1 #endif + #if USE_COMPUTED_GOTO -#define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op]; + +#define MINT_IN_SWITCH(op) goto *in_labels[op]; #define MINT_IN_CASE(x) LAB_ ## x: #define MINT_IN_DISPATCH(op) goto *in_labels[op]; -#if DEBUG_INTERP -#define MINT_IN_BREAK if (tracing > 1) { MINT_IN_DISPATCH(*ip); } else { COUNT_OP(*ip); goto *in_labels[*ip]; } -#else -#define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; } -#endif +#define MINT_IN_BREAK { goto *in_labels[*ip]; } #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */ + #else -#define MINT_IN_SWITCH(op) switch (op) + +#define MINT_IN_SWITCH(op) COUNT_OP(op); switch (op) #define MINT_IN_CASE(x) case x: #define MINT_IN_DISPATCH(op) goto main_loop; #define MINT_IN_BREAK break #define MINT_IN_DEFAULT default: + #endif static GSList* @@ -2834,7 +2835,7 @@ interp_create_method_pointer (MonoMethod *method, gboolean compile, MonoError *e } #if COUNT_OPS -static int opcode_counts[512]; +static long opcode_counts[MINT_LASTOP]; #define COUNT_OP(op) opcode_counts[op]++ #else @@ -6949,6 +6950,46 @@ interp_stop_single_stepping (void) ss_enabled = FALSE; } +#if COUNT_OPS + +static int +opcode_count_comparer (const void * pa, const void * pb) +{ + long counta = opcode_counts [*(int*)pa]; + long countb = opcode_counts [*(int*)pb]; + + if (counta < countb) + return 1; + else if (counta > countb) + return -1; + else + return 0; +} + +static void +interp_print_op_count (void) +{ + int ordered_ops [MINT_LASTOP]; + int i; + + for (i = 0; i < MINT_LASTOP; i++) + ordered_ops [i] = i; + qsort (ordered_ops, MINT_LASTOP, sizeof (int), opcode_count_comparer); + + for (i = 0; i < MINT_LASTOP; i++) { + g_print ("%s : %ld\n", mono_interp_opname (ordered_ops [i]), opcode_counts [ordered_ops [i]]); + } +} +#endif + +static void +interp_cleanup (void) +{ +#if COUNT_OPS + interp_print_op_count (); +#endif +} + static void register_interp_stats (void) { diff --git a/src/mono/mono/mini/interp/mintops.h b/src/mono/mono/mini/interp/mintops.h index b3d4755..389dce8 100644 --- a/src/mono/mono/mini/interp/mintops.h +++ b/src/mono/mono/mini/interp/mintops.h @@ -29,6 +29,7 @@ typedef enum #define OPDEF(a,b,c,d,e,f) a, enum { #include "mintops.def" + MINT_LASTOP }; #undef OPDEF diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 4fe0b6d..de0d56c 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -4780,6 +4780,8 @@ mini_cleanup (MonoDomain *domain) mini_jit_cleanup (); + mini_get_interp_callbacks ()->cleanup (); + mono_tramp_info_cleanup (); mono_arch_cleanup ();