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

Yuriy Taraday yorik.sar at gmail.com
Thu Apr 23 15:38:51 CEST 2009


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 at cs.unipr.it>wrote:

> 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.
>



More information about the PPL-devel mailing list