jvmci return array

Tom Rodriguez tom.rodriguez at oracle.com
Tue Jan 18 21:15:59 UTC 2022



> On Jan 18, 2022, at 11:18 AM, Vladimir Kozlov <vladimir.kozlov at oracle.com> wrote:
> 
> CCing to Doug, JVMCI expert.
> 
> Thanks,
> Vladimir K
> 
> On 1/18/22 9:55 AM, Fotios Kounelis wrote:
>> Hello,
>> I am trying to create a new native function inside jvmciRuntime.cpp. I want this function to return an integer array. While I have found on JNI a similar example with jintArray and SetIntArrayRegion() function, in the jvmci, the API is different.
>> I was able to return an integer and read it in the GraalVM compiler but I am struggling with an array. Would the program for jvmci be similar to the JNI? If yes, which is the equivalent of SetIntArrayRegion() for this API, assuming I have the code below?
>> jintArray result;
>> JRT_BLOCK_ENTRY(jintArray , JVMCIRuntime::object_hash_get(JavaThread * thread, jint * ar1))
>>   JRT_BLOCK;
>>     jintArray result;
>>     result = oopFactory::new_intArray(valueArraySize, CHECK_0);
>>     int* valueArray; //this is the array that contains the data to fill result
>>     // fill result with values in the thread
>>     return result;
>>     JRT_BLOCK_END;
>> JRT_END
>> Otherwise, could you give me an example of how to return an int array?

I’m not quite clear what you’re trying to do here but you’re mixing JNI concepts with HotSpot internals.  jintArray is a JNI return type but new_intArray returns a typeArrayOop which is the hotspot internal representation of a primitive array.  To fill the values into the result you’ll need to use the int_at_put methods with manually computed offsets or you could possibly copy the logic from the Set*ArrayRegion macros implemented in jni.cpp.  Also to return an oop from a function like this you need to pass it out using JavaThread::set_vm_result which requires proper unpacking logic by a stub caller.  The real return type would then be void.  Look for other uses of set_vm_result in that file for examples.

tom

>> Best regards,
>> Fotis



More information about the hotspot-dev mailing list