Merge pull request #3289 from BrzVlad/fix-critical-finalizer
[mono.git] / mono / sgen / sgen-gc.h
index 44092858c112a57d0f83b318d9889aaea745af38..c08502dc55e2e0517bbf59df732619f56ae42748 100644 (file)
@@ -116,16 +116,40 @@ extern guint64 stat_objects_copied_major;
                g_error (__VA_ARGS__);  \
 } } while (0)
 
+#ifndef HOST_WIN32
+# define LOG_TIMESTAMP  \
+       do {    \
+               time_t t;                                                                       \
+               struct tm tod;                                                                  \
+               time(&t);                                                                       \
+               localtime_r(&t, &tod);                                                          \
+               strftime(logTime, sizeof(logTime), "%Y-%m-%d %H:%M:%S", &tod);                  \
+       } while (0)
+#else
+# define LOG_TIMESTAMP  \
+       do {    \
+               time_t t;                                                                       \
+               struct tm *tod;                                                                 \
+               time(&t);                                                                       \
+               tod = localtime(&t);                                                            \
+               strftime(logTime, sizeof(logTime), "%F %T", tod);                               \
+       } while (0)
+#endif
 
 #define SGEN_LOG(level, format, ...) do {      \
        if (G_UNLIKELY ((level) <= SGEN_MAX_DEBUG_LEVEL && (level) <= gc_debug_level)) {        \
-               mono_gc_printf (gc_debug_file, format "\n", ##__VA_ARGS__);     \
+               char logTime[80];                                                               \
+               LOG_TIMESTAMP;                                                                  \
+               mono_gc_printf (gc_debug_file, "%s " format "\n", logTime, ##__VA_ARGS__);      \
 } } while (0)
 
 #define SGEN_COND_LOG(level, cond, format, ...) do {   \
-       if (G_UNLIKELY ((level) <= SGEN_MAX_DEBUG_LEVEL && (level) <= gc_debug_level)) {        \
-               if (cond)       \
-                       mono_gc_printf (gc_debug_file, format "\n", ##__VA_ARGS__);     \
+       if (G_UNLIKELY ((level) <= SGEN_MAX_DEBUG_LEVEL && (level) <= gc_debug_level)) {                \
+               if (cond) {                                                                             \
+                       char logTime[80];                                                               \
+                       LOG_TIMESTAMP;                                                                  \
+                       mono_gc_printf (gc_debug_file, "%s " format "\n", logTime, ##__VA_ARGS__);      \
+               }                                                                                       \
 } } while (0)
 
 extern int gc_debug_level;
@@ -263,6 +287,7 @@ sgen_get_nursery_end (void)
 List of what each bit on of the vtable gc bits means. 
 */
 enum {
+       // When the Java bridge has determined an object is "bridged", it uses these two bits to cache that information.
        SGEN_GC_BIT_BRIDGE_OBJECT = 1,
        SGEN_GC_BIT_BRIDGE_OPAQUE_OBJECT = 2,
        SGEN_GC_BIT_FINALIZER_AWARE = 4,
@@ -278,6 +303,8 @@ void sgen_check_section_scan_starts (GCMemSection *section);
 
 void sgen_conservatively_pin_objects_from (void **start, void **end, void *start_nursery, void *end_nursery, int pin_type);
 
+gboolean sgen_gc_initialized (void);
+
 /* Keep in sync with description_for_type() in sgen-internal.c! */
 enum {
        INTERNAL_MEM_PIN_QUEUE,
@@ -315,6 +342,8 @@ enum {
        INTERNAL_MEM_CARDTABLE_MOD_UNION,
        INTERNAL_MEM_BINARY_PROTOCOL,
        INTERNAL_MEM_TEMPORARY,
+       INTERNAL_MEM_LOG_ENTRY,
+       INTERNAL_MEM_COMPLEX_DESCRIPTORS,
        INTERNAL_MEM_FIRST_CLIENT
 };
 
@@ -431,9 +460,9 @@ void* sgen_alloc_internal_dynamic (size_t size, int type, gboolean assert_on_fai
 void sgen_free_internal_dynamic (void *addr, size_t size, int type);
 
 void sgen_pin_stats_enable (void);
-void sgen_pin_stats_register_object (GCObject *obj, size_t size);
+void sgen_pin_stats_register_object (GCObject *obj, int generation);
 void sgen_pin_stats_register_global_remset (GCObject *obj);
-void sgen_pin_stats_print_class_stats (void);
+void sgen_pin_stats_report (void);
 
 void sgen_sort_addresses (void **array, size_t size);
 void sgen_add_to_global_remset (gpointer ptr, GCObject *obj);
@@ -570,6 +599,7 @@ sgen_update_reference (GCObject **p, GCObject *o, gboolean allow_null)
 
 typedef void (*sgen_cardtable_block_callback) (mword start, mword size);
 void sgen_major_collector_iterate_live_block_ranges (sgen_cardtable_block_callback callback);
+void sgen_major_collector_iterate_block_ranges (sgen_cardtable_block_callback callback);
 
 typedef enum {
        ITERATE_OBJECTS_SWEEP = 1,
@@ -624,6 +654,7 @@ struct _SgenMajorCollector {
        void (*pin_major_object) (GCObject *obj, SgenGrayQueue *queue);
        void (*scan_card_table) (CardTableScanType scan_type, ScanCopyContext ctx);
        void (*iterate_live_block_ranges) (sgen_cardtable_block_callback callback);
+       void (*iterate_block_ranges) (sgen_cardtable_block_callback callback);
        void (*update_cardtable_mod_union) (void);
        void (*init_to_space) (void);
        void (*sweep) (void);
@@ -782,7 +813,7 @@ void sgen_process_fin_stage_entries (void);
 gboolean sgen_have_pending_finalizers (void);
 void sgen_object_register_for_finalization (GCObject *obj, void *user_data);
 
-int sgen_gather_finalizers_if (SgenObjectPredicateFunc predicate, void *user_data, GCObject **out_array, int out_size);
+void sgen_finalize_if (SgenObjectPredicateFunc predicate, void *user_data, volatile gboolean *suspend);
 void sgen_remove_finalizers_if (SgenObjectPredicateFunc predicate, void *user_data, int generation);
 
 void sgen_register_disappearing_link (GCObject *obj, void **link, gboolean track, gboolean in_gc);
@@ -802,7 +833,7 @@ void sgen_set_pinned_from_failed_allocation (mword objsize);
 
 void sgen_ensure_free_space (size_t size, int generation);
 void sgen_gc_collect (int generation);
-void sgen_perform_collection (size_t requested_size, int generation_to_collect, const char *reason, gboolean wait_to_finish);
+void sgen_perform_collection (size_t requested_size, int generation_to_collect, const char *reason, gboolean wait_to_finish, gboolean stw);
 
 int sgen_gc_collection_count (int generation);
 /* FIXME: what exactly does this return? */
@@ -811,16 +842,8 @@ size_t sgen_gc_get_total_heap_allocation (void);
 
 /* STW */
 
-typedef struct {
-       int generation;
-       const char *reason;
-       gboolean is_overflow;
-       gint64 total_time;
-       gint64 stw_time;
-} GGTimingInfo;
-
 void sgen_stop_world (int generation);
-void sgen_restart_world (int generation, GGTimingInfo *timing);
+void sgen_restart_world (int generation);
 gboolean sgen_is_world_stopped (void);
 
 gboolean sgen_set_allow_synchronous_major (gboolean flag);
@@ -840,6 +863,7 @@ struct _LOSObject {
 
 extern LOSObject *los_object_list;
 extern mword los_memory_usage;
+extern mword los_memory_usage_total;
 
 void sgen_los_free_object (LOSObject *obj);
 void* sgen_los_alloc_large_inner (GCVTable vtable, size_t size);
@@ -951,6 +975,8 @@ extern int default_nursery_size;
 extern guint32 tlab_size;
 extern NurseryClearPolicy nursery_clear_policy;
 extern gboolean sgen_try_free_some_memory;
+extern mword total_promoted_size;
+extern mword total_allocated_major;
 
 extern MonoCoopMutex gc_mutex;