Merge pull request #2803 from BrzVlad/feature-conc-pinned-scan
[mono.git] / mono / sgen / sgen-gc.c
index d9bc6485945160ff79c0fa85b20e1cddb4c10e4b..5ec907371f38451a493b5de735ff26c44620c6cf 100644 (file)
  * Copyright 2011 Xamarin, Inc.
  * Copyright (C) 2012 Xamarin Inc
  *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License 2.0 as published by the Free Software Foundation;
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License 2.0 along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  *
  * Important: allocation provides always zeroed memory, having to do
  * a memset after allocation is deadly for performance.
@@ -343,7 +332,6 @@ nursery_canaries_enabled (void)
  * ######################################################################
  */
 MonoCoopMutex gc_mutex;
-gboolean sgen_try_free_some_memory;
 
 #define SCAN_START_SIZE        SGEN_SCAN_START_SIZE
 
@@ -1088,6 +1076,12 @@ finish_gray_stack (int generation, ScanCopyContext ctx)
        if (sgen_client_bridge_need_processing ())
                sgen_client_bridge_reset_data ();
 
+       /*
+        * Mark all strong toggleref objects. This must be done before we walk ephemerons or finalizers
+        * to ensure they see the full set of live objects.
+        */
+       sgen_client_mark_togglerefs (start_addr, end_addr, ctx);
+
        /*
         * Walk the ephemeron tables marking all values with reachable keys. This must be completely done
         * before processing finalizable objects and non-tracking weak links to avoid finalizing/clearing
@@ -1100,8 +1094,6 @@ finish_gray_stack (int generation, ScanCopyContext ctx)
                ++ephemeron_rounds;
        } while (!done_with_ephemerons);
 
-       sgen_client_mark_togglerefs (start_addr, end_addr, ctx);
-
        if (sgen_client_bridge_need_processing ()) {
                /*Make sure the gray stack is empty before we process bridge objects so we get liveness right*/
                sgen_drain_gray_stack (ctx);
@@ -1717,7 +1709,7 @@ major_copy_or_mark_from_roots (size_t *old_next_pin_slot, CopyOrMarkFromRootsMod
 
        sgen_client_pre_collection_checks ();
 
-       if (!concurrent) {
+       if (mode != COPY_OR_MARK_FROM_ROOTS_START_CONCURRENT) {
                /* Remsets are not useful for a major collection */
                remset.clear_cards ();
        }
@@ -3192,11 +3184,7 @@ sgen_gc_lock (void)
 void
 sgen_gc_unlock (void)
 {
-       gboolean try_free = sgen_try_free_some_memory;
-       sgen_try_free_some_memory = FALSE;
        mono_coop_mutex_unlock (&gc_mutex);
-       if (try_free)
-               mono_thread_hazardous_try_free_some ();
 }
 
 void
@@ -3263,8 +3251,6 @@ sgen_restart_world (int generation, GGTimingInfo *timing)
 
        binary_protocol_world_restarted (generation, sgen_timestamp ());
 
-       sgen_try_free_some_memory = TRUE;
-
        if (sgen_client_bridge_need_processing ())
                sgen_client_bridge_processing_finish (generation);