@@ -32,8 +32,52 @@ extern "C" {
3232JNIEXPORT jarray JNICALL
3333JVM_CopyOfSpecialArray (JNIEnv *env, jarray orig, jint from, jint to)
3434{
35- assert (!" JVM_CopyOfSpecialArray unimplemented" );
36- return NULL ;
35+ j9object_t origObj = NULL ;
36+ j9object_t newArrayObj = NULL ;
37+ J9Class *origClass = NULL ;
38+ J9Class *componentClass = NULL ;
39+ UDATA origLength = 0 ;
40+ jint len = 0 ;
41+ jarray out = NULL ;
42+ J9VMThread *currentThread = (J9VMThread *)env;
43+ J9InternalVMFunctions *vmFuncs = currentThread->javaVM ->internalVMFunctions ;
44+ vmFuncs->internalEnterVMFromJNI (currentThread);
45+
46+ if (NULL == orig) {
47+ vmFuncs->setCurrentException (currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL );
48+ goto done;
49+ }
50+ origObj = J9_JNI_UNWRAP_REFERENCE (orig);
51+ origClass = J9OBJECT_CLAZZ (currentThread, origObj);
52+ origLength = J9INDEXABLEOBJECT_SIZE (currentThread, origObj);
53+ if (from < 0 || to > (jint)origLength || from > to) {
54+ vmFuncs->setCurrentException (currentThread, J9VMCONSTANTPOOL_JAVALANGARRAYINDEXOUTOFBOUNDSEXCEPTION, NULL );
55+ goto done;
56+ }
57+ if (from >= to) {
58+ vmFuncs->setCurrentException (currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, NULL );
59+ goto done;
60+ }
61+
62+ len = to - from;
63+ newArrayObj = currentThread->javaVM ->memoryManagerFunctions ->J9AllocateIndexableObject (currentThread, origClass, len, J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
64+ if (!newArrayObj) {
65+ vmFuncs->setHeapOutOfMemoryError (currentThread);
66+ goto done;
67+ }
68+
69+ for (jint i = 0 ; i < len; i++) {
70+ j9object_t value = vmFuncs->loadFlattenableArrayElement (currentThread, origObj, from + i, false );
71+ if (NULL == value) {
72+ continue ;
73+ }
74+ vmFuncs->storeFlattenableArrayElement (currentThread, newArrayObj, i, value);
75+ }
76+
77+ out = (jarray)vmFuncs->j9jni_createLocalRef (env, newArrayObj);
78+ done:
79+ vmFuncs->internalExitVMToJNI (currentThread);
80+ return out;
3781}
3882
3983JNIEXPORT jboolean JNICALL
0 commit comments