Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set InterfaceHandle correctly for methods inherited from Object #1554

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still be setting method to null if getITableIndexForMethod() returned -1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is there a path through this code (or the caller) that allows returning with a null J9Method without having set an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to return null and throw an exception.

lookupImpl() throws an exception when it returns null.
getMethodForSpecialSend() asserts notNull on the result

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you adjust the formatting on this? The lines seem excessively tabbed over

Something like this is more readable

					size_t nameAndSigLength = J9UTF8_LENGTH(className)
							+ J9UTF8_LENGTH(methodName) + J9UTF8_LENGTH(sig)
							+ 4 /* period, parentheses, and terminating null */;

+ 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