@@ -133,37 +133,41 @@ static MethodHandle arrayLengthGetter(Class<?> arrayType) {
133133 * <p>
134134 * @param receiverClass Class of the object to invoke the method on.
135135 * @param name Name of the method.
136+ * @param type Callsite signature. Need not match exactly, except the number of parameters.
136137 * @param definition Whitelist to check.
137138 * @return pointer to matching method to invoke. never returns null.
138139 * @throws IllegalArgumentException if no matching whitelisted method was found.
139140 */
140- static MethodHandle lookupMethod (Class <?> receiverClass , String name , Definition definition ) {
141- // check whitelist for matching method
142- for (Class <?> clazz = receiverClass ; clazz != null ; clazz = clazz .getSuperclass ()) {
143- RuntimeClass struct = definition .runtimeMap .get (clazz );
144-
145- if (struct != null ) {
146- Method method = struct .methods .get (name );
147- if (method != null ) {
148- return method .handle ;
149- }
150- }
151-
152- for (final Class <?> iface : clazz .getInterfaces ()) {
153- struct = definition .runtimeMap .get (iface );
154-
155- if (struct != null ) {
156- Method method = struct .methods .get (name );
157- if (method != null ) {
158- return method .handle ;
159- }
160- }
161- }
162- }
163-
164- // no matching methods in whitelist found
165- throw new IllegalArgumentException ("Unable to find dynamic method [" + name + "] " +
166- "for class [" + receiverClass .getCanonicalName () + "]." );
141+ static MethodHandle lookupMethod (Class <?> receiverClass , String name , MethodType type , Definition definition ) {
142+ // we don't consider receiver an argument/counting towards arity
143+ type = type .dropParameterTypes (0 , 1 );
144+ Definition .MethodKey key = new Definition .MethodKey (name , type .parameterCount ());
145+ // check whitelist for matching method
146+ for (Class <?> clazz = receiverClass ; clazz != null ; clazz = clazz .getSuperclass ()) {
147+ RuntimeClass struct = definition .runtimeMap .get (clazz );
148+
149+ if (struct != null ) {
150+ Method method = struct .methods .get (key );
151+ if (method != null ) {
152+ return method .handle ;
153+ }
154+ }
155+
156+ for (final Class <?> iface : clazz .getInterfaces ()) {
157+ struct = definition .runtimeMap .get (iface );
158+
159+ if (struct != null ) {
160+ Method method = struct .methods .get (key );
161+ if (method != null ) {
162+ return method .handle ;
163+ }
164+ }
165+ }
166+ }
167+
168+ // no matching methods in whitelist found
169+ throw new IllegalArgumentException ("Unable to find dynamic method [" + name + "] with signature [" + type + "] " +
170+ "for class [" + receiverClass .getCanonicalName () + "]." );
167171 }
168172
169173 /**
0 commit comments