@@ -629,59 +629,62 @@ bool Ref_Initialize()
629
629
if (pBuckets == NULL )
630
630
return false ;
631
631
632
- ZeroMemory (pBuckets,
633
- INITIAL_HANDLE_TABLE_ARRAY_SIZE * sizeof (HandleTableBucket *));
632
+ ZeroMemory (pBuckets, INITIAL_HANDLE_TABLE_ARRAY_SIZE * sizeof (HandleTableBucket *));
634
633
635
- // Crate the first bucket
636
- HandleTableBucket * pBucket = new (nothrow) HandleTableBucket;
637
- if (pBucket != NULL )
634
+ g_gcGlobalHandleStore = new (nothrow) GCHandleStore ();
635
+ if (g_gcGlobalHandleStore == NULL )
638
636
{
639
- pBucket->HandleTableIndex = 0 ;
637
+ delete[] pBuckets;
638
+ return false ;
639
+ }
640
640
641
- int n_slots = getNumberOfSlots ();
641
+ // Initialize the bucket in the global handle store
642
+ HandleTableBucket* pBucket = &g_gcGlobalHandleStore->_underlyingBucket ;
642
643
643
- HandleTableBucketHolder bucketHolder ( pBucket, n_slots) ;
644
+ pBucket-> HandleTableIndex = 0 ;
644
645
645
- // create the handle table set for the first bucket
646
- pBucket->pTable = new (nothrow) HHANDLETABLE[n_slots];
647
- if (pBucket->pTable == NULL )
648
- goto CleanupAndFail;
646
+ int n_slots = getNumberOfSlots ();
649
647
650
- ZeroMemory (pBucket->pTable ,
651
- n_slots * sizeof (HHANDLETABLE));
652
- for (int uCPUindex = 0 ; uCPUindex < n_slots; uCPUindex++)
653
- {
654
- pBucket->pTable [uCPUindex] = HndCreateHandleTable (s_rgTypeFlags, _countof (s_rgTypeFlags), ADIndex (1 ));
655
- if (pBucket->pTable [uCPUindex] == NULL )
656
- goto CleanupAndFail;
648
+ HandleTableBucketHolder bucketHolder (pBucket, n_slots);
657
649
658
- HndSetHandleTableIndex (pBucket->pTable [uCPUindex], 0 );
659
- }
650
+ // create the handle table set for the first bucket
651
+ pBucket->pTable = new (nothrow) HHANDLETABLE[n_slots];
652
+ if (pBucket->pTable == NULL )
653
+ goto CleanupAndFail;
660
654
661
- pBuckets[0 ] = pBucket;
662
- bucketHolder.SuppressRelease ();
655
+ ZeroMemory (pBucket->pTable ,
656
+ n_slots * sizeof (HHANDLETABLE));
657
+ for (int uCPUindex = 0 ; uCPUindex < n_slots; uCPUindex++)
658
+ {
659
+ pBucket->pTable [uCPUindex] = HndCreateHandleTable (s_rgTypeFlags, _countof (s_rgTypeFlags), ADIndex (1 ));
660
+ if (pBucket->pTable [uCPUindex] == NULL )
661
+ goto CleanupAndFail;
663
662
664
- g_HandleTableMap.pBuckets = pBuckets;
665
- g_HandleTableMap.dwMaxIndex = INITIAL_HANDLE_TABLE_ARRAY_SIZE;
666
- g_HandleTableMap.pNext = NULL ;
663
+ HndSetHandleTableIndex (pBucket->pTable [uCPUindex], 0 );
664
+ }
667
665
668
- g_gcGlobalHandleStore = new (nothrow) GCHandleStore (g_HandleTableMap.pBuckets [0 ]);
669
- if (g_gcGlobalHandleStore == NULL )
670
- goto CleanupAndFail;
666
+ pBuckets[0 ] = pBucket;
667
+ bucketHolder.SuppressRelease ();
671
668
672
- // Allocate contexts used during dependent handle promotion scanning. There's one of these for every GC
673
- // heap since they're scanned in parallel.
674
- g_pDependentHandleContexts = new (nothrow) DhContext[n_slots];
675
- if (g_pDependentHandleContexts == NULL )
676
- goto CleanupAndFail;
669
+ g_HandleTableMap.pBuckets = pBuckets;
670
+ g_HandleTableMap.dwMaxIndex = INITIAL_HANDLE_TABLE_ARRAY_SIZE;
671
+ g_HandleTableMap.pNext = NULL ;
677
672
678
- return true ;
679
- }
673
+ // Allocate contexts used during dependent handle promotion scanning. There's one of these for every GC
674
+ // heap since they're scanned in parallel.
675
+ g_pDependentHandleContexts = new (nothrow) DhContext[n_slots];
676
+ if (g_pDependentHandleContexts == NULL )
677
+ goto CleanupAndFail;
680
678
679
+ return true ;
681
680
682
681
CleanupAndFail:
683
682
if (pBuckets != NULL )
684
683
delete[] pBuckets;
684
+
685
+ if (g_gcGlobalHandleStore != NULL )
686
+ delete g_gcGlobalHandleStore;
687
+
685
688
return false ;
686
689
}
687
690
@@ -701,9 +704,6 @@ void Ref_Shutdown()
701
704
// don't destroy any of the indexed handle tables; they should
702
705
// be destroyed externally.
703
706
704
- // destroy the global handle table bucket tables
705
- Ref_DestroyHandleTableBucket (g_HandleTableMap.pBuckets [0 ]);
706
-
707
707
// destroy the handle table bucket array
708
708
HandleTableMap *walk = &g_HandleTableMap;
709
709
while (walk) {
@@ -721,9 +721,22 @@ void Ref_Shutdown()
721
721
}
722
722
723
723
#ifndef FEATURE_REDHAWK
724
- // ATTENTION: interface changed
725
- // Note: this function called only from AppDomain::Init()
726
- HandleTableBucket *Ref_CreateHandleTableBucket (ADIndex uADIndex)
724
+ HandleTableBucket* Ref_CreateHandleTableBucket (void * context)
725
+ {
726
+ HandleTableBucket* result = new (nothrow) HandleTableBucket ();
727
+ if (result == nullptr )
728
+ return nullptr ;
729
+
730
+ if (!Ref_InitializeHandleTableBucket (result, context))
731
+ {
732
+ delete result;
733
+ return nullptr ;
734
+ }
735
+
736
+ return result;
737
+ }
738
+
739
+ bool Ref_InitializeHandleTableBucket (HandleTableBucket* bucket, void * context)
727
740
{
728
741
CONTRACTL
729
742
{
@@ -733,26 +746,24 @@ HandleTableBucket *Ref_CreateHandleTableBucket(ADIndex uADIndex)
733
746
}
734
747
CONTRACTL_END;
735
748
736
- HandleTableBucket *result = NULL ;
737
- HandleTableMap *walk;
738
-
739
- walk = &g_HandleTableMap;
749
+ HandleTableBucket *result = bucket;
750
+ HandleTableMap *walk = &g_HandleTableMap;
751
+
740
752
HandleTableMap *last = NULL ;
741
753
uint32_t offset = 0 ;
742
754
743
- result = new HandleTableBucket;
744
755
result->pTable = NULL ;
745
756
746
757
// create handle table set for the bucket
747
758
int n_slots = getNumberOfSlots ();
748
759
749
760
HandleTableBucketHolder bucketHolder (result, n_slots);
750
761
751
- result->pTable = new HHANDLETABLE [ n_slots ];
752
- ZeroMemory (result->pTable , n_slots * sizeof (HHANDLETABLE));
762
+ result->pTable = new HHANDLETABLE[ n_slots];
763
+ ZeroMemory (result->pTable , n_slots * sizeof (HHANDLETABLE));
753
764
754
765
for (int uCPUindex=0 ; uCPUindex < n_slots; uCPUindex++) {
755
- result->pTable [uCPUindex] = HndCreateHandleTable (s_rgTypeFlags, _countof (s_rgTypeFlags), uADIndex );
766
+ result->pTable [uCPUindex] = HndCreateHandleTable (s_rgTypeFlags, _countof (s_rgTypeFlags), ADIndex ((DWORD)( uintptr_t )context) );
756
767
if (!result->pTable [uCPUindex])
757
768
COMPlusThrowOM ();
758
769
}
@@ -769,7 +780,7 @@ HandleTableBucket *Ref_CreateHandleTableBucket(ADIndex uADIndex)
769
780
if (Interlocked::CompareExchangePointer (&walk->pBuckets [i], result, NULL ) == 0 ) {
770
781
// Get a free slot.
771
782
bucketHolder.SuppressRelease ();
772
- return result ;
783
+ return true ;
773
784
}
774
785
}
775
786
}
0 commit comments