-
Notifications
You must be signed in to change notification settings - Fork 778
Add implementation for JVM_CopyOfSpecialArray #23007
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,8 +32,52 @@ extern "C" { | |
| JNIEXPORT jarray JNICALL | ||
| JVM_CopyOfSpecialArray(JNIEnv *env, jarray orig, jint from, jint to) | ||
| { | ||
| assert(!"JVM_CopyOfSpecialArray unimplemented"); | ||
| 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); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add parenthesis around each statement. |
||
| vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGARRAYINDEXOUTOFBOUNDSEXCEPTION, NULL); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the ri throw ArrayIndexOutOfBoundsException for
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It throws |
||
| 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 | ||
|
|
||
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that the
copyFlattenableArraymethod 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.