|
26 | 26 |
|
27 | 27 | import java.lang.invoke.MethodType; |
28 | 28 |
|
| 29 | +import org.graalvm.nativeimage.impl.ClassLoading; |
| 30 | + |
| 31 | +import com.oracle.svm.core.hub.DynamicHub; |
29 | 32 | import com.oracle.svm.core.hub.crema.CremaSupport; |
30 | 33 | import com.oracle.svm.core.hub.registry.SymbolsSupport; |
31 | 34 | import com.oracle.svm.core.methodhandles.Target_java_lang_invoke_MethodHandleNatives; |
@@ -137,32 +140,41 @@ private String resolveStringConstant(int stringIndex, @SuppressWarnings("unused" |
137 | 140 | return string; |
138 | 141 | } |
139 | 142 |
|
140 | | - private InterpreterResolvedJavaType resolveClassConstant(int classIndex, InterpreterResolvedJavaType accessingKlass) { |
| 143 | + private static InterpreterResolvedObjectType resolveObjectType(Symbol<Type> type, InterpreterResolvedObjectType accessingClass) { |
| 144 | + DynamicHub hub = DynamicHub.fromClass(CremaSupport.singleton().resolveOrThrow(type, accessingClass)); |
| 145 | + assert !hub.isPrimitive(); |
| 146 | + return (InterpreterResolvedObjectType) hub.getInterpreterType(); |
| 147 | + } |
| 148 | + |
| 149 | + private InterpreterResolvedJavaType resolveClassConstant(int classIndex, InterpreterResolvedObjectType accessingKlass) { |
141 | 150 | assert accessingKlass != null; |
142 | 151 | assert tagAt(classIndex) == Tag.CLASS; |
143 | 152 |
|
144 | 153 | Object entry = this.cachedEntries[classIndex]; |
145 | 154 | Symbol<Type> type = null; |
146 | 155 |
|
| 156 | + boolean allowArbitraryClassLoading; |
147 | 157 | if (entry == null) { |
148 | 158 | // CP comes from dynamically loaded .class file. |
149 | 159 | Symbol<Name> className = this.className(classIndex); |
150 | 160 | type = SymbolsSupport.getTypes().fromClassNameEntry(className); |
| 161 | + allowArbitraryClassLoading = true; |
151 | 162 | } else if (entry instanceof UnresolvedJavaType unresolvedJavaType) { |
152 | 163 | Throwable cause = unresolvedJavaType.getCause(); |
153 | 164 | if (cause != null) { |
154 | 165 | throw uncheckedThrow(cause); |
155 | 166 | } |
156 | 167 | // CP comes from build-time JVMCI type, derive type from UnresolvedJavaType. |
157 | 168 | type = SymbolsSupport.getTypes().getOrCreateValidType(unresolvedJavaType.getName()); |
| 169 | + allowArbitraryClassLoading = false; |
158 | 170 | } else { |
159 | 171 | throw VMError.shouldNotReachHere("Invalid cached CP entry, expected unresolved type, but got " + entry); |
160 | 172 | } |
161 | 173 |
|
162 | 174 | assert type != null; |
163 | 175 |
|
164 | | - try { |
165 | | - InterpreterResolvedObjectType result = CremaRuntimeAccess.getInstance().lookupOrLoadType(type, accessingKlass); |
| 176 | + try (var _ = ClassLoading.allowArbitraryClassLoading(allowArbitraryClassLoading)) { |
| 177 | + InterpreterResolvedObjectType result = resolveObjectType(type, accessingKlass); |
166 | 178 | return result; |
167 | 179 | } catch (LinkageError e) { |
168 | 180 | // Comment from Hotspot: |
@@ -201,7 +213,7 @@ private InterpreterResolvedJavaField resolveFieldRefConstant(int fieldIndex, Int |
201 | 213 | Symbol<Type> holderType = SymbolsSupport.getTypes().getOrCreateValidType(unresolvedJavaField.getDeclaringClass().getName()); |
202 | 214 | assert !TypeSymbols.isPrimitive(holderType) && !TypeSymbols.isArray(holderType); |
203 | 215 | // Perf. note: The holder is re-resolved every-time (never cached). |
204 | | - holder = CremaRuntimeAccess.getInstance().lookupOrLoadType(holderType, accessingClass); |
| 216 | + holder = resolveObjectType(holderType, accessingClass); |
205 | 217 | } else { |
206 | 218 | throw VMError.shouldNotReachHere("Invalid cached CP entry, expected unresolved field, but got " + entry); |
207 | 219 | } |
@@ -237,7 +249,7 @@ private InterpreterResolvedJavaMethod resolveClassMethodRefConstant(int methodIn |
237 | 249 | methodSignature = SymbolsSupport.getSignatures().getOrCreateValidSignature(unresolvedJavaMethod.getSignature().toMethodDescriptor()); |
238 | 250 | Symbol<Type> holderType = SymbolsSupport.getTypes().getOrCreateValidType(unresolvedJavaMethod.getDeclaringClass().getName()); |
239 | 251 | // Perf. note: The holder is re-resolved every-time (never cached). |
240 | | - holder = CremaRuntimeAccess.getInstance().lookupOrLoadType(holderType, accessingClass); |
| 252 | + holder = resolveObjectType(holderType, accessingClass); |
241 | 253 | } else { |
242 | 254 | throw VMError.shouldNotReachHere("Invalid cached CP entry, expected unresolved method, but got " + entry); |
243 | 255 | } |
@@ -275,7 +287,7 @@ private InterpreterResolvedJavaMethod resolveInterfaceMethodRefConstant(int inte |
275 | 287 | methodSignature = SymbolsSupport.getSignatures().getOrCreateValidSignature(unresolvedJavaMethod.getSignature().toMethodDescriptor()); |
276 | 288 | Symbol<Type> holderType = SymbolsSupport.getTypes().getOrCreateValidType(unresolvedJavaMethod.getDeclaringClass().getName()); |
277 | 289 | // Perf. note: The holder is re-resolved every-time (never cached). |
278 | | - holder = CremaRuntimeAccess.getInstance().lookupOrLoadType(holderType, accessingClass); |
| 290 | + holder = resolveObjectType(holderType, accessingClass); |
279 | 291 | } else { |
280 | 292 | throw VMError.shouldNotReachHere("Invalid cached CP entry, expected unresolved method, but got " + entry); |
281 | 293 | } |
@@ -322,8 +334,10 @@ public static MethodType signatureToMethodType(Symbol<Type>[] signature, Interpr |
322 | 334 | } |
323 | 335 |
|
324 | 336 | private static Class<?> resolveSymbolAndAccessCheck(InterpreterResolvedObjectType accessingClass, Symbol<Type> type) { |
325 | | - Class<?> clazz = CremaSupport.singleton().resolveOrThrow(type, accessingClass); |
326 | | - // GR-62339 check access |
327 | | - return clazz; |
| 337 | + try (var _ = ClassLoading.allowArbitraryClassLoading()) { |
| 338 | + Class<?> clazz = CremaSupport.singleton().resolveOrThrow(type, accessingClass); |
| 339 | + // GR-62339 check access |
| 340 | + return clazz; |
| 341 | + } |
328 | 342 | } |
329 | 343 | } |
0 commit comments