Skip to content

Commit 347dfcb

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). 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]>
1 parent 30f423a commit 347dfcb

File tree

10 files changed

+75
-37
lines changed

10 files changed

+75
-37
lines changed

debugtools/DDR_VM/src/com/ibm/j9ddr/AuxFieldInfo29.dat

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ J9JavaVM.hiddenLockwordFieldShape = required
264264
J9JavaVM.identityHashData = required
265265
J9JavaVM.impdep1PC = U8*
266266
J9JavaVM.initialMethods = required
267-
J9JavaVM.isIndexableDataAddrPresent = U_32
267+
J9JavaVM.isIndexableDataAddrPresent = UDATA
268268
J9JavaVM.intReflectClass = required
269269
J9JavaVM.j2seVersion = required
270270
J9JavaVM.j9ras = required

runtime/gc_glue_java/EnvironmentDelegate.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ 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 (indexableObjectModel->isVirtualLargeObjectHeapEnabled() && indexableObjectModel->isInlineContiguousArraylet((J9IndexableObject *)objectPtr)) {
211211
_gcEnv._shouldFixupDataAddrForContiguous = indexableObjectModel->shouldFixupDataAddrForContiguous((J9IndexableObject *)objectPtr);
212212
} else {
213213
_gcEnv._shouldFixupDataAddrForContiguous = false;

runtime/gc_include/ObjectAllocationAPI.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class MM_ObjectAllocationAPI
321321
: _gcAllocationType(currentThread->javaVM->gcAllocationType)
322322
, _contiguousIndexableHeaderSize(currentThread->contiguousIndexableHeaderSize)
323323
#if defined(J9VM_ENV_DATA64)
324-
, _isIndexableDataAddrPresent(currentThread->isIndexableDataAddrPresent)
324+
, _isIndexableDataAddrPresent(currentThread->javaVM->isIndexableDataAddrPresent)
325325
#endif /* defined(J9VM_ENV_DATA64) */
326326
#if defined(J9VM_GC_BATCH_CLEAR_TLH)
327327
, _initializeSlotsOnTLHAllocate(currentThread->javaVM->initializeSlotsOnTLHAllocate)

runtime/gc_modron_startup/mminit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,7 @@ gcInitializeDefaults(J9JavaVM* vm)
29722972
#if defined(J9VM_ENV_DATA64)
29732973
vm->isIndexableDualHeaderShapeEnabled = TRUE;
29742974
vm->isIndexableDataAddrPresent = FALSE;
2975-
vm->isVirtualLargeObjectHeapEnabled = FALSE;
2975+
vm->indexableObjectLayout = J9IndexableObjectLayout_NoDataAddr_NoArraylet;
29762976
#endif /* defined(J9VM_ENV_DATA64) */
29772977

29782978
/* enable estimateFragmentation for all GCs as default for java, but not the estimated result would not affect concurrentgc kickoff by default */

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

+6-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_Arraylet (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,9 @@ 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+
/* set indexableObjectLayout = J9IndexableObjectLayout_DataAddr_NoArraylet (Balanced GC and off-heap enabled) */
151+
vm->indexableObjectLayout = J9IndexableObjectLayout_DataAddr_NoArraylet;
152+
/* reset vm->unsafeIndexableHeaderSize for off-heap case */
150153
vm->unsafeIndexableHeaderSize = 0;
151154
} else {
152155
#if defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD)

runtime/gc_vlhgc/VLHGCAccessBarrier.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ 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(_extensions->isVirtualLargeObjectHeapEnabled);
258258
/* Adjacency check against dst object since src object may be overwritten during sliding compaction. */
259259
if (_extensions->indexableObjectModel.isDataAdjacentToHeader(dst))
260260
#endif /* defined(J9VM_ENV_DATA64) */

runtime/oti/j9accessbarrier.h

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

126+
#define J9ISCONTIGUOUSARRAY(vmThread, array) \
127+
(J9VMTHREAD_COMPRESS_OBJECT_REFERENCES(vmThread) \
128+
? (0 != ((J9IndexableObjectContiguousCompressed *)(array))->size) \
129+
: (0 != ((J9IndexableObjectContiguousFull *)(array))->size))
130+
131+
#define J9ISCONTIGUOUSARRAY_VM(javaVM, array) \
132+
(J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM) \
133+
? (0 != ((J9IndexableObjectContiguousCompressed *)(array))->size) \
134+
: (0 != ((J9IndexableObjectContiguousFull *)(array))->size))
135+
126136
#if defined(J9VM_ENV_DATA64)
127137
#define J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPDISABLED_EA(vmThread, array, index, elemType) \
128138
(J9VMTHREAD_COMPRESS_OBJECT_REFERENCES(vmThread) \
@@ -145,18 +155,39 @@ typedef struct J9IndexableObject* mm_j9array_t;
145155
: (&((elemType*)((((J9IndexableObjectWithDataAddressContiguousFull *)(array))->dataAddr)))[index]))
146156

147157
#define J9JAVAARRAYCONTIGUOUS_EA(vmThread, array, index, elemType) \
148-
(((vmThread)->isIndexableDataAddrPresent) \
149-
? (((vmThread)->isVirtualLargeObjectHeapEnabled) \
150-
? J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPENABLED_EA(vmThread, array, index, elemType) \
151-
: J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPDISABLED_EA(vmThread, array, index, elemType)) \
152-
: J9JAVAARRAYCONTIGUOUS_BASE_EA(vmThread, array, index, elemType))
158+
(&((elemType*)((((UDATA)(array)) + (vmThread)->contiguousIndexableHeaderSize)))[(index)])
153159

154160
#define J9JAVAARRAYCONTIGUOUS_EA_VM(javaVM, array, index, elemType) \
155-
(((javaVM)->isIndexableDataAddrPresent) \
156-
? (((javaVM)->isVirtualLargeObjectHeapEnabled) \
157-
? J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPENABLED_EA_VM(javaVM, array, index, elemType) \
158-
: J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPDISABLED_EA_VM(javaVM, array, index, elemType)) \
159-
: J9JAVAARRAYCONTIGUOUS_BASE_EA_VM(javaVM, array, index, elemType))
161+
(&((elemType*)((((UDATA)(array)) + (javaVM)->contiguousIndexableHeaderSize)))[(index)])
162+
163+
/*
164+
* if standard GC (J9IndexableObjectLayout_NoDataAddr_NoArraylet)
165+
* contiguous-base
166+
* else if off-heap enabled (J9IndexableObjectLayout_DataAddr_NoArraylet)
167+
* contiguous-via-dataAddr
168+
* else balancedGC with off-heap disabled or Metronome GC (J9IndexableObjectLayout_NoDataAddr_Arraylet or J9IndexableObjectLayout_DataAddr_Arraylet)
169+
* if contigious
170+
* contiguous
171+
* else
172+
* discontigous vc
173+
*/
174+
#define J9JAVAARRAY_EA(vmThread, array, index, elemType) \
175+
((J9IndexableObjectLayout_NoDataAddr_NoArraylet == (vmThread)->indexableObjectLayout) \
176+
? J9JAVAARRAYCONTIGUOUS_BASE_EA(vmThread, array, index, elemType) \
177+
: ((J9IndexableObjectLayout_DataAddr_NoArraylet == (vmThread)->indexableObjectLayout) \
178+
? J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPENABLED_EA(vmThread, array, index, elemType) \
179+
: (J9ISCONTIGUOUSARRAY(vmThread, array) \
180+
? J9JAVAARRAYCONTIGUOUS_EA(vmThread, array, index, elemType) \
181+
: J9JAVAARRAYDISCONTIGUOUS_EA(vmThread, array, index, elemType))))
182+
183+
#define J9JAVAARRAY_EA_VM(javaVM, array, index, elemType) \
184+
((J9IndexableObjectLayout_NoDataAddr_NoArraylet == (javaVM)->indexableObjectLayout) \
185+
? J9JAVAARRAYCONTIGUOUS_BASE_EA_VM(javaVM, array, index, elemType) \
186+
: ((J9IndexableObjectLayout_DataAddr_NoArraylet == (javaVM)->indexableObjectLayout) \
187+
? J9JAVAARRAYCONTIGUOUS_WITH_DATAADDRESS_VIRTUALLARGEOBJECTHEAPENABLED_EA_VM(javaVM, array, index, elemType) \
188+
: (J9ISCONTIGUOUSARRAY_VM(javaVM, array) \
189+
? J9JAVAARRAYCONTIGUOUS_EA_VM(javaVM, array, index, elemType) \
190+
: J9JAVAARRAYDISCONTIGUOUS_EA_VM(javaVM, array, index, elemType))))
160191

161192
#else /* defined(J9VM_ENV_DATA64) */
162193
#define J9JAVAARRAYCONTIGUOUS_EA(vmThread, array, index, elemType) \
@@ -165,21 +196,10 @@ typedef struct J9IndexableObject* mm_j9array_t;
165196
#define J9JAVAARRAYCONTIGUOUS_EA_VM(javaVM, array, index, elemType) \
166197
J9JAVAARRAYCONTIGUOUS_BASE_EA_VM(javaVM, array, index, elemType)
167198

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-
180199
/* TODO: queries compressed twice - optimize? */
181200
#define J9JAVAARRAY_EA(vmThread, array, index, elemType) (J9ISCONTIGUOUSARRAY(vmThread, array) ? J9JAVAARRAYCONTIGUOUS_EA(vmThread, array, index, elemType) : J9JAVAARRAYDISCONTIGUOUS_EA(vmThread, array, index, elemType))
182201
#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))
202+
#endif /* defined(J9VM_ENV_DATA64) */
183203

184204
/*
185205
* Private helpers for reference field types

runtime/oti/j9nonbuilder.h

+18-4
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 */
@@ -5540,8 +5547,7 @@ typedef struct J9VMThread {
55405547
UDATA contiguousIndexableHeaderSize;
55415548
UDATA discontiguousIndexableHeaderSize;
55425549
#if defined(J9VM_ENV_DATA64)
5543-
U_32 isIndexableDataAddrPresent;
5544-
U_32 isVirtualLargeObjectHeapEnabled;
5550+
U_32 indexableObjectLayout; /* can be J9IndexableObjectLayout_NoDataAddr_NoArraylet,J9IndexableObjectLayout_DataAddr_NoArraylet, J9IndexableObjectLayout_NoDataAddr_Arraylet, J9IndexableObjectLayout_DataAddr_Arraylet */
55455551
#endif /* defined(J9VM_ENV_DATA64) */
55465552
void* gpInfo;
55475553
void* jitVMwithThreadInfo;
@@ -5660,6 +5666,10 @@ typedef struct J9VMThread {
56605666
#endif /* defined(J9VM_OPT_JFR) */
56615667
} J9VMThread;
56625668

5669+
#if defined(J9VM_ENV_DATA64)
5670+
#define J9VMTHREAD_IS_ARRAYLET_ENABLED(vmThread) (J9IndexableObjectLayout_ArrayletMask & (vmThread)->indexableObjectLayout)
5671+
#define J9VMTHREAD_IS_INDEXBLE_DATAADDR_PRESENT(vmThread) (J9IndexableObjectLayout_DataAddrMask & (vmThread)->indexableObjectLayout)
5672+
#endif
56635673
#define J9VMTHREAD_ALIGNMENT 0x100
56645674
#define J9VMTHREAD_RESERVED_C_STACK_FRACTION 8
56655675
#define J9VMTHREAD_STATE_RUNNING 1
@@ -6105,8 +6115,8 @@ typedef struct J9JavaVM {
61056115
UDATA contiguousIndexableHeaderSize;
61066116
UDATA discontiguousIndexableHeaderSize;
61076117
#if defined(J9VM_ENV_DATA64)
6108-
U_32 isIndexableDataAddrPresent;
6109-
U_32 isVirtualLargeObjectHeapEnabled;
6118+
UDATA isIndexableDataAddrPresent;
6119+
U_32 indexableObjectLayout; /* can be J9IndexableObjectLayout_NoDataAddr_NoArraylet,J9IndexableObjectLayout_DataAddr_NoArraylet, J9IndexableObjectLayout_NoDataAddr_Arraylet, J9IndexableObjectLayout_DataAddr_Arraylet */
61106120
U_32 isIndexableDualHeaderShapeEnabled;
61116121
#endif /* defined(J9VM_ENV_DATA64) */
61126122
struct J9VMThread* exclusiveVMAccessQueueHead;
@@ -6347,6 +6357,10 @@ typedef struct J9JavaVM {
63476357
#define J9JAVAVM_OBJECT_HEADER_SIZE(vm) (J9JAVAVM_COMPRESS_OBJECT_REFERENCES(vm) ? sizeof(J9ObjectCompressed) : sizeof(J9ObjectFull))
63486358
#define J9JAVAVM_CONTIGUOUS_INDEXABLE_HEADER_SIZE(vm) ((vm)->contiguousIndexableHeaderSize)
63496359
#define J9JAVAVM_DISCONTIGUOUS_INDEXABLE_HEADER_SIZE(vm) ((vm)->discontiguousIndexableHeaderSize)
6360+
#if defined(J9VM_ENV_DATA64)
6361+
#define J9JAVAVM_ARRAYLET_ENABLED(vm) (J9IndexableObjectLayout_ArrayletMask & (vm)->indexableObjectLayout)
6362+
#define J9JAVAVM_IS_INDEXBLEDATAADDRPRESENT(vm) (J9IndexableObjectLayout_DataAddrMask & (vm)->indexableObjectLayout)
6363+
#endif
63506364

63516365
#if JAVA_SPEC_VERSION >= 16
63526366
/* The mask for the signature type identifier */

runtime/vm/vmthread.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ allocateVMThread(J9JavaVM *vm, omrthread_t osThread, UDATA privateFlags, void *m
196196
newThread->discontiguousIndexableHeaderSize = vm->discontiguousIndexableHeaderSize;
197197
newThread->unsafeIndexableHeaderSize = vm->unsafeIndexableHeaderSize;
198198
#if defined(J9VM_ENV_DATA64)
199-
newThread->isIndexableDataAddrPresent = vm->isIndexableDataAddrPresent;
200-
newThread->isVirtualLargeObjectHeapEnabled = vm->isVirtualLargeObjectHeapEnabled;
199+
newThread->indexableObjectLayout = vm->indexableObjectLayout;
201200
#endif /* defined(J9VM_ENV_DATA64) */
202201

203202
newThread->privateFlags = privateFlags;

0 commit comments

Comments
 (0)