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
-
55
53
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
56
54
import com .oracle .truffle .espresso .classfile .ConstantPool ;
57
55
import com .oracle .truffle .espresso .classfile .JavaKind ;
@@ -212,19 +210,22 @@ private static Field tryResolveField(int fieldIndex, Klass symbolicHolder, Runti
212
210
RuntimeConstantPool constantPool = getRuntimeConstantPool (self , meta );
213
211
if (safeTagAt (constantPool , cpi , meta ) == ConstantPool .Tag .CLASS ) {
214
212
ResolvedConstant resolvedConstant = constantPool .peekResolvedOrNull (cpi , meta );
215
- if (resolvedConstant == null || !resolvedConstant .isSuccess ()) {
216
- return toJVMCIUnresolvedType (TypeSymbols .nameToType (constantPool .className (cpi )), meta );
217
- }
218
- Klass klass = (Klass ) resolvedConstant .value ();
219
- LOGGER .finer (() -> "ECP.lookupType found " + klass );
220
- return toJVMCIObjectType (klass , meta );
213
+ return resolvedConstantToJVMCIObjectType (resolvedConstant , constantPool , cpi , meta );
221
214
}
222
215
if (safeTagAt (constantPool , cpi , meta ) == ConstantPool .Tag .UTF8 ) {
223
216
return toJVMCIUnresolvedType (TypeSymbols .nameToType (constantPool .utf8At (cpi )), meta );
224
217
}
225
218
throw meta .throwIllegalArgumentExceptionBoundary ();
226
219
}
227
220
221
+ private static StaticObject resolvedConstantToJVMCIObjectType (ResolvedConstant resolvedConstant , RuntimeConstantPool constantPool , int cpi , Meta meta ) {
222
+ if (resolvedConstant == null || !resolvedConstant .isSuccess ()) {
223
+ return toJVMCIUnresolvedType (TypeSymbols .nameToType (constantPool .className (cpi )), meta );
224
+ }
225
+ Klass klass = (Klass ) resolvedConstant .value ();
226
+ return toJVMCIObjectType (klass , meta );
227
+ }
228
+
228
229
@ Substitution (hasReceiver = true )
229
230
@ TruffleBoundary
230
231
public static @ JavaType (internalName = "Lcom/oracle/truffle/espresso/jvmci/meta/EspressoResolvedJavaMethod;" ) StaticObject lookupResolvedMethod (StaticObject self , int cpi , int opcode ,
@@ -358,6 +359,7 @@ private static Method tryResolveMethod(int methodIndex, Klass symbolicHolder, Ru
358
359
StaticObject cpHolder = meta .jvmci .EspressoConstantPool_holder .getObject (self );
359
360
ObjectKlass cpHolderKlass = (ObjectKlass ) meta .jvmci .HIDDEN_OBJECTKLASS_MIRROR .getHiddenObject (cpHolder );
360
361
RuntimeConstantPool constantPool = cpHolderKlass .getConstantPool ();
362
+ int classCpi ;
361
363
switch (opcode ) {
362
364
case CHECKCAST :
363
365
case INSTANCEOF :
@@ -367,15 +369,10 @@ private static Method tryResolveMethod(int methodIndex, Klass symbolicHolder, Ru
367
369
case LDC :
368
370
case LDC_W :
369
371
case LDC2_W :
370
- if (safeTagAt (constantPool , cpi , meta ) == ConstantPool .Tag .CLASS ) {
371
- ResolvedConstant resolvedConstant = constantPool .peekResolvedOrNull (cpi , meta );
372
- if (resolvedConstant == null || !resolvedConstant .isSuccess ()) {
373
- return toJVMCIUnresolvedType (TypeSymbols .nameToType (constantPool .className (cpi )), meta );
374
- }
375
- Klass klass = (Klass ) resolvedConstant .value ();
376
- LOGGER .finer (() -> "ECP.lookupReferencedType found " + klass );
377
- return toJVMCIObjectType (klass , meta );
372
+ if (safeTagAt (constantPool , cpi , meta ) != ConstantPool .Tag .CLASS ) {
373
+ throw meta .throwIllegalArgumentExceptionBoundary ("Opcode and constant pool entry types mismatch" );
378
374
}
375
+ classCpi = cpi ;
379
376
break ;
380
377
case GETSTATIC :
381
378
case PUTSTATIC :
@@ -385,27 +382,28 @@ private static Method tryResolveMethod(int methodIndex, Klass symbolicHolder, Ru
385
382
case INVOKESPECIAL :
386
383
case INVOKESTATIC :
387
384
case INVOKEINTERFACE :
388
- if (safeTagAt (constantPool , cpi , meta ).isMember ()) {
389
- int holderClassIndex = constantPool .memberClassIndex (cpi );
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 ) {
398
- Symbol <Name > holderName = constantPool .memberClassName (cpi );
399
- return toJVMCIUnresolvedType (TypeSymbols .nameToType (holderName ), meta );
400
- }
401
- Klass finalHolderKlass = holderKlass ;
402
- LOGGER .finer (() -> "ECP.lookupReferencedType found " + finalHolderKlass );
403
- return toJVMCIObjectType (holderKlass , meta );
385
+ if (!safeTagAt (constantPool , cpi , meta ).isMember ()) {
386
+ throw meta .throwIllegalArgumentExceptionBoundary ("Opcode and constant pool entry types mismatch" );
404
387
}
388
+ classCpi = constantPool .memberClassIndex (cpi );
405
389
break ;
406
- }
407
- LOGGER .warning (() -> "Unsupported CP entry type for lookupReferencedType: " + safeTagAt (constantPool , cpi , meta ) + " " + constantPool .toString (cpi ) + " for " + Bytecodes .nameOf (opcode ));
408
- throw meta .throwIllegalArgumentExceptionBoundary ();
390
+ default :
391
+ LOGGER .warning (() -> "Unsupported CP entry type for lookupReferencedType: " + safeTagAt (constantPool , cpi , meta ) + " " + constantPool .toString (cpi ) + " for " +
392
+ Bytecodes .nameOf (opcode ));
393
+ throw meta .throwIllegalArgumentExceptionBoundary ("Unsupported CP entry type" );
394
+ }
395
+ Klass klass ;
396
+ try {
397
+ klass = findObjectType (classCpi , constantPool , false , meta );
398
+ } catch (EspressoException e ) {
399
+ throw EspressoError .shouldNotReachHere ("findObjectType with resolve=false should never throw" , e );
400
+ }
401
+ if (klass == null ) {
402
+ Symbol <Name > className = constantPool .className (classCpi );
403
+ return toJVMCIUnresolvedType (TypeSymbols .nameToType (className ), meta );
404
+ }
405
+ LOGGER .finer (() -> "ECP.lookupReferencedType found " + klass );
406
+ return toJVMCIObjectType (klass , meta );
409
407
}
410
408
411
409
@ Substitution (hasReceiver = true )
@@ -506,27 +504,13 @@ public static boolean loadReferencedType0(StaticObject self, int cpi, int opcode
506
504
}
507
505
switch (tag ) {
508
506
case CLASS -> {
509
- if (resolvedConstantOrNull == null || !resolvedConstantOrNull .isSuccess ()) {
510
- EspressoError .guarantee (!resolve || resolvedConstantOrNull != null , "Should have been resolved" );
511
- return toJVMCIUnresolvedType (TypeSymbols .nameToType (constantPool .className (cpi )), meta );
512
- }
513
- Klass klass = (Klass ) resolvedConstantOrNull .value ();
514
- LOGGER .finer (() -> "ECP.lookupConstant found " + klass );
515
- return toJVMCIObjectType (klass , meta );
507
+ EspressoError .guarantee (!resolve || resolvedConstantOrNull != null , "Should have been resolved" );
508
+ return resolvedConstantToJVMCIObjectType (resolvedConstantOrNull , constantPool , cpi , meta );
516
509
}
517
510
case STRING -> {
518
511
return wrapEspressoObjectConstant (constantPool .resolvedStringAt (cpi ), meta );
519
512
}
520
- case METHODHANDLE -> {
521
- if (resolvedConstantOrNull != null ) {
522
- return wrapEspressoObjectConstant ((StaticObject ) resolvedConstantOrNull .value (), meta );
523
- } else if (resolve ) {
524
- throw EspressoError .shouldNotReachHere ();
525
- } else {
526
- return StaticObject .NULL ;
527
- }
528
- }
529
- case METHODTYPE -> {
513
+ case METHODHANDLE , METHODTYPE -> {
530
514
if (resolvedConstantOrNull != null ) {
531
515
return wrapEspressoObjectConstant ((StaticObject ) resolvedConstantOrNull .value (), meta );
532
516
} else if (resolve ) {
0 commit comments