private object PerThreadJavaCoder(int index) { var elem = perThreadJavaCodersMap.get(this); if (elem == null) { var elemNew = new java.util.concurrent.atomic.AtomicReferenceArray(2); elem = perThreadJavaCodersMap.putIfAbsent(this, elemNew) ?? elemNew; } var coders = (java.util.concurrent.atomic.AtomicReferenceArray)elem; elem = coders.get(index); if (elem == null) { var elemNew = (index == 0) ? (object)JavaCharset.newDecoder() .onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPLACE) .onMalformedInput(java.nio.charset.CodingErrorAction.REPLACE) : (object)JavaCharset.newEncoder() .onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPLACE) .onMalformedInput(java.nio.charset.CodingErrorAction.REPLACE); elem = coders.getAndSet(index, elemNew) ?? elemNew; } return(elem); }
// // // public static object TryCast(object parentObject, System.Type castToType, java.util.concurrent.atomic.AtomicReferenceArray proxyArray, int proxyIndex, java.lang.Class proxyClass, System.Type proxyType) { // helper method for IGenericObject.TryCast methods, which are created // by CilInterfaceBuilder.BuildTryCastMethod. invoked by TryCast() of // a class that implements one or more generic interfaces, and has an // array of proxy objects for those interfaces. // // castToType is the generic type passed to IGenericObject.TryCast. // proxyType is the type of the generic interface which corresponds // to the proxy object at index proxyIndex of the array proxyArray. // // if the types match, then the proxy object is created (if necessary), // cached in the proxy array for future calls, and returned. // if the types do not match, returns null. if (!object.ReferenceEquals(castToType, proxyType)) { // a type implementing IA<T1> may be assigned to IA<T2>, // depending on variance of generic parameters. // note that this is checked by IsAssignableGenericInterface, // which does not rely on the java Signature attribute. if (!(proxyType is RuntimeType proxyRuntimeType && proxyRuntimeType.IsCastableToGenericInterface(castToType, (parentObject is system.Array.ProxySyncRoot parentArray)))) { return(null); } } var proxyObject = proxyArray.get(proxyIndex); if (proxyObject == null) { var constructor = proxyClass.getDeclaredConstructor( new java.lang.Class[] { (java.lang.Class) typeof(java.lang.Object) }); proxyObject = constructor.newInstance(new object[1] { parentObject }); if (!proxyArray.compareAndSet(proxyIndex, null, proxyObject)) { proxyObject = proxyArray.get(proxyIndex); } } return(proxyObject); }