[interp] Fix COUNT_OPS
authorVlad Brezae <brezaevlad@gmail.com>
Thu, 12 Sep 2019 09:45:35 +0000 (12:45 +0300)
committerLarry Ewing <lewing@microsoft.com>
Fri, 13 Sep 2019 00:29:13 +0000 (19:29 -0500)
And make it print the sorted opcode counts when runtime is shutting down

Commit migrated from https://github.com/mono/mono/commit/54a7e61115ba556fbef59c0849ded109baa67cde

src/mono/mono/mini/ee.h
src/mono/mono/mini/interp-stubs.c
src/mono/mono/mini/interp/interp.c
src/mono/mono/mini/interp/mintops.h
src/mono/mono/mini/mini-runtime.c

index ca9b34a..2bd5da5 100644 (file)
@@ -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 {
 
index 2b10d4c..a77e85c 100644 (file)
@@ -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 ();
index f9884bf..0638453 100644 (file)
@@ -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)
 {
index b3d4755..389dce8 100644 (file)
@@ -29,6 +29,7 @@ typedef enum
 #define OPDEF(a,b,c,d,e,f) a,
 enum {
 #include "mintops.def"
+       MINT_LASTOP
 };
 #undef OPDEF
 
index 4fe0b6d..de0d56c 100644 (file)
@@ -4780,6 +4780,8 @@ mini_cleanup (MonoDomain *domain)
 
        mini_jit_cleanup ();
 
+       mini_get_interp_callbacks ()->cleanup ();
+
        mono_tramp_info_cleanup ();
 
        mono_arch_cleanup ();