Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions runtime/j9vm/valhallavmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,52 @@ extern "C" {
JNIEXPORT jarray JNICALL
JVM_CopyOfSpecialArray(JNIEnv *env, jarray orig, jint from, jint to)
{
assert(!"JVM_CopyOfSpecialArray unimplemented");
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed there is a copyFlattenableArray method in ValueTypeHelpers.hpp. Can this method be reused here?

Copy link
Author

@AditiS11 AditiS11 Dec 5, 2025

Choose a reason for hiding this comment

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

I feel that the copyFlattenableArray method can’t be used here because it requires a special Valhalla stack frame to be built before the call. I’m not sure how the frame could be constructed from here.

return NULL;
j9object_t origObj = NULL;
j9object_t newArrayObj = NULL;
J9Class *origClass = NULL;
J9Class *componentClass = NULL;
UDATA origLength = 0;
jint len = 0;
jarray out = NULL;
J9VMThread *currentThread = (J9VMThread *)env;
J9InternalVMFunctions *vmFuncs = currentThread->javaVM->internalVMFunctions;
vmFuncs->internalEnterVMFromJNI(currentThread);

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the extra space.

if (NULL == orig) {
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL);
goto done;
}
origObj = J9_JNI_UNWRAP_REFERENCE(orig);
origClass = J9OBJECT_CLAZZ(currentThread, origObj);
origLength = J9INDEXABLEOBJECT_SIZE(currentThread, origObj);
if (from < 0 || to > (jint)origLength || from > to) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add parenthesis around each statement.

vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGARRAYINDEXOUTOFBOUNDSEXCEPTION, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the ri throw ArrayIndexOutOfBoundsException for from > to as well?

Copy link
Author

Choose a reason for hiding this comment

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

It throws IllegalArgumentException if from >= to. Will change it.

goto done;
}
if (from >= to) {
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, NULL);
goto done;
}

len = to - from;
newArrayObj = currentThread->javaVM->memoryManagerFunctions->J9AllocateIndexableObject(currentThread, origClass, len, J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
if (!newArrayObj) {
vmFuncs->setHeapOutOfMemoryError(currentThread);
goto done;
}

for (jint i = 0; i < len; i++) {
j9object_t value = vmFuncs->loadFlattenableArrayElement(currentThread, origObj, from + i, false);
if (NULL == value) {
continue;
}
vmFuncs->storeFlattenableArrayElement(currentThread, newArrayObj, i, value);
}

out = (jarray)vmFuncs->j9jni_createLocalRef(env, newArrayObj);
done:
vmFuncs->internalExitVMToJNI(currentThread);
return out;
}

JNIEXPORT jboolean JNICALL
Expand Down