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

Optimize array access macros to reduce using is-contiguous check #20888

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

LinHu2016
Copy link
Contributor

@LinHu2016 LinHu2016 commented Jan 6, 2025

Optimize array access macros to use is-contiguous check only in presence
of arraylets

Along with new offheap feature support, Macro Array Element Access
J9JAVAARRAY_EA/J9JAVAARRAY_EA_VM need 1 or 2 more runtime flags check to
handle new cases/new structures. extra runtime condition checks in the
Macro, which is called in hotspot, could cause certain performance
regression in some platforms. especially for standard GC cases, off-heap
would not contribute any benefit at all.

Optimize Macro J9JAVAARRAY_EA/J9JAVAARRAY_EA_VM to avoid runtime check
IsContiguousArray for stamdard GC and balanced GC with off-heap eanable
cases, because there is no discontigouos array for these cases(except o
size array).
1, replace isVirtualLargeObjectHeapEnabled and
isIndexableDataAddrPresent flag with indexableObjectLayout in JavaVM and
J9VmThread.
2, indexableObjectLayout have only 4 states
J9IndexableObjectLayout_NoDataAddr_NoArraylet 0x0 /* StandardGC case /
J9IndexableObjectLayout_NoDataAddr_Arraylet 0x1 /
Metronome GC case /
J9IndexableObjectLayout_DataAddr_NoArraylet 0x2 /
Balanced GC Offheap
enabled case /
J9IndexableObjectLayout_DataAddr_Arraylet 0x3 /
Balanced GC Offheap
disabled case */
3, in Macro J9JAVAARRAY_EA/J9JAVAARRAY_EA_VM, check StandardGC case and
Balanced GC Offheap enabled case first in order to reduce runtime
condition check for standard GC(Balanced GC Offheap enabled case too),
then avoid performance regression(reduce flag numbers in J9VmThread
also could help reduce the regression for some platforms).
4, flag isVirtualLargeObjectHeapEnabled and isIndexableDataAddrPresent
has been removed from J9VmThread
flag isVirtualLargeObjectHeapEnabled has been removed from JavaVM (we
still keep flag isIndexableDataAddrPresent in JavaVM for minimizing the
changes).

Signed-off-by: lhu [email protected]

@LinHu2016 LinHu2016 force-pushed the off-heap-optimize4gencon branch 3 times, most recently from 38fe9a6 to b09c9b9 Compare January 8, 2025 16:50
@@ -5647,6 +5655,10 @@ typedef struct J9VMThread {
#endif /* defined(J9VM_OPT_JFR) */
} J9VMThread;

#if defined(J9VM_ENV_DATA64)
#define J9VMTHREAD_ARRAYLET_ENABLED(vmThread) (J9IndexableObjectLayout_ArrayletMask & (vmThread)->indexableObjectLayout)
#define J9VMTHREAD_IS_INDEXBLEDATAADDRPRESENT(vmThread) (J9IndexableObjectLayout_DataAddrMask & (vmThread)->indexableObjectLayout)
Copy link
Contributor

Choose a reason for hiding this comment

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

add extra '_' for easier reading J9VMTHREAD_IS_INDEXBLE_DATAADDR_PRESENT
add 'IS' to J9VMTHREAD_IS_ARRAYLET_ENABLED

@@ -6093,7 +6105,8 @@ typedef struct J9JavaVM {
UDATA discontiguousIndexableHeaderSize;
#if defined(J9VM_ENV_DATA64)
U_32 isIndexableDataAddrPresent;
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is being explicitly used by DDR, let's revert the type back to what was before we put recent Offheap changes and what was also the type the last time we released JVM (which is UDATA)

eventually, we should remove it altogether (but that would need some extra DDR changes to handle cores with and without this field)

@LinHu2016 LinHu2016 force-pushed the off-heap-optimize4gencon branch 11 times, most recently from 87e01b2 to e94cb71 Compare January 12, 2025 18:46
vm->unsafeIndexableHeaderSize = vm->contiguousIndexableHeaderSize;
}
/* set default unsafeIndexableHeaderSize */
vm->unsafeIndexableHeaderSize = vm->contiguousIndexableHeaderSize;
Copy link
Contributor

@amicic amicic Jan 13, 2025

Choose a reason for hiding this comment

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

let's do changes related to setting unsafeIndexableHeaderSize as a separate PR before we proceed with array access macro changes

that looks like something should have been done as the part of original offheap changes (we should not have queried isVirtualLargeObjectHeapEnabled in a relatively common code path). the new way is cleaner (set default, and override it for offheap enabled on its own specific path)

@LinHu2016 LinHu2016 force-pushed the off-heap-optimize4gencon branch from e94cb71 to 347dfcb Compare January 14, 2025 15:26
? (((vmThread)->isVirtualLargeObjectHeapEnabled) \
? J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPENABLED_EA(vmThread, array, index, elemType) \
: J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPDISABLED_EA(vmThread, array, index, elemType)) \
: J9JAVAARRAYCONTIGUOUS_BASE_EA(vmThread, array, index, elemType))
Copy link
Contributor

@dmitripivkine dmitripivkine Jan 14, 2025

Choose a reason for hiding this comment

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

I think we are removing only usage of two DISABLED macros above. These macros can be removed.

(J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM) \
? (0 != ((J9IndexableObjectContiguousCompressed *)(array))->size) \
: (0 != ((J9IndexableObjectContiguousFull *)(array))->size))

/* TODO: queries compressed twice - optimize? */
#define J9JAVAARRAY_EA(vmThread, array, index, elemType) (J9ISCONTIGUOUSARRAY(vmThread, array) ? J9JAVAARRAYCONTIGUOUS_EA(vmThread, array, index, elemType) : J9JAVAARRAYDISCONTIGUOUS_EA(vmThread, array, index, elemType))
Copy link
Contributor

Choose a reason for hiding this comment

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

as we discussed in person, we could optimized 32 bit similarly, although there are only 2 layouts (with and without arraylet and no dataAddr),

but let's do it in a separate change

@@ -108,7 +108,9 @@ MM_Heap *
MM_ConfigurationRealtime::createHeapWithManager(MM_EnvironmentBase *env, uintptr_t heapBytesRequested, MM_HeapRegionManager *regionManager)
{
MM_GCExtensionsBase *extensions = env->getExtensions();

J9JavaVM *vm = (J9JavaVM *)extensions->getOmrVM()->_language_vm;
/* set indexableObjectLayout = J9IndexableObjectLayout_NoDataAddr_Arraylet (metronome GC)*/
Copy link
Contributor

Choose a reason for hiding this comment

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

the code line is fairly self explanatory, but if you want to add a comment let's try be a bit more creative rather than just repeating the code:

"Let VM know that Metronome has discontiguous indexable object (arraylet layout)"

@@ -136,6 +136,9 @@ MM_ConfigurationIncrementalGenerational::createHeapWithManager(MM_EnvironmentBas

#if defined(J9VM_ENV_DATA64)
extensions->indexableObjectModel.setIsDataAddressPresent(true);
J9JavaVM *vm = (J9JavaVM *)extensions->getOmrVM()->_language_vm;
/* set indexableObjectLayout = J9IndexableObjectLayout_DataAddr_Arraylet (Balanced GC and off-heap disabled) */
Copy link
Contributor

@amicic amicic Jan 14, 2025

Choose a reason for hiding this comment

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

again, be a more creative, something like:

"Let VM know that indexable objects in Balanced always have dataAddr, and let's assume initially it has arraylets, which can be later overridden if Offheap is Enabled."

/* reset vm->isVirtualLargeObjectHeapEnabled and vm->unsafeIndexableHeaderSize for off-heap case */
J9JavaVM *vm = (J9JavaVM *)extensions->getOmrVM()->_language_vm;
vm->isVirtualLargeObjectHeapEnabled = TRUE;
/* set indexableObjectLayout = J9IndexableObjectLayout_DataAddr_NoArraylet (Balanced GC and off-heap enabled) */
Copy link
Contributor

Choose a reason for hiding this comment

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

"Overriding the original assumption that Balanced has arraylets."

@amicic
Copy link
Contributor

amicic commented Jan 14, 2025

Change the title to be more specific:

Optimize array access macros to use is-contiguous check only in presence of arraylets

@LinHu2016 LinHu2016 force-pushed the off-heap-optimize4gencon branch from 347dfcb to 961b71f Compare January 14, 2025 22:31
@@ -6347,6 +6357,10 @@ typedef struct J9JavaVM {
#define J9JAVAVM_OBJECT_HEADER_SIZE(vm) (J9JAVAVM_COMPRESS_OBJECT_REFERENCES(vm) ? sizeof(J9ObjectCompressed) : sizeof(J9ObjectFull))
#define J9JAVAVM_CONTIGUOUS_INDEXABLE_HEADER_SIZE(vm) ((vm)->contiguousIndexableHeaderSize)
#define J9JAVAVM_DISCONTIGUOUS_INDEXABLE_HEADER_SIZE(vm) ((vm)->discontiguousIndexableHeaderSize)
#if defined(J9VM_ENV_DATA64)
#define J9JAVAVM_ARRAYLET_ENABLED(vm) (J9IndexableObjectLayout_ArrayletMask & (vm)->indexableObjectLayout)
#define J9JAVAVM_IS_INDEXBLEDATAADDRPRESENT(vm) (J9IndexableObjectLayout_DataAddrMask & (vm)->indexableObjectLayout)
Copy link
Contributor

Choose a reason for hiding this comment

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

make the name consistent with those that us vmThread

@LinHu2016 LinHu2016 force-pushed the off-heap-optimize4gencon branch from 961b71f to 31701a1 Compare January 15, 2025 18:47
@LinHu2016 LinHu2016 changed the title Optimize Macro J9JAVAARRAY_EA to reduce offheap changes side affection Optimize array access macros to reduce using is-contiguous check Jan 15, 2025
@@ -5540,8 +5547,7 @@ typedef struct J9VMThread {
UDATA contiguousIndexableHeaderSize;
UDATA discontiguousIndexableHeaderSize;
#if defined(J9VM_ENV_DATA64)
UDATA isIndexableDataAddrPresent;
U_32 isVirtualLargeObjectHeapEnabled;
U_32 indexableObjectLayout; /* can be J9IndexableObjectLayout_NoDataAddr_NoArraylet,J9IndexableObjectLayout_DataAddr_NoArraylet, J9IndexableObjectLayout_NoDataAddr_Arraylet, J9IndexableObjectLayout_DataAddr_Arraylet */
Copy link
Contributor

Choose a reason for hiding this comment

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

Either this comment should be shorter, some like "valid values are #define J9IndexableObjectLayout_xyz"
or we don't any comment here (as is the case with other fields) but we comment just above J9IndexableObjectLayout #defines that they are used in indexableObjectLayout field.

(same for J9JavaVM)

* if contigious
* contiguous
* else
* discontigous vc
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the meaning of 'vc'?

Copy link
Contributor Author

@LinHu2016 LinHu2016 Jan 15, 2025

Choose a reason for hiding this comment

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

it was a typo. removed it

@LinHu2016 LinHu2016 force-pushed the off-heap-optimize4gencon branch from 31701a1 to 36c306a Compare January 15, 2025 22:50
@@ -140,6 +140,13 @@
#define J9ArrayShape32Bit 0x2
#define J9ArrayShape64Bit 0x3

/* J9IndexableObjectLayout_xxx are used in indexableObjectLayout fieldo */
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in 'fieldo' (extra 'o' at the end)
and while you are editing it, add '... field in J9VMThread and J9JavaVM'

Optimize array access macros to use is-contiguous check only in presence
of arraylets

Along with new offheap feature support, Macro Array Element Access
J9JAVAARRAY_EA/J9JAVAARRAY_EA_VM need 1 or 2 more runtime flags check to
handle new cases/new structures. extra runtime condition checks in the
Macro, which is called in hotspot, could cause certain performance
regression in some platforms. especially for standard GC cases, off-heap
would not contribute any benefit at all.

Optimize Macro J9JAVAARRAY_EA/J9JAVAARRAY_EA_VM to avoid runtime check
IsContiguousArray for stamdard GC and balanced GC with off-heap eanable
cases, because there is no discontigouos array for these cases(except o
size array).
1, replace isVirtualLargeObjectHeapEnabled and
isIndexableDataAddrPresent flag with indexableObjectLayout in JavaVM and
J9VmThread.
2, indexableObjectLayout have only 4 states
J9IndexableObjectLayout_NoDataAddr_NoArraylet 0x0 /* StandardGC case */
J9IndexableObjectLayout_NoDataAddr_Arraylet 0x1 /* Metronome GC case */
J9IndexableObjectLayout_DataAddr_NoArraylet 0x2 /* Balanced GC Offheap
enabled case */
J9IndexableObjectLayout_DataAddr_Arraylet 0x3 /* Balanced GC Offheap
disabled case */
3, in Macro J9JAVAARRAY_EA/J9JAVAARRAY_EA_VM, check StandardGC case and
Balanced GC Offheap enabled case first in order to reduce runtime
 condition check for standard GC(Balanced GC Offheap enabled case too),
 then avoid performance regression(reduce flag numbers in J9VmThread
 also could help reduce the regression for some platforms).
4, flag isVirtualLargeObjectHeapEnabled and isIndexableDataAddrPresent
has been removed from J9VmThread
flag isVirtualLargeObjectHeapEnabled has been removed from JavaVM (we
still keep flag isIndexableDataAddrPresent in JavaVM for minimizing the
changes).

Signed-off-by: lhu <[email protected]>
@LinHu2016 LinHu2016 force-pushed the off-heap-optimize4gencon branch from 36c306a to cd7ba08 Compare January 16, 2025 15:16
@amicic
Copy link
Contributor

amicic commented Jan 16, 2025

jenkins test sanity aix jdk21

@amicic amicic merged commit 5b2c4ec into eclipse-openj9:master Jan 16, 2025
6 checks passed
@keithc-ca
Copy link
Contributor

DDR needs to be updated to adapt to the removal of the field J9JavaVM.isIndexableDataAddrPresent.

@amicic
Copy link
Contributor

amicic commented Jan 17, 2025

DDR needs to be updated to adapt to the removal of the field J9JavaVM.isIndexableDataAddrPresent.

isIndexableDataAddrPresent was removed only from J9VMThread (and that one was not referenced by DDR), but not from J9JavaVM.

@keithc-ca
Copy link
Contributor

Sorry, you're right, J9JavaVM.isIndexableDataAddrPresent is still present.

@amicic amicic added the comp:gc label Mar 17, 2025
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.

4 participants