Skip to content

Commit 38fe9a6

Browse files
committed
Optimize Macro J9JAVAARRAY_EA to reduce offheap changes side affection
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). Signed-off-by: lhu <[email protected]>
1 parent d471e57 commit 38fe9a6

8 files changed

+94
-27
lines changed

runtime/gc_glue_java/EnvironmentDelegate.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ class MM_EnvironmentDelegate
207207
#if defined(J9VM_ENV_DATA64)
208208
if (objectModel->isIndexable(objectPtr)) {
209209
GC_ArrayObjectModel *indexableObjectModel = &_extensions->indexableObjectModel;
210-
if (_vmThread->isVirtualLargeObjectHeapEnabled && indexableObjectModel->isInlineContiguousArraylet((J9IndexableObject *)objectPtr)) {
210+
// if (_vmThread->isVirtualLargeObjectHeapEnabled && indexableObjectModel->isInlineContiguousArraylet((J9IndexableObject *)objectPtr)) {
211+
if (indexableObjectModel->isVirtualLargeObjectHeapEnabled() && indexableObjectModel->isInlineContiguousArraylet((J9IndexableObject *)objectPtr)) {
211212
_gcEnv._shouldFixupDataAddrForContiguous = indexableObjectModel->shouldFixupDataAddrForContiguous((J9IndexableObject *)objectPtr);
212213
} else {
213214
_gcEnv._shouldFixupDataAddrForContiguous = false;

runtime/gc_modron_startup/mminit.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,9 @@ gcInitializeDefaults(J9JavaVM* vm)
29722972
#if defined(J9VM_ENV_DATA64)
29732973
vm->isIndexableDualHeaderShapeEnabled = TRUE;
29742974
vm->isIndexableDataAddrPresent = FALSE;
2975-
vm->isVirtualLargeObjectHeapEnabled = FALSE;
2975+
// vm->isVirtualLargeObjectHeapEnabled = FALSE;
2976+
/* set indexableObjectLayout = J9IndexableObjectLayout_NoDataAddr_NoArraylet as default (standard GC)*/
2977+
vm->indexableObjectLayout = J9IndexableObjectLayout_NoDataAddr_NoArraylet;
29762978
#endif /* defined(J9VM_ENV_DATA64) */
29772979

29782980
/* enable estimateFragmentation for all GCs as default for java, but not the estimated result would not affect concurrentgc kickoff by default */
@@ -3325,11 +3327,11 @@ initializeIndexableObjectHeaderSizes(J9JavaVM* vm)
33253327
#else /* defined(J9VM_ENV_DATA64) */
33263328
setIndexableObjectHeaderSizeWithoutDataAddress(vm);
33273329
#endif /* defined(J9VM_ENV_DATA64) */
3328-
if (MM_GCExtensions::getExtensions(vm)->isVirtualLargeObjectHeapEnabled) {
3329-
vm->unsafeIndexableHeaderSize = 0;
3330-
} else {
3331-
vm->unsafeIndexableHeaderSize = vm->contiguousIndexableHeaderSize;
3332-
}
3330+
// if (MM_GCExtensions::getExtensions(vm)->isVirtualLargeObjectHeapEnabled) {
3331+
// vm->unsafeIndexableHeaderSize = 0;
3332+
// } else {
3333+
// vm->unsafeIndexableHeaderSize = vm->contiguousIndexableHeaderSize;
3334+
// }
33333335
}
33343336

33353337
#if defined(J9VM_ENV_DATA64)

runtime/gc_realtime/ConfigurationRealtime.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ MM_Heap *
108108
MM_ConfigurationRealtime::createHeapWithManager(MM_EnvironmentBase *env, uintptr_t heapBytesRequested, MM_HeapRegionManager *regionManager)
109109
{
110110
MM_GCExtensionsBase *extensions = env->getExtensions();
111-
111+
J9JavaVM *vm = (J9JavaVM *)extensions->getOmrVM()->_language_vm;
112+
/* set indexableObjectLayout = J9IndexableObjectLayout_NoDataAddr_Arraylet (metronome GC)*/
113+
vm->indexableObjectLayout = J9IndexableObjectLayout_NoDataAddr_Arraylet;
112114
#if defined(J9VM_GC_SPARSE_HEAP_ALLOCATION)
113115
PORT_ACCESS_FROM_ENVIRONMENT(env);
114116

runtime/gc_vlhgc/ConfigurationIncrementalGenerational.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ MM_ConfigurationIncrementalGenerational::createHeapWithManager(MM_EnvironmentBas
136136

137137
#if defined(J9VM_ENV_DATA64)
138138
extensions->indexableObjectModel.setIsDataAddressPresent(true);
139+
J9JavaVM *vm = (J9JavaVM *)extensions->getOmrVM()->_language_vm;
140+
/* set indexableObjectLayout = J9IndexableObjectLayout_DataAddr_NoArraylet (Balanced GC and off-heap disabled) */
141+
vm->indexableObjectLayout = J9IndexableObjectLayout_DataAddr_Arraylet;
139142
#if defined(J9VM_GC_SPARSE_HEAP_ALLOCATION)
140143
if (extensions->isVirtualLargeObjectHeapRequested) {
141144
/* Create off-heap */
@@ -144,9 +147,10 @@ MM_ConfigurationIncrementalGenerational::createHeapWithManager(MM_EnvironmentBas
144147
extensions->largeObjectVirtualMemory = largeObjectVirtualMemory;
145148
extensions->indexableObjectModel.setEnableVirtualLargeObjectHeap(true);
146149
extensions->isVirtualLargeObjectHeapEnabled = true;
147-
/* reset vm->isVirtualLargeObjectHeapEnabled and vm->unsafeIndexableHeaderSize for off-heap case */
148-
J9JavaVM *vm = (J9JavaVM *)extensions->getOmrVM()->_language_vm;
149-
vm->isVirtualLargeObjectHeapEnabled = TRUE;
150+
// vm->isVirtualLargeObjectHeapEnabled = TRUE;
151+
/* set indexableObjectLayout = J9IndexableObjectLayout_DataAddr_NoArraylet (Balanced GC and off-heap enabled) */
152+
vm->indexableObjectLayout = J9IndexableObjectLayout_DataAddr_NoArraylet;
153+
/* reset vm->unsafeIndexableHeaderSize for off-heap case */
150154
vm->unsafeIndexableHeaderSize = 0;
151155
} else {
152156
#if defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD)

runtime/gc_vlhgc/VLHGCAccessBarrier.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ MM_VLHGCAccessBarrier::indexableDataDisplacement(J9VMThread *vmThread, J9Indexab
254254
IDATA displacement = 0;
255255

256256
#if defined(J9VM_ENV_DATA64)
257-
Assert_MM_true(vmThread->isVirtualLargeObjectHeapEnabled);
257+
// Assert_MM_true(vmThread->isVirtualLargeObjectHeapEnabled);
258+
Assert_MM_true(_extensions->isVirtualLargeObjectHeapEnabled);
258259
/* Adjacency check against dst object since src object may be overwritten during sliding compaction. */
259260
if (_extensions->indexableObjectModel.isDataAdjacentToHeader(dst))
260261
#endif /* defined(J9VM_ENV_DATA64) */

runtime/oti/j9accessbarrier.h

+51-12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ typedef struct J9IndexableObject* mm_j9array_t;
123123
? (&((elemType*)((((J9IndexableObjectContiguousCompressed *)(array)) + 1)))[index]) \
124124
: (&((elemType*)((((J9IndexableObjectContiguousFull *)(array)) + 1)))[index]))
125125

126+
// using global variable contiguousIndexableHeaderSize instead of checking J9JAVAVM_COMPRESS_OBJECT_REFERENCES
127+
/*
128+
129+
#define J9JAVAARRAYCONTIGUOUS_BASE_EA(vmThread, array, index, elemType) \
130+
(&((elemType*)((((UDATA)(array)) + (vmThread)->contiguousIndexableHeaderSize)))[(index)])
131+
132+
#define J9JAVAARRAYCONTIGUOUS_BASE_EA_VM(javaVM, array, index, elemType) \
133+
(&((elemType*)((((UDATA)(array)) + (javaVM)->contiguousIndexableHeaderSize)))[(index)])
134+
*/
135+
136+
#define J9ISCONTIGUOUSARRAY(vmThread, array) \
137+
(J9VMTHREAD_COMPRESS_OBJECT_REFERENCES(vmThread) \
138+
? (0 != ((J9IndexableObjectContiguousCompressed *)(array))->size) \
139+
: (0 != ((J9IndexableObjectContiguousFull *)(array))->size))
140+
141+
#define J9ISCONTIGUOUSARRAY_VM(javaVM, array) \
142+
(J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM) \
143+
? (0 != ((J9IndexableObjectContiguousCompressed *)(array))->size) \
144+
: (0 != ((J9IndexableObjectContiguousFull *)(array))->size))
145+
126146
#if defined(J9VM_ENV_DATA64)
127147
#define J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPDISABLED_EA(vmThread, array, index, elemType) \
128148
(J9VMTHREAD_COMPRESS_OBJECT_REFERENCES(vmThread) \
@@ -144,6 +164,7 @@ typedef struct J9IndexableObject* mm_j9array_t;
144164
? (&((elemType*)((((J9IndexableObjectWithDataAddressContiguousCompressed *)(array))->dataAddr)))[index]) \
145165
: (&((elemType*)((((J9IndexableObjectWithDataAddressContiguousFull *)(array))->dataAddr)))[index]))
146166

167+
/*
147168
#define J9JAVAARRAYCONTIGUOUS_EA(vmThread, array, index, elemType) \
148169
(((vmThread)->isIndexableDataAddrPresent) \
149170
? (((vmThread)->isVirtualLargeObjectHeapEnabled) \
@@ -157,6 +178,35 @@ typedef struct J9IndexableObject* mm_j9array_t;
157178
? J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPENABLED_EA_VM(javaVM, array, index, elemType) \
158179
: J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPDISABLED_EA_VM(javaVM, array, index, elemType)) \
159180
: J9JAVAARRAYCONTIGUOUS_BASE_EA_VM(javaVM, array, index, elemType))
181+
*/
182+
/*
183+
* if standard GC (J9IndexableObjectLayout_NoDataAddr_NoArraylet)
184+
* contiguous-base
185+
* else if off-heap enabled (J9IndexableObjectLayout_DataAddr_NoArraylet)
186+
* contiguous-via-dataAddr
187+
* else balancedGC with off-heap disabled or Metronome GC (J9IndexableObjectLayout_NoDataAddr_Arraylet or J9IndexableObjectLayout_DataAddr_Arraylet)
188+
* if contigious
189+
* contiguous-base
190+
* else
191+
* discontigous-base
192+
*/
193+
#define J9JAVAARRAY_EA(vmThread, array, index, elemType) \
194+
((J9IndexableObjectLayout_NoDataAddr_NoArraylet == (vmThread)->indexableObjectLayout) \
195+
? J9JAVAARRAYCONTIGUOUS_BASE_EA(vmThread, array, index, elemType) \
196+
: ((J9IndexableObjectLayout_DataAddr_NoArraylet == (vmThread)->indexableObjectLayout) \
197+
? J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPENABLED_EA(vmThread, array, index, elemType) \
198+
: (J9ISCONTIGUOUSARRAY(vmThread, array) \
199+
? J9JAVAARRAYCONTIGUOUS_BASE_EA(vmThread, array, index, elemType) \
200+
: J9JAVAARRAYDISCONTIGUOUS_EA(vmThread, array, index, elemType))))
201+
202+
#define J9JAVAARRAY_EA_VM(javaVM, array, index, elemType) \
203+
((J9IndexableObjectLayout_NoDataAddr_NoArraylet == (javaVM)->indexableObjectLayout) \
204+
? J9JAVAARRAYCONTIGUOUS_BASE_EA_VM(javaVM, array, index, elemType) \
205+
: ((J9IndexableObjectLayout_DataAddr_NoArraylet == (javaVM)->indexableObjectLayout) \
206+
? J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPENABLED_EA_VM(javaVM, array, index, elemType) \
207+
: (J9ISCONTIGUOUSARRAY_VM(javaVM, array) \
208+
? J9JAVAARRAYCONTIGUOUS_BASE_EA_VM(javaVM, array, index, elemType) \
209+
: J9JAVAARRAYDISCONTIGUOUS_EA_VM(javaVM, array, index, elemType))))
160210

161211
#else /* defined(J9VM_ENV_DATA64) */
162212
#define J9JAVAARRAYCONTIGUOUS_EA(vmThread, array, index, elemType) \
@@ -165,21 +215,10 @@ typedef struct J9IndexableObject* mm_j9array_t;
165215
#define J9JAVAARRAYCONTIGUOUS_EA_VM(javaVM, array, index, elemType) \
166216
J9JAVAARRAYCONTIGUOUS_BASE_EA_VM(javaVM, array, index, elemType)
167217

168-
#endif /* defined(J9VM_ENV_DATA64) */
169-
170-
#define J9ISCONTIGUOUSARRAY(vmThread, array) \
171-
(J9VMTHREAD_COMPRESS_OBJECT_REFERENCES(vmThread) \
172-
? (0 != ((J9IndexableObjectContiguousCompressed *)(array))->size) \
173-
: (0 != ((J9IndexableObjectContiguousFull *)(array))->size))
174-
175-
#define J9ISCONTIGUOUSARRAY_VM(javaVM, array) \
176-
(J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM) \
177-
? (0 != ((J9IndexableObjectContiguousCompressed *)(array))->size) \
178-
: (0 != ((J9IndexableObjectContiguousFull *)(array))->size))
179-
180218
/* TODO: queries compressed twice - optimize? */
181219
#define J9JAVAARRAY_EA(vmThread, array, index, elemType) (J9ISCONTIGUOUSARRAY(vmThread, array) ? J9JAVAARRAYCONTIGUOUS_EA(vmThread, array, index, elemType) : J9JAVAARRAYDISCONTIGUOUS_EA(vmThread, array, index, elemType))
182220
#define J9JAVAARRAY_EA_VM(javaVM, array, index, elemType) (J9ISCONTIGUOUSARRAY_VM(javaVM, array) ? J9JAVAARRAYCONTIGUOUS_EA_VM(javaVM, array, index, elemType) : J9JAVAARRAYDISCONTIGUOUS_EA_VM(javaVM, array, index, elemType))
221+
#endif /* defined(J9VM_ENV_DATA64) */
183222

184223
/*
185224
* Private helpers for reference field types

runtime/oti/j9nonbuilder.h

+19-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@
140140
#define J9ArrayShape32Bit 0x2
141141
#define J9ArrayShape64Bit 0x3
142142

143+
/* for Macro */
144+
#define J9IndexableObjectLayout_NoDataAddr_NoArraylet 0x0 /* StandardGC case */
145+
#define J9IndexableObjectLayout_NoDataAddr_Arraylet 0x1 /* Metronome GC case */
146+
#define J9IndexableObjectLayout_DataAddr_NoArraylet 0x2 /* Balanced GC Offheap enabled case */
147+
#define J9IndexableObjectLayout_DataAddr_Arraylet 0x3 /* Balanced GC Offheap disabled case */
148+
#define J9IndexableObjectLayout_DataAddrMask 0x2
149+
#define J9IndexableObjectLayout_ArrayletMask 0x1
143150
/* @ddr_namespace: map_to_type=J9ClassInitFlags */
144151

145152
/* Constants from J9ClassInitFlags */
@@ -5528,7 +5535,8 @@ typedef struct J9VMThread {
55285535
UDATA discontiguousIndexableHeaderSize;
55295536
#if defined(J9VM_ENV_DATA64)
55305537
U_32 isIndexableDataAddrPresent;
5531-
U_32 isVirtualLargeObjectHeapEnabled;
5538+
// U_32 isVirtualLargeObjectHeapEnabled;
5539+
U_32 indexableObjectLayout; /* can be J9IndexableObjectLayout_NoDataAddr_NoArraylet,J9IndexableObjectLayout_DataAddr_NoArraylet, J9IndexableObjectLayout_NoDataAddr_Arraylet, J9IndexableObjectLayout_DataAddr_Arraylet */
55325540
#endif /* defined(J9VM_ENV_DATA64) */
55335541
void* gpInfo;
55345542
void* jitVMwithThreadInfo;
@@ -5647,6 +5655,10 @@ typedef struct J9VMThread {
56475655
#endif /* defined(J9VM_OPT_JFR) */
56485656
} J9VMThread;
56495657

5658+
#if defined(J9VM_ENV_DATA64)
5659+
#define J9VMTHREAD_ARRAYLET_ENABLED(vmThread) (J9IndexableObjectLayout_ArrayletMask & (vmThread)->indexableObjectLayout)
5660+
#define J9VMTHREAD_IS_INDEXBLEDATAADDRPRESENT(vmThread) (J9IndexableObjectLayout_DataAddrMask & (vmThread)->indexableObjectLayout)
5661+
#endif
56505662
#define J9VMTHREAD_ALIGNMENT 0x100
56515663
#define J9VMTHREAD_RESERVED_C_STACK_FRACTION 8
56525664
#define J9VMTHREAD_STATE_RUNNING 1
@@ -6093,7 +6105,8 @@ typedef struct J9JavaVM {
60936105
UDATA discontiguousIndexableHeaderSize;
60946106
#if defined(J9VM_ENV_DATA64)
60956107
U_32 isIndexableDataAddrPresent;
6096-
U_32 isVirtualLargeObjectHeapEnabled;
6108+
// U_32 isVirtualLargeObjectHeapEnabled;
6109+
U_32 indexableObjectLayout; /* can be J9IndexableObjectLayout_NoDataAddr_NoArraylet,J9IndexableObjectLayout_DataAddr_NoArraylet, J9IndexableObjectLayout_NoDataAddr_Arraylet, J9IndexableObjectLayout_DataAddr_Arraylet */
60976110
U_32 isIndexableDualHeaderShapeEnabled;
60986111
#endif /* defined(J9VM_ENV_DATA64) */
60996112
struct J9VMThread* exclusiveVMAccessQueueHead;
@@ -6334,6 +6347,10 @@ typedef struct J9JavaVM {
63346347
#define J9JAVAVM_OBJECT_HEADER_SIZE(vm) (J9JAVAVM_COMPRESS_OBJECT_REFERENCES(vm) ? sizeof(J9ObjectCompressed) : sizeof(J9ObjectFull))
63356348
#define J9JAVAVM_CONTIGUOUS_INDEXABLE_HEADER_SIZE(vm) ((vm)->contiguousIndexableHeaderSize)
63366349
#define J9JAVAVM_DISCONTIGUOUS_INDEXABLE_HEADER_SIZE(vm) ((vm)->discontiguousIndexableHeaderSize)
6350+
#if defined(J9VM_ENV_DATA64)
6351+
#define J9JAVAVM_ARRAYLET_ENABLED(vm) (J9IndexableObjectLayout_ArrayletMask & (vm)->indexableObjectLayout)
6352+
#define J9JAVAVM_IS_INDEXBLEDATAADDRPRESENT(vm) (J9IndexableObjectLayout_DataAddrMask & (vm)->indexableObjectLayout)
6353+
#endif
63376354

63386355
#if JAVA_SPEC_VERSION >= 16
63396356
/* The mask for the signature type identifier */

runtime/vm/vmthread.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ allocateVMThread(J9JavaVM *vm, omrthread_t osThread, UDATA privateFlags, void *m
197197
newThread->unsafeIndexableHeaderSize = vm->unsafeIndexableHeaderSize;
198198
#if defined(J9VM_ENV_DATA64)
199199
newThread->isIndexableDataAddrPresent = vm->isIndexableDataAddrPresent;
200-
newThread->isVirtualLargeObjectHeapEnabled = vm->isVirtualLargeObjectHeapEnabled;
200+
// newThread->isVirtualLargeObjectHeapEnabled = vm->isVirtualLargeObjectHeapEnabled;
201+
newThread->indexableObjectLayout = vm->indexableObjectLayout;
201202
#endif /* defined(J9VM_ENV_DATA64) */
202203

203204
newThread->privateFlags = privateFlags;

0 commit comments

Comments
 (0)