@@ -20,6 +20,32 @@ typedef struct CollectMetadataContext
20
20
MonoMetadataSnapshot * metadata ;
21
21
} CollectMetadataContext ;
22
22
23
+ typedef struct AllDomainAssembliesForeachData
24
+ {
25
+ MonoDomainAssemblyFunc func ;
26
+ void * user_data ;
27
+
28
+ } AllDomainAssembliesForeachData ;
29
+
30
+ static void AllDomainAssembliesForeachHelper (MonoDomain * domain , void * user_data )
31
+ {
32
+ AllDomainAssembliesForeachData * data = (AllDomainAssembliesForeachData * )user_data ;
33
+
34
+ mono_domain_assembly_foreach (domain , data -> func , data -> user_data );
35
+ }
36
+
37
+ static void AllDomainAssembliesForeach (MonoDomainAssemblyFunc func , void * user_data )
38
+ {
39
+ AllDomainAssembliesForeachData data ;
40
+
41
+ data .func = func ;
42
+ data .user_data = user_data ;
43
+
44
+ AllDomainAssembliesForeachHelper (mono_domain_get (), & data );
45
+
46
+ // mono_domain_foreach(AllDomainAssembliesForeachHelper, &data);
47
+ }
48
+
23
49
static void ContextInsertClass (CollectMetadataContext * context , MonoClass * klass )
24
50
{
25
51
if (klass -> inited && g_hash_table_lookup (context -> allTypes , klass ) == NULL )
@@ -56,27 +82,74 @@ static void CollectGenericClass(gpointer value, gpointer user_data)
56
82
ContextInsertClass (context , genericClass -> cached_class );
57
83
}
58
84
59
- static void CollectAssemblyMetaData (MonoAssembly * assembly , void * user_data )
85
+ MonoClass * MonoLookupDynamiClass (MonoImage * image , guint32 token , MonoGenericContext * context , MonoError * error )
86
+ {
87
+ MonoClass * handle_class ;
88
+ error_init (error );
89
+ return (MonoClass * )mono_reflection_lookup_dynamic_token (image , token , FALSE, & handle_class , context , error );
90
+ }
91
+
92
+ static void CollectImageMetaData (MonoImage * image , CollectMetadataContext * context )
60
93
{
61
94
int i ;
62
- CollectMetadataContext * context = (CollectMetadataContext * )user_data ;
63
- MonoImage * image = mono_assembly_get_image (assembly );
64
95
MonoTableInfo * tdef = & image -> tables [MONO_TABLE_TYPEDEF ];
65
96
66
- for ( i = 0 ; i < tdef -> rows - 1 ; ++ i )
97
+ if ( image -> module_count > 0 )
67
98
{
68
- MonoClass * klass = mono_class_get (image , (i + 2 ) | MONO_TOKEN_TYPE_DEF );
69
- ContextInsertClass (context , klass );
99
+ for (i = 0 ; i < image -> module_count ; ++ i )
100
+ {
101
+ MonoImage * moduleImage = image -> modules [i ];
102
+
103
+ if (moduleImage )
104
+ CollectImageMetaData (moduleImage , context );
105
+ }
106
+ }
107
+
108
+ if (image -> dynamic )
109
+ {
110
+ MonoDynamicImage * dynamicImage = (MonoDynamicImage * )image ;
111
+ GList * types = g_hash_table_get_keys (dynamicImage -> typeref );
112
+ GList * type ;
113
+
114
+ for (type = types ; type != NULL ; type = type -> next )
115
+ {
116
+ MonoType * monoType = (MonoType * )type -> data ;
117
+ MonoClass * klass = mono_type_get_class (monoType );
118
+
119
+ if (klass )
120
+ ContextInsertClass (context , klass );
121
+ }
122
+ }
123
+
124
+ for (i = 1 ; i < tdef -> rows ; ++ i )
125
+ {
126
+ MonoClass * klass ;
127
+ MonoError error ;
128
+
129
+ guint32 token = (i + 1 ) | MONO_TOKEN_TYPE_DEF ;
130
+
131
+ klass = mono_class_get_checked (image , token , & error );
132
+
133
+ if (klass )
134
+ ContextInsertClass (context , klass );
70
135
}
71
136
72
137
if (image -> array_cache )
73
- g_hash_table_foreach (image -> array_cache , CollectHashMapListClasses , user_data );
138
+ g_hash_table_foreach (image -> array_cache , CollectHashMapListClasses , context );
74
139
75
140
if (image -> szarray_cache )
76
- g_hash_table_foreach (image -> szarray_cache , CollectHashMapClass , user_data );
141
+ g_hash_table_foreach (image -> szarray_cache , CollectHashMapClass , context );
77
142
78
143
if (image -> ptr_cache )
79
- g_hash_table_foreach (image -> ptr_cache , CollectHashMapClass , user_data );
144
+ g_hash_table_foreach (image -> ptr_cache , CollectHashMapClass , context );
145
+ }
146
+
147
+ static void CollectAssemblyMetaData (MonoAssembly * assembly , void * user_data )
148
+ {
149
+ MonoImage * image = mono_assembly_get_image (assembly );
150
+ CollectMetadataContext * context = (CollectMetadataContext * )user_data ;
151
+
152
+ CollectImageMetaData (image , context );
80
153
}
81
154
82
155
static int FindClassIndex (GHashTable * hashTable , MonoClass * klass )
@@ -169,7 +242,7 @@ static void CollectMetadata(MonoMetadataSnapshot* metadata)
169
242
context .currentIndex = 0 ;
170
243
context .metadata = metadata ;
171
244
172
- mono_assembly_foreach (( GFunc ) CollectAssemblyMetaData , & context );
245
+ AllDomainAssembliesForeach ( CollectAssemblyMetaData , & context );
173
246
174
247
mono_metadata_generic_class_foreach (CollectGenericClass , & context );
175
248
@@ -251,7 +324,8 @@ static void IncrementCountForImageMemPoolNumChunks(MonoAssembly *assembly, void
251
324
static int MonoImagesMemPoolNumChunks ()
252
325
{
253
326
int count = 0 ;
254
- mono_assembly_foreach ((GFunc )IncrementCountForImageMemPoolNumChunks , & count );
327
+
328
+ AllDomainAssembliesForeach ((GFunc )IncrementCountForImageMemPoolNumChunks , & count );
255
329
return count ;
256
330
}
257
331
@@ -291,7 +365,7 @@ static void MonoImagesCountCallback(MonoAssembly *assembly, void *user_data)
291
365
static int MonoImagesCount ()
292
366
{
293
367
int count = 0 ;
294
- mono_assembly_foreach ((GFunc )MonoImagesCountCallback , & count );
368
+ AllDomainAssembliesForeach ((GFunc )MonoImagesCountCallback , & count );
295
369
return count ;
296
370
}
297
371
@@ -370,9 +444,9 @@ static void* CaptureHeapInfo(void* monoManagedHeap)
370
444
mono_mempool_foreach_block (domain -> mp , AllocateMemoryForMemPoolChunk , & iterationContext );
371
445
mono_domain_unlock (domain );
372
446
// Allocate memory for each image mem pool chunk
373
- mono_assembly_foreach ((GFunc )AllocateMemoryForImageMemPool , & iterationContext );
447
+ AllDomainAssembliesForeach ((GFunc )AllocateMemoryForImageMemPool , & iterationContext );
374
448
// Allocate memory for each image->class_cache hash table.
375
- mono_assembly_foreach ((GFunc )AllocateMemoryForImageClassCache , & iterationContext );
449
+ AllDomainAssembliesForeach ((GFunc )AllocateMemoryForImageClassCache , & iterationContext );
376
450
// Allocate memory for each image->class_cache hash table.
377
451
mono_metadata_image_set_foreach ((GFunc )AllocateMemoryForImageSetMemPool , & iterationContext );
378
452
@@ -469,8 +543,8 @@ static void CaptureManagedHeap(MonoManagedHeap* heap)
469
543
GC_foreach_heap_section (& iterationContext , CopyHeapSection );
470
544
mono_mempool_foreach_block (rootDomain -> mp , CopyMemPoolChunk , & iterationContext );
471
545
mono_mempool_foreach_block (domain -> mp , CopyMemPoolChunk , & iterationContext );
472
- mono_assembly_foreach ((GFunc )CopyImageMemPool , & iterationContext );
473
- mono_assembly_foreach ((GFunc )CopyImageClassCache , & iterationContext );
546
+ AllDomainAssembliesForeach ((GFunc )CopyImageMemPool , & iterationContext );
547
+ AllDomainAssembliesForeach ((GFunc )CopyImageClassCache , & iterationContext );
474
548
mono_metadata_image_set_foreach ((GFunc )CopyImageSetMemPool , & iterationContext );
475
549
476
550
GC_start_world_external ();
@@ -546,7 +620,7 @@ static void VerifySnapshot(MonoManagedMemorySnapshot* snapshot)
546
620
547
621
if (!ManagedHeapContainsAddress (& snapshot -> heap , type -> typeInfoAddress ))
548
622
{
549
- fprintf (file , "The memory for type '%s' @ 0x%016X is not the part the snapshot.\n" , type -> name , type -> typeInfoAddress );
623
+ fprintf (file , "The memory for type '%s' @ 0x%016llX is not the part the snapshot.\n" , type -> name , type -> typeInfoAddress );
550
624
}
551
625
}
552
626
0 commit comments