Skip to content

Commit

Permalink
Merge pull request #20450 from keithc-ca/length_as_long
Browse files Browse the repository at this point in the history
Add GetStringUTFLengthAsLong for Java 24+
  • Loading branch information
pshipton authored Nov 1, 2024
2 parents 732aefd + ba6c33d commit 6e11a68
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 219 deletions.
2 changes: 2 additions & 0 deletions runtime/include/jni.h.m4
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ struct JNINativeInterface_ {
jobjectRefType (JNICALL * GetObjectRefType)(JNIEnv* env, jobject obj);
ifelse(eval(JAVA_SPEC_VERSION >= 9), 1, ` jobject (JNICALL * GetModule)(JNIEnv *env, jclass clazz);', `dnl')
ifelse(eval(JAVA_SPEC_VERSION >= 19), 1, ` jboolean (JNICALL * IsVirtualThread)(JNIEnv *env, jobject obj);', `dnl')
ifelse(eval(JAVA_SPEC_VERSION >= 24), 1, ` jlong (JNICALL *GetStringUTFLengthAsLong)(JNIEnv *env, jstring string);', `dnl')
};

struct JNIEnv_ {
Expand Down Expand Up @@ -700,6 +701,7 @@ struct JNIEnv_ {
jobjectRefType GetObjectRefType(jobject obj) { return functions->GetObjectRefType(this, obj); }
ifelse(eval(JAVA_SPEC_VERSION >= 9), 1, ` jobject GetModule(jclass clazz) { return functions->GetModule(this, clazz); }', `dnl')
ifelse(eval(JAVA_SPEC_VERSION >= 19), 1, ` jboolean IsVirtualThread(JNIEnv *env, jobject obj) { return functions->IsVirtualThread(this, obj); }', `dnl')
ifelse(eval(JAVA_SPEC_VERSION >= 24), 1, ` jlong GetStringUTFLengthAsLong(JNIEnv *env, jstring string) { return functions->GetStringUTFLengthAsLong(this, string); }', `dnl')
#endif
};

Expand Down
4 changes: 4 additions & 0 deletions runtime/j9vm31/exports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,7 @@ endif()
if(NOT JAVA_SPEC_VERSION LESS 19)
omr_add_exports(jvm31 IsVirtualThread)
endif()

if(NOT JAVA_SPEC_VERSION LESS 24)
omr_add_exports(jvm31 GetStringUTFLengthAsLong)
endif()
3 changes: 3 additions & 0 deletions runtime/j9vm31/j9vm31.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ jobject JNICALL GetModule(JNIEnv *env, jclass clazz);
#if JAVA_SPEC_VERSION >= 19
jboolean JNICALL IsVirtualThread(JNIEnv *env, jobject obj);
#endif /* JAVA_SPEC_VERSION >= 19 */
#if JAVA_SPEC_VERSION >= 24
jlong JNICALL GetStringUTFLengthAsLong(JNIEnv *env, jstring string);
#endif /* JAVA_SPEC_VERSION >= 24 */

/* The JNI convert functions that the shim library will implement. */
jint JNICALL GetStringPlatform(JNIEnv* env, jstring instr, char* outstr, jint outlen, const char* encoding);
Expand Down
3 changes: 3 additions & 0 deletions runtime/j9vm31/jnicsup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ struct JNINativeInterface_ EsJNIFunctions = {
#if JAVA_SPEC_VERSION >= 19
IsVirtualThread,
#endif /* JAVA_SPEC_VERSION >= 19 */
#if JAVA_SPEC_VERSION >= 24
GetStringUTFLengthAsLong,
#endif /* JAVA_SPEC_VERSION >= 24 */
};

static void initializeJNIEnv31(JNIEnv31 * jniEnv31, jlong jniEnv64);
Expand Down
16 changes: 15 additions & 1 deletion runtime/j9vm31/jnimisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,26 @@ GetStringUTFLength(JNIEnv *env, jstring string)
const jint NUM_ARGS = 2;
J9_CEL4RO64_ArgType argTypes[NUM_ARGS] = { CEL4RO64_type_JNIEnv64, CEL4RO64_type_jstring };
uint64_t argValues[NUM_ARGS] = { JNIENV64_FROM_JNIENV31(env), string };
jsize returnValue = NULL;
jsize returnValue = 0;
FUNCTION_DESCRIPTOR_FROM_JNIENV31(env, GetStringUTFLength);
j9_cel4ro64_call_function(functionDescriptor, argTypes, argValues, NUM_ARGS, CEL4RO64_type_jsize, &returnValue);
return returnValue;
}

#if JAVA_SPEC_VERSION >= 24
jlong JNICALL
GetStringUTFLengthAsLong(JNIEnv *env, jstring string)
{
const jint NUM_ARGS = 2;
J9_CEL4RO64_ArgType argTypes[NUM_ARGS] = { CEL4RO64_type_JNIEnv64, CEL4RO64_type_jstring };
uint64_t argValues[NUM_ARGS] = { JNIENV64_FROM_JNIENV31(env), string };
jlong returnValue = 0;
FUNCTION_DESCRIPTOR_FROM_JNIENV31(env, GetStringUTFLengthAsLong);
j9_cel4ro64_call_function(functionDescriptor, argTypes, argValues, NUM_ARGS, CEL4RO64_type_jlong, &returnValue);
return returnValue;
}
#endif /* JAVA_SPEC_VERSION >= 24 */

const char* JNICALL
GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
{
Expand Down
Loading

0 comments on commit 6e11a68

Please sign in to comment.