IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeVerifierJavaType.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2015 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24using System;
25
26#if IMPORTER || EXPORTER
27using IKVM.Reflection;
29
30using Type = IKVM.Reflection.Type;
31#endif
32
33namespace IKVM.Runtime
34{
35
37 {
38
39 readonly RuntimeContext context;
40
41 internal readonly RuntimeJavaType Invalid = null;
42 internal readonly RuntimeJavaType Null;
43 internal readonly RuntimeJavaType UninitializedThis;
44 internal readonly RuntimeJavaType Unloadable;
45 internal readonly RuntimeJavaType ExtendedFloat;
46 internal readonly RuntimeJavaType ExtendedDouble;
47
54 {
55 this.context = context ?? throw new ArgumentNullException(nameof(context));
56
57 Null = new RuntimeVerifierJavaType(context, "null", 0, null, null);
58 UninitializedThis = new RuntimeVerifierJavaType(context, "uninitialized-this", 0, null, null);
59 Unloadable = new RuntimeUnloadableJavaType(context, "<verifier>");
60 ExtendedFloat = new RuntimeVerifierJavaType(context, "<extfloat>", 0, null, null);
61 ExtendedDouble = new RuntimeVerifierJavaType(context, "<extdouble>", 0, null, null);
62 }
63
64 }
65
66 // this is a container for the special verifier TypeWrappers
67 sealed class RuntimeVerifierJavaType : RuntimeJavaType
68 {
69
70 // the TypeWrapper constructor interns the name, so we have to pre-intern here to make sure we have the same string object
71 // (if it has only been interned previously)
72 static readonly string This = string.Intern("this");
73 static readonly string New = string.Intern("new");
74 static readonly string Fault = string.Intern("<fault>");
75
76 readonly int index;
77 readonly RuntimeJavaType underlyingType;
78 readonly MethodAnalyzer methodAnalyzer;
79
88 public RuntimeVerifierJavaType(RuntimeContext context, string name, int index, RuntimeJavaType underlyingType, MethodAnalyzer methodAnalyzer) :
89 base(context, TypeFlags.None, RuntimeJavaType.VerifierTypeModifiersHack, name)
90 {
91 this.index = index;
92 this.underlyingType = underlyingType;
93 this.methodAnalyzer = methodAnalyzer;
94 }
95
96#if EXPORTER
97
98 internal class MethodAnalyzer
99 {
100
101 readonly RuntimeContext context;
102
108 public MethodAnalyzer(RuntimeContext context)
109 {
110 this.context = context ?? throw new ArgumentNullException(nameof(context));
111 }
112
113 internal void ClearFaultBlockException(int dummy) { }
114
115 public RuntimeContext Context => context;
116
117 }
118
119#endif
120
121 public override string ToString()
122 {
123 return GetType().Name + "[" + Name + "," + index + "," + underlyingType + "]";
124 }
125
126 internal static RuntimeJavaType MakeNew(RuntimeJavaType type, int bytecodeIndex)
127 {
128 return new RuntimeVerifierJavaType(type.Context, New, bytecodeIndex, type, null);
129 }
130
131 internal static RuntimeJavaType MakeFaultBlockException(MethodAnalyzer ma, int handlerIndex)
132 {
133 return new RuntimeVerifierJavaType(ma.Context, Fault, handlerIndex, null, ma);
134 }
135
136 // NOTE the "this" type is special, it can only exist in local[0] and on the stack
137 // as soon as the type on the stack is merged or popped it turns into its underlying type.
138 // It exists to capture the verification rules for non-virtual base class method invocation in .NET 2.0,
139 // which requires that the invocation is done on a "this" reference that was directly loaded onto the
140 // stack (using ldarg_0).
141 internal static RuntimeJavaType MakeThis(RuntimeJavaType type)
142 {
143 return new RuntimeVerifierJavaType(type.Context, This, 0, type, null);
144 }
145
146 internal static bool IsNotPresentOnStack(RuntimeJavaType w)
147 {
148 return IsNew(w) || IsFaultBlockException(w);
149 }
150
151 internal static bool IsNew(RuntimeJavaType w)
152 {
153 return w != null && w.IsVerifierType && ReferenceEquals(w.Name, New);
154 }
155
156 internal static bool IsFaultBlockException(RuntimeJavaType w)
157 {
158 return w != null && w.IsVerifierType && ReferenceEquals(w.Name, Fault);
159 }
160
161 internal static bool IsNullOrUnloadable(RuntimeJavaType w)
162 {
163 return w == w.Context.VerifierJavaTypeFactory.Null || w.IsUnloadable;
164 }
165
166 internal static bool IsThis(RuntimeJavaType w)
167 {
168 return w != null && w.IsVerifierType && ReferenceEquals(w.Name, This);
169 }
170
171 internal static void ClearFaultBlockException(RuntimeJavaType w)
172 {
173 var vtw = (RuntimeVerifierJavaType)w;
174 vtw.methodAnalyzer.ClearFaultBlockException(vtw.Index);
175 }
176
177 internal int Index
178 {
179 get
180 {
181 return index;
182 }
183 }
184
185 internal RuntimeJavaType UnderlyingType
186 {
187 get
188 {
189 return underlyingType;
190 }
191 }
192
193 internal override RuntimeJavaType BaseTypeWrapper
194 {
195 get { return null; }
196 }
197
198 internal override RuntimeClassLoader ClassLoader => null;
199
200 protected override void LazyPublishMembers()
201 {
202 throw new InvalidOperationException("LazyPublishMembers called on " + this);
203 }
204
205 internal override Type TypeAsTBD
206 {
207 get
208 {
209 throw new InvalidOperationException("get_Type called on " + this);
210 }
211 }
212
213 internal override RuntimeJavaType[] Interfaces
214 {
215 get
216 {
217 throw new InvalidOperationException("get_Interfaces called on " + this);
218 }
219 }
220
221 internal override RuntimeJavaType[] InnerClasses
222 {
223 get
224 {
225 throw new InvalidOperationException("get_InnerClasses called on " + this);
226 }
227 }
228
229 internal override RuntimeJavaType DeclaringTypeWrapper
230 {
231 get
232 {
233 throw new InvalidOperationException("get_DeclaringTypeWrapper called on " + this);
234 }
235 }
236
237 internal override void Finish()
238 {
239 throw new InvalidOperationException("Finish called on " + this);
240 }
241 }
242
243}
IKVM.Reflection.Type Type
global::java.lang.invoke.LambdaForm.Name Name
Maintains services relevant to an instane of the IKVM runtime.
RuntimeVerifierJavaTypeFactory(RuntimeContext context)
Initializes a new instance.
RuntimeVerifierJavaType(RuntimeContext context, string name, int index, RuntimeJavaType underlyingType, MethodAnalyzer methodAnalyzer)
Initializes a new instance.