106106import com .oracle .truffle .espresso .runtime .dispatch .staticobject .InteropLookupAndInvoke ;
107107import com .oracle .truffle .espresso .runtime .dispatch .staticobject .InteropLookupAndInvokeFactory ;
108108import com .oracle .truffle .espresso .runtime .staticobject .StaticObject ;
109- import com .oracle .truffle .espresso .shared .meta .SignaturePolymorphicIntrinsic ;
109+ import com .oracle .truffle .espresso .shared .lookup .LookupMode ;
110+ import com .oracle .truffle .espresso .shared .lookup .LookupSuccessInvocationFailure ;
110111import com .oracle .truffle .espresso .shared .meta .TypeAccess ;
111112import com .oracle .truffle .espresso .substitutions .JavaType ;
112113import com .oracle .truffle .espresso .vm .InterpreterToVM ;
@@ -1369,30 +1370,6 @@ public StaticObject allocateReferenceArray(int length, IntFunction<StaticObject>
13691370
13701371 // region Lookup
13711372
1372- public enum LookupMode {
1373- ALL (true , true ),
1374- INSTANCE_ONLY (true , false ),
1375- STATIC_ONLY (false , true );
1376-
1377- private final boolean instances ;
1378- private final boolean statics ;
1379-
1380- LookupMode (boolean instances , boolean statics ) {
1381- this .instances = instances ;
1382- this .statics = statics ;
1383- }
1384-
1385- public boolean include (Member <?> m ) {
1386- if (m == null ) {
1387- return false ;
1388- }
1389- if (statics && m .isStatic ()) {
1390- return true ;
1391- }
1392- return instances && !m .isStatic ();
1393- }
1394- }
1395-
13961373 public final Field requireDeclaredField (Symbol <Name > fieldName , Symbol <Type > fieldType ) {
13971374 Field obj = lookupDeclaredField (fieldName , fieldType );
13981375 if (obj == null ) {
@@ -1490,20 +1467,10 @@ public final Method requireDeclaredMethod(Symbol<Name> methodName, Symbol<Signat
14901467 return obj ;
14911468 }
14921469
1493- public final Method lookupDeclaredMethod (Symbol <Name > methodName , Symbol <Signature > signature ) {
1494- return lookupDeclaredMethod (methodName , signature , LookupMode .ALL );
1495- }
1496-
1497- @ ExplodeLoop
14981470 public final Method lookupDeclaredMethod (Symbol <Name > methodName , Symbol <Signature > signature , LookupMode lookupMode ) {
1499- KLASS_LOOKUP_DECLARED_METHOD_COUNT .inc ();
1500- // TODO(peterssen): Improve lookup performance.
1501- for (Method method : getDeclaredMethods ()) {
1502- if (lookupMode .include (method )) {
1503- if (methodName .equals (method .getName ()) && signature .equals (method .getRawSignature ())) {
1504- return method ;
1505- }
1506- }
1471+ Method result = lookupDeclaredMethod (methodName , signature );
1472+ if (lookupMode .include (result )) {
1473+ return result ;
15071474 }
15081475 return null ;
15091476 }
@@ -1558,17 +1525,6 @@ protected static int fastLookupImpl(Klass target, ObjectKlass.KlassVersion[] kla
15581525 return -1 ; // not found
15591526 }
15601527
1561- /**
1562- * Give the accessing klass if there is a chance the method to be resolved is a method handle
1563- * intrinsics.
1564- */
1565- public abstract Method lookupMethod (Symbol <Name > methodName , Symbol <Signature > signature , LookupMode lookupMode );
1566-
1567- @ Override
1568- public final Method lookupMethod (Symbol <Name > methodName , Symbol <Signature > signature ) {
1569- return lookupMethod (methodName , signature , LookupMode .ALL );
1570- }
1571-
15721528 public final Method vtableLookup (int vtableIndex ) {
15731529 if (this instanceof ObjectKlass ) {
15741530 return ((ObjectKlass ) this ).vtableLookupImpl (vtableIndex );
@@ -1581,41 +1537,6 @@ public final Method vtableLookup(int vtableIndex) {
15811537 return null ;
15821538 }
15831539
1584- public Method lookupSignaturePolymorphicMethod (Symbol <Name > methodName , Symbol <Signature > signature , LookupMode lookupMode ) {
1585- Method m = lookupSignaturePolymorphicDeclaredMethod (methodName , lookupMode );
1586- if (m != null ) {
1587- return findMethodHandleIntrinsic (m , signature );
1588- }
1589- return null ;
1590- }
1591-
1592- public Method lookupSignaturePolymorphicDeclaredMethod (Symbol <Name > methodName , LookupMode lookupMode ) {
1593- for (Method m : getDeclaredMethods ()) {
1594- if (lookupMode .include (m )) {
1595- if (m .getName () == methodName && m .isDeclaredSignaturePolymorphic ()) {
1596- return m ;
1597- }
1598- }
1599- }
1600- return null ;
1601- }
1602-
1603- @ Override
1604- public Method lookupDeclaredSignaturePolymorphicMethod (Symbol <Name > methodName ) {
1605- return lookupSignaturePolymorphicDeclaredMethod (methodName , LookupMode .ALL );
1606- }
1607-
1608- @ TruffleBoundary
1609- private Method findMethodHandleIntrinsic (Method m , Symbol <Signature > signature ) {
1610- assert m .isDeclaredSignaturePolymorphic ();
1611- SignaturePolymorphicIntrinsic iid = SignaturePolymorphicIntrinsic .getId (m );
1612- Symbol <Signature > sig = signature ;
1613- if (iid .isStaticSignaturePolymorphic ()) {
1614- sig = getSignatures ().toBasic (signature , true );
1615- }
1616- return m .findIntrinsic (sig );
1617- }
1618-
16191540 /**
16201541 * Returns the access flags provided by the .class file, e.g. ignores inner class access flags.
16211542 */
@@ -1886,14 +1807,6 @@ public final Klass getSuperClass() {
18861807 return getSuperKlass ();
18871808 }
18881809
1889- @ Override
1890- public final Method lookupInterfaceMethod (Symbol <Name > methodName , Symbol <Signature > methodSignature ) {
1891- if (this instanceof ObjectKlass ) {
1892- return ((ObjectKlass ) this ).resolveInterfaceMethod (methodName , methodSignature );
1893- }
1894- return null ;
1895- }
1896-
18971810 @ Override
18981811 public List <Klass > getSuperInterfacesList () {
18991812 return Arrays .asList (getSuperInterfaces ());
@@ -1906,15 +1819,59 @@ public List<Method> getDeclaredMethodsList() {
19061819
19071820 @ Override
19081821 public List <Method > getImplicitInterfaceMethodsList () {
1822+ if (isInterface ()) {
1823+ return null ;
1824+ }
19091825 if (this instanceof ObjectKlass ) {
19101826 return Method .versionsToMethodList (((ObjectKlass ) this ).getMirandaMethods ());
19111827 }
19121828 return Collections .emptyList ();
19131829 }
19141830
1831+ @ TruffleBoundary
1832+ public final Method lookupDeclaredMethod (Symbol <Name > methodName , Symbol <Signature > signature ) {
1833+ KLASS_LOOKUP_DECLARED_METHOD_COUNT .inc ();
1834+ return TypeAccess .super .lookupDeclaredMethod (methodName , signature );
1835+ }
1836+
1837+ @ Override
1838+ @ TruffleBoundary
1839+ public Method lookupDeclaredSignaturePolymorphicMethod (Symbol <Name > methodName ) {
1840+ KLASS_LOOKUP_DECLARED_METHOD_COUNT .inc ();
1841+ return TypeAccess .super .lookupDeclaredSignaturePolymorphicMethod (methodName );
1842+ }
1843+
1844+ @ Override
1845+ @ TruffleBoundary
1846+ public Method lookupMethod (Symbol <Name > methodName , Symbol <Signature > signature ) {
1847+ try {
1848+ KLASS_LOOKUP_METHOD_COUNT .inc ();
1849+ return TypeAccess .super .lookupMethod (methodName , signature );
1850+ } catch (LookupSuccessInvocationFailure e ) {
1851+ return e .<Method > getResult ().forFailing ();
1852+ }
1853+ }
1854+
19151855 @ Override
1856+ @ TruffleBoundary
19161857 public final Method lookupInstanceMethod (Symbol <Name > methodName , Symbol <Signature > methodSignature ) {
1917- return lookupMethod (methodName , methodSignature , LookupMode .INSTANCE_ONLY );
1858+ try {
1859+ KLASS_LOOKUP_METHOD_COUNT .inc ();
1860+ return TypeAccess .super .lookupInstanceMethod (methodName , methodSignature );
1861+ } catch (LookupSuccessInvocationFailure e ) {
1862+ return e .<Method > getResult ().forFailing ();
1863+ }
1864+ }
1865+
1866+ @ Override
1867+ @ TruffleBoundary
1868+ public final Method lookupInterfaceMethod (Symbol <Name > methodName , Symbol <Signature > methodSignature ) {
1869+ try {
1870+ KLASS_LOOKUP_METHOD_COUNT .inc ();
1871+ return TypeAccess .super .lookupInterfaceMethod (methodName , methodSignature );
1872+ } catch (LookupSuccessInvocationFailure e ) {
1873+ return e .<Method > getResult ().forFailing ();
1874+ }
19181875 }
19191876
19201877 @ Override
0 commit comments