@@ -217,7 +217,7 @@ typedef struct MonoAotOptions {
217217 gboolean use_trampolines_page ;
218218 gboolean no_instances ;
219219 // We are collecting inflated methods and emitting non-inflated
220- gboolean dedup_skip ;
220+ gboolean dedup ;
221221 // The name of the assembly for which the AOT module is going to have all deduped methods moved to.
222222 // When set, we are emitting inflated methods only
223223 char * dedup_include ;
@@ -295,13 +295,6 @@ typedef struct _UnwindInfoSectionCacheItem {
295295} UnwindInfoSectionCacheItem ;
296296#endif
297297
298- typedef enum {
299- DEDUP_NONE , // dedup is turned off
300- DEDUP_SKIP , // dedup is on, dedup assembly is not provided
301- DEDUP_COLLECT , // dedup is on, this assembly is not the dedup image, so just collect the methods
302- DEDUP_EMIT // dedup is on, this assembly is the dedup image, emit collected methods
303- } DedupPhase ;
304-
305298typedef struct MonoAotCompile {
306299 MonoImage * image ;
307300 GPtrArray * methods ;
@@ -388,6 +381,7 @@ typedef struct MonoAotCompile {
388381 gboolean llvm ;
389382 gboolean has_jitted_code ;
390383 gboolean is_full_aot ;
384+ gboolean dedup_collect_only ;
391385 MonoAotFileFlags flags ;
392386 MonoDynamicStream blob ;
393387 gboolean blob_closed ;
@@ -422,8 +416,8 @@ typedef struct MonoAotCompile {
422416 FILE * compiled_methods_outfile ;
423417 int datafile_offset ;
424418 int gc_name_offset ;
425-
426- DedupPhase dedup_phase ;
419+ // In this mode, we are emitting dedupable methods that we encounter
420+ gboolean dedup_emit_mode ;
427421} MonoAotCompile ;
428422
429423typedef struct {
@@ -525,12 +519,6 @@ mono_aot_mode_is_hybrid (MonoAotOptions *opts)
525519 return opts -> mode == MONO_AOT_MODE_HYBRID ;
526520}
527521
528- static void
529- dedup_change_phase (MonoAotCompile * acfg , int next_phase )
530- {
531- acfg -> dedup_phase = next_phase ;
532- }
533-
534522static void
535523aot_printf (MonoAotCompile * acfg , const gchar * format , ...)
536524{
@@ -4312,21 +4300,6 @@ get_method_index (MonoAotCompile *acfg, MonoMethod *method)
43124300 return index - 1 ;
43134301}
43144302
4315- static gboolean
4316- collect_dedup_method (MonoAotCompile * acfg , MonoMethod * method )
4317- {
4318- // Check if the dedup is enabled, and if the current method can be deduplicated
4319- if ((acfg -> dedup_phase == DEDUP_SKIP || acfg -> dedup_phase == DEDUP_COLLECT ) && mono_aot_can_dedup (method )) {
4320- // Remember for later
4321- if (acfg -> dedup_phase == DEDUP_COLLECT && !g_hash_table_lookup (dedup_methods , method ))
4322- g_hash_table_insert (dedup_methods , method , method );
4323- return TRUE;
4324- }
4325- return FALSE;
4326- }
4327-
4328-
4329-
43304303static int
43314304add_method_full (MonoAotCompile * acfg , MonoMethod * method , gboolean extra , int depth )
43324305{
@@ -4416,8 +4389,16 @@ add_extra_method_full (MonoAotCompile *acfg, MonoMethod *method, gboolean prefer
44164389 mono_error_assert_ok (error );
44174390 }
44184391
4419- if (collect_dedup_method (acfg , method ))
4420- return ;
4392+ if ((acfg -> aot_opts .dedup || acfg -> aot_opts .dedup_include ) && mono_aot_can_dedup (method )) {
4393+ if (acfg -> aot_opts .dedup ) {
4394+ /* Don't emit instances */
4395+ return ;
4396+ } else if (!acfg -> dedup_emit_mode ) {
4397+ /* Remember for later */
4398+ if (!g_hash_table_lookup (dedup_methods , method ))
4399+ g_hash_table_insert (dedup_methods , method , method );
4400+ }
4401+ }
44214402
44224403 if (acfg -> aot_opts .log_generics )
44234404 aot_printf (acfg , "%*sAdding method %s.\n" , depth , "" , mono_method_get_full_name (method ));
@@ -6409,7 +6390,7 @@ is_direct_callable (MonoAotCompile *acfg, MonoMethod *method, MonoJumpInfo *patc
64096390 if (callee_cfg ) {
64106391 gboolean direct_callable = TRUE;
64116392
6412- if (direct_callable && acfg -> dedup_phase != DEDUP_NONE && mono_aot_can_dedup (patch_info -> data .method ))
6393+ if (direct_callable && ( acfg -> aot_opts . dedup || acfg -> aot_opts . dedup_include ) && mono_aot_can_dedup (patch_info -> data .method ))
64136394 direct_callable = FALSE;
64146395
64156396 if (direct_callable && !acfg -> llvm && !(!callee_cfg -> has_got_slots && mono_class_is_before_field_init (callee_cfg -> method -> klass )))
@@ -8812,7 +8793,7 @@ mono_aot_parse_options (const char *aot_options, MonoAotOptions *opts)
88128793 } else if (str_begins_with (arg , "internal-logfile=" )) {
88138794 opts -> logfile = g_strdup (arg + strlen ("internal-logfile=" ));
88148795 } else if (str_begins_with (arg , "dedup-skip" )) {
8815- opts -> dedup_skip = TRUE;
8796+ opts -> dedup = TRUE;
88168797 } else if (str_begins_with (arg , "dedup-include=" )) {
88178798 opts -> dedup_include = g_strdup (arg + strlen ("dedup-include=" ));
88188799 } else if (str_begins_with (arg , "mtriple=" )) {
@@ -14079,7 +14060,6 @@ acfg_create (MonoAssembly *ass, guint32 jit_opts)
1407914060 acfg -> gshared_instances = g_hash_table_new (NULL , NULL );
1408014061 acfg -> prefer_instances = g_hash_table_new (NULL , NULL );
1408114062 acfg -> exported_methods = g_ptr_array_new ();
14082- acfg -> dedup_phase = DEDUP_NONE ;
1408314063 mono_os_mutex_init_recursive (& acfg -> mutex );
1408414064
1408514065 init_got_info (& acfg -> got_info );
@@ -14726,20 +14706,15 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
1472614706
1472714707 acfg = acfg_create (ass , jit_opts );
1472814708 memcpy (& acfg -> aot_opts , aot_options , sizeof (MonoAotOptions ));
14729- if (acfg -> aot_opts .dedup_skip || acfg -> aot_opts .dedup_include ) {
14730- if (acfg -> aot_opts .dedup_skip )
14731- dedup_change_phase (acfg , DEDUP_SKIP );
14732- else if (acfg -> aot_opts .dedup_include && ass != dedup_assembly )
14733- dedup_change_phase (acfg , DEDUP_COLLECT );
14734- else
14735- dedup_change_phase (acfg , DEDUP_EMIT );
14736- }
14709+
14710+ if (acfg -> aot_opts .dedup_include && ass != dedup_assembly )
14711+ acfg -> dedup_collect_only = TRUE;
1473714712
1473814713 if (acfg -> aot_opts .logfile ) {
1473914714 acfg -> logfile = fopen (acfg -> aot_opts .logfile , "a+" );
1474014715 }
1474114716
14742- if (acfg -> aot_opts .compiled_methods_outfile && acfg -> dedup_phase != DEDUP_COLLECT ) {
14717+ if (acfg -> aot_opts .compiled_methods_outfile && ! acfg -> dedup_collect_only ) {
1474314718 acfg -> compiled_methods_outfile = fopen (acfg -> aot_opts .compiled_methods_outfile , "w+" );
1474414719 if (!acfg -> compiled_methods_outfile )
1474514720 aot_printerrf (acfg , "Unable to open compiled-methods-outfile specified file %s\n" , acfg -> aot_opts .compiled_methods_outfile );
@@ -14790,14 +14765,14 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
1479014765 if (acfg -> jit_opts & MONO_OPT_GSHAREDVT )
1479114766 mono_set_generic_sharing_vt_supported (TRUE);
1479214767
14793- if (acfg -> dedup_phase != DEDUP_COLLECT )
14768+ if (! acfg -> dedup_collect_only )
1479414769 aot_printf (acfg , "Mono Ahead of Time compiler - compiling assembly %s\n" , image -> name );
1479514770
1479614771 if (!acfg -> aot_opts .deterministic )
1479714772 generate_aotid ((guint8 * ) & acfg -> image -> aotid );
1479814773
1479914774 char * aotid = mono_guid_to_string (acfg -> image -> aotid );
14800- if (acfg -> dedup_phase != DEDUP_COLLECT && !acfg -> aot_opts .deterministic )
14775+ if (! acfg -> dedup_collect_only && !acfg -> aot_opts .deterministic )
1480114776 aot_printf (acfg , "AOTID %s\n" , aotid );
1480214777 g_free (aotid );
1480314778
@@ -14903,9 +14878,9 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
1490314878 if (mini_safepoints_enabled ())
1490414879 acfg -> flags = (MonoAotFileFlags )(acfg -> flags | MONO_AOT_FILE_FLAG_SAFEPOINTS );
1490514880
14906- // The methods in dedup AOT module must be available on runtime startup
14881+ // The methods in dedup-emit amodules must be available on runtime startup
1490714882 // Note: Only one such amodule can have this attribute
14908- if (acfg -> dedup_phase == DEDUP_EMIT )
14883+ if (ass == dedup_assembly )
1490914884 acfg -> flags = (MonoAotFileFlags )(acfg -> flags | MONO_AOT_FILE_FLAG_EAGER_LOAD );
1491014885
1491114886 if (acfg -> aot_opts .instances_logfile_path ) {
@@ -14997,14 +14972,16 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
1499714972 return 1 ;
1499814973 }
1499914974
15000- if (acfg -> dedup_phase == DEDUP_EMIT ) {
14975+ if (ass == dedup_assembly ) {
1500114976 /* Add collected dedup-able methods */
1500214977 aot_printf (acfg , "Adding %d dedup-ed methods.\n" , g_hash_table_size (dedup_methods ));
1500314978
1500414979 GHashTableIter iter ;
1500514980 MonoMethod * key ;
1500614981 MonoMethod * method ;
1500714982
14983+ acfg -> dedup_emit_mode = TRUE;
14984+
1500814985 g_hash_table_iter_init (& iter , dedup_methods );
1500914986 while (g_hash_table_iter_next (& iter , (gpointer * )& key , (gpointer * )& method ))
1501014987 add_method_full (acfg , method , TRUE, 0 );
@@ -15087,7 +15064,7 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
1508715064 TV_GETTIME (btv );
1508815065
1508915066 acfg -> stats .jit_time = GINT64_TO_INT (TV_ELAPSED (atv , btv ));
15090- if (acfg -> dedup_phase == DEDUP_COLLECT ) {
15067+ if (acfg -> dedup_collect_only ) {
1509115068 /* We only collected methods from this assembly */
1509215069 acfg_free (acfg );
1509315070 return 0 ;
0 commit comments