|
JNIPort for Dolphin Smalltalk |
|
Back to Goodies |
The JNIHelper DLLJNIHelper is a C DLL, plus the Smalltalk code to use it. It exists only because of the mismatch between the Dolphin and JVM models of threads. The JVM has three callback “hooks”; these are callback functions that JNI clients can replace with their own functions. The hook functions are called:
Dolphin's external interfacing is (with some extensions to handle The JNIHelper library provides a way around this. It provides replacements for the JNI hooks that can be called from any thread. The way it works is (slightly simplified) that when the replacement hook function is called, it stores the data provided with the call on an internal queue, and then returns immediately to the caller. A separate thread waits for data to appear on the queue, and when it does, it calls back into Dolphin to allow JNIPort to consume the data. Since the caller never waits for Dolphin, this should avoid the risk of deadlock. An additional feature of JNI Helper is to allow the JVM's debugging stream to be redirected to the Window's system debug stream, where it can be viewed with a tool like DebugView from http://www.sysinternals.com/. This should completely eliminate any possibility of the debugging output causing deadlocks. It is possible to use JNIPort without the JNIHelper. You can either just not use the hooks at all (set from the configuration) which will side-step the problem entirely, or you can accept a risk of deadlock. Unless you are using more than one Java thread then you will probably get away with it. (But note that some Java features use threads even if you haven't explicitly started any — AWT/Swing for one.) The DolphinJNIHelper DLL, and the C source and a VC++ project file, are in the Extras\ folder which is part of the JNIPort download. Put the DLL somewhere where Dolphin can find it. Please note: I recommend that you rebuild the DLL from source if you can, or, at minimum, run it through a reputable, and up to date, virus checker. |
Copyright © Chris Uppal, 2003-2005
Java, JNI (probably), JVM (possibly), and God knows what else, are trademarks of Sun Microsystems, Inc.