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

Refactor vTable Access #2409

Merged
merged 1 commit into from
Jul 18, 2018
Merged

Refactor vTable Access #2409

merged 1 commit into from
Jul 18, 2018

Conversation

fengxue-IS
Copy link
Contributor

@fengxue-IS fengxue-IS commented Jul 17, 2018

  • 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

@fengxue-IS
Copy link
Contributor Author

@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))
Copy link
Contributor

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

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

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
Copy link
Contributor

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.

@@ -3454,6 +3454,11 @@ typedef struct J9ITable {
struct J9ITable* next;
} J9ITable;

typedef struct J9VTableHeader {
UDATA size;
UDATA* initialVirtualMethod;
Copy link
Contributor

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*


/* 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++) {
Copy link
Contributor

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.


for (i = 2; i <= vTableSize; i++) {
/* Skip the first two slots containing vtable size and the resolve method */
Copy link
Contributor

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) */
Copy link
Contributor

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.

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

space after =

while (tempIndex > 1) {
while (tempIndex > 0) {
/* Decrement the index, convert from one based to zero based index */
tempIndex--;
Copy link
Contributor

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.

/* + 1 to account for size slot */
memcpy(vTableAddress, superVTable, (vTableWriteIndex + 1) * sizeof(UDATA));
memcpy(vTableAddress, superVTable, (vTableWriteIndex * sizeof(UDATA) + sizeof(J9VTableHeader)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Bracket multiply

superclassVTableIndex--;
*/
Copy link
Contributor

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

/* fill in vtable, add new entry */
vTableAddress[vTableWriteIndex] = (UDATA)storeValue;
/* move up the vTableWriteIndex */
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this comment.

@fengxue-IS fengxue-IS force-pushed the vtable2 branch 2 times, most recently from 15f5328 to 284d3c4 Compare July 17, 2018 19:56
@fengxue-IS
Copy link
Contributor Author

fixed comments and type casting with J9Method **

@fengxue-IS fengxue-IS force-pushed the vtable2 branch 2 times, most recently from ae31513 to c6d8d89 Compare July 17, 2018 21:41
@fengxue-IS
Copy link
Contributor Author

@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))
Copy link
Contributor

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>
@gacholio
Copy link
Contributor

jenkins test sanity xlinux jdk8

@gacholio gacholio self-assigned this Jul 18, 2018
@gacholio gacholio merged commit be4ecff into eclipse-openj9:master Jul 18, 2018
gacholio added a commit to gacholio/openj9 that referenced this pull request Jul 18, 2018
Signed-off-by: Graham Chapman <graham_chapman@ca.ibm.com>
gacholio added a commit that referenced this pull request Jul 18, 2018
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