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

Conversation

pdbain-ibm
Copy link
Contributor

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.

Fixes #1524

Signed-off-by: Peter Bain peter_bain@ca.ibm.com

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

@pdbain-ibm
Copy link
Contributor Author

@DanHeidinga any other comments?

*methodIndex = getITableIndexForMethod(method, lookupClass);
if (-1 == *methodIndex) {
method = NULL;
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGNOSUCHMETHODERROR, NULL);
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 sent the method name & signature as the message for this exception?

if (J9_ARE_ANY_BITS_SET(J9_CLASS_FROM_METHOD(method)->romClass->modifiers, J9_JAVA_INTERFACE)) {
*methodIndex = getITableIndexForMethod(method, lookupClass);
if (-1 == *methodIndex) {
char msg[64]; /* long enough for most name and signature combinations */
Copy link
Member

Choose a reason for hiding this comment

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

Let's write the code to allocate a buffer if this assumption is invalid. Not uncommon for ~40+ chars to be consumed by the package name. We've got examples of that pattern in exceptionsupport.c (I think)

@pdbain-ibm pdbain-ibm force-pushed the interface branch 2 times, most recently from 297666c to 7df1abb Compare April 2, 2018 12:23
@pdbain-ibm
Copy link
Contributor Author

Dan
No problem. Since this situation is uncommon, I will allocate and free buffer unconditionally.
Testing now...

+ J9UTF8_LENGTH(methodName) + J9UTF8_LENGTH(sig)
+ 4 /* period, parentheses, and terminating null */;
char *msg = (char *)j9mem_allocate_memory(nameAndSigLength, OMRMEM_CATEGORY_VM);
Assert_JCL_notNull(msg);
Copy link
Member

Choose a reason for hiding this comment

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

We don't assert on the return of j9mem_allocate_memory. The code can either throw the NSME or it can throw a NativeOOM but crashing the VM isn't the right choice.

size_t nameAndSigLength = J9UTF8_LENGTH(className)
+ J9UTF8_LENGTH(methodName) + J9UTF8_LENGTH(sig)
+ 4 /* period, parentheses, and terminating null */;
char *msg = (char *)j9mem_allocate_memory(nameAndSigLength, OMRMEM_CATEGORY_VM);
Copy link
Member

Choose a reason for hiding this comment

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

The (char *) cast isn't required for the return value of j9mem_allocate_memory() in C code.

@@ -78,6 +78,7 @@ static UDATA
lookupInterfaceMethod(J9VMThread *currentThread, J9Class *lookupClass, J9UTF8 *name, J9UTF8 *signature, UDATA *methodIndex)
{
J9Method *method;
PORT_ACCESS_FROM_VMC(currentThread);
Copy link
Member

Choose a reason for hiding this comment

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

This can be moved to the smallest enclosing the scope - the one using j9mem_allocate_memory

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 */;

@pdbain-ibm pdbain-ibm force-pushed the interface branch 2 times, most recently from 600edca to d259692 Compare April 2, 2018 13:40
@pdbain-ibm
Copy link
Contributor Author

Thank you. Formatting, declarations, and allocation failure updated accordingly.

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

Choose a reason for hiding this comment

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

The format string isn't correct. It needs to be %.*s.%.*s(%.*s) to handle the non-null terminated UTF8s.

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>
@pdbain-ibm
Copy link
Contributor Author

Fixed format string.

@DanHeidinga
Copy link
Member

Jenkins test sanity plinux

@DanHeidinga DanHeidinga self-assigned this Apr 2, 2018
@DanHeidinga DanHeidinga merged commit c46f389 into eclipse-openj9:master Apr 3, 2018
@DanHeidinga
Copy link
Member

@pdbain-ibm Can you create another PR to add your simple test case from #1524 to the JSR 292 test bucket?

@pdbain-ibm
Copy link
Contributor Author

pdbain-ibm commented Apr 3, 2018

Issue for test case: #1593.
@DanHeidinga would you please assign that issue to me.

@pdbain-ibm pdbain-ibm deleted the interface branch March 19, 2019 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants