@@ -59,7 +59,7 @@ public BridgeProcessing (MarkCrossReferencesArgs* args)
5959 public void Process ( )
6060 {
6161 PrepareForJavaCollection ( ) ;
62- BridgeProcessingJniHelper . Trigger ( ) ;
62+ BridgeProcessingJniHelper . TriggerJavaGC ( ) ;
6363 CleanupAfterJavaCollection ( ) ;
6464 s_logger ? . LogGcSummary ( crossRefs ) ;
6565 }
@@ -133,7 +133,7 @@ void AddCircularReferences (ref StronglyConnectedComponent scc)
133133 var prevRef = new JniObjectReference ( prev ->ControlBlock ->Handle , JniObjectReferenceType . Global ) ;
134134 var nextRef = new JniObjectReference ( next ->ControlBlock ->Handle , JniObjectReferenceType . Global ) ;
135135
136- bool referenceAdded = AddReference ( prevRef , nextRef ) ;
136+ bool referenceAdded = BridgeProcessingJniHelper . AddReference ( prevRef , nextRef , s_logger ) ;
137137 if ( ! referenceAdded ) {
138138 throw new InvalidOperationException ( "Failed to add reference between objects in a strongly connected component" ) ;
139139 }
@@ -148,7 +148,7 @@ void AddCrossReference (nuint sourceIndex, nuint destIndex)
148148 var ( fromRef , fromContextPtr ) = SelectCrossReferenceTarget ( sourceIndex ) ;
149149 var ( toRef , _) = SelectCrossReferenceTarget ( destIndex ) ;
150150
151- if ( AddReference ( fromRef , toRef ) && fromContextPtr != IntPtr . Zero ) {
151+ if ( BridgeProcessingJniHelper . AddReference ( fromRef , toRef , s_logger ) && fromContextPtr != IntPtr . Zero ) {
152152 HandleContext * fromContext = ( HandleContext * ) fromContextPtr ;
153153 fromContext ->ControlBlock ->RefsAdded = 1 ;
154154 }
@@ -176,37 +176,6 @@ void AddCrossReference (nuint sourceIndex, nuint destIndex)
176176 return ( reference , ( IntPtr ) context ) ;
177177 }
178178
179- bool AddReference ( JniObjectReference from , JniObjectReference to )
180- {
181- if ( ! from . IsValid || ! to . IsValid ) {
182- return false ;
183- }
184-
185- // Try the optimized path for GCUserPeerable (NativeAOT)
186- if ( ! RuntimeFeature . IsCoreClrRuntime ) {
187- if ( BridgeProcessingJniHelper . TryAddManagedReference ( from , to ) ) {
188- return true ;
189- }
190- }
191-
192- // Fall back to reflection-based approach
193- var fromClassRef = JniEnvironment . Types . GetObjectClass ( from ) ;
194- using var fromClass = new JniType ( ref fromClassRef , JniObjectReferenceOptions . CopyAndDispose ) ;
195-
196- JniMethodInfo addMethod ;
197- try {
198- addMethod = fromClass . GetInstanceMethod ( "monodroidAddReference" , "(Ljava/lang/Object;)V" ) ;
199- } catch ( Java . Lang . NoSuchMethodError ) {
200- s_logger ? . LogMissingAddReferencesMethod ( fromClass ) ;
201- return false ;
202- }
203-
204- JniArgumentValue * args = stackalloc JniArgumentValue [ 1 ] ;
205- args [ 0 ] = new JniArgumentValue ( to ) ;
206- JniEnvironment . InstanceMethods . CallVoidMethod ( from , addMethod , args ) ;
207- return true ;
208- }
209-
210179 void TakeWeakGlobalRef ( HandleContext * context )
211180 {
212181 Debug . Assert ( context != null && context ->ControlBlock != null , "Context or control block is null" ) ;
0 commit comments