21
21
* questions.
22
22
*/
23
23
24
- package com .oracle .truffle .espresso .resolver ;
24
+ package com .oracle .truffle .espresso .shared . resolver ;
25
25
26
- import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
27
- import com .oracle .truffle .espresso .classfile .descriptors .Symbol ;
28
- import com .oracle .truffle .espresso .classfile .descriptors .Symbol .Name ;
29
- import com .oracle .truffle .espresso .classfile .descriptors .Symbol .Signature ;
30
- import com .oracle .truffle .espresso .classfile .descriptors .Symbol .Type ;
31
- import com .oracle .truffle .espresso .resolver .meta .ClassType ;
32
- import com .oracle .truffle .espresso .resolver .meta .ErrorType ;
33
- import com .oracle .truffle .espresso .resolver .meta .FieldType ;
34
- import com .oracle .truffle .espresso .resolver .meta .MethodType ;
35
- import com .oracle .truffle .espresso .resolver .meta .RuntimeAccess ;
36
-
37
- public final class LinkResolver <R extends RuntimeAccess <C , M , F >, C extends ClassType <C , M , F >, M extends MethodType <C , M , F >, F extends FieldType <C , M , F >> {
38
- private final LinkResolverImpl <R , C , M , F > impl = new LinkResolverImpl <>();
26
+ import com .oracle .truffle .espresso .shared .descriptors .Symbol ;
27
+ import com .oracle .truffle .espresso .shared .descriptors .Symbol .Name ;
28
+ import com .oracle .truffle .espresso .shared .descriptors .Symbol .Signature ;
29
+ import com .oracle .truffle .espresso .shared .descriptors .Symbol .Type ;
30
+ import com .oracle .truffle .espresso .classfile .resolver .meta .ErrorType ;
31
+ import com .oracle .truffle .espresso .classfile .resolver .meta .FieldAccess ;
32
+ import com .oracle .truffle .espresso .classfile .resolver .meta .MethodAccess ;
33
+ import com .oracle .truffle .espresso .classfile .resolver .meta .RuntimeAccess ;
34
+ import com .oracle .truffle .espresso .classfile .resolver .meta .TypeAccess ;
39
35
36
+ /**
37
+ * Provides resolution capabilities according to the Java Virtual Machine Specification on behalf of
38
+ * a VM.
39
+ *
40
+ * @param <R> The class providing VM access.
41
+ * @param <C> The class representing the VM-side java {@link java.lang.Class}.
42
+ * @param <M> The class representing the VM-side java {@link java.lang.reflect.Method}.
43
+ * @param <F> The class representing the VM-side java {@link java.lang.reflect.Field}.
44
+ */
45
+ public final class LinkResolver <R extends RuntimeAccess <C , M , F >, C extends TypeAccess <C , M , F >, M extends MethodAccess <C , M , F >, F extends FieldAccess <C , M , F >> {
40
46
/**
41
47
* Symbolically resolves a field.
42
48
*
@@ -50,7 +56,7 @@ public final class LinkResolver<R extends RuntimeAccess<C, M, F>, C extends Clas
50
56
public F resolveFieldSymbol (R meta , C accessingKlass ,
51
57
Symbol <Name > name , Symbol <Type > type , C symbolicHolder ,
52
58
boolean accessCheck , boolean loadingConstraints ) {
53
- return impl . resolveFieldSymbol (meta , accessingKlass , name , type , symbolicHolder , accessCheck , loadingConstraints );
59
+ return resolveFieldSymbolImpl (meta , accessingKlass , name , type , symbolicHolder , accessCheck , loadingConstraints );
54
60
}
55
61
56
62
/**
@@ -66,7 +72,7 @@ public F resolveFieldSymbol(R meta, C accessingKlass,
66
72
* @param fieldAccessType The {@link FieldAccessType} representing the access site to resolve.
67
73
*/
68
74
public F resolveFieldAccess (R meta , C currentKlass , M currentMethod , F symbolicResolution , FieldAccessType fieldAccessType ) {
69
- return impl . resolveFieldAccess (meta , symbolicResolution , fieldAccessType , currentKlass , currentMethod );
75
+ return resolveFieldAccessImpl (meta , symbolicResolution , fieldAccessType , currentKlass , currentMethod );
70
76
}
71
77
72
78
/**
@@ -83,7 +89,7 @@ public M resolveMethodSymbol(R meta, C accessingKlass,
83
89
Symbol <Name > name , Symbol <Signature > signature , C symbolicHolder ,
84
90
boolean interfaceLookup ,
85
91
boolean accessCheck , boolean loadingConstraints ) {
86
- return impl . resolveMethodSymbol (meta , accessingKlass , name , signature , symbolicHolder , interfaceLookup , accessCheck , loadingConstraints );
92
+ return resolveMethodSymbolImpl (meta , accessingKlass , name , signature , symbolicHolder , interfaceLookup , accessCheck , loadingConstraints );
87
93
}
88
94
89
95
/**
@@ -97,11 +103,10 @@ public M resolveMethodSymbol(R meta, C accessingKlass,
97
103
* {@code symbolicResolution.getDeclaringKlass()}.
98
104
*/
99
105
public ResolvedCall <C , M , F > resolveCallSite (R meta , C currentKlass , M symbolicResolution , CallSiteType callSiteType , C symbolicHolder ) {
100
- return impl . resolveCallSite (meta , currentKlass , symbolicResolution , callSiteType , symbolicHolder );
106
+ return resolveCallSiteImpl (meta , currentKlass , symbolicResolution , callSiteType , symbolicHolder );
101
107
}
102
- }
103
108
104
- final class LinkResolverImpl < R extends RuntimeAccess < C , M , F >, C extends ClassType < C , M , F >, M extends MethodType < C , M , F >, F extends FieldType < C , M , F >> {
109
+ // Implementation
105
110
106
111
private static final String AN_INTERFACE = "an interface" ;
107
112
private static final String A_CLASS = "a class" ;
@@ -110,24 +115,23 @@ final class LinkResolverImpl<R extends RuntimeAccess<C, M, F>, C extends ClassTy
110
115
private static final String INIT = "<init>" ;
111
116
private static final String CLINIT = "<clinit>" ;
112
117
113
- @ TruffleBoundary
114
- public F resolveFieldSymbol (R meta , C accessingKlass ,
118
+ private F resolveFieldSymbolImpl (R meta , C accessingKlass ,
115
119
Symbol <Name > name , Symbol <Type > type , C symbolicHolder ,
116
120
boolean accessCheck , boolean loadingConstraints ) {
117
121
F f = symbolicHolder .lookupField (name , type );
118
122
if (f == null ) {
119
123
throw meta .throwError (ErrorType .NoSuchFieldError , "%s" , name );
120
124
}
121
125
if (accessCheck ) {
122
- meta . fieldAccessCheck ( f , accessingKlass , symbolicHolder );
126
+ f . accessChecks ( accessingKlass , symbolicHolder );
123
127
}
124
128
if (loadingConstraints ) {
125
- meta . fieldLoadingConstraints ( f , accessingKlass );
129
+ f . loadingConstraints ( accessingKlass );
126
130
}
127
131
return f ;
128
132
}
129
133
130
- public F resolveFieldAccess (R meta , F field , FieldAccessType fieldAccessType ,
134
+ private F resolveFieldAccessImpl (R meta , F field , FieldAccessType fieldAccessType ,
131
135
C currentKlass , M currentMethod ) {
132
136
/*
133
137
* PUTFIELD/GETFIELD: Otherwise, if the resolved field is a static field, putfield throws an
@@ -142,7 +146,7 @@ public F resolveFieldAccess(R meta, F field, FieldAccessType fieldAccessType,
142
146
"Expected %s field %s.%s" ,
143
147
(fieldAccessType .isStatic ()) ? STATIC : NON_STATIC ,
144
148
field .getDeclaringClass ().getJavaName (),
145
- field .getName ());
149
+ field .getSymbolicName ());
146
150
}
147
151
if (fieldAccessType .isPut ()) {
148
152
/*
@@ -160,19 +164,19 @@ public F resolveFieldAccess(R meta, F field, FieldAccessType fieldAccessType,
160
164
"Update to %s final field %s.%s attempted from a different class (%s) than the field's declaring class" ,
161
165
(fieldAccessType .isStatic ()) ? STATIC : NON_STATIC ,
162
166
field .getDeclaringClass ().getJavaName (),
163
- field .getName (),
167
+ field .getSymbolicName (),
164
168
currentKlass .getJavaName ());
165
169
}
166
- boolean enforceInitializerCheck = meta . enforceInitializerCheck ( field );
170
+ boolean enforceInitializerCheck = field . shouldEnforceInitializerCheck ( );
167
171
if (enforceInitializerCheck ) {
168
172
if (!((fieldAccessType .isStatic () && currentMethod .isClassInitializer ()) ||
169
173
(!fieldAccessType .isStatic () && currentMethod .isConstructor ()))) {
170
174
throw meta .throwError (ErrorType .IllegalAccessError ,
171
175
"Update to %s final field %s.%s attempted from a different method (%s) than the initializer method %s " ,
172
176
(fieldAccessType .isStatic ()) ? STATIC : NON_STATIC ,
173
177
field .getDeclaringClass ().getJavaName (),
174
- field .getName (),
175
- currentMethod .getName (),
178
+ field .getSymbolicName (),
179
+ currentMethod .getSymbolicName (),
176
180
(fieldAccessType .isStatic ()) ? CLINIT : INIT );
177
181
}
178
182
}
@@ -181,8 +185,7 @@ public F resolveFieldAccess(R meta, F field, FieldAccessType fieldAccessType,
181
185
return field ;
182
186
}
183
187
184
- @ TruffleBoundary
185
- public M resolveMethodSymbol (R meta , C accessingKlass , Symbol <Name > name ,
188
+ private M resolveMethodSymbolImpl (R meta , C accessingKlass , Symbol <Name > name ,
186
189
Symbol <Signature > signature , C symbolicHolder ,
187
190
boolean interfaceLookup ,
188
191
boolean accessCheck , boolean loadingConstraints ) {
@@ -200,18 +203,18 @@ public M resolveMethodSymbol(R meta, C accessingKlass, Symbol<Name> name,
200
203
resolved = symbolicHolder .lookupMethod (name , signature );
201
204
}
202
205
if (resolved == null ) {
203
- throw meta .throwError (ErrorType .NoSuchMethodError , symbolicHolder .getJavaName () + "." + name + signature );
206
+ throw meta .throwError (ErrorType .NoSuchMethodError , "%s.%s%s" , symbolicHolder .getJavaName (), name , signature );
204
207
}
205
208
if (accessCheck ) {
206
- meta . methodAccessCheck ( resolved , accessingKlass , symbolicHolder );
209
+ resolved . accessChecks ( accessingKlass , symbolicHolder );
207
210
}
208
- if (loadingConstraints && !meta . skipLoadingConstraints ( resolved )) {
209
- meta . methodLoadingConstraints ( resolved , accessingKlass );
211
+ if (loadingConstraints && !resolved . shouldSkipLoadingConstraints ( )) {
212
+ resolved . loadingConstraints ( accessingKlass );
210
213
}
211
214
return resolved ;
212
215
}
213
216
214
- public ResolvedCall <C , M , F > resolveCallSite (R meta , C currentKlass , M symbolicResolution ,
217
+ private ResolvedCall <C , M , F > resolveCallSiteImpl (R meta , C currentKlass , M symbolicResolution ,
215
218
CallSiteType callSiteType , C symbolicHolder ) {
216
219
M resolved = symbolicResolution ;
217
220
CallKind callKind ;
@@ -222,8 +225,8 @@ public ResolvedCall<C, M, F> resolveCallSite(R meta, C currentKlass, M symbolicR
222
225
if (!resolved .isStatic ()) {
223
226
throw meta .throwError (ErrorType .IncompatibleClassChangeError , "Expected static method '%s.%s%s'" ,
224
227
resolved .getDeclaringClass ().getJavaName (),
225
- resolved .getName (),
226
- resolved .getRawSignature ());
228
+ resolved .getSymbolicName (),
229
+ resolved .getSymbolicSignature ());
227
230
}
228
231
callKind = CallKind .STATIC ;
229
232
break ;
@@ -234,8 +237,8 @@ public ResolvedCall<C, M, F> resolveCallSite(R meta, C currentKlass, M symbolicR
234
237
(meta .getJavaVersion ().java8OrEarlier () && resolved .isPrivate ())) {
235
238
throw meta .throwError (ErrorType .IncompatibleClassChangeError , "Expected instance not static method '%s.%s%s'" ,
236
239
resolved .getDeclaringClass ().getJavaName (),
237
- resolved .getName (),
238
- resolved .getRawSignature ());
240
+ resolved .getSymbolicName (),
241
+ resolved .getSymbolicSignature ());
239
242
}
240
243
if (resolved .isPrivate ()) {
241
244
assert meta .getJavaVersion ().java9OrLater () : "Should have thrown in previous check." ;
@@ -254,8 +257,8 @@ public ResolvedCall<C, M, F> resolveCallSite(R meta, C currentKlass, M symbolicR
254
257
if (resolved .isStatic ()) {
255
258
throw meta .throwError (ErrorType .IncompatibleClassChangeError , "Expected instance method '%s.%s%s'" ,
256
259
resolved .getDeclaringClass ().getJavaName (),
257
- resolved .getName (),
258
- resolved .getRawSignature ());
260
+ resolved .getSymbolicName (),
261
+ resolved .getSymbolicSignature ());
259
262
}
260
263
if (resolved .isFinalFlagSet () || resolved .getDeclaringClass ().isFinalFlagSet () || resolved .isPrivate ()) {
261
264
callKind = CallKind .DIRECT ;
@@ -268,21 +271,21 @@ public ResolvedCall<C, M, F> resolveCallSite(R meta, C currentKlass, M symbolicR
268
271
// class in which it is declared is not the class symbolically referenced by the
269
272
// instruction, a NoSuchMethodError is thrown.
270
273
if (resolved .isConstructor ()) {
271
- if (resolved .getDeclaringClass ().getName () != symbolicHolder .getName ()) {
274
+ if (resolved .getDeclaringClass ().getSymbolicName () != symbolicHolder .getSymbolicName ()) {
272
275
throw meta .throwError (ErrorType .NoSuchMethodError ,
273
276
"%s.%s%s" ,
274
277
resolved .getDeclaringClass ().getJavaName (),
275
- resolved .getName (),
276
- resolved .getRawSignature ());
278
+ resolved .getSymbolicName (),
279
+ resolved .getSymbolicSignature ());
277
280
}
278
281
}
279
282
// Otherwise, if the resolved method is a class (static) method, the invokespecial
280
283
// instruction throws an IncompatibleClassChangeError.
281
284
if (resolved .isStatic ()) {
282
285
throw meta .throwError (ErrorType .IncompatibleClassChangeError , "Expected instance not static method '%s.%s%s'" ,
283
286
resolved .getDeclaringClass ().getJavaName (),
284
- resolved .getName (),
285
- resolved .getRawSignature ());
287
+ resolved .getSymbolicName (),
288
+ resolved .getSymbolicSignature ());
286
289
}
287
290
// If all of the following are true, let C be the direct superclass of the current
288
291
// class:
@@ -302,7 +305,7 @@ public ResolvedCall<C, M, F> resolveCallSite(R meta, C currentKlass, M symbolicR
302
305
currentKlass .getSuperClass () != null &&
303
306
symbolicHolder != currentKlass .getSuperClass () &&
304
307
symbolicHolder .isAssignableFrom (currentKlass )) {
305
- resolved = currentKlass .getSuperClass ().lookupInstanceMethod (resolved .getName (), resolved .getRawSignature ());
308
+ resolved = currentKlass .getSuperClass ().lookupInstanceMethod (resolved .getSymbolicName (), resolved .getSymbolicSignature ());
306
309
}
307
310
}
308
311
callKind = CallKind .DIRECT ;
@@ -312,4 +315,4 @@ public ResolvedCall<C, M, F> resolveCallSite(R meta, C currentKlass, M symbolicR
312
315
}
313
316
return new ResolvedCall <>(callKind , resolved );
314
317
}
315
- }
318
+ }
0 commit comments