I have the following JNI/JVMTI code:
jfieldID field = ...;
jobject fieldValue = (*jni_env)->GetObjectField(jni_env, jObjectInstance, field);
jclass fieldClass = (*jni_env)->GetObjectClass(jni_env, fieldValue);
char* signature_ptr;
char* generic_ptr;
(*jvmti_env)->GetClassSignature(jvmti_env, fieldClass, &signature_ptr, &generic_ptr);
This code works as long field is a reference type (java.lang.Object and subtypes). If field is a primitive type, it will crash the JVM when it tries to execute GetObjectClass.
My question is: How can I use field and fieldValue to figure out if it is a primitive type and if it's a primitive type, which one (int, long, boolean etc.)?
I am new to JNI/JVMTI so if the answer is obvious, please bear with me.
Thanks!