Skip to content

Commit

Permalink
Array base offset zero
Browse files Browse the repository at this point in the history
Signed-off-by: tajila <[email protected]>
  • Loading branch information
tajila committed Jul 3, 2024
1 parent 2f8672c commit 24513b0
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 77 deletions.
12 changes: 12 additions & 0 deletions runtime/gc_modron_startup/mminit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3323,6 +3323,12 @@ setIndexableObjectHeaderSizeWithDataAddress(J9JavaVM* vm)
vm->contiguousIndexableHeaderSize = sizeof(J9IndexableObjectWithDataAddressContiguousFull);
vm->discontiguousIndexableHeaderSize = sizeof(J9IndexableObjectWithDataAddressDiscontiguousFull);
}

if (MM_GCExtensions::getExtensions(vm)->isVirtualLargeObjectHeapEnabled) {
vm->unsafeIndexableHeaderSize = 0;
} else {
vm->unsafeIndexableHeaderSize = vm->contiguousIndexableHeaderSize;
}
}
#endif /* defined(J9VM_ENV_DATA64) */

Expand All @@ -3336,6 +3342,12 @@ setIndexableObjectHeaderSizeWithoutDataAddress(J9JavaVM* vm)
vm->contiguousIndexableHeaderSize = sizeof(J9IndexableObjectContiguousFull);
vm->discontiguousIndexableHeaderSize = sizeof(J9IndexableObjectDiscontiguousFull);
}

if (MM_GCExtensions::getExtensions(vm)->isVirtualLargeObjectHeapEnabled) {
vm->unsafeIndexableHeaderSize = 0;
} else {
vm->unsafeIndexableHeaderSize = vm->contiguousIndexableHeaderSize;
}
}

#if defined(OMR_GC_CONCURRENT_SCAVENGER)
Expand Down
7 changes: 4 additions & 3 deletions runtime/jcl/common/sun_misc_Unsafe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "ArrayCopyHelpers.hpp"
#include "AtomicSupport.hpp"
#include "ObjectMonitor.hpp"
#include "UnsafeAPI.hpp"
#include "VMHelpers.hpp"

extern "C" {
Expand Down Expand Up @@ -572,7 +573,7 @@ copyMemory(J9VMThread* currentThread, j9object_t sourceObject, UDATA sourceOffse
UDATA destOffset, UDATA actualSize)
{
/* Because array data is always 8-aligned, only the alignment of the offsets (and byte size) need be considered */
UDATA const headerSize = J9VMTHREAD_CONTIGUOUS_INDEXABLE_HEADER_SIZE(currentThread);
UDATA const headerSize = VM_UnsafeAPI::arrayBase(currentThread);
UDATA logElementSize = determineCommonAlignment(sourceOffset, destOffset, actualSize);
UDATA sourceIndex = (sourceOffset - headerSize) >> logElementSize;
UDATA destIndex = (destOffset - headerSize) >> logElementSize;
Expand All @@ -595,7 +596,7 @@ static VMINLINE void
copyMemoryByte(J9VMThread* currentThread, j9object_t sourceObject, UDATA sourceOffset, j9object_t destObject,
UDATA destOffset)
{
UDATA const headerSize = J9VMTHREAD_CONTIGUOUS_INDEXABLE_HEADER_SIZE(currentThread);
UDATA const headerSize = VM_UnsafeAPI::arrayBase(currentThread);
UDATA sourceIndex = sourceOffset - headerSize;
UDATA destIndex = destOffset - headerSize;

Expand Down Expand Up @@ -695,7 +696,7 @@ Java_sun_misc_Unsafe_setMemory__Ljava_lang_Object_2JJB(JNIEnv *env, jobject rece
if (!J9ROMCLASS_IS_PRIMITIVE_TYPE(((J9ArrayClass*)clazz)->componentType->romClass)) {
goto illegal;
}
offset -= J9VMTHREAD_CONTIGUOUS_INDEXABLE_HEADER_SIZE(currentThread);
offset -= VM_UnsafeAPI::arrayBase(currentThread);
VM_ArrayCopyHelpers::primitiveArrayFill(currentThread, object, (UDATA)offset, actualSize, (U_8)value);
}
vmFuncs->internalExitVMToJNI(currentThread);
Expand Down
16 changes: 8 additions & 8 deletions runtime/oti/UnsafeAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "j9.h"
#include "ArrayCopyHelpers.hpp"
#include "ObjectAccessBarrierAPI.hpp"
#include "ut_j9vm.h"
#include "VMHelpers.hpp"
#include "AtomicSupport.hpp"

Expand Down Expand Up @@ -90,10 +89,6 @@ class VM_UnsafeAPI
*/
private:

static VMINLINE UDATA arrayBase(J9VMThread *currentThread) {
return J9VMTHREAD_CONTIGUOUS_INDEXABLE_HEADER_SIZE(currentThread);
}

static VMINLINE UDATA logFJ9ObjectSize(J9VMThread *currentThread) {
return (4 == J9VMTHREAD_REFERENCE_SIZE(currentThread)) ? 2 : 3;
}
Expand Down Expand Up @@ -335,6 +330,9 @@ class VM_UnsafeAPI
protected:

public:
static VMINLINE UDATA arrayBase(J9VMThread *currentThread) {
return J9VMTHREAD_UNSAFE_INDEXABLE_HEADER_SIZE(currentThread);
}

static VMINLINE void loadFence()
{
Expand Down Expand Up @@ -526,7 +524,7 @@ class VM_UnsafeAPI
compareAndSwapObject(J9VMThread *currentThread, MM_ObjectAccessBarrierAPI *objectAccessBarrier, j9object_t object, UDATA offset, j9object_t *compareValue, j9object_t *swapValue)
{
bool result = false;

if (VM_VMHelpers::objectIsArray(currentThread, object)) {
UDATA index = convertOffsetToIndex(currentThread, offset, logFJ9ObjectSize(currentThread));
result = objectAccessBarrier->inlineIndexableObjectCompareAndSwapObject(currentThread, object, index, *compareValue, *swapValue, true);
Expand All @@ -550,7 +548,7 @@ class VM_UnsafeAPI
{
UDATA logElementSize = 3;
bool result = false;

if (NULL == object) {
result = (compareValue == VM_AtomicSupport::lockCompareExchangeU64((U_64*)offset, compareValue, swapValue));
} else {
Expand Down Expand Up @@ -606,7 +604,9 @@ class VM_UnsafeAPI
static VMINLINE j9object_t
compareAndExchangeObject(J9VMThread *currentThread, MM_ObjectAccessBarrierAPI *objectAccessBarrier, j9object_t object, UDATA offset, j9object_t *compareValue, j9object_t *swapValue)
{
Assert_VM_notNull(object);
if (J9_UNEXPECTED(NULL != object)) {
currentThread->javaVM->internalVMFunctions->triggerAssertion(currentThread, "object is null");
}

j9object_t result = NULL;

Expand Down
4 changes: 4 additions & 0 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -5183,6 +5183,7 @@ typedef struct J9InternalVMFunctions {
#if defined(J9VM_ZOS_3164_INTEROPERABILITY) && (JAVA_SPEC_VERSION >= 17)
I_32 (*invoke31BitJNI_OnXLoad)(struct J9JavaVM *vm, void *handle, jboolean isOnLoad, void *reserved);
#endif /* defined(J9VM_ZOS_3164_INTEROPERABILITY) && (JAVA_SPEC_VERSION >= 17) */
void (*triggerAssertion)(struct J9VMThread *currentThread, const char* message);
} J9InternalVMFunctions;

/* Jazz 99339: define a new structure to replace JavaVM so as to pass J9NativeLibrary to JVMTIEnv */
Expand Down Expand Up @@ -5427,6 +5428,7 @@ typedef struct J9VMThread {
void* gcExtensions;
UDATA contiguousIndexableHeaderSize;
UDATA discontiguousIndexableHeaderSize;
UDATA unsafeIndexableHeaderSize;
#if defined(J9VM_ENV_DATA64)
UDATA isIndexableDataAddrPresent;
#endif /* defined(J9VM_ENV_DATA64) */
Expand Down Expand Up @@ -5604,6 +5606,7 @@ typedef struct J9VMThread {
#define J9VMTHREAD_OBJECT_HEADER_SIZE(vmThread) (J9VMTHREAD_COMPRESS_OBJECT_REFERENCES(vmThread) ? sizeof(J9ObjectCompressed) : sizeof(J9ObjectFull))
#define J9VMTHREAD_CONTIGUOUS_INDEXABLE_HEADER_SIZE(vmThread) ((vmThread)->contiguousIndexableHeaderSize)
#define J9VMTHREAD_DISCONTIGUOUS_INDEXABLE_HEADER_SIZE(vmThread) ((vmThread)->discontiguousIndexableHeaderSize)
#define J9VMTHREAD_UNSAFE_INDEXABLE_HEADER_SIZE(vmThread) ((vmThread)->unsafeIndexableHeaderSize)

typedef struct JFRState {
char *jfrFileName;
Expand Down Expand Up @@ -5973,6 +5976,7 @@ typedef struct J9JavaVM {
UDATA arrayletLeafLogSize;
UDATA contiguousIndexableHeaderSize;
UDATA discontiguousIndexableHeaderSize;
UDATA unsafeIndexableHeaderSize;
#if defined(J9VM_ENV_DATA64)
UDATA isIndexableDataAddrPresent;
BOOLEAN isIndexableDualHeaderShapeEnabled;
Expand Down
11 changes: 11 additions & 0 deletions runtime/oti/vm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,17 @@ void
setCRIUSingleThreadModeJVMCRIUException(J9VMThread *vmThread, U_32 moduleName, U_32 messageNumber);
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

/**
* Triggers a VM assertion
*
* @param currentThread vmthread token
* @param message the assertion message
*
* @return void
*/
void
triggerAssertion(J9VMThread *currentThread, const char* message);

/* ---------------- extendedMessageNPE.cpp ---------------- */

/**
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4249,7 +4249,7 @@ class INTERPRETER_CLASS

if (J9CLASS_IS_ARRAY(receiverClass)) {
I_64 arrayDataSize = J9INDEXABLEOBJECT_SIZE(_currentThread, receiver) * J9ARRAYCLASS_GET_STRIDE(receiverClass);
I_64 headerSize = J9VMTHREAD_CONTIGUOUS_INDEXABLE_HEADER_SIZE(_currentThread);
I_64 headerSize = J9VMTHREAD_UNSAFE_INDEXABLE_HEADER_SIZE(_currentThread);
returnDoubleFromINL(REGISTER_ARGS, arrayDataSize + headerSize, 2);
} else {
I_64 headerSize = (I_64)J9VMTHREAD_OBJECT_HEADER_SIZE(_currentThread);
Expand Down
Loading

0 comments on commit 24513b0

Please sign in to comment.