@@ -217,7 +217,7 @@ typedef struct MonoAotOptions {
217
217
gboolean use_trampolines_page ;
218
218
gboolean no_instances ;
219
219
// We are collecting inflated methods and emitting non-inflated
220
- gboolean dedup_skip ;
220
+ gboolean dedup ;
221
221
// The name of the assembly for which the AOT module is going to have all deduped methods moved to.
222
222
// When set, we are emitting inflated methods only
223
223
char * dedup_include ;
@@ -295,13 +295,6 @@ typedef struct _UnwindInfoSectionCacheItem {
295
295
} UnwindInfoSectionCacheItem ;
296
296
#endif
297
297
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
-
305
298
typedef struct MonoAotCompile {
306
299
MonoImage * image ;
307
300
GPtrArray * methods ;
@@ -388,6 +381,7 @@ typedef struct MonoAotCompile {
388
381
gboolean llvm ;
389
382
gboolean has_jitted_code ;
390
383
gboolean is_full_aot ;
384
+ gboolean dedup_collect_only ;
391
385
MonoAotFileFlags flags ;
392
386
MonoDynamicStream blob ;
393
387
gboolean blob_closed ;
@@ -422,8 +416,8 @@ typedef struct MonoAotCompile {
422
416
FILE * compiled_methods_outfile ;
423
417
int datafile_offset ;
424
418
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 ;
427
421
} MonoAotCompile ;
428
422
429
423
typedef struct {
@@ -525,12 +519,6 @@ mono_aot_mode_is_hybrid (MonoAotOptions *opts)
525
519
return opts -> mode == MONO_AOT_MODE_HYBRID ;
526
520
}
527
521
528
- static void
529
- dedup_change_phase (MonoAotCompile * acfg , int next_phase )
530
- {
531
- acfg -> dedup_phase = next_phase ;
532
- }
533
-
534
522
static void
535
523
aot_printf (MonoAotCompile * acfg , const gchar * format , ...)
536
524
{
@@ -4312,21 +4300,6 @@ get_method_index (MonoAotCompile *acfg, MonoMethod *method)
4312
4300
return index - 1 ;
4313
4301
}
4314
4302
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
-
4330
4303
static int
4331
4304
add_method_full (MonoAotCompile * acfg , MonoMethod * method , gboolean extra , int depth )
4332
4305
{
@@ -4416,8 +4389,16 @@ add_extra_method_full (MonoAotCompile *acfg, MonoMethod *method, gboolean prefer
4416
4389
mono_error_assert_ok (error );
4417
4390
}
4418
4391
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
+ }
4421
4402
4422
4403
if (acfg -> aot_opts .log_generics )
4423
4404
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
6409
6390
if (callee_cfg ) {
6410
6391
gboolean direct_callable = TRUE;
6411
6392
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 ))
6413
6394
direct_callable = FALSE;
6414
6395
6415
6396
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)
8812
8793
} else if (str_begins_with (arg , "internal-logfile=" )) {
8813
8794
opts -> logfile = g_strdup (arg + strlen ("internal-logfile=" ));
8814
8795
} else if (str_begins_with (arg , "dedup-skip" )) {
8815
- opts -> dedup_skip = TRUE;
8796
+ opts -> dedup = TRUE;
8816
8797
} else if (str_begins_with (arg , "dedup-include=" )) {
8817
8798
opts -> dedup_include = g_strdup (arg + strlen ("dedup-include=" ));
8818
8799
} else if (str_begins_with (arg , "mtriple=" )) {
@@ -14079,7 +14060,6 @@ acfg_create (MonoAssembly *ass, guint32 jit_opts)
14079
14060
acfg -> gshared_instances = g_hash_table_new (NULL , NULL );
14080
14061
acfg -> prefer_instances = g_hash_table_new (NULL , NULL );
14081
14062
acfg -> exported_methods = g_ptr_array_new ();
14082
- acfg -> dedup_phase = DEDUP_NONE ;
14083
14063
mono_os_mutex_init_recursive (& acfg -> mutex );
14084
14064
14085
14065
init_got_info (& acfg -> got_info );
@@ -14726,20 +14706,15 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
14726
14706
14727
14707
acfg = acfg_create (ass , jit_opts );
14728
14708
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;
14737
14712
14738
14713
if (acfg -> aot_opts .logfile ) {
14739
14714
acfg -> logfile = fopen (acfg -> aot_opts .logfile , "a+" );
14740
14715
}
14741
14716
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 ) {
14743
14718
acfg -> compiled_methods_outfile = fopen (acfg -> aot_opts .compiled_methods_outfile , "w+" );
14744
14719
if (!acfg -> compiled_methods_outfile )
14745
14720
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)
14790
14765
if (acfg -> jit_opts & MONO_OPT_GSHAREDVT )
14791
14766
mono_set_generic_sharing_vt_supported (TRUE);
14792
14767
14793
- if (acfg -> dedup_phase != DEDUP_COLLECT )
14768
+ if (! acfg -> dedup_collect_only )
14794
14769
aot_printf (acfg , "Mono Ahead of Time compiler - compiling assembly %s\n" , image -> name );
14795
14770
14796
14771
if (!acfg -> aot_opts .deterministic )
14797
14772
generate_aotid ((guint8 * ) & acfg -> image -> aotid );
14798
14773
14799
14774
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 )
14801
14776
aot_printf (acfg , "AOTID %s\n" , aotid );
14802
14777
g_free (aotid );
14803
14778
@@ -14903,9 +14878,9 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
14903
14878
if (mini_safepoints_enabled ())
14904
14879
acfg -> flags = (MonoAotFileFlags )(acfg -> flags | MONO_AOT_FILE_FLAG_SAFEPOINTS );
14905
14880
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
14907
14882
// Note: Only one such amodule can have this attribute
14908
- if (acfg -> dedup_phase == DEDUP_EMIT )
14883
+ if (ass == dedup_assembly )
14909
14884
acfg -> flags = (MonoAotFileFlags )(acfg -> flags | MONO_AOT_FILE_FLAG_EAGER_LOAD );
14910
14885
14911
14886
if (acfg -> aot_opts .instances_logfile_path ) {
@@ -14997,14 +14972,16 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
14997
14972
return 1 ;
14998
14973
}
14999
14974
15000
- if (acfg -> dedup_phase == DEDUP_EMIT ) {
14975
+ if (ass == dedup_assembly ) {
15001
14976
/* Add collected dedup-able methods */
15002
14977
aot_printf (acfg , "Adding %d dedup-ed methods.\n" , g_hash_table_size (dedup_methods ));
15003
14978
15004
14979
GHashTableIter iter ;
15005
14980
MonoMethod * key ;
15006
14981
MonoMethod * method ;
15007
14982
14983
+ acfg -> dedup_emit_mode = TRUE;
14984
+
15008
14985
g_hash_table_iter_init (& iter , dedup_methods );
15009
14986
while (g_hash_table_iter_next (& iter , (gpointer * )& key , (gpointer * )& method ))
15010
14987
add_method_full (acfg , method , TRUE, 0 );
@@ -15087,7 +15064,7 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
15087
15064
TV_GETTIME (btv );
15088
15065
15089
15066
acfg -> stats .jit_time = GINT64_TO_INT (TV_ELAPSED (atv , btv ));
15090
- if (acfg -> dedup_phase == DEDUP_COLLECT ) {
15067
+ if (acfg -> dedup_collect_only ) {
15091
15068
/* We only collected methods from this assembly */
15092
15069
acfg_free (acfg );
15093
15070
return 0 ;
0 commit comments