FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Emulating JNI

 
Post new topic   Reply to topic     Forum Index -> Tioport
View previous topic :: View next topic  
Author Message
keinfarbton



Joined: 03 Dec 2005
Posts: 224
Location: Stuttgart - Germany

PostPosted: Sat Feb 17, 2007 2:19 pm    Post subject: Emulating JNI Reply with quote

TioPort does convertion of java code. JNI implementation (C) need to be ported manually. In the case of SWT this is a lot of code. A better way would be to able to simply compile the C file and have a mechanism to emulate the JNI interface to combine the converted code with the C code.

Suggestions, how a implementation can work?
Back to top
View user's profile Send private message
keinfarbton



Joined: 03 Dec 2005
Posts: 224
Location: Stuttgart - Germany

PostPosted: Mon Feb 19, 2007 1:08 pm    Post subject: Reply with quote

I think i found a way and i actually testing it. see branches/jni. This will probably bring tioported app closer to the enable-reflection target.
Back to top
View user's profile Send private message
keinfarbton



Joined: 03 Dec 2005
Posts: 224
Location: Stuttgart - Germany

PostPosted: Wed Feb 21, 2007 6:44 pm    Post subject: Reply with quote

A problem occured, I hope someone can give me a tip.
A function or method with a signature known at runtime shall be called.

What I need is the part of the implementation, that pushes the arguments on the stack, calls the method and gets the return value.
Is asm needed? Or perhaps it can be done in D. I don't know.

Code:
//...
jint CallIntMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...);
jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);

jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...);
jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);
 
// ...
// more methods with the other return types


* env is the ptr to my jni implementation
* obj is a void* ptr to the object
* methodId is the function ptr to the method

I am able to retrieve the methods signature with obj and methodId.
In this case the return type is know by the prototype.

Any hint for a implementation?
Back to top
View user's profile Send private message
keinfarbton



Joined: 03 Dec 2005
Posts: 224
Location: Stuttgart - Germany

PostPosted: Fri Mar 02, 2007 8:16 pm    Post subject: Reply with quote

With restriction... It works now.
Here is a screenshot of the running paint example.
http://www.dsource.org/projects/tioport/browser/trunk/doc/paint.png?format=raw
With using the emulated JNI, the text tool bug is also gone.
Now the convertion is free of all manual edits and the c-libs do link without the need for recompiling them.

The problem above (CallIntMethod) still exists. I have not found a generic way to make these calls. In case of SWT i know the few kind of signatures it uses, so i did a manual implementation for each used signature.
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Sat Mar 03, 2007 6:19 pm    Post subject: Reply with quote

Great work, Frank!

Are there any people working on the win32 version yet?
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Sat Mar 03, 2007 6:27 pm    Post subject: Reply with quote

Yeah, that's a freakin' awesome effort behind all that. Good one!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Tioport All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group