Merge pull request #1088 from BrzVlad/pushless
[mono.git] / mono / mini / mini-gc.c
old mode 100755 (executable)
new mode 100644 (file)
index ca38406..1566cb0
@@ -436,6 +436,9 @@ static int callee_saved_regs [] = { AMD64_RBP, AMD64_RBX, AMD64_R12, AMD64_R13,
 static int callee_saved_regs [] = { X86_EBX, X86_ESI, X86_EDI };
 #elif defined(TARGET_ARM)
 static int callee_saved_regs [] = { ARMREG_V1, ARMREG_V2, ARMREG_V3, ARMREG_V4, ARMREG_V5, ARMREG_V7, ARMREG_FP };
+#elif defined(TARGET_ARM64)
+// FIXME:
+static int callee_saved_regs [] = { };
 #elif defined(TARGET_S390X)
 static int callee_saved_regs [] = { s390_r6, s390_r7, s390_r8, s390_r9, s390_r10, s390_r11, s390_r12, s390_r13, s390_r14 };
 #endif
@@ -595,13 +598,15 @@ thread_suspend_func (gpointer user_data, void *sigctx, MonoContext *ctx)
 
        if (tls->tid != GetCurrentThreadId ()) {
                /* Happens on osx because threads are not suspended using signals */
+#ifndef TARGET_WIN32
                gboolean res;
+#endif
 
                g_assert (tls->info);
 #ifdef TARGET_WIN32
                return;
 #else
-               res = mono_thread_state_init_from_handle (&tls->unwind_state, (MonoNativeThreadId)tls->tid, tls->info->native_handle);
+               res = mono_thread_state_init_from_handle (&tls->unwind_state, tls->info);
 #endif
        } else {
                tls->unwind_state.unwind_data [MONO_UNWIND_DATA_LMF] = mono_get_lmf ();
@@ -702,6 +707,7 @@ static void
 conservative_pass (TlsData *tls, guint8 *stack_start, guint8 *stack_end)
 {
        MonoJitInfo *ji;
+       MonoMethod *method;
        MonoContext ctx, new_ctx;
        MonoLMF *lmf;
        guint8 *stack_limit;
@@ -811,10 +817,15 @@ conservative_pass (TlsData *tls, guint8 *stack_start, guint8 *stack_end)
                        continue;
                }
 
+               if (ji)
+                       method = jinfo_get_method (ji);
+               else
+                       method = NULL;
+
                /* The last frame can be in any state so mark conservatively */
                if (last) {
                        if (ji) {
-                               DEBUG (char *fname = mono_method_full_name (ji->method, TRUE); fprintf (logfile, "Mark(0): %s+0x%x (%p)\n", fname, pc_offset, (gpointer)MONO_CONTEXT_GET_IP (&ctx)); g_free (fname));
+                               DEBUG (char *fname = mono_method_full_name (method, TRUE); fprintf (logfile, "Mark(0): %s+0x%x (%p)\n", fname, pc_offset, (gpointer)MONO_CONTEXT_GET_IP (&ctx)); g_free (fname));
                        }
                        DEBUG (fprintf (logfile, "\t <Last frame>\n"));
                        last = FALSE;
@@ -841,8 +852,8 @@ conservative_pass (TlsData *tls, guint8 *stack_start, guint8 *stack_end)
                pc_offset = (guint8*)MONO_CONTEXT_GET_IP (&ctx) - (guint8*)ji->code_start;
 
                /* These frames are very problematic */
-               if (ji->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
-                       DEBUG (char *fname = mono_method_full_name (ji->method, TRUE); fprintf (logfile, "Mark(0): %s+0x%x (%p)\n", fname, pc_offset, (gpointer)MONO_CONTEXT_GET_IP (&ctx)); g_free (fname));
+               if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) {
+                       DEBUG (char *fname = mono_method_full_name (method, TRUE); fprintf (logfile, "Mark(0): %s+0x%x (%p)\n", fname, pc_offset, (gpointer)MONO_CONTEXT_GET_IP (&ctx)); g_free (fname));
                        DEBUG (fprintf (logfile, "\tSkip.\n"));
                        continue;
                }
@@ -873,7 +884,7 @@ conservative_pass (TlsData *tls, guint8 *stack_start, guint8 *stack_end)
                emap = ji->gc_info;
 
                if (!emap) {
-                       DEBUG (char *fname = mono_method_full_name (ji->method, TRUE); fprintf (logfile, "Mark(0): %s+0x%x (%p)\n", fname, pc_offset, (gpointer)MONO_CONTEXT_GET_IP (&ctx)); g_free (fname));
+                       DEBUG (char *fname = mono_method_full_name (jinfo_get_method (ji), TRUE); fprintf (logfile, "Mark(0): %s+0x%x (%p)\n", fname, pc_offset, (gpointer)MONO_CONTEXT_GET_IP (&ctx)); g_free (fname));
                        DEBUG (fprintf (logfile, "\tNo GC Map.\n"));
                        continue;
                }
@@ -885,14 +896,14 @@ conservative_pass (TlsData *tls, guint8 *stack_start, guint8 *stack_end)
                 * Debugging aid to control the number of frames scanned precisely
                 */
                if (!precise_frame_limit_inited) {
-                       if (getenv ("MONO_PRECISE_COUNT"))
-                               precise_frame_limit = atoi (getenv ("MONO_PRECISE_COUNT"));
+                       if (g_getenv ("MONO_PRECISE_COUNT"))
+                               precise_frame_limit = atoi (g_getenv ("MONO_PRECISE_COUNT"));
                        precise_frame_limit_inited = TRUE;
                }
                                
                if (precise_frame_limit != -1) {
                        if (precise_frame_count [FALSE] == precise_frame_limit)
-                               printf ("LAST PRECISE FRAME: %s\n", mono_method_full_name (ji->method, TRUE));
+                               printf ("LAST PRECISE FRAME: %s\n", mono_method_full_name (method, TRUE));
                        if (precise_frame_count [FALSE] > precise_frame_limit)
                                continue;
                }
@@ -913,7 +924,7 @@ conservative_pass (TlsData *tls, guint8 *stack_start, guint8 *stack_end)
                frame_start = fp + map->start_offset + map->map_offset;
                frame_end = fp + map->end_offset;
 
-               DEBUG (char *fname = mono_method_full_name (ji->method, TRUE); fprintf (logfile, "Mark(0): %s+0x%x (%p) limit=%p fp=%p frame=%p-%p (%d)\n", fname, pc_offset, (gpointer)MONO_CONTEXT_GET_IP (&ctx), stack_limit, fp, frame_start, frame_end, (int)(frame_end - frame_start)); g_free (fname));
+               DEBUG (char *fname = mono_method_full_name (jinfo_get_method (ji), TRUE); fprintf (logfile, "Mark(0): %s+0x%x (%p) limit=%p fp=%p frame=%p-%p (%d)\n", fname, pc_offset, (gpointer)MONO_CONTEXT_GET_IP (&ctx), stack_limit, fp, frame_start, frame_end, (int)(frame_end - frame_start)); g_free (fname));
 
                /* Find the callsite index */
                if (map->callsite_entry_size == 1) {
@@ -935,7 +946,7 @@ conservative_pass (TlsData *tls, guint8 *stack_start, guint8 *stack_end)
                                        break;
                }
                if (i == map->ncallsites) {
-                       printf ("Unable to find ip offset 0x%x in callsite list of %s.\n", pc_offset + 1, mono_method_full_name (ji->method, TRUE));
+                       printf ("Unable to find ip offset 0x%x in callsite list of %s.\n", pc_offset + 1, mono_method_full_name (method, TRUE));
                        g_assert_not_reached ();
                }
                cindex = i;
@@ -1114,7 +1125,7 @@ precise_pass (TlsData *tls, guint8 *stack_start, guint8 *stack_end)
                fi = &tls->frames [findex];
                frame_start = stack_start + fi->frame_start_offset;
 
-               DEBUG (char *fname = mono_method_full_name (fi->ji->method, TRUE); fprintf (logfile, "Mark(1): %s\n", fname); g_free (fname));
+               DEBUG (char *fname = mono_method_full_name (jinfo_get_method (fi->ji), TRUE); fprintf (logfile, "Mark(1): %s\n", fname); g_free (fname));
 
                /* 
                 * FIXME: Add a function to mark using a bitmap, to avoid doing a 
@@ -1241,10 +1252,10 @@ mini_gc_init_gc_map (MonoCompile *cfg)
                static int precise_count;
 
                precise_count ++;
-               if (getenv ("MONO_GCMAP_COUNT")) {
-                       if (precise_count == atoi (getenv ("MONO_GCMAP_COUNT")))
+               if (g_getenv ("MONO_GCMAP_COUNT")) {
+                       if (precise_count == atoi (g_getenv ("MONO_GCMAP_COUNT")))
                                printf ("LAST: %s\n", mono_method_full_name (cfg->method, TRUE));
-                       if (precise_count > atoi (getenv ("MONO_GCMAP_COUNT")))
+                       if (precise_count > atoi (g_getenv ("MONO_GCMAP_COUNT")))
                                return;
                }
        }
@@ -1860,7 +1871,11 @@ sp_offset_to_fp_offset (MonoCompile *cfg, int sp_offset)
 #elif defined(TARGET_X86)
        /* The offset is computed from the sp at the start of the call sequence */
        g_assert (cfg->frame_reg == X86_EBP);
+#ifdef MONO_X86_NO_PUSHES
+       return (- cfg->arch.sp_fp_offset + sp_offset);
+#else
        return (- cfg->arch.sp_fp_offset - sp_offset);  
+#endif
 #else
        NOT_IMPLEMENTED;
        return -1;
@@ -2047,7 +2062,11 @@ compute_frame_size (MonoCompile *cfg)
 #ifdef TARGET_AMD64
        min_offset = MIN (min_offset, -cfg->arch.sp_fp_offset);
 #elif defined(TARGET_X86)
+#ifdef MONO_X86_NO_PUSHES
+       min_offset = MIN (min_offset, -cfg->arch.sp_fp_offset);
+#else
        min_offset = MIN (min_offset, - (cfg->arch.sp_fp_offset + cfg->arch.param_area_size));
+#endif
 #elif defined(TARGET_ARM)
        // FIXME:
 #elif defined(TARGET_s390X)
@@ -2443,9 +2462,9 @@ static void
 parse_debug_options (void)
 {
        char **opts, **ptr;
-       char *env;
+       const char *env;
 
-       env = getenv ("MONO_GCMAP_DEBUG");
+       env = g_getenv ("MONO_GCMAP_DEBUG");
        if (!env)
                return;