Skip to content

Commit

Permalink
Set InterfaceHandle correctly for methods inherited from Object
Browse files Browse the repository at this point in the history
When calling lookup().getVirtual() on an interface for a method in
java.lang.Object, don't check the itables for the method.  Instead, set the
methodIndex to -1 and return the concrete method.

If the method cannot be found,  throw an exception.

Signed-off-by: Peter Bain <peter_bain@ca.ibm.com>
  • Loading branch information
pdbain-ibm committed Apr 2, 2018
1 parent d4931e7 commit 838aac1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 26 additions & 3 deletions runtime/jcl/common/java_dyn_methodhandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,32 @@ lookupInterfaceMethod(J9VMThread *currentThread, J9Class *lookupClass, J9UTF8 *n
vmFuncs->setCurrentExceptionNLS(currentThread, J9VMCONSTANTPOOL_JAVALANGINCOMPATIBLECLASSCHANGEERROR, J9NLS_JCL_PRIVATE_INTERFACE_REQUIRES_INVOKESPECIAL);
method = NULL;
} else {
*methodIndex = getITableIndexForMethod(method, lookupClass);
if (*methodIndex == -1) {
method = NULL;
if (J9_ARE_ANY_BITS_SET(J9_CLASS_FROM_METHOD(method)->romClass->modifiers, J9_JAVA_INTERFACE)) {
*methodIndex = getITableIndexForMethod(method, lookupClass);
if (-1 == *methodIndex) {
PORT_ACCESS_FROM_VMC(currentThread);
J9Class *clazz = J9_CLASS_FROM_METHOD(method);
J9UTF8 *className = J9ROMCLASS_CLASSNAME(clazz->romClass);
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
J9UTF8 *methodName = J9ROMMETHOD_NAME(romMethod);
J9UTF8 *sig = J9ROMMETHOD_SIGNATURE(romMethod);
size_t nameAndSigLength = J9UTF8_LENGTH(className)
+ J9UTF8_LENGTH(methodName) + J9UTF8_LENGTH(sig)
+ 4 /* period, parentheses, and terminating null */;
char *msg = j9mem_allocate_memory(nameAndSigLength, OMRMEM_CATEGORY_VM);
if (NULL != msg) {
j9str_printf(PORTLIB, msg, nameAndSigLength, "%.*s.%.*s(%.*s)",
J9UTF8_LENGTH(className), J9UTF8_DATA(className),
J9UTF8_LENGTH(methodName), J9UTF8_DATA(methodName),
J9UTF8_LENGTH(sig), J9UTF8_DATA(sig));
vmFuncs->setCurrentExceptionUTF(currentThread,
J9VMCONSTANTPOOL_JAVALANGNOSUCHMETHODERROR, msg);
j9mem_free_memory(msg);
} else {
vmFuncs->setNativeOutOfMemoryError(currentThread, 0, 0);
}
method = NULL;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/oti/util_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,8 @@ getITableIndexForMethod(J9Method * method, J9Class *targetInterface);
* Returns the first ROM method following the argument.
* If this is called on the last ROM method in a ROM class
* it will return an undefined value.
* The defining class of method must be an interface; do not use this
* for methods inherited from java.lang.Object.
*
* @param[in] romMethod - the current ROM method
* @return - the ROM method following the current one
Expand Down

0 comments on commit 838aac1

Please sign in to comment.