hotspot/src/jdk.aot/unix/native/libjelfshim/jdk_tools_jaotc_jnilibelf_JNILibELFAPI.c
changeset 44086 9a5b97523f70
parent 42650 1f304d0c888b
equal deleted inserted replaced
44085:68b17649266b 44086:9a5b97523f70
    68 /**
    68 /**
    69  * Unbox the Pointer object the encapsulated native address.
    69  * Unbox the Pointer object the encapsulated native address.
    70  */
    70  */
    71 
    71 
    72 static jlong getNativeAddress(JNIEnv* env, jobject ptrObj) {
    72 static jlong getNativeAddress(JNIEnv* env, jobject ptrObj) {
    73    jclass ptrClass;
       
    74    jfieldID fidNumber;
       
    75    jlong nativeAddress = -1;
    73    jlong nativeAddress = -1;
    76     assert (ptrObj != NULL);
    74    assert (ptrObj != NULL);
    77    // Get a reference to ptr object's class
    75    // Get a reference to ptr object's class
    78    ptrClass = (*env)->GetObjectClass(env, ptrObj);
    76    jclass ptrClass = (*env)->GetObjectClass(env, ptrObj);
    79 
    77    if (ptrClass != NULL) {
    80    // Get the Field ID of the instance variables "address"
    78        // Get the Field ID of the instance variables "address"
    81    fidNumber = (*env)->GetFieldID(env, ptrClass, "address", "J");
    79        jfieldID fidNumber = (*env)->GetFieldID(env, ptrClass, "address", "J");
    82    if (fidNumber != NULL) {
    80        if (fidNumber != NULL) {
    83        // Get the long given the Field ID
    81            // Get the long given the Field ID
    84        nativeAddress = (*env)->GetLongField(env, ptrObj, fidNumber);
    82            nativeAddress = (*env)->GetLongField(env, ptrObj, fidNumber);
       
    83        }
    85    }
    84    }
    86    // fprintf(stderr, "Native address : %lx\n", nativeAddress);
    85    // fprintf(stderr, "Native address : %lx\n", nativeAddress);
    87    return nativeAddress;
    86    return nativeAddress;
    88 }
    87 }
    89 
    88 
    90 /**
    89 /**
    91  * Box the nativeAddress as a Pointer object.
    90  * Box the nativeAddress as a Pointer object.
    92  */
    91  */
    93 static jobject makePointerObject(JNIEnv* env, jlong nativeAddr) {
    92 static jobject makePointerObject(JNIEnv* env, jlong nativeAddr) {
       
    93    jobject retObj = NULL;
    94    jclass ptrClass = (*env)->FindClass(env, "jdk/tools/jaotc/jnilibelf/Pointer");
    94    jclass ptrClass = (*env)->FindClass(env, "jdk/tools/jaotc/jnilibelf/Pointer");
    95    // Call back constructor to allocate a Pointer object, with an int argument
    95    if (ptrClass != NULL) {
    96    jmethodID constructorId = (*env)->GetMethodID(env, ptrClass, "<init>", "(J)V");
    96        // Call back constructor to allocate a Pointer object, with an int argument
    97    jobject retObj = (*env)->NewObject(env, ptrClass, constructorId, nativeAddr);
    97        jmethodID constructorId = (*env)->GetMethodID(env, ptrClass, "<init>", "(J)V");
       
    98        if (constructorId != NULL) {
       
    99            retObj = (*env)->NewObject(env, ptrClass, constructorId, nativeAddr);
       
   100        }
       
   101    }
    98    return retObj;
   102    return retObj;
    99 }
   103 }
   100 
   104 
   101 JNIEXPORT jobject JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1begin
   105 JNIEXPORT jobject JNICALL Java_jdk_tools_jaotc_jnilibelf_JNILibELFAPI_elf_1begin
   102 (JNIEnv* env, jclass UNUSED(class), jint filedes, jint cmd, jobject ptrObj) {
   106 (JNIEnv* env, jclass UNUSED(class), jint filedes, jint cmd, jobject ptrObj) {