IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeContext.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Concurrent;
3
6
7
8
9#if IMPORTER
11#endif
12
13#if EXPORTER
15#endif
16
17#if IMPORTER == false
19#endif
20
21namespace IKVM.Runtime
22{
23
28 {
29
30 readonly RuntimeContextOptions options;
31 readonly IDiagnosticHandler diagnostics;
32 readonly ISymbolResolver resolver;
33 readonly bool bootstrap;
34 readonly ConcurrentDictionary<Type, object> singletons = new();
35
36 Types types;
37 CoreClasses javaBase;
38 AttributeHelper attributeHelper;
39 RuntimeClassLoaderFactory classLoaderFactory;
40 RuntimeAssemblyClassLoaderFactory assemblyClassLoaderFactory;
41 RuntimeManagedJavaTypeFactory managedJavaTypeFactory;
42 RuntimeManagedByteCodeJavaTypeFactory managedByteCodeJavaTypeFactory;
43 RuntimePrimitiveJavaTypeFactory primitiveJavaTypeFactory;
44 RuntimeVerifierJavaTypeFactory verifierJavaTypeFactory;
45
46#if IMPORTER == false && EXPORTER == false
47 ExceptionHelper exceptionHelper;
48#endif
49
50#if IMPORTER == false
51 StubGenerator stubGenerator;
52#endif
53
54#if EXPORTER == false
55 CodeEmitterFactory codeEmitterFactory;
56 DynamicClassLoaderFactory dynamicClassLoaderFactory;
57 ByteCodeHelperMethods byteCodeHelperMethods;
58 Serialization serialization;
59 InterlockedMethods interlockedMethods;
60 CompilerFactory compilerFactory;
61 MethodAnalyzerFactory methodAnalyzerFactory;
62 MethodHandleUtil methodHandleUtil;
63 Boxer boxer;
64#endif
65
66#if IMPORTER
67 ProxyGenerator proxyGenerator;
68#endif
69
70#if IMPORTER || EXPORTER
71 StaticCompiler staticCompiler;
72 FakeTypes fakeTypes;
73#endif
74
75#if IMPORTER || EXPORTER
76
84 public RuntimeContext(RuntimeContextOptions options, IDiagnosticHandler diagnostics, ISymbolResolver resolver, bool bootstrap, StaticCompiler staticCompiler)
85 {
86 this.options = options ?? throw new ArgumentNullException(nameof(options));
87 this.diagnostics = diagnostics ?? throw new ArgumentNullException(nameof(diagnostics));
88 this.resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));
89 this.bootstrap = bootstrap;
90 this.staticCompiler = staticCompiler;
91 }
92
93#else
94
102 public RuntimeContext(RuntimeContextOptions options, IDiagnosticHandler diagnostics, ISymbolResolver resolver, bool bootstrap)
103 {
104 this.options = options ?? throw new ArgumentNullException(nameof(options));
105 this.diagnostics = diagnostics ?? throw new ArgumentNullException(nameof(diagnostics));
106 this.resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));
107 this.bootstrap = bootstrap;
108 }
109
110#endif
111
115 public IDiagnosticHandler Diagnostics => diagnostics;
116
124 T GetOrCreateSingleton<T>(ref T value, Func<T> create)
125 {
126 if (value == null)
127 lock (this)
128 value ??= create();
129
130 return value;
131 }
132
139 public T GetOrCreateSingleton<T>(Func<T> create) => (T)singletons.GetOrAdd(typeof(T), _ => create());
140
144 public RuntimeContextOptions Options => options;
145
149 public ISymbolResolver Resolver => resolver;
150
154 public bool Bootstrap => bootstrap;
155
159 public Types Types => GetOrCreateSingleton(ref types, () => new Types(this));
160
164 public CoreClasses JavaBase => GetOrCreateSingleton(ref javaBase, () => new CoreClasses(this));
165
169 public AttributeHelper AttributeHelper => GetOrCreateSingleton(ref attributeHelper, () => new AttributeHelper(this));
170
174 public RuntimePrimitiveJavaTypeFactory PrimitiveJavaTypeFactory => GetOrCreateSingleton(ref primitiveJavaTypeFactory, () => new RuntimePrimitiveJavaTypeFactory(this));
175
179 public RuntimeVerifierJavaTypeFactory VerifierJavaTypeFactory => GetOrCreateSingleton(ref verifierJavaTypeFactory, () => new RuntimeVerifierJavaTypeFactory(this));
180
181#if IMPORTER == false
182
186 public StubGenerator StubGenerator => GetOrCreateSingleton(ref stubGenerator, () => new StubGenerator(this));
187
188#endif
189
190#if EXPORTER == false
191
195 public CodeEmitterFactory CodeEmitterFactory => GetOrCreateSingleton(ref codeEmitterFactory, () => new CodeEmitterFactory(this));
196
200 public DynamicClassLoaderFactory DynamicClassLoaderFactory => GetOrCreateSingleton(ref dynamicClassLoaderFactory, () => new DynamicClassLoaderFactory(this));
201
205 public ByteCodeHelperMethods ByteCodeHelperMethods => GetOrCreateSingleton(ref byteCodeHelperMethods, () => new ByteCodeHelperMethods(this));
206
210 public Serialization Serialization => GetOrCreateSingleton(ref serialization, () => new Serialization(this));
211
216 public CompilerFactory CompilerFactory => GetOrCreateSingleton(ref compilerFactory, () => new CompilerFactory(this, bootstrap));
217
221 public InterlockedMethods InterlockedMethods => GetOrCreateSingleton(ref interlockedMethods, () => new InterlockedMethods(this));
222
226 public MethodAnalyzerFactory MethodAnalyzerFactory => GetOrCreateSingleton(ref methodAnalyzerFactory, () => new MethodAnalyzerFactory(this));
227
231 public MethodHandleUtil MethodHandleUtil => GetOrCreateSingleton(ref methodHandleUtil, () => new MethodHandleUtil(this));
232
236 public Boxer Boxer => GetOrCreateSingleton(ref boxer, () => new Boxer(this));
237
238#endif
239
240#if IMPORTER == false && EXPORTER == false
241
245 public ExceptionHelper ExceptionHelper => GetOrCreateSingleton(ref exceptionHelper, () => new ExceptionHelper(this));
246
247#endif
248
252 public RuntimeClassLoaderFactory ClassLoaderFactory => GetOrCreateSingleton(ref classLoaderFactory, () => new RuntimeClassLoaderFactory(this));
253
257 public RuntimeAssemblyClassLoaderFactory AssemblyClassLoaderFactory => GetOrCreateSingleton(ref assemblyClassLoaderFactory, () => new RuntimeAssemblyClassLoaderFactory(this));
258
262 public RuntimeManagedJavaTypeFactory ManagedJavaTypeFactory => GetOrCreateSingleton(ref managedJavaTypeFactory, () => new RuntimeManagedJavaTypeFactory(this));
263
267 public RuntimeManagedByteCodeJavaTypeFactory ManagedByteCodeJavaTypeFactory => GetOrCreateSingleton(ref managedByteCodeJavaTypeFactory, () => new RuntimeManagedByteCodeJavaTypeFactory(this));
268
269#if IMPORTER || EXPORTER
270
274 public StaticCompiler StaticCompiler => staticCompiler;
275
279 public FakeTypes FakeTypes => GetOrCreateSingleton(ref fakeTypes, () => new FakeTypes(this));
280
281#endif
282
283#if IMPORTER
284
288 public ProxyGenerator ProxyGenerator => GetOrCreateSingleton(ref proxyGenerator, () => new ProxyGenerator(this));
289
290#endif
291
292 }
293
294}
Provides methods to help in generating IKVM attributes.
Manages instances of Compiler.
Maintains instances of DynamicClassLoader.
Provides instances of MethodAnalyzer.
Maintains instances of RuntimeAssemblyClassLoader.
Manages instances of RuntimeClassLoader.
Maintains services relevant to an instane of the IKVM runtime.
AttributeHelper AttributeHelper
Gets the AttributeHelper associated with this instance of the runtime.
RuntimeManagedByteCodeJavaTypeFactory ManagedByteCodeJavaTypeFactory
Gets the RuntimeManagedJavaTypeFactory associated with this instance of the runtime.
CodeEmitterFactory CodeEmitterFactory
Gets the CodeEmitterFactory associated with this instance of the runtime.
StubGenerator StubGenerator
Gets the StubGenerator associated with this instance of the runtime.
Types Types
Gets the Types associated with this instance of the runtime.
MethodHandleUtil MethodHandleUtil
Gets the MethodHandleUtil associated with this instance of the runtime.
RuntimeManagedJavaTypeFactory ManagedJavaTypeFactory
Gets the RuntimeManagedJavaTypeFactory associated with this instance of the runtime.
bool Bootstrap
Gets whether or not the runtime is running in bootstrap mode; that is, we are compiling the Java base...
MethodAnalyzerFactory MethodAnalyzerFactory
Gets the MethodAnalyzerFactory associated with this instance of the runtime.
DynamicClassLoaderFactory DynamicClassLoaderFactory
Gets the DynamicClassLoaderFactory associated with this instance of the runtime.
RuntimeContextOptions Options
Gets the RuntimeContextOptions associated with this instance of the runtime.
Serialization Serialization
Gets the Serialization associated with this instance of the runtime.
ByteCodeHelperMethods ByteCodeHelperMethods
Gets the ByteCodeHelperMethods associated with this instance of the runtime.
CompilerFactory CompilerFactory
Gets the CompilerFactory associated with this instance of the runtime.
ExceptionHelper ExceptionHelper
Gets the ExceptionHelper associated with this instance of the runtime.
RuntimeContext(RuntimeContextOptions options, IDiagnosticHandler diagnostics, ISymbolResolver resolver, bool bootstrap)
Initializes a new instance.
Boxer Boxer
Gets the Boxer associated with this instance of the runtime.
RuntimeAssemblyClassLoaderFactory AssemblyClassLoaderFactory
Gets the RuntimeAssemblyClassLoaderFactory associated with this instance of the runtime.
RuntimePrimitiveJavaTypeFactory PrimitiveJavaTypeFactory
Gets the RuntimePrimitiveJavaTypeFactory associated with this instance of the runtime.
RuntimeVerifierJavaTypeFactory VerifierJavaTypeFactory
Gets the RuntimeVerifierJavaTypeFactory associated with this instance of the runtime.
InterlockedMethods InterlockedMethods
Gets the InterlockedMethods associated with this instance of the runtime.
ISymbolResolver Resolver
Gets the ISymbolResolver associated with this instance of the runtime.
CoreClasses JavaBase
Gets the CoreClasses associated with this instance of the runtime.
RuntimeClassLoaderFactory ClassLoaderFactory
Gets the RuntimeClassLoaderFactory associated with this instance of the runtime.
Manages instances of RuntimeManagedJavaType.
Provides various cached system types.
Definition Types.cs:38
Holds the static compiler information.
Exposes methods to accept diagnostic invocations.
Provides an interface to resolve a maaged type symbols.