File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
src/Java.Interop/Java.Interop Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 11using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Reflection ;
5- using System . Text ;
2+ using System . Threading ;
3+
64using Java . Interop ;
75
86namespace Java . Interop {
@@ -30,6 +28,11 @@ public JniInstanceMethodID GetConstructor (string signature)
3028 return JniMembers . GetMethodID ( SafeHandle , "<init>" , signature ) ;
3129 }
3230
31+ public JniLocalReference AllocObject ( )
32+ {
33+ return JniActivator . AllocObject ( SafeHandle ) ;
34+ }
35+
3336 public JniLocalReference NewObject ( JniInstanceMethodID constructor , params JValue [ ] @params )
3437 {
3538 return JniActivator . NewObject ( SafeHandle , constructor , @params ) ;
@@ -39,5 +42,15 @@ public JniInstanceMethodID GetInstanceMethod (string name, string signature)
3942 {
4043 return JniMembers . GetMethodID ( SafeHandle , name , signature ) ;
4144 }
45+
46+ public JniInstanceMethodID GetCachedInstanceMethod ( ref JniInstanceMethodID cachedMethod , string name , string signature )
47+ {
48+ if ( cachedMethod != null && ! cachedMethod . IsInvalid )
49+ return cachedMethod ;
50+ var m = GetInstanceMethod ( name , signature ) ;
51+ if ( Interlocked . CompareExchange ( ref cachedMethod , m , null ) != null )
52+ m . Dispose ( ) ;
53+ return cachedMethod ;
54+ }
4255 }
4356}
You can’t perform that action at this time.
0 commit comments