26using System.Collections.Concurrent;
37using System.Reflection;
49 internal readonly ConcurrentDictionary<string, RuntimeJavaType> dynamicTypes =
new();
50 DynamicClassLoader instance;
59 this.context = context ??
throw new ArgumentNullException(nameof(context));
63 AppDomain.CurrentDomain.TypeResolve +=
new ResolveEventHandler(OnTypeResolve);
66 dynamicTypes.TryAdd(
"<Module>",
null);
78 Assembly OnTypeResolve(
object sender, ResolveEventArgs args)
80 return Resolve(dynamicTypes, args.Name);
89 Assembly Resolve(ConcurrentDictionary<string, RuntimeJavaType> dict,
string name)
91 if (dict.TryGetValue(name, out var type))
96 return type.TypeAsTBD.Assembly;
98 catch (RetargetableJavaException e)
114 [
System.Security.SecuritySafeCritical]
122 if (loader is RuntimeAssemblyClassLoader acl)
124 var name = acl.MainAssembly.GetName().Name + context.Options.DynamicAssemblySuffixAndPublicKey;
125 foreach (var attr
in acl.MainAssembly.GetCustomAttributes<InternalsVisibleToAttribute>())
127 if (attr.AssemblyName == name)
131 n.KeyPair = DynamicClassLoader.ForgedKeyPair.Instance;
133 return new DynamicClassLoader(context, loader.
Diagnostics, DynamicClassLoader.CreateModuleBuilder(context, n),
true);
138 return instance ??=
new DynamicClassLoader(context, loader.
Diagnostics, DynamicClassLoader.CreateModuleBuilder(context),
false);
149 return dynamicTypes.TryAdd(name,
null);
159 public static string TypeNameMangleImpl(ConcurrentDictionary<string, RuntimeJavaType> dict,
string name, RuntimeJavaType javaType)
162 const int MaxLength = 1000;
164 if (name.Length > MaxLength)
165 name = name.Substring(0, MaxLength) +
"/truncated";
167 var mangledTypeName =
TypeNameUtil.ReplaceIllegalCharacters(name);
168 var baseTypeName = mangledTypeName;
172 while (dict.TryAdd(mangledTypeName, javaType) ==
false)
175 mangledTypeName = baseTypeName +
"/" + (++instanceId);
178 return mangledTypeName;
java.security.ProtectionDomain ProtectionDomain
IKVM.Reflection.Type Type
IKVM.Reflection.Assembly Assembly
IKVM.Reflection.AssemblyName AssemblyName
Maintains instances of DynamicClassLoader.
static string TypeNameMangleImpl(ConcurrentDictionary< string, RuntimeJavaType > dict, string name, RuntimeJavaType javaType)
Associated the given Java type with the given type name, ensuring the actual stored name is unique.
bool ReserveName(string name)
Reserves the given type name.
DynamicClassLoader GetOrCreate(RuntimeClassLoader loader)
Gets the DynamicClassLoader instance which should be used for dynamic classes emitted by the given cl...
DynamicClassLoaderFactory(RuntimeContext context)
Initializes a new instance.
Runtime support for a class loader.
virtual IDiagnosticHandler Diagnostics
Gets the IDiagnosticHandler events originated by this class loader should be sent to.
Maintains services relevant to an instane of the IKVM runtime.
void GenericCompilerWarning(string arg0)
The 'GenericCompilerWarning' diagnostic.