[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [RFC] JavaHL: Moving some of the C++ object address logic into Java

From: Vladimir Berezniker <vmpn_at_hitechman.com>
Date: Tue, 26 Jun 2012 21:12:16 -0400

On Tue, Jun 26, 2012 at 3:18 PM, Hyrum K Wright
<hyrum.wright_at_wandisco.com> wrote:
> On Sun, Jun 24, 2012 at 9:20 PM, Vladimir Berezniker <vmpn_at_hitechman.com> wrote:
>> Hi All,
>>
>> In the current JavaHL code the C++ objects are attached via pointer stored in
>> the long cppAddr field in java object.  The way C++ code gets hold of the
>> cppAddr value is to read this field using the GetLongField(). In summary
>>
>> Java:
>>
>> class JHLClass
>> {
>>  long cppAddr;
>>  public native method();
>> }
>>
>>
>> JNI Stub:
>>
>> Java_method(JNIEnv *env, jobject jthis)
>> {
>>  JHLClass cppObj = JHLClass::getCppObject(jthis);
>> }
>>
>> C++:
>>
>> class JHLClass
>> {
>>  JHLClass getCppObject(jobject jthis) { .... }
>> }
>>
>>
>> I was thinking why not simplify this by doing all object->jlong lookup in the
>> java land. What takes about 20 lines of C++ takes 1 line in java, at a cost of
>> implementing 3 line java wrapper method that converts from caller visible
>> method signature to native method signature. As follows:
>>
>> class JHLClass
>> {
>>  long cppAddr;
>>
>>  private native static method(long cppAddr);
>>  method() {
>>    method(cppAddr);
>>  }
>> }
>>
>> JNI Stub:
>>
>> Java_method(JNIEnv *env, jlong cppAdder)
>> {
>>  JHLClass cppObj = reinterpret_cast<SVNFile *>(fileCppAddr);
>> }
>>
>> C++: No additional code necessary
>>
>> This will require a related change in JNIStackElement, as it won't have jthis
>> anymore. But this logic also can move up to java code in a similar manner.
>>
>> What do others think? Any objections at least of doing this in RA functions?
>
> While I can't comment on the specific implications of your plan,
> generally the more we can write in Java in the JavaHL bindings, the
> better.  Hopefully that nugget of wisdom gives you some insight. :)
>
That answers it. I will put a patch together to illustrate the above
on real code.

Thank you,

Vladimir
Received on 2012-06-27 03:12:51 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.