|
37 | 37 | import com.oracle.truffle.api.interop.UnsupportedTypeException;
|
38 | 38 | import com.oracle.truffle.api.library.CachedLibrary;
|
39 | 39 | import com.oracle.truffle.api.nodes.NodeInfo;
|
| 40 | +import com.oracle.truffle.api.profiles.InlinedBranchProfile; |
40 | 41 | import com.oracle.truffle.espresso.EspressoLanguage;
|
41 | 42 | import com.oracle.truffle.espresso.impl.ArrayKlass;
|
42 | 43 | import com.oracle.truffle.espresso.impl.Field;
|
@@ -262,21 +263,30 @@ public Object doInternalTypeConverter(Object value, Klass targetType,
|
262 | 263 | })
|
263 | 264 | public Object doGeneric(Object value, Klass targetType,
|
264 | 265 | @Bind("getMeta()") Meta meta,
|
265 |
| - @CachedLibrary(limit = "LIMIT") InteropLibrary interop) throws UnsupportedTypeException { |
266 |
| - try { |
267 |
| - return getUncachedToEspresso(targetType, meta).execute(value); |
268 |
| - } catch (IllegalStateException ex) { |
269 |
| - // hit the unknown type case, so inline generic handling for that here |
270 |
| - if (targetType instanceof ObjectKlass) { |
271 |
| - try { |
272 |
| - checkHasAllFieldsOrThrow(value, (ObjectKlass) targetType, interop, getMeta()); |
273 |
| - return StaticObject.createForeign(getLanguage(), targetType, value, interop); |
274 |
| - } catch (ClassCastException e) { |
275 |
| - throw UnsupportedTypeException.create(new Object[]{value}, targetType.getTypeAsString()); |
276 |
| - } |
| 266 | + @CachedLibrary(limit = "LIMIT") InteropLibrary interop, |
| 267 | + @Cached LookupTypeConverterNode lookupTypeConverterNode, |
| 268 | + @Cached LookupInternalTypeConverterNode lookupInternalTypeConverterNode, |
| 269 | + @Cached ToReference.DynamicToReference converterToEspresso, |
| 270 | + @Cached InlinedBranchProfile unknownProfile) throws UnsupportedTypeException { |
| 271 | + ToEspressoNode uncachedToEspresso = getUncachedToEspresso(targetType, meta); |
| 272 | + if (uncachedToEspresso != null) { |
| 273 | + return uncachedToEspresso.execute(value); |
| 274 | + } |
| 275 | + unknownProfile.enter(this); |
| 276 | + // hit the unknown type case, so inline generic handling for that here |
| 277 | + if (targetType instanceof ObjectKlass) { |
| 278 | + StaticObject result = ToReference.tryConverterForUnknownTarget(value, interop, lookupTypeConverterNode, lookupInternalTypeConverterNode, converterToEspresso, meta); |
| 279 | + if (result != null) { |
| 280 | + return result; |
| 281 | + } |
| 282 | + try { |
| 283 | + checkHasAllFieldsOrThrow(value, (ObjectKlass) targetType, interop, getMeta()); |
| 284 | + return StaticObject.createForeign(getLanguage(), targetType, value, interop); |
| 285 | + } catch (ClassCastException e) { |
| 286 | + throw UnsupportedTypeException.create(new Object[]{value}, targetType.getTypeAsString()); |
277 | 287 | }
|
278 |
| - throw UnsupportedTypeException.create(new Object[]{value}, targetType.getTypeAsString()); |
279 | 288 | }
|
| 289 | + throw UnsupportedTypeException.create(new Object[]{value}, targetType.getTypeAsString()); |
280 | 290 | }
|
281 | 291 | }
|
282 | 292 |
|
|
0 commit comments