View previous topic :: View next topic |
Author |
Message |
keinfarbton
Joined: 03 Dec 2005 Posts: 224 Location: Stuttgart - Germany
|
Posted: Sat Feb 17, 2007 2:19 pm Post subject: Emulating JNI |
|
|
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 |
|
|
keinfarbton
Joined: 03 Dec 2005 Posts: 224 Location: Stuttgart - Germany
|
Posted: Mon Feb 19, 2007 1:08 pm Post subject: |
|
|
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 |
|
|
keinfarbton
Joined: 03 Dec 2005 Posts: 224 Location: Stuttgart - Germany
|
Posted: Wed Feb 21, 2007 6:44 pm Post subject: |
|
|
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 |
|
|
keinfarbton
Joined: 03 Dec 2005 Posts: 224 Location: Stuttgart - Germany
|
Posted: Fri Mar 02, 2007 8:16 pm Post subject: |
|
|
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 |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Sat Mar 03, 2007 6:19 pm Post subject: |
|
|
Great work, Frank!
Are there any people working on the win32 version yet? |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Sat Mar 03, 2007 6:27 pm Post subject: |
|
|
Yeah, that's a freakin' awesome effort behind all that. Good one! |
|
Back to top |
|
|
|