Merge pull request #2645 from alexrp/profiler-stability
authorRodrigo Kumpera <kumpera@gmail.com>
Wed, 2 Mar 2016 20:33:07 +0000 (15:33 -0500)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 2 Mar 2016 20:33:07 +0000 (15:33 -0500)
Fix a crash in the MONO_LLS_FOREACH_SAFE macro

1  2 
mono/metadata/sgen-mono.c
mono/utils/mono-threads.c

index 34ab667d2c89190bce9802a130041f8ae3cb5368,8f08eef36e6b7ebd5c703ade6bdf82a864c9b799..8421b903ba6f967366bba0f2d7c7b337510ac1ee
@@@ -1198,12 -1198,14 +1198,12 @@@ create_allocator (int atype, gboolean s
                /* catch */
                clause->flags = MONO_EXCEPTION_CLAUSE_NONE;
                clause->try_len = mono_mb_get_pos (mb) - clause->try_offset;
 -              clause->data.catch_class = mono_class_from_name (mono_defaults.corlib,
 +              clause->data.catch_class = mono_class_load_from_name (mono_defaults.corlib,
                                "System", "OverflowException");
 -              g_assert (clause->data.catch_class);
                clause->handler_offset = mono_mb_get_label (mb);
  
 -              oom_exc_class = mono_class_from_name (mono_defaults.corlib,
 +              oom_exc_class = mono_class_load_from_name (mono_defaults.corlib,
                                "System", "OutOfMemoryException");
 -              g_assert (oom_exc_class);
                ctor = mono_class_get_method_from_name (oom_exc_class, ".ctor", 0);
                g_assert (ctor);
  
        info->d.alloc.gc_name = "sgen";
        info->d.alloc.alloc_type = atype;
  
 -      res = mono_mb_create (mb, csig, 8, info);
 -      mono_mb_free (mb);
  #ifndef DISABLE_JIT
 -      mono_method_get_header (res)->init_locals = FALSE;
 +      mb->init_locals = FALSE;
  #endif
  
 +      res = mono_mb_create (mb, csig, 8, info);
 +      mono_mb_free (mb);
 +
  
        return res;
  }
@@@ -2342,8 -2343,6 +2342,6 @@@ mono_gc_scan_object (void *obj, void *g
  void
  sgen_client_scan_thread_data (void *start_nursery, void *end_nursery, gboolean precise, ScanCopyContext ctx)
  {
-       SgenThreadInfo *info;
        scan_area_arg_start = start_nursery;
        scan_area_arg_end = end_nursery;
  
                                }
                        }
                }
-       } END_FOREACH_THREAD
+       } FOREACH_THREAD_END
  }
  
  /*
index 921398bca1815651b709ca557e495bf5082d3777,ae4cb7d482cf1a0a201687af4a3fc5d3cd22b684..5d08308885afd113ee3e52b0abd8b2eb6ed3ead9
@@@ -187,7 -187,6 +187,6 @@@ mono_threads_end_global_suspend (void
  static void
  dump_threads (void)
  {
-       MonoThreadInfo *info;
        MonoThreadInfo *cur = mono_thread_info_current ();
  
        MOSTLY_ASYNC_SAFE_PRINTF ("STATE CUE CARD: (? means a positive number, usually 1 or 2, * means any number)\n");
  #else
                MOSTLY_ASYNC_SAFE_PRINTF ("--thread %p id %p [%p] state %x  %s\n", info, (void *) mono_thread_info_get_tid (info), (void*)(size_t)info->native_handle, info->thread_state, info == cur ? "GC INITIATOR" : "" );
  #endif
-       } END_FOREACH_THREAD_SAFE
+       } FOREACH_THREAD_SAFE_END
  }
  
  gboolean
@@@ -271,7 -269,7 +269,7 @@@ mono_thread_info_lookup (MonoNativeThre
  {
                MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();
  
-       if (!mono_lls_find (&thread_list, hp, (uintptr_t)id)) {
+       if (!mono_lls_find (&thread_list, hp, (uintptr_t)id, HAZARD_FREE_ASYNC_CTX)) {
                mono_hazard_pointer_clear_all (hp, -1);
                return NULL;
        } 
@@@ -285,7 -283,7 +283,7 @@@ mono_thread_info_insert (MonoThreadInf
  {
        MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();
  
-       if (!mono_lls_insert (&thread_list, hp, (MonoLinkedListSetNode*)info)) {
+       if (!mono_lls_insert (&thread_list, hp, (MonoLinkedListSetNode*)info, HAZARD_FREE_SAFE_CTX)) {
                mono_hazard_pointer_clear_all (hp, -1);
                return FALSE;
        } 
@@@ -301,7 -299,7 +299,7 @@@ mono_thread_info_remove (MonoThreadInf
        gboolean res;
  
        THREADS_DEBUG ("removing info %p\n", info);
-       res = mono_lls_remove (&thread_list, hp, (MonoLinkedListSetNode*)info);
+       res = mono_lls_remove (&thread_list, hp, (MonoLinkedListSetNode*)info, HAZARD_FREE_SAFE_CTX);
        mono_hazard_pointer_clear_all (hp, -1);
        return res;
  }
@@@ -426,7 -424,7 +424,7 @@@ unregister_thread (void *arg
        g_byte_array_free (info->stackdata, /*free_segment=*/TRUE);
  
        /*now it's safe to free the thread info.*/
-       mono_thread_hazardous_free_or_queue (info, free_thread_info, TRUE, FALSE);
+       mono_thread_hazardous_free_or_queue (info, free_thread_info, HAZARD_FREE_MAY_LOCK, HAZARD_FREE_SAFE_CTX);
        mono_thread_small_id_free (small_id);
  }
  
@@@ -637,7 -635,7 +635,7 @@@ mono_threads_init (MonoThreadInfoCallba
        mono_coop_sem_init (&global_suspend_semaphore, 1);
        mono_os_sem_init (&suspend_semaphore, 0);
  
-       mono_lls_init (&thread_list, NULL);
+       mono_lls_init (&thread_list, NULL, HAZARD_FREE_NO_LOCK);
        mono_thread_smr_init ();
        mono_threads_init_platform ();
        mono_threads_init_coop ();
@@@ -1133,35 -1131,35 +1131,35 @@@ sleep_interrupt (gpointer data
  static inline guint32
  sleep_interruptable (guint32 ms, gboolean *alerted)
  {
 -      guint32 start, now, end;
 +      gint64 now, end;
  
        g_assert (INFINITE == G_MAXUINT32);
  
        g_assert (alerted);
        *alerted = FALSE;
  
 -      start = mono_msec_ticks ();
 -
 -      if (start < G_MAXUINT32 - ms) {
 -              end = start + ms;
 -      } else {
 -              /* start + ms would overflow guint32 */
 -              end = G_MAXUINT32;
 -      }
 +      if (ms != INFINITE)
 +              end = mono_100ns_ticks () + (ms * 1000 * 10);
  
        mono_lazy_initialize (&sleep_init, sleep_initialize);
  
        mono_coop_mutex_lock (&sleep_mutex);
  
 -      for (now = mono_msec_ticks (); ms == INFINITE || now - start < ms; now = mono_msec_ticks ()) {
 +      for (;;) {
 +              if (ms != INFINITE) {
 +                      now = mono_100ns_ticks ();
 +                      if (now > end)
 +                              break;
 +              }
 +
                mono_thread_info_install_interrupt (sleep_interrupt, NULL, alerted);
                if (*alerted) {
                        mono_coop_mutex_unlock (&sleep_mutex);
                        return WAIT_IO_COMPLETION;
                }
  
 -              if (ms < INFINITE)
 -                      mono_coop_cond_timedwait (&sleep_cond, &sleep_mutex, end - now);
 +              if (ms != INFINITE)
 +                      mono_coop_cond_timedwait (&sleep_cond, &sleep_mutex, (end - now) / 10 / 1000);
                else
                        mono_coop_cond_wait (&sleep_cond, &sleep_mutex);