50
50
import static com .oracle .truffle .espresso .substitutions .jvmci .Target_com_oracle_truffle_espresso_jvmci_meta_EspressoResolvedInstanceType .toJVMCIField ;
51
51
import static com .oracle .truffle .espresso .substitutions .jvmci .Target_com_oracle_truffle_espresso_jvmci_meta_EspressoResolvedInstanceType .toJVMCIMethod ;
52
52
53
+ import java .util .logging .Level ;
54
+
53
55
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
54
56
import com .oracle .truffle .espresso .classfile .ConstantPool ;
55
57
import com .oracle .truffle .espresso .classfile .JavaKind ;
77
79
import com .oracle .truffle .espresso .meta .Meta ;
78
80
import com .oracle .truffle .espresso .nodes .methodhandle .MHInvokeGenericNode ;
79
81
import com .oracle .truffle .espresso .runtime .EspressoContext ;
82
+ import com .oracle .truffle .espresso .runtime .EspressoException ;
80
83
import com .oracle .truffle .espresso .runtime .EspressoLinkResolver ;
81
84
import com .oracle .truffle .espresso .runtime .MethodHandleIntrinsics ;
82
85
import com .oracle .truffle .espresso .runtime .staticobject .StaticObject ;
@@ -209,13 +212,12 @@ private static Field tryResolveField(int fieldIndex, Klass symbolicHolder, Runti
209
212
RuntimeConstantPool constantPool = getRuntimeConstantPool (self , meta );
210
213
if (safeTagAt (constantPool , cpi , meta ) == ConstantPool .Tag .CLASS ) {
211
214
ResolvedConstant resolvedConstant = constantPool .peekResolvedOrNull (cpi , meta );
212
- if (resolvedConstant != null ) {
213
- Klass klass = (Klass ) resolvedConstant .value ();
214
- LOGGER .finer (() -> "ECP.lookupType found " + klass );
215
- return toJVMCIObjectType (klass , meta );
216
- } else {
215
+ if (resolvedConstant == null || !resolvedConstant .isSuccess ()) {
217
216
return toJVMCIUnresolvedType (TypeSymbols .nameToType (constantPool .className (cpi )), meta );
218
217
}
218
+ Klass klass = (Klass ) resolvedConstant .value ();
219
+ LOGGER .finer (() -> "ECP.lookupType found " + klass );
220
+ return toJVMCIObjectType (klass , meta );
219
221
}
220
222
if (safeTagAt (constantPool , cpi , meta ) == ConstantPool .Tag .UTF8 ) {
221
223
return toJVMCIUnresolvedType (TypeSymbols .nameToType (constantPool .utf8At (cpi )), meta );
@@ -367,13 +369,12 @@ private static Method tryResolveMethod(int methodIndex, Klass symbolicHolder, Ru
367
369
case LDC2_W :
368
370
if (safeTagAt (constantPool , cpi , meta ) == ConstantPool .Tag .CLASS ) {
369
371
ResolvedConstant resolvedConstant = constantPool .peekResolvedOrNull (cpi , meta );
370
- if (resolvedConstant != null ) {
371
- Klass klass = (Klass ) resolvedConstant .value ();
372
- LOGGER .finer (() -> "ECP.lookupReferencedType found " + klass );
373
- return toJVMCIObjectType (klass , meta );
374
- } else {
372
+ if (resolvedConstant == null || !resolvedConstant .isSuccess ()) {
375
373
return toJVMCIUnresolvedType (TypeSymbols .nameToType (constantPool .className (cpi )), meta );
376
374
}
375
+ Klass klass = (Klass ) resolvedConstant .value ();
376
+ LOGGER .finer (() -> "ECP.lookupReferencedType found " + klass );
377
+ return toJVMCIObjectType (klass , meta );
377
378
}
378
379
break ;
379
380
case GETSTATIC :
@@ -386,14 +387,20 @@ private static Method tryResolveMethod(int methodIndex, Klass symbolicHolder, Ru
386
387
case INVOKEINTERFACE :
387
388
if (safeTagAt (constantPool , cpi , meta ).isMember ()) {
388
389
int holderClassIndex = constantPool .memberClassIndex (cpi );
389
- Klass holderKlass = findObjectType (holderClassIndex , constantPool , false , meta );
390
- if (holderKlass != null ) {
391
- LOGGER .finer (() -> "ECP.lookupReferencedType found " + holderKlass );
392
- return toJVMCIObjectType (holderKlass , meta );
393
- } else {
390
+ Klass holderKlass ;
391
+ try {
392
+ holderKlass = findObjectType (holderClassIndex , constantPool , false , meta );
393
+ } catch (EspressoException e ) {
394
+ LOGGER .log (Level .FINE , "ECP.lookupReferencedType exception during lookup" , e );
395
+ holderKlass = null ;
396
+ }
397
+ if (holderKlass == null ) {
394
398
Symbol <Name > holderName = constantPool .memberClassName (cpi );
395
399
return toJVMCIUnresolvedType (TypeSymbols .nameToType (holderName ), meta );
396
400
}
401
+ Klass finalHolderKlass = holderKlass ;
402
+ LOGGER .finer (() -> "ECP.lookupReferencedType found " + finalHolderKlass );
403
+ return toJVMCIObjectType (holderKlass , meta );
397
404
}
398
405
break ;
399
406
}
@@ -499,15 +506,13 @@ public static boolean loadReferencedType0(StaticObject self, int cpi, int opcode
499
506
}
500
507
switch (tag ) {
501
508
case CLASS -> {
502
- if (resolvedConstantOrNull != null ) {
503
- Klass klass = (Klass ) resolvedConstantOrNull .value ();
504
- LOGGER .finer (() -> "ECP.lookupConstant found " + klass );
505
- return toJVMCIObjectType (klass , meta );
506
- } else if (resolve ) {
507
- throw EspressoError .shouldNotReachHere ();
508
- } else {
509
+ if (resolvedConstantOrNull == null || !resolvedConstantOrNull .isSuccess ()) {
510
+ EspressoError .guarantee (!resolve || resolvedConstantOrNull != null , "Should have been resolved" );
509
511
return toJVMCIUnresolvedType (TypeSymbols .nameToType (constantPool .className (cpi )), meta );
510
512
}
513
+ Klass klass = (Klass ) resolvedConstantOrNull .value ();
514
+ LOGGER .finer (() -> "ECP.lookupConstant found " + klass );
515
+ return toJVMCIObjectType (klass , meta );
511
516
}
512
517
case STRING -> {
513
518
return wrapEspressoObjectConstant (constantPool .resolvedStringAt (cpi ), meta );
0 commit comments