Re: [PPL-devel] [Fwd: Re: Some troubles I met while building PPL.]

Yuriy Taraday wrote:
Oh, we didn't mention this function before. I'm curious why "const jobject&"? jobject - just a pointer and constant referencing to a pointer looks pointless.
[...]
//! Returns a pointer to the C++ object wrapped by \p ppl_object. void* get_ptr(JNIEnv* env, const jobject& ppl_object);
I guess that, since we are not JNI experts, we just tried to take a safer approach whereby the `jobject' datatype is treated as a black box.
Usually, when we need to pass a "black box" datatype as an argument, we pass it by reference; since we do not need to modify it in this function, we also qualify it using const.
I just realized that we haven't been fully systematic in this respect, since we also have the helper function
//! Returns \c true if and only if \p obj is a null Java reference. jboolean is_null(JNIEnv* env, jobject obj);
which is passing its jobject argument by copy.
Cheers, Enea Zaffanella.

The JNI API guarantees that jobject is just a simple reference (weak or strong) to an object, without any overhead, all garbage collector stuff (reference counting etc.) must be performed explicitly with a corresponding calls. So jobject isn't larger than a pointer and it's safe to pass it by value.
On Thu, Apr 23, 2009 at 2:33 PM, Enea Zaffanella zaffanella@cs.unipr.itwrote:
Yuriy Taraday wrote:
Oh, we didn't mention this function before. I'm curious why "const jobject&"? jobject - just a pointer and constant referencing to a pointer looks pointless.
[...]
//! Returns a pointer to the C++ object wrapped by \p ppl_object.
void* get_ptr(JNIEnv* env, const jobject& ppl_object);
I guess that, since we are not JNI experts, we just tried to take a safer approach whereby the `jobject' datatype is treated as a black box.
Usually, when we need to pass a "black box" datatype as an argument, we pass it by reference; since we do not need to modify it in this function, we also qualify it using const.
I just realized that we haven't been fully systematic in this respect, since we also have the helper function
//! Returns \c true if and only if \p obj is a null Java reference. jboolean is_null(JNIEnv* env, jobject obj);
which is passing its jobject argument by copy.
Cheers, Enea Zaffanella.

Yuriy Taraday wrote:
The JNI API guarantees that jobject is just a simple reference (weak or strong) to an object, without any overhead, all garbage collector stuff (reference counting etc.) must be performed explicitly with a corresponding calls. So jobject isn't larger than a pointer and it's safe to pass it by value.
Fine.
We are currently doing a whole pass through the Java interface glue code: this change will be included among others. I will notify you when we are ready, so that you will be able to give it a try.
Cheers, Enea Zaffanella.

Enea Zaffanella wrote:
Yuriy Taraday wrote:
The JNI API guarantees that jobject is just a simple reference (weak or strong) to an object, without any overhead, all garbage collector stuff (reference counting etc.) must be performed explicitly with a corresponding calls. So jobject isn't larger than a pointer and it's safe to pass it by value.
Fine.
We are currently doing a whole pass through the Java interface glue code: this change will be included among others. I will notify you when we are ready, so that you will be able to give it a try.
ops ... I was almost forgetting about this notification.
We completed the pass on the Java interface. Notice that, differently from ppl-0.10.2, in the current git master branch the library has to be explicitly initialized (after loading it) by calling static method
Parma_Polyhedra_Library.initialize_library()
This function, besides appropriately setting the floating point rounding mode, will also load JNI class/field/method ID caches. As reported in the NEWS file, the Java interface now supports basic timeout facilities.
Please report to ppl-devel any residual issue you may notice.
Cheers, Enea Zaffanella.
participants (2)
-
Enea Zaffanella
-
Yuriy Taraday