-
Notifications
You must be signed in to change notification settings - Fork 738
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
Refactor vTable Access #2409
Refactor vTable Access #2409
Conversation
@gacholio Can you please take a look? |
runtime/oti/j9.h
Outdated
@@ -301,4 +301,12 @@ static const struct { \ | |||
#define J9_VM_FUNCTION_VIA_JAVAVM(javaVM, function) ((javaVM)->internalVMFunctions->function) | |||
#endif /* J9_INTERNAL_TO_VM */ | |||
|
|||
#define J9VTABLE_HEADER_FROM_RAM_CLASS(clazz) ((J9VTableHeader *)((J9Class *)clazz + 1)) | |||
#define J9VTABLE_FROM_HEADER(vtableHeader) ((UDATA *) ((J9VTableHeader *)vtableHeader + 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be J9Method** and a bunch of the casting could be avoided.
runtime/oti/j9.h
Outdated
#define J9VTABLE_HEADER_FROM_RAM_CLASS(clazz) ((J9VTableHeader *)((J9Class *)clazz + 1)) | ||
#define J9VTABLE_FROM_HEADER(vtableHeader) ((UDATA *) ((J9VTableHeader *)vtableHeader + 1)) | ||
#define J9VTABLE_FROM_RAM_CLASS(clazz) J9VTABLE_FROM_HEADER(J9VTABLE_HEADER_FROM_RAM_CLASS(clazz)) | ||
#define J9VTABLE_OFFSET_FROM_INDEX(index) (sizeof(J9Class) + sizeof(J9VTableHeader) + index * sizeof(UDATA)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please bracket the multiplication. Also index itself needs bracketting.
runtime/oti/j9.h
Outdated
#define J9VTABLE_OFFSET_FROM_INDEX(index) (sizeof(J9Class) + sizeof(J9VTableHeader) + index * sizeof(UDATA)) | ||
|
||
/* Skip 1 slot (the vTable size slot) */ | ||
#define JIT_VTABLE_START_ADDRESS(clazz) ((UDATA *)clazz - (sizeof(J9VTableHeader) / sizeof(UDATA))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clazz needs bracketting.
J9Method ** superVTable = (J9Method **)((char *)superCl + sizeof(J9Class)); // a pointer to an array of j9method pointers (the vtable!) | ||
J9Method ** subVTable = (J9Method **)((char *)cl + sizeof(J9Class)); | ||
J9VTableHeader * superVTableHeader = J9VTABLE_HEADER_FROM_RAM_CLASS(superCl); | ||
intptrj_t methodCount = (intptrj_t)superVTableHeader->size; //Vtable starts at end of j9class. First entry is num methods in vtable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment here no longer applies.
runtime/oti/j9nonbuilder.h
Outdated
@@ -3454,6 +3454,11 @@ typedef struct J9ITable { | |||
struct J9ITable* next; | |||
} J9ITable; | |||
|
|||
typedef struct J9VTableHeader { | |||
UDATA size; | |||
UDATA* initialVirtualMethod; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well be J9Method*
runtime/util/hshelp.c
Outdated
|
||
/* Search the vTable for a public method of the correct name. */ | ||
for (searchIndex = 2; searchIndex <= vTableSize; searchIndex++) { | ||
J9Method *vTableMethod = (J9Method *)vTable[searchIndex]; | ||
for (searchIndex; searchIndex < vTableSize; searchIndex++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
searchIndex; does nothing. It would be much clearer to initialize it to 0 again here.
runtime/util/hshelp.c
Outdated
|
||
for (i = 2; i <= vTableSize; i++) { | ||
/* Skip the first two slots containing vtable size and the resolve method */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment no longer applies.
runtime/oti/j9.h
Outdated
#define J9VTABLE_FROM_RAM_CLASS(clazz) J9VTABLE_FROM_HEADER(J9VTABLE_HEADER_FROM_RAM_CLASS(clazz)) | ||
#define J9VTABLE_OFFSET_FROM_INDEX(index) (sizeof(J9Class) + sizeof(J9VTableHeader) + index * sizeof(UDATA)) | ||
|
||
/* Skip 1 slot (the vTable size slot) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is incorrect - update to say that is skips the header.
runtime/util/resolvehelp.c
Outdated
@@ -68,14 +68,15 @@ getMethodForSpecialSend(J9VMThread *vmStruct, J9Class *currentClass, J9Class *re | |||
* 3) Walk the current class vtable backwards to find the most "recent" override of that method | |||
* 4) Lookup the method at vtableIndex in currentClass's super class | |||
*/ | |||
UDATA superVTableSize = (*(UDATA*)(superclass + 1) * sizeof(UDATA)) + sizeof(J9Class); | |||
J9VTableHeader * superVTable = J9VTABLE_HEADER_FROM_RAM_CLASS(superclass); | |||
UDATA superVTableEnd =J9VTABLE_OFFSET_FROM_INDEX(superVTable->size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after =
runtime/vm/createramclass.cpp
Outdated
while (tempIndex > 1) { | ||
while (tempIndex > 0) { | ||
/* Decrement the index, convert from one based to zero based index */ | ||
tempIndex--; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For single statements, -= 1 is preferred.
runtime/vm/createramclass.cpp
Outdated
/* + 1 to account for size slot */ | ||
memcpy(vTableAddress, superVTable, (vTableWriteIndex + 1) * sizeof(UDATA)); | ||
memcpy(vTableAddress, superVTable, (vTableWriteIndex * sizeof(UDATA) + sizeof(J9VTableHeader))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bracket multiply
runtime/vm/createramclass.cpp
Outdated
superclassVTableIndex--; | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the comment, but remove the commented out code
runtime/vm/createramclass.cpp
Outdated
/* fill in vtable, add new entry */ | ||
vTableAddress[vTableWriteIndex] = (UDATA)storeValue; | ||
/* move up the vTableWriteIndex */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this comment.
15f5328
to
284d3c4
Compare
fixed comments and type casting with |
ae31513
to
c6d8d89
Compare
@gacholio fix all the issues in your comments, can I get a re-review? |
runtime/oti/j9.h
Outdated
@@ -301,4 +301,12 @@ static const struct { \ | |||
#define J9_VM_FUNCTION_VIA_JAVAVM(javaVM, function) ((javaVM)->internalVMFunctions->function) | |||
#endif /* J9_INTERNAL_TO_VM */ | |||
|
|||
#define J9VTABLE_HEADER_FROM_RAM_CLASS(clazz) ((J9VTableHeader *)((J9Class *)(clazz) + 1)) | |||
#define J9VTABLE_FROM_HEADER(vtableHeader) ((J9Method **) ((J9VTableHeader *)(vtableHeader) + 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these could use some extra brackets to isolate the cast from the +1, since either interpretation is syntactically valid, but have wildly different results.
- add vTable Header structure - update vtable indexing to be zero based - modify vtable size field to hold the real method count - add macro for getting JIT vtable start address - switch all vtable variable assignment to use new macros - calculate vtable offset dynamically based on header size - changed default vtable type to <J9Method**> - removed old comments on magic indexes Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
jenkins test sanity xlinux jdk8 |
Signed-off-by: Graham Chapman <graham_chapman@ca.ibm.com>
Fix warning introduced in #2409
Signed-off-by: Jack Lu Jack.S.Lu@ibm.com