@@ -305,9 +305,7 @@ static void AllocateMemoryForMemPool(MonoMemPool* pool, void *user_data)
305
305
306
306
static void AllocateMemoryForImageMemPool (MonoImage * image , gpointer value , void * user_data )
307
307
{
308
- mono_image_lock (image );
309
308
AllocateMemoryForMemPool (image -> mempool , user_data );
310
- mono_image_unlock (image );
311
309
}
312
310
313
311
static void CopyMemPool (MonoMemPool * pool , SectionIterationContext * context )
@@ -317,26 +315,17 @@ static void CopyMemPool(MonoMemPool *pool, SectionIterationContext *context)
317
315
318
316
static void CopyImageMemPool (MonoImage * image , gpointer value , SectionIterationContext * context )
319
317
{
320
- mono_image_lock (image );
321
318
CopyMemPool (image -> mempool , context );
322
- mono_image_unlock (image );
323
319
}
324
320
325
321
static void AllocateMemoryForImageClassCache (MonoImage * image , gpointer * value , void * user_data )
326
322
{
327
- mono_image_lock (image );
328
-
329
323
AllocateMemoryForSection (user_data , image -> class_cache .table , ((uint8_t * )image -> class_cache .table ) + image -> class_cache .size );
330
- mono_image_unlock (image );
331
324
}
332
325
333
326
static void CopyImageClassCache (MonoImage * image , gpointer value , SectionIterationContext * context )
334
327
{
335
- mono_image_lock (image );
336
-
337
328
CopyHeapSection (context , image -> class_cache .table , ((uint8_t * )image -> class_cache .table ) + image -> class_cache .size );
338
-
339
- mono_image_unlock (image );
340
329
}
341
330
342
331
static void IncrementCountForImageSetMemPoolNumChunks (MonoImageSet * imageSet , void * user_data )
@@ -491,18 +480,7 @@ static void CaptureManagedHeap(MonoManagedHeap* heap, GHashTable* monoImages)
491
480
data .heap = heap ;
492
481
data .monoImages = monoImages ;
493
482
494
- while (TRUE)
495
- {
496
- GC_call_with_alloc_lock (CaptureHeapInfo , & data );
497
- GC_stop_world_external ();
498
-
499
- if (MonoManagedHeapStillValid (heap , monoImages ))
500
- break ;
501
-
502
- GC_start_world_external ();
503
-
504
- FreeMonoManagedHeap (heap );
505
- }
483
+ CaptureHeapInfo (& data );
506
484
507
485
iterationContext .currentSection = heap -> sections ;
508
486
@@ -512,8 +490,6 @@ static void CaptureManagedHeap(MonoManagedHeap* heap, GHashTable* monoImages)
512
490
g_hash_table_foreach (monoImages , (GHFunc )CopyImageMemPool , & iterationContext );
513
491
g_hash_table_foreach (monoImages , (GHFunc )CopyImageClassCache , & iterationContext );
514
492
mono_metadata_image_set_foreach (CopyImageSetMemPool , & iterationContext );
515
-
516
- GC_start_world_external ();
517
493
}
518
494
519
495
static void GCHandleIterationCallback (MonoObject * managedObject , GList * * managedObjects )
@@ -638,6 +614,11 @@ static void CollectMonoImageFromAssembly(MonoAssembly *assembly, void *user_data
638
614
639
615
MonoManagedMemorySnapshot * mono_unity_capture_memory_snapshot ()
640
616
{
617
+ GC_disable ();
618
+ GC_wait_for_gc_completion (TRUE);
619
+
620
+ GC_stop_world_external ();
621
+
641
622
MonoManagedMemorySnapshot * snapshot ;
642
623
snapshot = g_new0 (MonoManagedMemorySnapshot , 1 );
643
624
@@ -656,6 +637,9 @@ MonoManagedMemorySnapshot* mono_unity_capture_memory_snapshot()
656
637
657
638
g_hash_table_destroy (monoImages );
658
639
640
+ GC_start_world_external ();
641
+ GC_enable ();
642
+
659
643
return snapshot ;
660
644
}
661
645
0 commit comments