|
45 | 45 | import com.oracle.truffle.api.library.CachedLibrary;
|
46 | 46 | import com.oracle.truffle.api.nodes.NodeInfo;
|
47 | 47 | import com.oracle.truffle.api.profiles.BranchProfile;
|
| 48 | +import com.oracle.truffle.api.profiles.InlinedBranchProfile; |
48 | 49 | import com.oracle.truffle.espresso.EspressoLanguage;
|
49 | 50 | import com.oracle.truffle.espresso.impl.ArrayKlass;
|
50 | 51 | import com.oracle.truffle.espresso.impl.Klass;
|
@@ -223,7 +224,8 @@ static ToReference getUncachedToReference(Klass targetType, Meta meta) {
|
223 | 224 | return ToReferenceFactory.ToByteArrayNodeGen.getUncached();
|
224 | 225 | }
|
225 | 226 | if (targetType.isArray()) {
|
226 |
| - throw new IllegalStateException("Generic arrays type mappings must be handled separately!"); |
| 227 | + // Generic arrays type mappings must be handled separately! |
| 228 | + return null; |
227 | 229 | }
|
228 | 230 | if (targetType.isJavaLangObject()) {
|
229 | 231 | return ToReferenceFactory.ToJavaLangObjectNodeGen.getUncached();
|
@@ -255,11 +257,8 @@ static ToReference getUncachedToReference(Klass targetType, Meta meta) {
|
255 | 257 | return ToReferenceFactory.ToMapNodeGen.getUncached();
|
256 | 258 | }
|
257 | 259 | }
|
258 |
| - if (isTypeMappingEnabled(targetType)) { |
259 |
| - throw new IllegalStateException("Interface type mappings must be handled separately!"); |
260 |
| - } else { |
261 |
| - throw new IllegalStateException("unknown types must be handled separately!"); |
262 |
| - } |
| 260 | + // Interface type mappings & unknown interface types must be handled separately! |
| 261 | + return null; |
263 | 262 | }
|
264 | 263 | if (isForeignException(targetType, meta)) {
|
265 | 264 | return ToReferenceFactory.ToForeignExceptionNodeGen.getUncached();
|
@@ -300,7 +299,7 @@ static ToReference getUncachedToReference(Klass targetType, Meta meta) {
|
300 | 299 | if (targetType == meta.java_math_BigInteger) {
|
301 | 300 | return ToReferenceFactory.ToBigIntegerNodeGen.getUncached();
|
302 | 301 | }
|
303 |
| - throw new IllegalStateException("unknown types must be handled separately!"); |
| 302 | + return null; |
304 | 303 | }
|
305 | 304 |
|
306 | 305 | @NodeInfo(shortName = "Dynamic toEspresso node")
|
@@ -454,21 +453,23 @@ public StaticObject doInternalTypeConverter(Object value, @SuppressWarnings("unu
|
454 | 453 | })
|
455 | 454 | public StaticObject doGeneric(Object value, Klass targetType,
|
456 | 455 | @Bind("getMeta()") Meta meta,
|
457 |
| - @CachedLibrary(limit = "LIMIT") InteropLibrary interop) throws UnsupportedTypeException { |
458 |
| - try { |
459 |
| - return getUncachedToReference(targetType, meta).execute(value); |
460 |
| - } catch (IllegalStateException ex) { |
461 |
| - // hit the unknown type case, so inline generic handling for that here |
462 |
| - if (targetType instanceof ObjectKlass) { |
463 |
| - try { |
464 |
| - checkHasAllFieldsOrThrow(value, (ObjectKlass) targetType, interop, getMeta()); |
465 |
| - return StaticObject.createForeign(getLanguage(), targetType, value, interop); |
466 |
| - } catch (ClassCastException e) { |
467 |
| - throw UnsupportedTypeException.create(new Object[]{value}, targetType.getTypeAsString()); |
468 |
| - } |
| 456 | + @CachedLibrary(limit = "LIMIT") InteropLibrary interop, |
| 457 | + @Cached InlinedBranchProfile unknownProfile) throws UnsupportedTypeException { |
| 458 | + ToReference uncachedToReference = getUncachedToReference(targetType, meta); |
| 459 | + if (uncachedToReference != null) { |
| 460 | + return uncachedToReference.execute(value); |
| 461 | + } |
| 462 | + unknownProfile.enter(this); |
| 463 | + // hit the unknown type case, so inline generic handling for that here |
| 464 | + if (targetType instanceof ObjectKlass) { |
| 465 | + try { |
| 466 | + checkHasAllFieldsOrThrow(value, (ObjectKlass) targetType, interop, getMeta()); |
| 467 | + return StaticObject.createForeign(getLanguage(), targetType, value, interop); |
| 468 | + } catch (ClassCastException e) { |
| 469 | + throw UnsupportedTypeException.create(new Object[]{value}, targetType.getTypeAsString()); |
469 | 470 | }
|
470 |
| - throw UnsupportedTypeException.create(new Object[]{value}, targetType.getTypeAsString()); |
471 | 471 | }
|
| 472 | + throw UnsupportedTypeException.create(new Object[]{value}, targetType.getTypeAsString()); |
472 | 473 | }
|
473 | 474 | }
|
474 | 475 |
|
|
0 commit comments